diff options
Diffstat (limited to 'src/ats/gnunet-service-ats_addresses_mlp.c')
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.c | 51 |
1 files changed, 36 insertions, 15 deletions
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c index 17b4697d4..fa4d3a106 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.c +++ b/src/ats/gnunet-service-ats_addresses_mlp.c | |||
@@ -32,7 +32,7 @@ | |||
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_YES | 35 | #define DEBUG_ATS GNUNET_NO |
36 | #define VERBOSE_GLPK GNUNET_NO | 36 | #define VERBOSE_GLPK GNUNET_NO |
37 | 37 | ||
38 | /** | 38 | /** |
@@ -314,7 +314,7 @@ static void | |||
314 | 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) |
315 | { | 315 | { |
316 | unsigned int n_addresses; | 316 | unsigned int n_addresses; |
317 | //int c; | 317 | int c; |
318 | char *name; | 318 | char *name; |
319 | 319 | ||
320 | /* Problem matrix*/ | 320 | /* Problem matrix*/ |
@@ -356,7 +356,7 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON | |||
356 | * | 356 | * |
357 | * c 7) quality | 357 | * c 7) quality |
358 | * #rows: |quality properties| | 358 | * #rows: |quality properties| |
359 | * #indices:|quality properties| + |n_addresses| | 359 | * #indices: |n_addresses| + |quality properties| |
360 | * | 360 | * |
361 | * c 8) utilization | 361 | * c 8) utilization |
362 | * #rows: 1 | 362 | * #rows: 1 |
@@ -367,7 +367,8 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON | |||
367 | * #indices: |n_addresses| + |peers| | 367 | * #indices: |n_addresses| + |peers| |
368 | * */ | 368 | * */ |
369 | 369 | ||
370 | int pi = ((7 * n_addresses) + (3 * n_addresses + mlp->m_q + 2)); | 370 | /* last +1 caused by glpk index starting with one */ |
371 | int pi = ((7 * n_addresses) + (4 * n_addresses + mlp->m_q + mlp->c_p + 2) + 1); | ||
371 | mlp->cm_size = pi; | 372 | mlp->cm_size = pi; |
372 | mlp->ci = 1; | 373 | mlp->ci = 1; |
373 | 374 | ||
@@ -453,7 +454,6 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON | |||
453 | /* Set row bound == 1 */ | 454 | /* Set row bound == 1 */ |
454 | glp_set_row_bnds (mlp->prob, peer->r_c2, GLP_FX, 1.0, 1.0); | 455 | glp_set_row_bnds (mlp->prob, peer->r_c2, GLP_FX, 1.0, 1.0); |
455 | 456 | ||
456 | |||
457 | /* Adding rows for c 9) */ | 457 | /* Adding rows for c 9) */ |
458 | peer->r_c9 = glp_add_rows (mlp->prob, 1); | 458 | peer->r_c9 = glp_add_rows (mlp->prob, 1); |
459 | GNUNET_asprintf(&name, "c9_%s", GNUNET_i2s(&peer->id)); | 459 | GNUNET_asprintf(&name, "c9_%s", GNUNET_i2s(&peer->id)); |
@@ -492,23 +492,44 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON | |||
492 | peer = peer->next; | 492 | peer = peer->next; |
493 | } | 493 | } |
494 | 494 | ||
495 | /* c 7) For all quality metrics */ | ||
495 | 496 | ||
496 | /* For all quality metrics */ | ||
497 | /* | ||
498 | for (c = 0; c < mlp->m_q; c++) | 497 | for (c = 0; c < mlp->m_q; c++) |
499 | { | 498 | { |
500 | struct ATS_Peer *p = mlp->peer_head; | 499 | struct ATS_Peer *p = mlp->peer_head; |
500 | struct ATS_Address *addr = p->head; | ||
501 | struct MLP_information * mlpi; | ||
502 | double value = 1.0; | ||
503 | |||
501 | while (p != NULL) | 504 | while (p != NULL) |
502 | { | 505 | { |
503 | ia[mlp->ci] = row_index; | 506 | /* Adding rows for c 7) */ |
507 | mlp->r_q[c] = glp_add_rows (mlp->prob, 1); | ||
508 | GNUNET_asprintf(&name, "c7_q%i_atsi_%i", c, mlp->q[c]); | ||
509 | glp_set_row_name (mlp->prob, mlp->r_q[c], name); | ||
510 | GNUNET_free (name); | ||
511 | /* Set row bound == 0 */ | ||
512 | glp_set_row_bnds (mlp->prob, mlp->r_q[c], GLP_LO, 0.0, 0.0); | ||
513 | |||
514 | /* Set -q_m */ | ||
515 | ia[mlp->ci] = mlp->r_q[c]; | ||
504 | ja[mlp->ci] = mlp->c_q[c]; | 516 | ja[mlp->ci] = mlp->c_q[c]; |
505 | ar[mlp->ci] = mlp->; | 517 | ar[mlp->ci] = -1; |
506 | mlp->ci++; | 518 | mlp->ci++; |
507 | 519 | ||
520 | while (addr != NULL) | ||
521 | { | ||
522 | mlpi = addr->mlp_information; | ||
523 | ia[mlp->ci] = mlp->r_q[c]; | ||
524 | ja[mlp->ci] = mlpi->c_b; | ||
525 | ar[mlp->ci] = p->f * value; | ||
526 | mlp->ci++; | ||
527 | |||
528 | addr = addr->next; | ||
529 | } | ||
508 | p = p->next; | 530 | p = p->next; |
509 | } | 531 | } |
510 | } | 532 | } |
511 | */ | ||
512 | } | 533 | } |
513 | 534 | ||
514 | 535 | ||
@@ -575,12 +596,10 @@ static int | |||
575 | mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses) | 596 | mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses) |
576 | { | 597 | { |
577 | int res = GNUNET_OK; | 598 | int res = GNUNET_OK; |
578 | |||
579 | int col; | 599 | int col; |
580 | /* | ||
581 | int c; | 600 | int c; |
582 | char *name; | 601 | char *name; |
583 | */ | 602 | |
584 | GNUNET_assert (mlp->prob == NULL); | 603 | GNUNET_assert (mlp->prob == NULL); |
585 | 604 | ||
586 | /* create the glpk problem */ | 605 | /* create the glpk problem */ |
@@ -625,7 +644,7 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHas | |||
625 | glp_set_obj_coef (mlp->prob, col, mlp->co_R); | 644 | glp_set_obj_coef (mlp->prob, col, mlp->co_R); |
626 | /* Column lower bound = 0.0 */ | 645 | /* Column lower bound = 0.0 */ |
627 | glp_set_col_bnds (mlp->prob, col, GLP_LO, 0.0, 0.0); | 646 | glp_set_col_bnds (mlp->prob, col, GLP_LO, 0.0, 0.0); |
628 | #if 0 | 647 | |
629 | /* Quality metric columns */ | 648 | /* Quality metric columns */ |
630 | col = glp_add_cols(mlp->prob, mlp->m_q); | 649 | col = glp_add_cols(mlp->prob, mlp->m_q); |
631 | for (c = 0; c < mlp->m_q; c++) | 650 | for (c = 0; c < mlp->m_q; c++) |
@@ -639,7 +658,7 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHas | |||
639 | /* Coefficient == Qm */ | 658 | /* Coefficient == Qm */ |
640 | glp_set_obj_coef (mlp->prob, col + c, mlp->co_Q[c]); | 659 | glp_set_obj_coef (mlp->prob, col + c, mlp->co_Q[c]); |
641 | } | 660 | } |
642 | #endif | 661 | |
643 | /* Add columns for addresses */ | 662 | /* Add columns for addresses */ |
644 | GNUNET_CONTAINER_multihashmap_iterate (addresses, create_columns_it, mlp); | 663 | GNUNET_CONTAINER_multihashmap_iterate (addresses, create_columns_it, mlp); |
645 | 664 | ||
@@ -1130,6 +1149,8 @@ GAS_mlp_address_update (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult | |||
1130 | #if DEBUG_ATS | 1149 | #if DEBUG_ATS |
1131 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updating existing address to peer `%s'\n", GNUNET_i2s (&address->peer)); | 1150 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updating existing address to peer `%s'\n", GNUNET_i2s (&address->peer)); |
1132 | #endif | 1151 | #endif |
1152 | mlpi = address->mlp_information; | ||
1153 | |||
1133 | } | 1154 | } |
1134 | 1155 | ||
1135 | /* Recalculate */ | 1156 | /* Recalculate */ |