aboutsummaryrefslogtreecommitdiff
path: root/src/ats/gnunet-service-ats_addresses_mlp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ats/gnunet-service-ats_addresses_mlp.c')
-rw-r--r--src/ats/gnunet-service-ats_addresses_mlp.c109
1 files changed, 93 insertions, 16 deletions
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