diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-01-17 10:47:00 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-01-17 10:47:00 +0000 |
commit | 9caca3944f49e78816c500fa58e94cae1f88a3d2 (patch) | |
tree | 0ada3172883651d8e5ea9c23ed96daed00f1ff17 /src/ats | |
parent | 4ed911cbd1b61b23225cd9d2fb3ab3b392729965 (diff) | |
download | gnunet-9caca3944f49e78816c500fa58e94cae1f88a3d2.tar.gz gnunet-9caca3944f49e78816c500fa58e94cae1f88a3d2.zip |
- more mlp
Diffstat (limited to 'src/ats')
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.c | 60 | ||||
-rw-r--r-- | src/ats/test_ats_mlp.c | 14 |
2 files changed, 66 insertions, 8 deletions
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c index aa72b9d90..9369d927b 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.c +++ b/src/ats/gnunet-service-ats_addresses_mlp.c | |||
@@ -33,6 +33,19 @@ | |||
33 | #include "glpk.h" | 33 | #include "glpk.h" |
34 | #endif | 34 | #endif |
35 | 35 | ||
36 | /** | ||
37 | * Intercept GLPK terminal output | ||
38 | * | ||
39 | */ | ||
40 | |||
41 | static int | ||
42 | mlp_term_hook (void *info, const char *s) | ||
43 | { | ||
44 | /* Not needed atm struct MLP_information *mlp = info; */ | ||
45 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", s); | ||
46 | /* 0: glpk prints output on terminal, != surpress output */ | ||
47 | return 1; | ||
48 | } | ||
36 | 49 | ||
37 | /** | 50 | /** |
38 | * Create the MLP problem | 51 | * Create the MLP problem |
@@ -79,8 +92,7 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp) | |||
79 | /* Column lower bound = 0.0 */ | 92 | /* Column lower bound = 0.0 */ |
80 | glp_set_col_bnds (mlp->prob, col, GLP_LO, 0.0, 0.0); | 93 | glp_set_col_bnds (mlp->prob, col, GLP_LO, 0.0, 0.0); |
81 | 94 | ||
82 | /* Relitivity r column */ | 95 | /* Relativity r column */ |
83 | |||
84 | col = glp_add_cols (mlp->prob, 1); | 96 | col = glp_add_cols (mlp->prob, 1); |
85 | mlp->c_r = col; | 97 | mlp->c_r = col; |
86 | /* Column name */ | 98 | /* Column name */ |
@@ -97,8 +109,10 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp) | |||
97 | mlp->c_q[c] = col + c; | 109 | mlp->c_q[c] = col + c; |
98 | GNUNET_asprintf (&name, "q_%u", mlp->q[c]); | 110 | GNUNET_asprintf (&name, "q_%u", mlp->q[c]); |
99 | glp_set_col_name (mlp->prob, col + c, name); | 111 | glp_set_col_name (mlp->prob, col + c, name); |
112 | /* Column lower bound = 0.0 */ | ||
100 | glp_set_col_bnds (mlp->prob, col + c, GLP_LO, 0.0, 0.0); | 113 | glp_set_col_bnds (mlp->prob, col + c, GLP_LO, 0.0, 0.0); |
101 | GNUNET_free (name); | 114 | GNUNET_free (name); |
115 | /* Coefficient == Qm */ | ||
102 | glp_set_obj_coef (mlp->prob, col + c, mlp->co_Q[c]); | 116 | glp_set_obj_coef (mlp->prob, col + c, mlp->co_Q[c]); |
103 | } | 117 | } |
104 | 118 | ||
@@ -157,7 +171,7 @@ lp_solv: | |||
157 | /* Problem was ill-defined, no way to handle that */ | 171 | /* Problem was ill-defined, no way to handle that */ |
158 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | 172 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, |
159 | "ats-mlp", | 173 | "ats-mlp", |
160 | "Solving LP problem failed: glp_simplex error 0x%X", res); | 174 | "Solving LP problem failed: glp_simplex error 0x%X\n", res); |
161 | return GNUNET_SYSERR; | 175 | return GNUNET_SYSERR; |
162 | } | 176 | } |
163 | } | 177 | } |
@@ -186,7 +200,7 @@ lp_solv: | |||
186 | default: | 200 | default: |
187 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | 201 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, |
188 | "ats-mlp", | 202 | "ats-mlp", |
189 | "Solving LP problem failed, no solution: glp_get_status 0x%X", res); | 203 | "Solving LP problem failed, no solution: glp_get_status 0x%X\n", res); |
190 | return GNUNET_SYSERR; | 204 | return GNUNET_SYSERR; |
191 | break; | 205 | break; |
192 | } | 206 | } |
@@ -234,7 +248,7 @@ mlp_solve_mlp_problem (struct GAS_MLP_Handle *mlp) | |||
234 | /* Problem was ill-defined, no way to handle that */ | 248 | /* Problem was ill-defined, no way to handle that */ |
235 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | 249 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, |
236 | "ats-mlp", | 250 | "ats-mlp", |
237 | "Solving MLP problem failed: glp_intopt error 0x%X", res); | 251 | "Solving MLP problem failed: glp_intopt error 0x%X\n", res); |
238 | return GNUNET_SYSERR; | 252 | return GNUNET_SYSERR; |
239 | } | 253 | } |
240 | 254 | ||
@@ -261,7 +275,7 @@ mlp_solve_mlp_problem (struct GAS_MLP_Handle *mlp) | |||
261 | default: | 275 | default: |
262 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | 276 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, |
263 | "ats-mlp", | 277 | "ats-mlp", |
264 | "Solving MLP problem failed, no solution: glp_mip_status 0x%X", res); | 278 | "Solving MLP problem failed, no solution: glp_mip_status 0x%X\n", res); |
265 | return GNUNET_SYSERR; | 279 | return GNUNET_SYSERR; |
266 | break; | 280 | break; |
267 | } | 281 | } |
@@ -392,6 +406,9 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
392 | mlp->max_iterations = max_iterations; | 406 | mlp->max_iterations = max_iterations; |
393 | mlp->max_exec_duration = max_duration; | 407 | mlp->max_exec_duration = max_duration; |
394 | 408 | ||
409 | /* Redirect GLPK output to GNUnet logging */ | ||
410 | glp_error_hook((void *) mlp, &mlp_term_hook); | ||
411 | |||
395 | /* Init LP solving parameters */ | 412 | /* Init LP solving parameters */ |
396 | glp_init_smcp(&mlp->control_param_lp); | 413 | glp_init_smcp(&mlp->control_param_lp); |
397 | #if DEBUG_MLP | 414 | #if DEBUG_MLP |
@@ -441,6 +458,9 @@ void | |||
441 | GAS_mlp_address_update (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address) | 458 | GAS_mlp_address_update (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address) |
442 | { | 459 | { |
443 | int new; | 460 | int new; |
461 | int col; | ||
462 | struct MLP_information *mlpi; | ||
463 | char * name; | ||
444 | 464 | ||
445 | GNUNET_STATISTICS_update (mlp->stats,"# LP address updates", 1, GNUNET_NO); | 465 | GNUNET_STATISTICS_update (mlp->stats,"# LP address updates", 1, GNUNET_NO); |
446 | 466 | ||
@@ -448,10 +468,34 @@ GAS_mlp_address_update (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult | |||
448 | if (address->mlp_information == NULL) | 468 | if (address->mlp_information == NULL) |
449 | { | 469 | { |
450 | new = GNUNET_YES; | 470 | new = GNUNET_YES; |
451 | address->mlp_information = GNUNET_malloc (sizeof (struct MLP_information)); | 471 | mlpi = GNUNET_malloc (sizeof (struct MLP_information)); |
472 | address->mlp_information = mlpi; | ||
452 | 473 | ||
453 | /* Add bandwidth columns */ | 474 | /* Add bandwidth column */ |
475 | col = glp_add_cols (mlp->prob, 2); | ||
476 | mlpi->c_b = col; | ||
477 | mlpi->c_n = col + 1; | ||
454 | 478 | ||
479 | GNUNET_asprintf (&name, "b_%s_%s", GNUNET_i2s (&address->peer), address->plugin); | ||
480 | glp_set_col_name (mlp->prob, mlpi->c_b , name); | ||
481 | GNUNET_free (name); | ||
482 | /* Lower bound == 0 */ | ||
483 | glp_set_col_bnds (mlp->prob, mlpi->c_b , GLP_LO, 0.0, 0.0); | ||
484 | /* Continuous value*/ | ||
485 | glp_set_col_kind (mlp->prob, mlpi->c_b , GLP_CV); | ||
486 | /* Objective function coefficient == 0 */ | ||
487 | glp_set_obj_coef (mlp->prob, mlpi->c_b , 0); | ||
488 | |||
489 | /* Add usage column */ | ||
490 | GNUNET_asprintf (&name, "n_%s_%s", GNUNET_i2s (&address->peer), address->plugin); | ||
491 | glp_set_col_name (mlp->prob, mlpi->c_n, name); | ||
492 | GNUNET_free (name); | ||
493 | /* Limit value : 0 <= value <= 1 */ | ||
494 | glp_set_col_bnds (mlp->prob, mlpi->c_n, GLP_DB, 0.0, 1.0); | ||
495 | /* Integer value*/ | ||
496 | glp_set_col_kind (mlp->prob, mlpi->c_n, GLP_IV); | ||
497 | /* Objective function coefficient == 0 */ | ||
498 | glp_set_obj_coef (mlp->prob, mlpi->c_n, 0); | ||
455 | 499 | ||
456 | /* Add */ | 500 | /* Add */ |
457 | } | 501 | } |
diff --git a/src/ats/test_ats_mlp.c b/src/ats/test_ats_mlp.c index e3e714557..dbae6168b 100644 --- a/src/ats/test_ats_mlp.c +++ b/src/ats/test_ats_mlp.c | |||
@@ -40,6 +40,8 @@ static int ret; | |||
40 | 40 | ||
41 | struct GNUNET_STATISTICS_Handle * stats; | 41 | struct GNUNET_STATISTICS_Handle * stats; |
42 | 42 | ||
43 | struct GNUNET_CONTAINER_MultiHashMap * addresses; | ||
44 | |||
43 | struct GAS_MLP_Handle *mlp; | 45 | struct GAS_MLP_Handle *mlp; |
44 | 46 | ||
45 | static void | 47 | static void |
@@ -51,13 +53,25 @@ check (void *cls, char *const *args, const char *cfgfile, | |||
51 | ret = 1; | 53 | ret = 1; |
52 | return; | 54 | return; |
53 | #endif | 55 | #endif |
56 | struct ATS_Address addr; | ||
57 | |||
54 | stats = GNUNET_STATISTICS_create("ats", cfg); | 58 | stats = GNUNET_STATISTICS_create("ats", cfg); |
55 | 59 | ||
60 | addresses = GNUNET_CONTAINER_multihashmap_create (10); | ||
61 | |||
62 | GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &addr.peer.hashPubKey); | ||
63 | addr.plugin = strdup ("dummy"); | ||
64 | GNUNET_CONTAINER_multihashmap_put(addresses, &addr.peer.hashPubKey, &addr, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
65 | |||
56 | mlp = GAS_mlp_init (cfg, NULL, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS); | 66 | mlp = GAS_mlp_init (cfg, NULL, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS); |
67 | |||
68 | GAS_mlp_address_update(mlp, addresses, &addr); | ||
69 | |||
57 | GNUNET_assert (mlp != NULL); | 70 | GNUNET_assert (mlp != NULL); |
58 | 71 | ||
59 | GAS_mlp_done (mlp); | 72 | GAS_mlp_done (mlp); |
60 | 73 | ||
74 | GNUNET_CONTAINER_multihashmap_destroy (addresses); | ||
61 | GNUNET_STATISTICS_destroy(stats, GNUNET_NO); | 75 | GNUNET_STATISTICS_destroy(stats, GNUNET_NO); |
62 | 76 | ||
63 | ret = 0; | 77 | ret = 0; |