aboutsummaryrefslogtreecommitdiff
path: root/src/ats
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-01-16 17:10:07 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-01-16 17:10:07 +0000
commit18a41e0fe392a136e89d7c5aed8a5a09cd48247b (patch)
treeb34952a5c0a486ba2e49e658eeb08e38179aead1 /src/ats
parent733fd9a46618ac78fd4255fccec6a207e93c8f26 (diff)
downloadgnunet-18a41e0fe392a136e89d7c5aed8a5a09cd48247b.tar.gz
gnunet-18a41e0fe392a136e89d7c5aed8a5a09cd48247b.zip
- implemented: quality metrics
Diffstat (limited to 'src/ats')
-rw-r--r--src/ats/gnunet-service-ats_addresses.c51
-rw-r--r--src/ats/gnunet-service-ats_addresses_mlp.c109
-rw-r--r--src/ats/gnunet-service-ats_addresses_mlp.h24
-rw-r--r--src/ats/test_ats_mlp.c2
4 files changed, 106 insertions, 80 deletions
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c
index 8693293d0..06eee9fb3 100644
--- a/src/ats/gnunet-service-ats_addresses.c
+++ b/src/ats/gnunet-service-ats_addresses.c
@@ -536,55 +536,6 @@ void
536GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, 536GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
537 const struct GNUNET_STATISTICS_Handle *stats) 537 const struct GNUNET_STATISTICS_Handle *stats)
538{ 538{
539#if HAVE_LIBGLPK
540 double D;
541 double R;
542 double U;
543 long long unsigned int tmp;
544 unsigned int b_min;
545 unsigned int n_min;
546
547 /* Get diversity coefficient from configuration */
548 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats",
549 "COEFFICIENT_D",
550 &tmp))
551 D = (double) tmp / 100;
552 else
553 D = 1.0;
554
555 /* Get proportionality coefficient from configuration */
556 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats",
557 "COEFFICIENT_R",
558 &tmp))
559 R = (double) tmp / 100;
560 else
561 R = 1.0;
562
563 /* Get utilization coefficient from configuration */
564 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats",
565 "COEFFICIENT_U",
566 &tmp))
567 U = (double) tmp / 100;
568 else
569 U = 1.0;
570
571 /* Get minimum bandwidth per used address from configuration */
572 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats",
573 "MIN_BANDWIDTH",
574 &tmp))
575 b_min = tmp;
576 else
577 b_min = 64000;
578
579 /* Get minimum number of connections from configuration */
580 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats",
581 "MIN_CONNECTIONS",
582 &tmp))
583 n_min = tmp;
584 else
585 n_min = 4;
586#endif
587
588 GNUNET_assert (GNUNET_OK == 539 GNUNET_assert (GNUNET_OK ==
589 GNUNET_CONFIGURATION_get_value_size (cfg, "ats", 540 GNUNET_CONFIGURATION_get_value_size (cfg, "ats",
590 "WAN_QUOTA_IN", 541 "WAN_QUOTA_IN",
@@ -601,7 +552,7 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
601#if HAVE_LIBGLPK 552#if HAVE_LIBGLPK
602 ats_mode = MLP; 553 ats_mode = MLP;
603 /* Init the MLP solver with default values */ 554 /* Init the MLP solver with default values */
604 mlp = GAS_mlp_init (stats, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS, D, U, R, b_min, n_min); 555 mlp = GAS_mlp_init (cfg, stats, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS);
605 break; 556 break;
606#else 557#else
607 558
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c
index 785cb736b..c0d4dc08e 100644
--- a/src/ats/gnunet-service-ats_addresses_mlp.c
+++ b/src/ats/gnunet-service-ats_addresses_mlp.c
@@ -46,6 +46,8 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp)
46{ 46{
47 int res = GNUNET_OK; 47 int res = GNUNET_OK;
48 int col; 48 int col;
49 int c;
50 char *name;
49 51
50 /* Set a problem name */ 52 /* Set a problem name */
51 glp_set_prob_name (mlp->prob, "gnunet ats bandwidth distribution"); 53 glp_set_prob_name (mlp->prob, "gnunet ats bandwidth distribution");
@@ -92,8 +94,14 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp)
92 col = glp_add_cols(mlp->prob, mlp->m); 94 col = glp_add_cols(mlp->prob, mlp->m);
93 mlp->c_q_start = col; 95 mlp->c_q_start = col;
94 mlp->c_q_end = col + mlp->m; 96 mlp->c_q_end = col + mlp->m;
95 97 for (c = 0; c < mlp->m; c++)
96 mlp->co_Q = GNUNET_malloc (mlp->m * sizeof (double)); 98 {
99 GNUNET_asprintf (&name, "q_%u", mlp->q[c]);
100 glp_set_col_name (mlp->prob, col + c, name);
101 glp_set_col_bnds (mlp->prob, col + c, GLP_LO, 0.0, 0.0);
102 GNUNET_free (name);
103 glp_set_obj_coef (mlp->prob, col + c, mlp->co_Q[c]);
104 }
97 105
98 return res; 106 return res;
99} 107}
@@ -285,24 +293,23 @@ mlp_solve_problem (struct GAS_MLP_Handle *mlp)
285 * @param stats the GNUNET_STATISTICS handle 293 * @param stats the GNUNET_STATISTICS handle
286 * @param max_duration maximum numbers of iterations for the LP/MLP Solver 294 * @param max_duration maximum numbers of iterations for the LP/MLP Solver
287 * @param max_iterations maximum time limit for the LP/MLP Solver 295 * @param max_iterations maximum time limit for the LP/MLP Solver
288 * @param D Diversity coefficient
289 * @param U Utilization coefficient
290 * @param R Proportionality coefficient
291 * @param b_min minimum bandwidth assigned to an address
292 * @param n_min minimum number of addresses with bandwidth assigned
293 *
294 * @return struct GAS_MLP_Handle * on success, NULL on fail 296 * @return struct GAS_MLP_Handle * on success, NULL on fail
295 */ 297 */
296struct GAS_MLP_Handle * 298struct GAS_MLP_Handle *
297GAS_mlp_init (const struct GNUNET_STATISTICS_Handle *stats, 299GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
300 const struct GNUNET_STATISTICS_Handle *stats,
298 struct GNUNET_TIME_Relative max_duration, 301 struct GNUNET_TIME_Relative max_duration,
299 unsigned int max_iterations, 302 unsigned int max_iterations)
300 double D, double U, double R,
301 unsigned int b_min,
302 unsigned int n_min)
303{ 303{
304 struct GAS_MLP_Handle * mlp = GNUNET_malloc (sizeof (struct GAS_MLP_Handle)); 304 struct GAS_MLP_Handle * mlp = GNUNET_malloc (sizeof (struct GAS_MLP_Handle));
305 305
306 double D;
307 double R;
308 double U;
309 long long unsigned int tmp;
310 unsigned int b_min;
311 unsigned int n_min;
312
306 /* Init GLPK environment */ 313 /* Init GLPK environment */
307 GNUNET_assert (glp_init_env() == 0); 314 GNUNET_assert (glp_init_env() == 0);
308 315
@@ -310,6 +317,78 @@ GAS_mlp_init (const struct GNUNET_STATISTICS_Handle *stats,
310 mlp->prob = glp_create_prob(); 317 mlp->prob = glp_create_prob();
311 GNUNET_assert (mlp->prob != NULL); 318 GNUNET_assert (mlp->prob != NULL);
312 319
320 /* Get diversity coefficient from configuration */
321 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats",
322 "COEFFICIENT_D",
323 &tmp))
324 D = (double) tmp / 100;
325 else
326 D = 1.0;
327
328 /* Get proportionality coefficient from configuration */
329 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats",
330 "COEFFICIENT_R",
331 &tmp))
332 R = (double) tmp / 100;
333 else
334 R = 1.0;
335
336 /* Get utilization coefficient from configuration */
337 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats",
338 "COEFFICIENT_U",
339 &tmp))
340 U = (double) tmp / 100;
341 else
342 U = 1.0;
343
344 /* Get quality metric coefficients from configuration */
345 int i_delay = -1;
346 int i_distance = -1;
347 int q[GNUNET_ATS_QualityPropertiesCount] = GNUNET_ATS_QualityProperties;
348 int c;
349 for (c = 0; c < GNUNET_ATS_QualityPropertiesCount; c++)
350 {
351 /* initialize quality coefficients with default value 1.0 */
352 mlp->co_Q[c] = 1.0;
353
354 mlp->q[c] = q[c];
355 if (q[c] == GNUNET_ATS_QUALITY_NET_DELAY)
356 i_delay = c;
357 if (q[c] == GNUNET_ATS_QUALITY_NET_DISTANCE)
358 i_distance = c;
359 }
360
361 if ((i_delay != -1) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats",
362 "COEFFICIENT_QUALITY_DELAY",
363 &tmp)))
364
365 mlp->co_Q[i_delay] = (double) tmp / 100;
366 else
367 mlp->co_Q[i_delay] = 1.0;
368
369 if ((i_distance != -1) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats",
370 "COEFFICIENT_QUALITY_DISTANCE",
371 &tmp)))
372 mlp->co_Q[i_distance] = (double) tmp / 100;
373 else
374 mlp->co_Q[i_distance] = 1.0;
375
376 /* Get minimum bandwidth per used address from configuration */
377 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats",
378 "MIN_BANDWIDTH",
379 &tmp))
380 b_min = tmp;
381 else
382 b_min = 64000;
383
384 /* Get minimum number of connections from configuration */
385 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats",
386 "MIN_CONNECTIONS",
387 &tmp))
388 n_min = tmp;
389 else
390 n_min = 4;
391
313 mlp->stats = (struct GNUNET_STATISTICS_Handle *) stats; 392 mlp->stats = (struct GNUNET_STATISTICS_Handle *) stats;
314 mlp->max_iterations = max_iterations; 393 mlp->max_iterations = max_iterations;
315 mlp->max_exec_duration = max_duration; 394 mlp->max_exec_duration = max_duration;
@@ -340,6 +419,7 @@ GAS_mlp_init (const struct GNUNET_STATISTICS_Handle *stats,
340 mlp->co_U = U; 419 mlp->co_U = U;
341 mlp->b_min = b_min; 420 mlp->b_min = b_min;
342 mlp->n_min = n_min; 421 mlp->n_min = n_min;
422 mlp->m = GNUNET_ATS_QualityPropertiesCount;
343 423
344 mlp_create_problem (mlp); 424 mlp_create_problem (mlp);
345 return mlp; 425 return mlp;
@@ -438,9 +518,6 @@ GAS_mlp_done (struct GAS_MLP_Handle *mlp)
438 if (mlp != NULL) 518 if (mlp != NULL)
439 glp_delete_prob(mlp->prob); 519 glp_delete_prob(mlp->prob);
440 520
441 if (mlp->co_Q != NULL)
442 GNUNET_free (mlp->co_Q);
443
444 /* Clean up GLPK environment */ 521 /* Clean up GLPK environment */
445 glp_free_env(); 522 glp_free_env();
446 523
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.h b/src/ats/gnunet-service-ats_addresses_mlp.h
index e604919be..62df7a733 100644
--- a/src/ats/gnunet-service-ats_addresses_mlp.h
+++ b/src/ats/gnunet-service-ats_addresses_mlp.h
@@ -136,14 +136,19 @@ struct GAS_MLP_Handle
136 int c_r; 136 int c_r;
137 double co_R; 137 double co_R;
138 138
139 /* ATS Quality metrics
140 * array with GNUNET_ATS_QualityPropertiesCount elements
141 * contains mapping to GNUNET_ATS_Property*/
142 int q[GNUNET_ATS_QualityPropertiesCount];
143
139 /* column index first quality metric (q_1) column */ 144 /* column index first quality metric (q_1) column */
140 int c_q_start; 145 int c_q_start;
141 146
142 /* column index last quality metric (q_n) column */ 147 /* column index last quality metric (q_n) column */
143 int c_q_end; 148 int c_q_end;
144 149
145 /* Array of quality metric coefficients (m elements) */ 150 /* quality metric coefficients*/
146 double *co_Q; 151 double co_Q[GNUNET_ATS_QualityPropertiesCount];
147 152
148 /* number of quality metrics */ 153 /* number of quality metrics */
149 int m; 154 int m;
@@ -172,24 +177,17 @@ struct MLP_information
172/** 177/**
173 * Init the MLP problem solving component 178 * Init the MLP problem solving component
174 * 179 *
180 * @param cfg configuration handle
175 * @param stats the GNUNET_STATISTICS handle 181 * @param stats the GNUNET_STATISTICS handle
176 * @param max_duration maximum numbers of iterations for the LP/MLP Solver 182 * @param max_duration maximum numbers of iterations for the LP/MLP Solver
177 * @param max_iterations maximum time limit for the LP/MLP Solver 183 * @param max_iterations maximum time limit for the LP/MLP Solver
178 * @param D Diversity coefficient
179 * @param U Utilization coefficient
180 * @param R Proportionality coefficient
181 * @param b_min minimum bandwidth assigned to an address
182 * @param n_min minimum number of addresses with bandwidth assigned
183 *
184 * @return struct GAS_MLP_Handle * on success, NULL on fail 184 * @return struct GAS_MLP_Handle * on success, NULL on fail
185 */ 185 */
186struct GAS_MLP_Handle * 186struct GAS_MLP_Handle *
187GAS_mlp_init (const struct GNUNET_STATISTICS_Handle *stats, 187GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
188 const struct GNUNET_STATISTICS_Handle *stats,
188 struct GNUNET_TIME_Relative max_duration, 189 struct GNUNET_TIME_Relative max_duration,
189 unsigned int max_iterations, 190 unsigned int max_iterations);
190 double D, double U, double R,
191 unsigned int b_min,
192 unsigned int n_min);
193 191
194 192
195/** 193/**
diff --git a/src/ats/test_ats_mlp.c b/src/ats/test_ats_mlp.c
index 32917d546..e3e714557 100644
--- a/src/ats/test_ats_mlp.c
+++ b/src/ats/test_ats_mlp.c
@@ -53,7 +53,7 @@ check (void *cls, char *const *args, const char *cfgfile,
53#endif 53#endif
54 stats = GNUNET_STATISTICS_create("ats", cfg); 54 stats = GNUNET_STATISTICS_create("ats", cfg);
55 55
56 mlp = GAS_mlp_init(NULL, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS); 56 mlp = GAS_mlp_init (cfg, NULL, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS);
57 GNUNET_assert (mlp != NULL); 57 GNUNET_assert (mlp != NULL);
58 58
59 GAS_mlp_done (mlp); 59 GAS_mlp_done (mlp);