diff options
Diffstat (limited to 'src/ats/gnunet-service-ats_addresses_mlp.c')
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.c | 82 |
1 files changed, 67 insertions, 15 deletions
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c index badad5588..17b4697d4 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.c +++ b/src/ats/gnunet-service-ats_addresses_mlp.c | |||
@@ -32,7 +32,8 @@ | |||
32 | #include "glpk.h" | 32 | #include "glpk.h" |
33 | 33 | ||
34 | #define WRITE_MLP GNUNET_NO | 34 | #define WRITE_MLP GNUNET_NO |
35 | #define DEBUG_ATS GNUNET_EXTRA_LOGGING | 35 | #define DEBUG_ATS GNUNET_YES |
36 | #define VERBOSE_GLPK GNUNET_NO | ||
36 | 37 | ||
37 | /** | 38 | /** |
38 | * Translate glpk solver error codes to text | 39 | * Translate glpk solver error codes to text |
@@ -313,7 +314,6 @@ static void | |||
313 | mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses) | 314 | mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses) |
314 | { | 315 | { |
315 | unsigned int n_addresses; | 316 | unsigned int n_addresses; |
316 | int row_index; | ||
317 | //int c; | 317 | //int c; |
318 | char *name; | 318 | char *name; |
319 | 319 | ||
@@ -357,9 +357,17 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON | |||
357 | * c 7) quality | 357 | * c 7) quality |
358 | * #rows: |quality properties| | 358 | * #rows: |quality properties| |
359 | * #indices:|quality properties| + |n_addresses| | 359 | * #indices:|quality properties| + |n_addresses| |
360 | * | ||
361 | * c 8) utilization | ||
362 | * #rows: 1 | ||
363 | * #indices: |n_addresses| + 1 | ||
364 | * | ||
365 | * c 9) relativity | ||
366 | * #rows: |peers| | ||
367 | * #indices: |n_addresses| + |peers| | ||
360 | * */ | 368 | * */ |
361 | 369 | ||
362 | int pi = ((7 * n_addresses) + (2 * n_addresses + mlp->m_q + 1)); | 370 | int pi = ((7 * n_addresses) + (3 * n_addresses + mlp->m_q + 2)); |
363 | mlp->cm_size = pi; | 371 | mlp->cm_size = pi; |
364 | mlp->ci = 1; | 372 | mlp->ci = 1; |
365 | 373 | ||
@@ -412,30 +420,73 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON | |||
412 | * | 420 | * |
413 | * c 2) 1 address per peer | 421 | * c 2) 1 address per peer |
414 | * sum (n_p1_1 + ... + n_p1_n) = 1 | 422 | * sum (n_p1_1 + ... + n_p1_n) = 1 |
415 | */ | 423 | * |
424 | * c 8) utilization | ||
425 | * sum (f_p * b_p1_1 + ... + f_p * b_p1_n) - u = 0 | ||
426 | * | ||
427 | * c 9) relativity | ||
428 | * V p : sum (bt_1 + ... +bt_n) - f_p * r = 0 | ||
429 | * */ | ||
416 | 430 | ||
417 | /* Adding rows for c 2) */ | 431 | /* Adding rows for c 8) */ |
418 | row_index = glp_add_rows (mlp->prob, mlp->c_p); | 432 | mlp->r_c8 = glp_add_rows (mlp->prob, mlp->c_p); |
433 | glp_set_row_name (mlp->prob, mlp->r_c8, "c8"); | ||
434 | /* Set row bound == 0 */ | ||
435 | glp_set_row_bnds (mlp->prob, mlp->r_c8, GLP_FX, 0.0, 0.0); | ||
436 | /* -u */ | ||
437 | ia[mlp->ci] = mlp->r_c8; | ||
438 | ja[mlp->ci] = mlp->c_u; | ||
439 | ar[mlp->ci] = -1; | ||
440 | mlp->ci++; | ||
419 | 441 | ||
420 | struct ATS_Peer * peer = mlp->peer_head; | 442 | struct ATS_Peer * peer = mlp->peer_head; |
421 | while (peer != NULL) | 443 | while (peer != NULL) |
422 | { | 444 | { |
423 | struct ATS_Address *addr = peer->head; | 445 | struct ATS_Address *addr = peer->head; |
424 | struct MLP_information *mlpi = NULL; | 446 | struct MLP_information *mlpi = NULL; |
425 | /* Adding row for c 2) */ | 447 | |
448 | /* Adding rows for c 2) */ | ||
449 | peer->r_c2 = glp_add_rows (mlp->prob, 1); | ||
426 | GNUNET_asprintf(&name, "c2_%s", GNUNET_i2s(&peer->id)); | 450 | GNUNET_asprintf(&name, "c2_%s", GNUNET_i2s(&peer->id)); |
427 | glp_set_row_name (mlp->prob, row_index, name); | 451 | glp_set_row_name (mlp->prob, peer->r_c2, name); |
428 | GNUNET_free (name); | 452 | GNUNET_free (name); |
429 | /* Set row bound == 1 */ | 453 | /* Set row bound == 1 */ |
430 | glp_set_row_bnds (mlp->prob, row_index, GLP_FX, 1.0, 1.0); | 454 | glp_set_row_bnds (mlp->prob, peer->r_c2, GLP_FX, 1.0, 1.0); |
455 | |||
456 | |||
457 | /* Adding rows for c 9) */ | ||
458 | peer->r_c9 = glp_add_rows (mlp->prob, 1); | ||
459 | GNUNET_asprintf(&name, "c9_%s", GNUNET_i2s(&peer->id)); | ||
460 | glp_set_row_name (mlp->prob, peer->r_c9, name); | ||
461 | GNUNET_free (name); | ||
462 | /* Set row bound == 0 */ | ||
463 | glp_set_row_bnds (mlp->prob, peer->r_c9, GLP_LO, 0.0, 0.0); | ||
464 | |||
465 | /* Set -r */ | ||
466 | ia[mlp->ci] = peer->r_c9; | ||
467 | ja[mlp->ci] = mlp->c_r; | ||
468 | ar[mlp->ci] = -1; | ||
469 | mlp->ci++; | ||
431 | 470 | ||
432 | while (addr != NULL) | 471 | while (addr != NULL) |
433 | { | 472 | { |
434 | mlpi = (struct MLP_information *) addr->mlp_information; | 473 | mlpi = (struct MLP_information *) addr->mlp_information; |
435 | ia[mlp->ci] = row_index; | 474 | |
475 | ia[mlp->ci] = peer->r_c2; | ||
436 | ja[mlp->ci] = mlpi->c_n; | 476 | ja[mlp->ci] = mlpi->c_n; |
437 | ar[mlp->ci] = 1; | 477 | ar[mlp->ci] = 1; |
438 | mlp->ci++; | 478 | mlp->ci++; |
479 | |||
480 | ia[mlp->ci] = mlp->r_c8; | ||
481 | ja[mlp->ci] = mlpi->c_b; | ||
482 | ar[mlp->ci] = peer->f; | ||
483 | mlp->ci++; | ||
484 | |||
485 | ia[mlp->ci] = peer->r_c9; | ||
486 | ja[mlp->ci] = mlpi->c_b; | ||
487 | ar[mlp->ci] = 1; | ||
488 | mlp->ci++; | ||
489 | |||
439 | addr = addr->next; | 490 | addr = addr->next; |
440 | } | 491 | } |
441 | peer = peer->next; | 492 | peer = peer->next; |
@@ -553,7 +604,7 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHas | |||
553 | glp_set_obj_coef (mlp->prob, col, mlp->co_D); | 604 | glp_set_obj_coef (mlp->prob, col, mlp->co_D); |
554 | /* Column lower bound = 0.0 */ | 605 | /* Column lower bound = 0.0 */ |
555 | glp_set_col_bnds (mlp->prob, col, GLP_LO, 0.0, 0.0); | 606 | glp_set_col_bnds (mlp->prob, col, GLP_LO, 0.0, 0.0); |
556 | #if 0 | 607 | |
557 | /* Utilization u column */ | 608 | /* Utilization u column */ |
558 | 609 | ||
559 | col = glp_add_cols (mlp->prob, 1); | 610 | col = glp_add_cols (mlp->prob, 1); |
@@ -574,7 +625,7 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHas | |||
574 | glp_set_obj_coef (mlp->prob, col, mlp->co_R); | 625 | glp_set_obj_coef (mlp->prob, col, mlp->co_R); |
575 | /* Column lower bound = 0.0 */ | 626 | /* Column lower bound = 0.0 */ |
576 | glp_set_col_bnds (mlp->prob, col, GLP_LO, 0.0, 0.0); | 627 | glp_set_col_bnds (mlp->prob, col, GLP_LO, 0.0, 0.0); |
577 | 628 | #if 0 | |
578 | /* Quality metric columns */ | 629 | /* Quality metric columns */ |
579 | col = glp_add_cols(mlp->prob, mlp->m_q); | 630 | col = glp_add_cols(mlp->prob, mlp->m_q); |
580 | for (c = 0; c < mlp->m_q; c++) | 631 | for (c = 0; c < mlp->m_q; c++) |
@@ -841,7 +892,7 @@ mlp_solve_problem (struct GAS_MLP_Handle *mlp) | |||
841 | } | 892 | } |
842 | 893 | ||
843 | #if DEBUG_ATS | 894 | #if DEBUG_ATS |
844 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Problem solved: %i %s\n", res, mlp_status_to_string(res)); | 895 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Problem solved\n"); |
845 | #endif | 896 | #endif |
846 | 897 | ||
847 | /* Process result */ | 898 | /* Process result */ |
@@ -975,7 +1026,7 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
975 | 1026 | ||
976 | /* Init LP solving parameters */ | 1027 | /* Init LP solving parameters */ |
977 | glp_init_smcp(&mlp->control_param_lp); | 1028 | glp_init_smcp(&mlp->control_param_lp); |
978 | #if DEBUG_ATS | 1029 | #if VERBOSE_GLPK |
979 | mlp->control_param_lp.msg_lev = GLP_MSG_ALL; | 1030 | mlp->control_param_lp.msg_lev = GLP_MSG_ALL; |
980 | #else | 1031 | #else |
981 | mlp->control_param_lp.msg_lev = GLP_MSG_OFF; | 1032 | mlp->control_param_lp.msg_lev = GLP_MSG_OFF; |
@@ -985,7 +1036,7 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
985 | 1036 | ||
986 | /* Init MLP solving parameters */ | 1037 | /* Init MLP solving parameters */ |
987 | glp_init_iocp(&mlp->control_param_mlp); | 1038 | glp_init_iocp(&mlp->control_param_mlp); |
988 | #if DEBUG_ATS | 1039 | #if VERBOSE_GLPK |
989 | mlp->control_param_mlp.msg_lev = GLP_MSG_ALL; | 1040 | mlp->control_param_mlp.msg_lev = GLP_MSG_ALL; |
990 | #else | 1041 | #else |
991 | mlp->control_param_mlp.msg_lev = GLP_MSG_OFF; | 1042 | mlp->control_param_mlp.msg_lev = GLP_MSG_OFF; |
@@ -1057,6 +1108,7 @@ GAS_mlp_address_update (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult | |||
1057 | { | 1108 | { |
1058 | peer->f_q[c] = 1.0; | 1109 | peer->f_q[c] = 1.0; |
1059 | } | 1110 | } |
1111 | peer->f = 1.0; | ||
1060 | 1112 | ||
1061 | memcpy (&peer->id, &address->peer, sizeof (struct GNUNET_PeerIdentity)); | 1113 | memcpy (&peer->id, &address->peer, sizeof (struct GNUNET_PeerIdentity)); |
1062 | GNUNET_assert(address->prev == NULL); | 1114 | GNUNET_assert(address->prev == NULL); |