diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-01-12 17:21:26 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-01-12 17:21:26 +0000 |
commit | e31812bc030130c0faf6ff6fe5ca44bee440f4fb (patch) | |
tree | e6ea5ea18627d6fb2f739c49837a48a124adc5a1 | |
parent | 06a019a9709560e03de00eef9f9edc37511410ab (diff) | |
download | gnunet-e31812bc030130c0faf6ff6fe5ca44bee440f4fb.tar.gz gnunet-e31812bc030130c0faf6ff6fe5ca44bee440f4fb.zip |
- even more mlp
-rw-r--r-- | src/ats/Makefile.am | 3 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats.c | 4 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 6 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.h | 6 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.c | 91 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.h | 41 |
6 files changed, 139 insertions, 12 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am index c8a78bc20..d6ffebc8f 100644 --- a/src/ats/Makefile.am +++ b/src/ats/Makefile.am | |||
@@ -66,7 +66,8 @@ test_ats_mlp_SOURCES = \ | |||
66 | test_ats_mlp.c | 66 | test_ats_mlp.c |
67 | test_ats_mlp_LDADD = \ | 67 | test_ats_mlp_LDADD = \ |
68 | $(GN_LIBGLPK) \ | 68 | $(GN_LIBGLPK) \ |
69 | $(top_builddir)/src/util/libgnunetutil.la | 69 | $(top_builddir)/src/util/libgnunetutil.la \ |
70 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
70 | endif | 71 | endif |
71 | 72 | ||
72 | test_ats_api_scheduling_SOURCES = \ | 73 | test_ats_api_scheduling_SOURCES = \ |
diff --git a/src/ats/gnunet-service-ats.c b/src/ats/gnunet-service-ats.c index ff623594a..7deca0b62 100644 --- a/src/ats/gnunet-service-ats.c +++ b/src/ats/gnunet-service-ats.c | |||
@@ -114,7 +114,7 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
114 | if (NULL != GSA_stats) | 114 | if (NULL != GSA_stats) |
115 | { | 115 | { |
116 | GNUNET_STATISTICS_destroy (GSA_stats, GNUNET_NO); | 116 | GNUNET_STATISTICS_destroy (GSA_stats, GNUNET_NO); |
117 | GSA_stats = 0; | 117 | GSA_stats = NULL; |
118 | } | 118 | } |
119 | } | 119 | } |
120 | 120 | ||
@@ -156,7 +156,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
156 | GAS_reservations_init (); | 156 | GAS_reservations_init (); |
157 | GAS_performance_init (server); | 157 | GAS_performance_init (server); |
158 | GAS_scheduling_init (server); | 158 | GAS_scheduling_init (server); |
159 | GAS_addresses_init (cfg); | 159 | GAS_addresses_init (cfg, GSA_stats); |
160 | GNUNET_SERVER_disconnect_notify (server, &client_disconnect_handler, NULL); | 160 | GNUNET_SERVER_disconnect_notify (server, &client_disconnect_handler, NULL); |
161 | GNUNET_SERVER_add_handlers (server, handlers); | 161 | GNUNET_SERVER_add_handlers (server, handlers); |
162 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task, | 162 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task, |
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 6df44f9c4..0b2d464b6 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -441,9 +441,11 @@ GAS_addresses_change_preference (const struct GNUNET_PeerIdentity *peer, | |||
441 | * Initialize address subsystem. | 441 | * Initialize address subsystem. |
442 | * | 442 | * |
443 | * @param cfg configuration to use | 443 | * @param cfg configuration to use |
444 | * @param stats the statistics handle to use | ||
444 | */ | 445 | */ |
445 | void | 446 | void |
446 | GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg) | 447 | GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, |
448 | const struct GNUNET_STATISTICS_Handle *stats) | ||
447 | { | 449 | { |
448 | GNUNET_assert (GNUNET_OK == | 450 | GNUNET_assert (GNUNET_OK == |
449 | GNUNET_CONFIGURATION_get_value_size (cfg, "ats", | 451 | GNUNET_CONFIGURATION_get_value_size (cfg, "ats", |
@@ -463,7 +465,7 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
463 | #if HAVE_LIBGLPK | 465 | #if HAVE_LIBGLPK |
464 | ats_mode = MLP; | 466 | ats_mode = MLP; |
465 | /* Init the MLP solver with default values */ | 467 | /* Init the MLP solver with default values */ |
466 | GAS_mlp_init (MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS); | 468 | GAS_mlp_init (stats, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS); |
467 | break; | 469 | break; |
468 | #else | 470 | #else |
469 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MLP mode was configured, but libglpk is not installed, switching to simple mode"); | 471 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MLP mode was configured, but libglpk is not installed, switching to simple mode"); |
diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h index 3709853a7..ad34c94f2 100644 --- a/src/ats/gnunet-service-ats_addresses.h +++ b/src/ats/gnunet-service-ats_addresses.h | |||
@@ -29,6 +29,7 @@ | |||
29 | 29 | ||
30 | #include "gnunet_util_lib.h" | 30 | #include "gnunet_util_lib.h" |
31 | #include "gnunet_ats_service.h" | 31 | #include "gnunet_ats_service.h" |
32 | #include "gnunet_statistics_service.h" | ||
32 | #include "ats.h" | 33 | #include "ats.h" |
33 | 34 | ||
34 | struct ATS_Address | 35 | struct ATS_Address |
@@ -76,10 +77,13 @@ struct ATS_Address | |||
76 | 77 | ||
77 | /** | 78 | /** |
78 | * Initialize address subsystem. | 79 | * Initialize address subsystem. |
80 | * | ||
79 | * @param cfg configuration to use | 81 | * @param cfg configuration to use |
82 | * @param stats the statistics handle to use | ||
80 | */ | 83 | */ |
81 | void | 84 | void |
82 | GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg); | 85 | GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, |
86 | const struct GNUNET_STATISTICS_Handle *stats); | ||
83 | 87 | ||
84 | 88 | ||
85 | /** | 89 | /** |
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c index 946a2848d..ca192b8a4 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.c +++ b/src/ats/gnunet-service-ats_addresses_mlp.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
29 | #include "gnunet-service-ats_addresses.h" | 29 | #include "gnunet-service-ats_addresses.h" |
30 | #include "gnunet-service-ats_addresses_mlp.h" | 30 | #include "gnunet-service-ats_addresses_mlp.h" |
31 | #include "gnunet_statistics_service.h" | ||
31 | #if HAVE_LIBGLPK | 32 | #if HAVE_LIBGLPK |
32 | #include "glpk.h" | 33 | #include "glpk.h" |
33 | #endif | 34 | #endif |
@@ -39,13 +40,16 @@ static struct GAS_MLP_Handle *GAS_mlp; | |||
39 | 40 | ||
40 | 41 | ||
41 | /** | 42 | /** |
42 | * Solves the MLP problem | 43 | * Solves the LP problem |
43 | * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure | 44 | * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure |
44 | */ | 45 | */ |
45 | int | 46 | int |
46 | mlp_solve_lp_problem (struct GAS_MLP_Handle *mlp) | 47 | mlp_solve_lp_problem (struct GAS_MLP_Handle *mlp) |
47 | { | 48 | { |
48 | int res; | 49 | int res; |
50 | struct GNUNET_TIME_Relative duration; | ||
51 | struct GNUNET_TIME_Absolute end; | ||
52 | struct GNUNET_TIME_Absolute start = GNUNET_TIME_absolute_get(); | ||
49 | 53 | ||
50 | /* LP presolver? | 54 | /* LP presolver? |
51 | * Presolver is required if the problem was modified and an existing | 55 | * Presolver is required if the problem was modified and an existing |
@@ -55,7 +59,6 @@ mlp_solve_lp_problem (struct GAS_MLP_Handle *mlp) | |||
55 | else | 59 | else |
56 | mlp->control_param_lp.presolve = GLP_OFF; | 60 | mlp->control_param_lp.presolve = GLP_OFF; |
57 | 61 | ||
58 | |||
59 | /* Solve LP problem to have initial valid solution */ | 62 | /* Solve LP problem to have initial valid solution */ |
60 | lp_solv: | 63 | lp_solv: |
61 | res = glp_simplex(mlp->prob, &mlp->control_param_lp); | 64 | res = glp_simplex(mlp->prob, &mlp->control_param_lp); |
@@ -91,6 +94,17 @@ lp_solv: | |||
91 | } | 94 | } |
92 | } | 95 | } |
93 | 96 | ||
97 | end = GNUNET_TIME_absolute_get (); | ||
98 | duration = GNUNET_TIME_absolute_get_difference (start, end); | ||
99 | mlp->lp_solved++; | ||
100 | mlp->lp_total_duration =+ duration.rel_value; | ||
101 | |||
102 | GNUNET_STATISTICS_update (mlp->stats,"# LP problem solved", 1, GNUNET_NO); | ||
103 | GNUNET_STATISTICS_set (mlp->stats,"# LP execution time", duration.rel_value, GNUNET_NO); | ||
104 | GNUNET_STATISTICS_set (mlp->stats,"# LP execution time average", | ||
105 | mlp->lp_total_duration / mlp->lp_solved, GNUNET_NO); | ||
106 | |||
107 | |||
94 | /* Analyze problem status */ | 108 | /* Analyze problem status */ |
95 | res = glp_get_status (mlp->prob); | 109 | res = glp_get_status (mlp->prob); |
96 | switch (res) { | 110 | switch (res) { |
@@ -116,16 +130,86 @@ lp_solv: | |||
116 | } | 130 | } |
117 | 131 | ||
118 | 132 | ||
133 | /** | ||
134 | * Solves the MLP problem | ||
135 | * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure | ||
136 | */ | ||
137 | int | ||
138 | mlp_solve_mlp_problem (struct GAS_MLP_Handle *mlp) | ||
139 | { | ||
140 | int res; | ||
141 | struct GNUNET_TIME_Relative duration; | ||
142 | struct GNUNET_TIME_Absolute end; | ||
143 | struct GNUNET_TIME_Absolute start = GNUNET_TIME_absolute_get(); | ||
144 | |||
145 | /* solve MLP problem */ | ||
146 | res = glp_intopt(mlp->prob, &mlp->control_param_mlp); | ||
147 | if (res == 0) | ||
148 | { | ||
149 | /* The MLP problem instance has been successfully solved. */ | ||
150 | } | ||
151 | else if (res == GLP_EITLIM) | ||
152 | { | ||
153 | /* simplex iteration limit has been exceeded. */ | ||
154 | // TODO Increase iteration limit? | ||
155 | } | ||
156 | else if (res == GLP_ETMLIM) | ||
157 | { | ||
158 | /* Time limit has been exceeded. */ | ||
159 | // TODO Increase time limit? | ||
160 | } | ||
161 | else | ||
162 | { | ||
163 | /* Problem was ill-defined, no way to handle that */ | ||
164 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | ||
165 | "ats-mlp", | ||
166 | "Solving MLP problem failed: glp_intopt error 0x%X", res); | ||
167 | return GNUNET_SYSERR; | ||
168 | } | ||
169 | |||
170 | end = GNUNET_TIME_absolute_get (); | ||
171 | duration = GNUNET_TIME_absolute_get_difference (start, end); | ||
172 | mlp->mlp_solved++; | ||
173 | mlp->mlp_total_duration =+ duration.rel_value; | ||
174 | |||
175 | GNUNET_STATISTICS_update (mlp->stats,"# MLP problem solved", 1, GNUNET_NO); | ||
176 | GNUNET_STATISTICS_set (mlp->stats,"# MLP execution time", duration.rel_value, GNUNET_NO); | ||
177 | GNUNET_STATISTICS_set (mlp->stats,"# MLP execution time average", | ||
178 | mlp->mlp_total_duration / mlp->mlp_solved, GNUNET_NO); | ||
179 | |||
180 | /* Analyze problem status */ | ||
181 | res = glp_mip_status(mlp->prob); | ||
182 | switch (res) { | ||
183 | /* solution is optimal */ | ||
184 | case GLP_OPT: | ||
185 | /* solution is feasible */ | ||
186 | case GLP_FEAS: | ||
187 | break; | ||
188 | |||
189 | /* Problem was ill-defined, no way to handle that */ | ||
190 | default: | ||
191 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | ||
192 | "ats-mlp", | ||
193 | "Solving MLP problem failed, no solution: glp_mip_status 0x%X", res); | ||
194 | return GNUNET_SYSERR; | ||
195 | break; | ||
196 | } | ||
197 | |||
198 | return GNUNET_OK; | ||
199 | } | ||
119 | 200 | ||
120 | /** | 201 | /** |
121 | * Init the MLP problem solving component | 202 | * Init the MLP problem solving component |
122 | * | 203 | * |
204 | * @param stats the GNUNET_STATISTICS handle | ||
123 | * @param max_duration maximum numbers of iterations for the LP/MLP Solver | 205 | * @param max_duration maximum numbers of iterations for the LP/MLP Solver |
124 | * @param max_iterations maximum time limit for the LP/MLP Solver | 206 | * @param max_iterations maximum time limit for the LP/MLP Solver |
125 | * @return GNUNET_OK on success, GNUNET_SYSERR on fail | 207 | * @return GNUNET_OK on success, GNUNET_SYSERR on fail |
126 | */ | 208 | */ |
127 | int | 209 | int |
128 | GAS_mlp_init (struct GNUNET_TIME_Relative max_duration, unsigned int max_iterations) | 210 | GAS_mlp_init (const struct GNUNET_STATISTICS_Handle *stats, |
211 | struct GNUNET_TIME_Relative max_duration, | ||
212 | unsigned int max_iterations) | ||
129 | { | 213 | { |
130 | GAS_mlp = GNUNET_malloc (sizeof (struct GAS_MLP_Handle)); | 214 | GAS_mlp = GNUNET_malloc (sizeof (struct GAS_MLP_Handle)); |
131 | 215 | ||
@@ -136,6 +220,7 @@ GAS_mlp_init (struct GNUNET_TIME_Relative max_duration, unsigned int max_iterati | |||
136 | GAS_mlp->prob = glp_create_prob(); | 220 | GAS_mlp->prob = glp_create_prob(); |
137 | GNUNET_assert (GAS_mlp->prob != NULL); | 221 | GNUNET_assert (GAS_mlp->prob != NULL); |
138 | 222 | ||
223 | GAS_mlp->stats = (struct GNUNET_STATISTICS_Handle *) stats; | ||
139 | GAS_mlp->max_iterations = max_iterations; | 224 | GAS_mlp->max_iterations = max_iterations; |
140 | GAS_mlp->max_exec_duration = max_duration; | 225 | GAS_mlp->max_exec_duration = max_duration; |
141 | 226 | ||
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.h b/src/ats/gnunet-service-ats_addresses_mlp.h index 9272a2914..2555846ff 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.h +++ b/src/ats/gnunet-service-ats_addresses_mlp.h | |||
@@ -25,7 +25,8 @@ | |||
25 | * @author Christian Grothoff | 25 | * @author Christian Grothoff |
26 | */ | 26 | */ |
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | 28 | #include "gnunet_statistics_service.h" | |
29 | #include "gnunet-service-ats_addresses.h" | ||
29 | #if HAVE_LIBGLPK | 30 | #if HAVE_LIBGLPK |
30 | #include "glpk.h" | 31 | #include "glpk.h" |
31 | #endif | 32 | #endif |
@@ -39,9 +40,17 @@ | |||
39 | #define MLP_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3) | 40 | #define MLP_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3) |
40 | #define MLP_MAX_ITERATIONS INT_MAX | 41 | #define MLP_MAX_ITERATIONS INT_MAX |
41 | 42 | ||
43 | /** | ||
44 | * MLP Handle | ||
45 | */ | ||
42 | struct GAS_MLP_Handle | 46 | struct GAS_MLP_Handle |
43 | { | 47 | { |
44 | /** | 48 | /** |
49 | * Statistics handle | ||
50 | */ | ||
51 | struct GNUNET_STATISTICS_Handle *stats; | ||
52 | |||
53 | /** | ||
45 | * GLPK (MLP) problem object | 54 | * GLPK (MLP) problem object |
46 | */ | 55 | */ |
47 | #if HAVE_LIBGLPK | 56 | #if HAVE_LIBGLPK |
@@ -70,7 +79,6 @@ struct GAS_MLP_Handle | |||
70 | */ | 79 | */ |
71 | unsigned int max_iterations; | 80 | unsigned int max_iterations; |
72 | 81 | ||
73 | |||
74 | /* state information */ | 82 | /* state information */ |
75 | 83 | ||
76 | /** | 84 | /** |
@@ -84,16 +92,43 @@ struct GAS_MLP_Handle | |||
84 | * presolver_required == GNUNET_NO | 92 | * presolver_required == GNUNET_NO |
85 | */ | 93 | */ |
86 | int presolver_required; | 94 | int presolver_required; |
95 | |||
96 | /* statistics */ | ||
97 | |||
98 | /** | ||
99 | * How often was the LP problem solved | ||
100 | */ | ||
101 | unsigned int lp_solved; | ||
102 | |||
103 | /** | ||
104 | * total duration of all lp solver executions | ||
105 | */ | ||
106 | uint64_t lp_total_duration; | ||
107 | |||
108 | /** | ||
109 | * How often was the MLP problem solved | ||
110 | */ | ||
111 | unsigned int mlp_solved; | ||
112 | |||
113 | /** | ||
114 | * total duration of all mlp solver executions | ||
115 | */ | ||
116 | uint64_t mlp_total_duration; | ||
87 | }; | 117 | }; |
88 | 118 | ||
119 | |||
89 | /** | 120 | /** |
90 | * Init the MLP problem solving component | 121 | * Init the MLP problem solving component |
122 | * | ||
123 | * @param stats the GNUNET_STATISTICS handle | ||
91 | * @param max_duration maximum numbers of iterations for the LP/MLP Solver | 124 | * @param max_duration maximum numbers of iterations for the LP/MLP Solver |
92 | * @param max_iterations maximum time limit for the LP/MLP Solver | 125 | * @param max_iterations maximum time limit for the LP/MLP Solver |
93 | * @return GNUNET_OK on success, GNUNET_SYSERR on fail | 126 | * @return GNUNET_OK on success, GNUNET_SYSERR on fail |
94 | */ | 127 | */ |
95 | int | 128 | int |
96 | GAS_mlp_init (struct GNUNET_TIME_Relative max_duration, unsigned int max_iterations); | 129 | GAS_mlp_init (const struct GNUNET_STATISTICS_Handle *stats, |
130 | struct GNUNET_TIME_Relative max_duration, | ||
131 | unsigned int max_iterations); | ||
97 | 132 | ||
98 | /** | 133 | /** |
99 | * Update address in the MLP problem | 134 | * Update address in the MLP problem |