diff options
Diffstat (limited to 'src/ats/gnunet-service-ats_addresses_mlp.c')
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.c | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c index 734d07a13..946a2848d 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.c +++ b/src/ats/gnunet-service-ats_addresses_mlp.c | |||
@@ -39,6 +39,85 @@ static struct GAS_MLP_Handle *GAS_mlp; | |||
39 | 39 | ||
40 | 40 | ||
41 | /** | 41 | /** |
42 | * Solves the MLP problem | ||
43 | * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure | ||
44 | */ | ||
45 | int | ||
46 | mlp_solve_lp_problem (struct GAS_MLP_Handle *mlp) | ||
47 | { | ||
48 | int res; | ||
49 | |||
50 | /* LP presolver? | ||
51 | * Presolver is required if the problem was modified and an existing | ||
52 | * valid basis is now invalid */ | ||
53 | if (mlp->presolver_required == GNUNET_YES) | ||
54 | mlp->control_param_lp.presolve = GLP_ON; | ||
55 | else | ||
56 | mlp->control_param_lp.presolve = GLP_OFF; | ||
57 | |||
58 | |||
59 | /* Solve LP problem to have initial valid solution */ | ||
60 | lp_solv: | ||
61 | res = glp_simplex(mlp->prob, &mlp->control_param_lp); | ||
62 | if (res == 0) | ||
63 | { | ||
64 | /* The LP problem instance has been successfully solved. */ | ||
65 | } | ||
66 | else if (res == GLP_EITLIM) | ||
67 | { | ||
68 | /* simplex iteration limit has been exceeded. */ | ||
69 | // TODO Increase iteration limit? | ||
70 | } | ||
71 | else if (res == GLP_ETMLIM) | ||
72 | { | ||
73 | /* Time limit has been exceeded. */ | ||
74 | // TODO Increase time limit? | ||
75 | } | ||
76 | else | ||
77 | { | ||
78 | /* Problem was ill-defined, retry with presolver */ | ||
79 | if (mlp->presolver_required == GNUNET_NO) | ||
80 | { | ||
81 | mlp->presolver_required = GNUNET_YES; | ||
82 | goto lp_solv; | ||
83 | } | ||
84 | else | ||
85 | { | ||
86 | /* Problem was ill-defined, no way to handle that */ | ||
87 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | ||
88 | "ats-mlp", | ||
89 | "Solving LP problem failed: glp_simplex error 0x%X", res); | ||
90 | return GNUNET_SYSERR; | ||
91 | } | ||
92 | } | ||
93 | |||
94 | /* Analyze problem status */ | ||
95 | res = glp_get_status (mlp->prob); | ||
96 | switch (res) { | ||
97 | /* solution is optimal */ | ||
98 | case GLP_OPT: | ||
99 | /* solution is feasible */ | ||
100 | case GLP_FEAS: | ||
101 | break; | ||
102 | |||
103 | /* Problem was ill-defined, no way to handle that */ | ||
104 | default: | ||
105 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | ||
106 | "ats-mlp", | ||
107 | "Solving LP problem failed, no solution: glp_get_status 0x%X", res); | ||
108 | return GNUNET_SYSERR; | ||
109 | break; | ||
110 | } | ||
111 | |||
112 | /* solved sucessfully, no presolver required next time */ | ||
113 | mlp->presolver_required = GNUNET_NO; | ||
114 | |||
115 | return GNUNET_OK; | ||
116 | } | ||
117 | |||
118 | |||
119 | |||
120 | /** | ||
42 | * Init the MLP problem solving component | 121 | * Init the MLP problem solving component |
43 | * | 122 | * |
44 | * @param max_duration maximum numbers of iterations for the LP/MLP Solver | 123 | * @param max_duration maximum numbers of iterations for the LP/MLP Solver |
@@ -62,10 +141,21 @@ GAS_mlp_init (struct GNUNET_TIME_Relative max_duration, unsigned int max_iterati | |||
62 | 141 | ||
63 | /* Init LP solving parameters */ | 142 | /* Init LP solving parameters */ |
64 | glp_init_smcp(&GAS_mlp->control_param_lp); | 143 | glp_init_smcp(&GAS_mlp->control_param_lp); |
144 | #if DEBUG_MLP | ||
145 | GAS_mlp->control_param_lp.msg_lev = GLP_MSG_ALL; | ||
146 | #else | ||
147 | GAS_mlp->control_param_lp.msg_lev = GLP_MSG_OFF; | ||
148 | #endif | ||
65 | GAS_mlp->control_param_lp.it_lim = max_iterations; | 149 | GAS_mlp->control_param_lp.it_lim = max_iterations; |
66 | GAS_mlp->control_param_lp.tm_lim = max_duration.rel_value; | 150 | GAS_mlp->control_param_lp.tm_lim = max_duration.rel_value; |
151 | |||
67 | /* Init MLP solving parameters */ | 152 | /* Init MLP solving parameters */ |
68 | glp_init_iocp(&GAS_mlp->control_param_mlp); | 153 | glp_init_iocp(&GAS_mlp->control_param_mlp); |
154 | #if DEBUG_MLP | ||
155 | GAS_mlp->control_param_mlp.msg_lev = GLP_MSG_ALL; | ||
156 | #else | ||
157 | GAS_mlp->control_param_mlp.msg_lev = GLP_MSG_OFF; | ||
158 | #endif | ||
69 | GAS_mlp->control_param_mlp.tm_lim = max_duration.rel_value; | 159 | GAS_mlp->control_param_mlp.tm_lim = max_duration.rel_value; |
70 | 160 | ||
71 | return GNUNET_OK; | 161 | return GNUNET_OK; |