aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-01-12 16:27:58 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-01-12 16:27:58 +0000
commit06a019a9709560e03de00eef9f9edc37511410ab (patch)
tree55b69b38f7232885e9723f8585527bd47adc1cf2
parent2a34cb363f69f5fcd824cdbe31d3bd888ea7092a (diff)
downloadgnunet-06a019a9709560e03de00eef9f9edc37511410ab.tar.gz
gnunet-06a019a9709560e03de00eef9f9edc37511410ab.zip
- more mlp
-rw-r--r--src/ats/gnunet-service-ats_addresses_mlp.c90
-rw-r--r--src/ats/gnunet-service-ats_addresses_mlp.h16
2 files changed, 106 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 */
45int
46mlp_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 */
60lp_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;
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.h b/src/ats/gnunet-service-ats_addresses_mlp.h
index e57fb22bc..9272a2914 100644
--- a/src/ats/gnunet-service-ats_addresses_mlp.h
+++ b/src/ats/gnunet-service-ats_addresses_mlp.h
@@ -33,6 +33,8 @@
33#ifndef GNUNET_SERVICE_ATS_ADDRESSES_MLP_H 33#ifndef GNUNET_SERVICE_ATS_ADDRESSES_MLP_H
34#define GNUNET_SERVICE_ATS_ADDRESSES_MLP_H 34#define GNUNET_SERVICE_ATS_ADDRESSES_MLP_H
35 35
36#define VERBOSE GNUNET_EXTRA_LOGGING
37#define DEBUG_MLP GNUNET_EXTRA_LOGGING
36 38
37#define MLP_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3) 39#define MLP_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3)
38#define MLP_MAX_ITERATIONS INT_MAX 40#define MLP_MAX_ITERATIONS INT_MAX
@@ -68,6 +70,20 @@ struct GAS_MLP_Handle
68 */ 70 */
69 unsigned int max_iterations; 71 unsigned int max_iterations;
70 72
73
74 /* state information */
75
76 /**
77 * Do we need to use the LP presolver?
78 *
79 * If the problem addresses were added or removed and the last basis was we
80 * need to use the presolver.
81 * presolver_required == GNUNET_YES
82 *
83 * If values were modified, we can reuse a valid basis
84 * presolver_required == GNUNET_NO
85 */
86 int presolver_required;
71}; 87};
72 88
73/** 89/**