aboutsummaryrefslogtreecommitdiff
path: root/src/ats
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-01-19 12:45:08 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-01-19 12:45:08 +0000
commit6525120b1e00378a99a0a70af700f0907e40eecd (patch)
treed0e50eb65b86bef37a7a869610603aa5cc99e08b /src/ats
parent6f4e34b7a3cb7263d6e8839fa1ba75e9f5a9162e (diff)
downloadgnunet-6525120b1e00378a99a0a70af700f0907e40eecd.tar.gz
gnunet-6525120b1e00378a99a0a70af700f0907e40eecd.zip
- disabling code : debugging was required
Diffstat (limited to 'src/ats')
-rw-r--r--src/ats/gnunet-service-ats_addresses_mlp.c162
-rw-r--r--src/ats/gnunet-service-ats_addresses_mlp.h3
2 files changed, 144 insertions, 21 deletions
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c
index 0794401bd..74869e94c 100644
--- a/src/ats/gnunet-service-ats_addresses_mlp.c
+++ b/src/ats/gnunet-service-ats_addresses_mlp.c
@@ -29,11 +29,10 @@
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#include "gnunet_statistics_service.h"
32#if HAVE_LIBGLPK
33#include "glpk.h" 32#include "glpk.h"
34#endif
35#include "float.h" 33#include "float.h"
36 34
35#define WRITE_MLP GNUNET_NO
37#define DEBUG_ATS GNUNET_YES 36#define DEBUG_ATS GNUNET_YES
38/* A very big value */ 37/* A very big value */
39#define M DBL_MAX 38#define M DBL_MAX
@@ -199,7 +198,7 @@ mlp_delete_problem (struct GAS_MLP_Handle *mlp)
199 if (mlp->ia != NULL) 198 if (mlp->ia != NULL)
200 { 199 {
201 GNUNET_free (mlp->ia); 200 GNUNET_free (mlp->ia);
202 mlp->ja = NULL; 201 mlp->ia = NULL;
203 } 202 }
204 203
205 /* delete column index */ 204 /* delete column index */
@@ -255,10 +254,10 @@ create_constraint_it (void *cls, const GNUNET_HashCode * key, void *value)
255 mlp->ci++; 254 mlp->ci++;
256 255
257 mlp->ia[mlp->ci] = row_index; 256 mlp->ia[mlp->ci] = row_index;
258 mlp->ja[mlp->ci] = mlpi->c_b; 257 mlp->ja[mlp->ci] = mlpi->c_n;
259 mlp->ar[mlp->ci] = -M; 258 mlp->ar[mlp->ci] = -M;
260 mlp->ci++; 259 mlp->ci++;
261 260#if 0
262 /* c 3) minimum bandwidth 261 /* c 3) minimum bandwidth
263 * b_t + (-n_t * b_min) >= 0 262 * b_t + (-n_t * b_min) >= 0
264 */ 263 */
@@ -274,7 +273,7 @@ create_constraint_it (void *cls, const GNUNET_HashCode * key, void *value)
274 mlp->ci++; 273 mlp->ci++;
275 274
276 mlp->ia[mlp->ci] = row_index; 275 mlp->ia[mlp->ci] = row_index;
277 mlp->ja[mlp->ci] = mlpi->c_b; 276 mlp->ja[mlp->ci] = mlpi->c_n;
278 mlp->ar[mlp->ci] = -mlp->b_min; 277 mlp->ar[mlp->ci] = -mlp->b_min;
279 mlp->ci++; 278 mlp->ci++;
280 279
@@ -286,6 +285,15 @@ create_constraint_it (void *cls, const GNUNET_HashCode * key, void *value)
286 mlp->ar[mlp->ci] = 1; 285 mlp->ar[mlp->ci] = 1;
287 mlp->ci++; 286 mlp->ci++;
288 287
288 /* c 6) maximize diversity
289 * (1)*n_1 + ... + (1)*n_m - d == 0
290 */
291 mlp->ia[mlp->ci] = mlp->r_c6;
292 mlp->ja[mlp->ci] = mlpi->c_n;
293 mlp->ar[mlp->ci] = 1;
294 mlp->ci++;
295#endif
296
289 return GNUNET_OK; 297 return GNUNET_OK;
290} 298}
291 299
@@ -302,6 +310,7 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON
302{ 310{
303 unsigned int n_addresses; 311 unsigned int n_addresses;
304 int row_index; 312 int row_index;
313 //int c;
305 314
306 /* Problem matrix*/ 315 /* Problem matrix*/
307 n_addresses = GNUNET_CONTAINER_multihashmap_size(addresses); 316 n_addresses = GNUNET_CONTAINER_multihashmap_size(addresses);
@@ -335,10 +344,17 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON
335 * #indices: 7 * |n_addresses| 344 * #indices: 7 * |n_addresses|
336 * 345 *
337 * optimality constraints: 346 * optimality constraints:
338 * tbc 347 *
348 * c 6) diversity
349 * #rows: 1
350 * #indices: |n_addresses| + 1
351 *
352 * c 7) quality
353 * #rows: |quality properties|
354 * #indices:|quality properties| + |n_addresses|
339 * */ 355 * */
340 356
341 int pi = (7 * n_addresses); 357 int pi = ((7 * n_addresses) /*+ (2 * n_addresses + mlp->m_q + 1)*/);
342 mlp->cm_size = pi; 358 mlp->cm_size = pi;
343 mlp->ci = 0; 359 mlp->ci = 0;
344 360
@@ -361,10 +377,27 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON
361 * c 1) bandwidth capping 377 * c 1) bandwidth capping
362 * c 3) minimum bandwidth 378 * c 3) minimum bandwidth
363 * c 4) minimum number of connections 379 * c 4) minimum number of connections
380 * c 6) maximize diversity
364 */ 381 */
365 mlp->r_c4 = glp_add_rows (mlp->prob, 1);
366 glp_set_row_bnds (mlp->prob, mlp->r_c4, GLP_LO, mlp->n_min, 0.0);
367 382
383 int min = mlp->n_min;
384 if (mlp->n_min > mlp->c_p)
385 min = mlp->c_p;
386/*
387 mlp->r_c4 = glp_add_rows (mlp->prob, 1);
388 glp_set_row_bnds (mlp->prob, mlp->r_c4, GLP_FX, min, min);
389*/
390 /* Add row for c6) */
391#if 0
392 mlp->r_c6 = glp_add_rows (mlp->prob, 1);
393 /* Set type type to fix */
394 glp_set_row_bnds (mlp->prob, mlp->r_c6, GLP_FX, 0.0, 0.0);
395 /* Setting -D */
396 ia[mlp->ci] = mlp->r_c6 ;
397 ja[mlp->ci] = mlp->c_d;
398 ar[mlp->ci] = -1;
399 mlp->ci++;
400#endif
368 GNUNET_CONTAINER_multihashmap_iterate (addresses, create_constraint_it, mlp); 401 GNUNET_CONTAINER_multihashmap_iterate (addresses, create_constraint_it, mlp);
369 402
370 /* Adding constraint rows 403 /* Adding constraint rows
@@ -374,7 +407,7 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON
374 * c 2) 1 address per peer 407 * c 2) 1 address per peer
375 * sum (n_p1_1 + ... + n_p1_n) = 1 408 * sum (n_p1_1 + ... + n_p1_n) = 1
376 */ 409 */
377 410return;
378 /* Adding rows for c 2) */ 411 /* Adding rows for c 2) */
379 row_index = glp_add_rows (mlp->prob, mlp->c_p); 412 row_index = glp_add_rows (mlp->prob, mlp->c_p);
380 413
@@ -396,9 +429,26 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON
396 429
397 addr = addr->next; 430 addr = addr->next;
398 } 431 }
399
400 peer = peer->next; 432 peer = peer->next;
401 } 433 }
434
435
436 /* For all quality metrics */
437/*
438 for (c = 0; c < mlp->m_q; c++)
439 {
440 struct ATS_Peer *p = mlp->peer_head;
441 while (p != NULL)
442 {
443 ia[mlp->ci] = row_index;
444 ja[mlp->ci] = mlp->c_q[c];
445 ar[mlp->ci] = mlp->;
446 mlp->ci++;
447
448 p = p->next;
449 }
450 }
451*/
402} 452}
403 453
404 454
@@ -428,6 +478,10 @@ create_columns_it (void *cls, const GNUNET_HashCode * key, void *value)
428 mlpi->c_b = col; 478 mlpi->c_b = col;
429 mlpi->c_n = col + 1; 479 mlpi->c_n = col + 1;
430 480
481 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
482 "ats-mlp",
483 "Culoumn %i %i\n", mlpi->c_b, mlpi->c_n);
484
431 GNUNET_asprintf (&name, "b_%s_%s", GNUNET_i2s (&address->peer), address->plugin); 485 GNUNET_asprintf (&name, "b_%s_%s", GNUNET_i2s (&address->peer), address->plugin);
432 glp_set_col_name (mlp->prob, mlpi->c_b , name); 486 glp_set_col_name (mlp->prob, mlpi->c_b , name);
433 GNUNET_free (name); 487 GNUNET_free (name);
@@ -438,6 +492,7 @@ create_columns_it (void *cls, const GNUNET_HashCode * key, void *value)
438 /* Objective function coefficient == 0 */ 492 /* Objective function coefficient == 0 */
439 glp_set_obj_coef (mlp->prob, mlpi->c_b , 0); 493 glp_set_obj_coef (mlp->prob, mlpi->c_b , 0);
440 494
495
441 /* Add usage column */ 496 /* Add usage column */
442 GNUNET_asprintf (&name, "n_%s_%s", GNUNET_i2s (&address->peer), address->plugin); 497 GNUNET_asprintf (&name, "n_%s_%s", GNUNET_i2s (&address->peer), address->plugin);
443 glp_set_col_name (mlp->prob, mlpi->c_n, name); 498 glp_set_col_name (mlp->prob, mlpi->c_n, name);
@@ -447,7 +502,7 @@ create_columns_it (void *cls, const GNUNET_HashCode * key, void *value)
447 /* Integer value*/ 502 /* Integer value*/
448 glp_set_col_kind (mlp->prob, mlpi->c_n, GLP_IV); 503 glp_set_col_kind (mlp->prob, mlpi->c_n, GLP_IV);
449 /* Objective function coefficient == 0 */ 504 /* Objective function coefficient == 0 */
450 glp_set_obj_coef (mlp->prob, mlpi->c_n, 0); 505 glp_set_obj_coef (mlp->prob, mlpi->c_n, 1);
451 506
452 return GNUNET_OK; 507 return GNUNET_OK;
453} 508}
@@ -464,10 +519,15 @@ static int
464mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses) 519mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses)
465{ 520{
466 int res = GNUNET_OK; 521 int res = GNUNET_OK;
522/*
467 int col; 523 int col;
468 int c; 524 int c;
469 char *name; 525 char *name;
526*/
527 GNUNET_assert (mlp->prob == NULL);
470 528
529 /* create the glpk problem */
530 mlp->prob = glp_create_prob ();
471 531
472 /* Set a problem name */ 532 /* Set a problem name */
473 glp_set_prob_name (mlp->prob, "gnunet ats bandwidth distribution"); 533 glp_set_prob_name (mlp->prob, "gnunet ats bandwidth distribution");
@@ -478,7 +538,7 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHas
478 /* Adding invariant columns */ 538 /* Adding invariant columns */
479 539
480 /* Diversity d column */ 540 /* Diversity d column */
481 541#if 0
482 col = glp_add_cols (mlp->prob, 1); 542 col = glp_add_cols (mlp->prob, 1);
483 mlp->c_d = col; 543 mlp->c_d = col;
484 /* Column name */ 544 /* Column name */
@@ -522,13 +582,16 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHas
522 /* Coefficient == Qm */ 582 /* Coefficient == Qm */
523 glp_set_obj_coef (mlp->prob, col + c, mlp->co_Q[c]); 583 glp_set_obj_coef (mlp->prob, col + c, mlp->co_Q[c]);
524 } 584 }
525 585#endif
526 /* Add columns for addresses */ 586 /* Add columns for addresses */
527 GNUNET_CONTAINER_multihashmap_iterate (addresses, create_columns_it, mlp); 587 GNUNET_CONTAINER_multihashmap_iterate (addresses, create_columns_it, mlp);
528 588
529 /* Add constraints */ 589 /* Add constraints */
530 mlp_add_constraints_all_addresses (mlp, addresses); 590 mlp_add_constraints_all_addresses (mlp, addresses);
531 591
592 /* Load the matrix */
593 glp_load_matrix(mlp->prob, (mlp->ci - 1), mlp->ia, mlp->ja, mlp->ar);
594
532 return res; 595 return res;
533} 596}
534 597
@@ -584,7 +647,7 @@ lp_solv:
584 /* Problem was ill-defined, no way to handle that */ 647 /* Problem was ill-defined, no way to handle that */
585 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 648 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
586 "ats-mlp", 649 "ats-mlp",
587 "Solving LP problem failed: %s\n", mlp_solve_to_string(res)); 650 "Solving LP problem failed: %i %s\n", res, mlp_solve_to_string(res));
588 return GNUNET_SYSERR; 651 return GNUNET_SYSERR;
589 } 652 }
590 } 653 }
@@ -727,10 +790,65 @@ mlp_solve_problem (struct GAS_MLP_Handle *mlp)
727{ 790{
728 int res; 791 int res;
729 mlp->last_execution = GNUNET_TIME_absolute_get (); 792 mlp->last_execution = GNUNET_TIME_absolute_get ();
793#if DEBUG_ATS
794 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Problem solving\n");
795#endif
796
797#if WRITE_MLP
798 char * name;
799 static int i;
800 i++;
801 GNUNET_asprintf(&name, "problem_%i", i);
802 glp_write_lp (mlp->prob, 0, name);
803 GNUNET_free (name);
804# endif
805
730 res = mlp_solve_lp_problem (mlp); 806 res = mlp_solve_lp_problem (mlp);
731 if (res == GNUNET_OK)
732 res = mlp_solve_mlp_problem (mlp);
733 807
808#if WRITE_MLP
809 GNUNET_asprintf(&name, "problem_%i_lp_solution", i);
810 glp_print_sol (mlp->prob, name);
811 GNUNET_free (name);
812# endif
813
814 if (res != GNUNET_OK)
815 {
816#if DEBUG_ATS
817 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "LP Problem solving failed\n");
818#endif
819 return GNUNET_SYSERR;
820 }
821
822 res = mlp_solve_mlp_problem (mlp);
823
824#if WRITE_MLP
825 GNUNET_asprintf(&name, "problem_%i_mlp_solution", i);
826 glp_print_mip (mlp->prob, name);
827 GNUNET_free (name);
828# endif
829
830
831 if (res != GNUNET_OK)
832 {
833#if DEBUG_ATS
834 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MLP Problem solving failed\n");
835#endif
836 return GNUNET_SYSERR;
837 }
838
839 res = glp_mip_status(mlp->prob);
840
841 if (res != GNUNET_OK)
842 {
843#if DEBUG_ATS
844 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "LP Problem solving failed\n");
845#endif
846 return GNUNET_SYSERR;
847 }
848
849#if DEBUG_ATS
850 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Problem solved: %i %s\n", res, mlp_status_to_string(res));
851#endif
734 852
735 /* Process result */ 853 /* Process result */
736 854
@@ -863,7 +981,7 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
863 981
864 /* Init LP solving parameters */ 982 /* Init LP solving parameters */
865 glp_init_smcp(&mlp->control_param_lp); 983 glp_init_smcp(&mlp->control_param_lp);
866#if DEBUG_MLP 984#if DEBUG_ATS
867 mlp->control_param_lp.msg_lev = GLP_MSG_ALL; 985 mlp->control_param_lp.msg_lev = GLP_MSG_ALL;
868#else 986#else
869 mlp->control_param_lp.msg_lev = GLP_MSG_OFF; 987 mlp->control_param_lp.msg_lev = GLP_MSG_OFF;
@@ -873,7 +991,7 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
873 991
874 /* Init MLP solving parameters */ 992 /* Init MLP solving parameters */
875 glp_init_iocp(&mlp->control_param_mlp); 993 glp_init_iocp(&mlp->control_param_mlp);
876#if DEBUG_MLP 994#if DEBUG_ATS
877 mlp->control_param_mlp.msg_lev = GLP_MSG_ALL; 995 mlp->control_param_mlp.msg_lev = GLP_MSG_ALL;
878#else 996#else
879 mlp->control_param_mlp.msg_lev = GLP_MSG_OFF; 997 mlp->control_param_mlp.msg_lev = GLP_MSG_OFF;
@@ -968,7 +1086,11 @@ GAS_mlp_address_update (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult
968 1086
969 /* Recalculate */ 1087 /* Recalculate */
970 if (new == GNUNET_YES) 1088 if (new == GNUNET_YES)
1089 {
1090 mlp_delete_problem (mlp);
1091 mlp_create_problem (mlp, addresses);
971 mlp->presolver_required = GNUNET_YES; 1092 mlp->presolver_required = GNUNET_YES;
1093 }
972 mlp_solve_problem (mlp); 1094 mlp_solve_problem (mlp);
973} 1095}
974 1096
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.h b/src/ats/gnunet-service-ats_addresses_mlp.h
index 4d55ff6e1..f41553940 100644
--- a/src/ats/gnunet-service-ats_addresses_mlp.h
+++ b/src/ats/gnunet-service-ats_addresses_mlp.h
@@ -34,7 +34,6 @@
34#ifndef GNUNET_SERVICE_ATS_ADDRESSES_MLP_H 34#ifndef GNUNET_SERVICE_ATS_ADDRESSES_MLP_H
35#define GNUNET_SERVICE_ATS_ADDRESSES_MLP_H 35#define GNUNET_SERVICE_ATS_ADDRESSES_MLP_H
36 36
37#define VERBOSE GNUNET_EXTRA_LOGGING
38#define DEBUG_MLP GNUNET_EXTRA_LOGGING 37#define DEBUG_MLP GNUNET_EXTRA_LOGGING
39 38
40#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)
@@ -168,6 +167,8 @@ struct GAS_MLP_Handle
168 167
169 /* Row index constraint 4: minimum connections */ 168 /* Row index constraint 4: minimum connections */
170 unsigned int r_c4; 169 unsigned int r_c4;
170 /* Row index constraint 6: maximize diversity */
171 unsigned int r_c6;
171 172
172 /* column index Diversity (D) column */ 173 /* column index Diversity (D) column */
173 int c_d; 174 int c_d;