diff options
Diffstat (limited to 'src/ats')
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.c | 133 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.h | 2 | ||||
-rw-r--r-- | src/ats/test_ats_mlp.c | 1 |
3 files changed, 93 insertions, 43 deletions
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c index b5f0bed8e..c7b1ee75c 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.c +++ b/src/ats/gnunet-service-ats_addresses_mlp.c | |||
@@ -34,8 +34,7 @@ | |||
34 | #endif | 34 | #endif |
35 | #include "float.h" | 35 | #include "float.h" |
36 | 36 | ||
37 | #define DEBUG_ATS GNUNET_NO | 37 | #define DEBUG_ATS GNUNET_YES |
38 | |||
39 | /* A very big value */ | 38 | /* A very big value */ |
40 | #define M DBL_MAX | 39 | #define M DBL_MAX |
41 | 40 | ||
@@ -175,19 +174,31 @@ mlp_delete_problem (struct GAS_MLP_Handle *mlp) | |||
175 | { | 174 | { |
176 | if (mlp != NULL) | 175 | if (mlp != NULL) |
177 | { | 176 | { |
178 | glp_delete_prob(mlp->prob); | 177 | if (mlp->prob != NULL) |
178 | glp_delete_prob(mlp->prob); | ||
179 | 179 | ||
180 | /* delete row index */ | 180 | /* delete row index */ |
181 | if (mlp->ia != NULL) | 181 | if (mlp->ia != NULL) |
182 | { | ||
182 | GNUNET_free (mlp->ia); | 183 | GNUNET_free (mlp->ia); |
184 | mlp->ja = NULL; | ||
185 | } | ||
183 | 186 | ||
184 | /* delete column index */ | 187 | /* delete column index */ |
185 | if (mlp->ja != NULL) | 188 | if (mlp->ja != NULL) |
189 | { | ||
186 | GNUNET_free (mlp->ja); | 190 | GNUNET_free (mlp->ja); |
191 | mlp->ja = NULL; | ||
192 | } | ||
187 | 193 | ||
188 | /* delete coefficients */ | 194 | /* delete coefficients */ |
189 | if (mlp->ar != NULL) | 195 | if (mlp->ar != NULL) |
196 | { | ||
190 | GNUNET_free (mlp->ar); | 197 | GNUNET_free (mlp->ar); |
198 | mlp->ar = NULL; | ||
199 | } | ||
200 | mlp->ci = 0; | ||
201 | mlp->prob = NULL; | ||
191 | } | 202 | } |
192 | } | 203 | } |
193 | 204 | ||
@@ -372,6 +383,59 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON | |||
372 | } | 383 | } |
373 | } | 384 | } |
374 | 385 | ||
386 | |||
387 | /** | ||
388 | * Add columns for all addresses | ||
389 | * | ||
390 | * @param cls GAS_MLP_Handle | ||
391 | * @param key Hashcode | ||
392 | * @param value ATS_Address | ||
393 | * | ||
394 | * @return GNUNET_OK to continue | ||
395 | */ | ||
396 | static int | ||
397 | create_columns_it (void *cls, const GNUNET_HashCode * key, void *value) | ||
398 | { | ||
399 | struct GAS_MLP_Handle *mlp = cls; | ||
400 | struct ATS_Address *address = value; | ||
401 | struct MLP_information *mlpi; | ||
402 | unsigned int col; | ||
403 | char *name; | ||
404 | |||
405 | GNUNET_assert (address->mlp_information != NULL); | ||
406 | mlpi = address->mlp_information; | ||
407 | |||
408 | /* Add bandwidth column */ | ||
409 | col = glp_add_cols (mlp->prob, 2); | ||
410 | mlpi->c_b = col; | ||
411 | mlpi->c_n = col + 1; | ||
412 | |||
413 | GNUNET_asprintf (&name, "b_%s_%s", GNUNET_i2s (&address->peer), address->plugin); | ||
414 | glp_set_col_name (mlp->prob, mlpi->c_b , name); | ||
415 | GNUNET_free (name); | ||
416 | /* Lower bound == 0 */ | ||
417 | glp_set_col_bnds (mlp->prob, mlpi->c_b , GLP_LO, 0.0, 0.0); | ||
418 | /* Continuous value*/ | ||
419 | glp_set_col_kind (mlp->prob, mlpi->c_b , GLP_CV); | ||
420 | /* Objective function coefficient == 0 */ | ||
421 | glp_set_obj_coef (mlp->prob, mlpi->c_b , 0); | ||
422 | |||
423 | /* Add usage column */ | ||
424 | GNUNET_asprintf (&name, "n_%s_%s", GNUNET_i2s (&address->peer), address->plugin); | ||
425 | glp_set_col_name (mlp->prob, mlpi->c_n, name); | ||
426 | GNUNET_free (name); | ||
427 | /* Limit value : 0 <= value <= 1 */ | ||
428 | glp_set_col_bnds (mlp->prob, mlpi->c_n, GLP_DB, 0.0, 1.0); | ||
429 | /* Integer value*/ | ||
430 | glp_set_col_kind (mlp->prob, mlpi->c_n, GLP_IV); | ||
431 | /* Objective function coefficient == 0 */ | ||
432 | glp_set_obj_coef (mlp->prob, mlpi->c_n, 0); | ||
433 | |||
434 | return GNUNET_OK; | ||
435 | } | ||
436 | |||
437 | |||
438 | |||
375 | /** | 439 | /** |
376 | * Create the MLP problem | 440 | * Create the MLP problem |
377 | * | 441 | * |
@@ -441,7 +505,11 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHas | |||
441 | glp_set_obj_coef (mlp->prob, col + c, mlp->co_Q[c]); | 505 | glp_set_obj_coef (mlp->prob, col + c, mlp->co_Q[c]); |
442 | } | 506 | } |
443 | 507 | ||
444 | /* Add columns for existing addresses */ | 508 | /* Add columns for addresses */ |
509 | GNUNET_CONTAINER_multihashmap_iterate (addresses, create_columns_it, mlp); | ||
510 | |||
511 | /* Add constraints */ | ||
512 | mlp_add_constraints_all_addresses (mlp, addresses); | ||
445 | 513 | ||
446 | return res; | 514 | return res; |
447 | } | 515 | } |
@@ -644,6 +712,10 @@ mlp_solve_problem (struct GAS_MLP_Handle *mlp) | |||
644 | res = mlp_solve_lp_problem (mlp); | 712 | res = mlp_solve_lp_problem (mlp); |
645 | if (res == GNUNET_OK) | 713 | if (res == GNUNET_OK) |
646 | res = mlp_solve_mlp_problem (mlp); | 714 | res = mlp_solve_mlp_problem (mlp); |
715 | |||
716 | |||
717 | /* Process result */ | ||
718 | |||
647 | if (mlp->mlp_task != GNUNET_SCHEDULER_NO_TASK) | 719 | if (mlp->mlp_task != GNUNET_SCHEDULER_NO_TASK) |
648 | { | 720 | { |
649 | GNUNET_SCHEDULER_cancel(mlp->mlp_task); | 721 | GNUNET_SCHEDULER_cancel(mlp->mlp_task); |
@@ -813,15 +885,14 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
813 | * | 885 | * |
814 | * @param mlp the MLP Handle | 886 | * @param mlp the MLP Handle |
815 | * @param addresses the address hashmap | 887 | * @param addresses the address hashmap |
888 | * the address has to be already removed from the hashmap | ||
816 | * @param address the address to update | 889 | * @param address the address to update |
817 | */ | 890 | */ |
818 | void | 891 | void |
819 | GAS_mlp_address_update (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address) | 892 | GAS_mlp_address_update (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address) |
820 | { | 893 | { |
821 | int new; | 894 | int new; |
822 | int col; | ||
823 | struct MLP_information *mlpi; | 895 | struct MLP_information *mlpi; |
824 | char * name; | ||
825 | 896 | ||
826 | GNUNET_STATISTICS_update (mlp->stats,"# LP address updates", 1, GNUNET_NO); | 897 | GNUNET_STATISTICS_update (mlp->stats,"# LP address updates", 1, GNUNET_NO); |
827 | 898 | ||
@@ -831,12 +902,6 @@ GAS_mlp_address_update (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult | |||
831 | else | 902 | else |
832 | new = GNUNET_NO; | 903 | new = GNUNET_NO; |
833 | 904 | ||
834 | if (mlp->prob == NULL) | ||
835 | { | ||
836 | mlp_create_problem(mlp, addresses); | ||
837 | mlp_add_constraints_all_addresses (mlp, addresses); | ||
838 | } | ||
839 | |||
840 | /* Do the update */ | 905 | /* Do the update */ |
841 | if (new == GNUNET_YES) | 906 | if (new == GNUNET_YES) |
842 | { | 907 | { |
@@ -874,33 +939,6 @@ GAS_mlp_address_update (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult | |||
874 | #endif | 939 | #endif |
875 | GNUNET_CONTAINER_DLL_insert (peer->head, peer->tail, address); | 940 | GNUNET_CONTAINER_DLL_insert (peer->head, peer->tail, address); |
876 | } | 941 | } |
877 | |||
878 | |||
879 | /* Add bandwidth column */ | ||
880 | col = glp_add_cols (mlp->prob, 2); | ||
881 | mlpi->c_b = col; | ||
882 | mlpi->c_n = col + 1; | ||
883 | |||
884 | GNUNET_asprintf (&name, "b_%s_%s", GNUNET_i2s (&address->peer), address->plugin); | ||
885 | glp_set_col_name (mlp->prob, mlpi->c_b , name); | ||
886 | GNUNET_free (name); | ||
887 | /* Lower bound == 0 */ | ||
888 | glp_set_col_bnds (mlp->prob, mlpi->c_b , GLP_LO, 0.0, 0.0); | ||
889 | /* Continuous value*/ | ||
890 | glp_set_col_kind (mlp->prob, mlpi->c_b , GLP_CV); | ||
891 | /* Objective function coefficient == 0 */ | ||
892 | glp_set_obj_coef (mlp->prob, mlpi->c_b , 0); | ||
893 | |||
894 | /* Add usage column */ | ||
895 | GNUNET_asprintf (&name, "n_%s_%s", GNUNET_i2s (&address->peer), address->plugin); | ||
896 | glp_set_col_name (mlp->prob, mlpi->c_n, name); | ||
897 | GNUNET_free (name); | ||
898 | /* Limit value : 0 <= value <= 1 */ | ||
899 | glp_set_col_bnds (mlp->prob, mlpi->c_n, GLP_DB, 0.0, 1.0); | ||
900 | /* Integer value*/ | ||
901 | glp_set_col_kind (mlp->prob, mlpi->c_n, GLP_IV); | ||
902 | /* Objective function coefficient == 0 */ | ||
903 | glp_set_obj_coef (mlp->prob, mlpi->c_n, 0); | ||
904 | } | 942 | } |
905 | else | 943 | else |
906 | { | 944 | { |
@@ -922,6 +960,7 @@ GAS_mlp_address_update (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult | |||
922 | * | 960 | * |
923 | * @param mlp the MLP Handle | 961 | * @param mlp the MLP Handle |
924 | * @param addresses the address hashmap | 962 | * @param addresses the address hashmap |
963 | * the address has to be already removed from the hashmap | ||
925 | * @param address the address to delete | 964 | * @param address the address to delete |
926 | */ | 965 | */ |
927 | void | 966 | void |
@@ -951,7 +990,6 @@ GAS_mlp_address_delete (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult | |||
951 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Deleting address for `%s'\n", GNUNET_i2s (&address->peer)); | 990 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Deleting address for `%s'\n", GNUNET_i2s (&address->peer)); |
952 | #endif | 991 | #endif |
953 | GNUNET_CONTAINER_DLL_remove (head->head, head->tail, address); | 992 | GNUNET_CONTAINER_DLL_remove (head->head, head->tail, address); |
954 | mlp->c_p --; | ||
955 | if ((head->head == NULL) && (head->tail == NULL)) | 993 | if ((head->head == NULL) && (head->tail == NULL)) |
956 | { | 994 | { |
957 | /* No address for peer left, remove peer */ | 995 | /* No address for peer left, remove peer */ |
@@ -960,13 +998,22 @@ GAS_mlp_address_delete (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult | |||
960 | #endif | 998 | #endif |
961 | GNUNET_CONTAINER_DLL_remove (mlp->peer_head, mlp->peer_tail, head); | 999 | GNUNET_CONTAINER_DLL_remove (mlp->peer_head, mlp->peer_tail, head); |
962 | GNUNET_free (head); | 1000 | GNUNET_free (head); |
1001 | mlp->c_p --; | ||
963 | } | 1002 | } |
964 | 1003 | ||
965 | /* Update problem */ | 1004 | /* Update problem */ |
1005 | mlp_delete_problem (mlp); | ||
1006 | if ((GNUNET_CONTAINER_multihashmap_size (addresses) > 0) && (mlp->c_p > 0)) | ||
1007 | { | ||
1008 | #if DEBUG_ATS | ||
1009 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "mlp_create_problem %i\n",__LINE__); | ||
1010 | #endif | ||
1011 | mlp_create_problem (mlp, addresses); | ||
966 | 1012 | ||
967 | /* Recalculate */ | 1013 | /* Recalculate */ |
968 | mlp->presolver_required = GNUNET_YES; | 1014 | mlp->presolver_required = GNUNET_YES; |
969 | mlp_solve_problem (mlp); | 1015 | mlp_solve_problem (mlp); |
1016 | } | ||
970 | } | 1017 | } |
971 | 1018 | ||
972 | /** | 1019 | /** |
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.h b/src/ats/gnunet-service-ats_addresses_mlp.h index f410339eb..dd26aa837 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.h +++ b/src/ats/gnunet-service-ats_addresses_mlp.h | |||
@@ -248,6 +248,7 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
248 | * | 248 | * |
249 | * @param mlp the MLP Handle | 249 | * @param mlp the MLP Handle |
250 | * @param addresses the address hashmap | 250 | * @param addresses the address hashmap |
251 | * the address has to be already added from the hashmap | ||
251 | * @param address the address to update | 252 | * @param address the address to update |
252 | */ | 253 | */ |
253 | void | 254 | void |
@@ -261,6 +262,7 @@ GAS_mlp_address_update (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult | |||
261 | * | 262 | * |
262 | * @param mlp the MLP Handle | 263 | * @param mlp the MLP Handle |
263 | * @param addresses the address hashmap | 264 | * @param addresses the address hashmap |
265 | * the address has to be already removed from the hashmap | ||
264 | * @param address the address to delete | 266 | * @param address the address to delete |
265 | */ | 267 | */ |
266 | void | 268 | void |
diff --git a/src/ats/test_ats_mlp.c b/src/ats/test_ats_mlp.c index 94009ee4e..b265c4bd7 100644 --- a/src/ats/test_ats_mlp.c +++ b/src/ats/test_ats_mlp.c | |||
@@ -79,6 +79,7 @@ check (void *cls, char *const *args, const char *cfgfile, | |||
79 | GNUNET_assert (mlp->addr_in_problem == 1); | 79 | GNUNET_assert (mlp->addr_in_problem == 1); |
80 | 80 | ||
81 | /* Delete an address */ | 81 | /* Delete an address */ |
82 | GNUNET_CONTAINER_multihashmap_remove (addresses, &addr.peer.hashPubKey, &addr); | ||
82 | GAS_mlp_address_delete (mlp, addresses, &addr); | 83 | GAS_mlp_address_delete (mlp, addresses, &addr); |
83 | 84 | ||
84 | GAS_mlp_done (mlp); | 85 | GAS_mlp_done (mlp); |