diff options
Diffstat (limited to 'src/ats/gnunet-service-ats_addresses_mlp.c')
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.c | 57 |
1 files changed, 36 insertions, 21 deletions
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c index 32730b206..f10e88007 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.c +++ b/src/ats/gnunet-service-ats_addresses_mlp.c | |||
@@ -924,6 +924,38 @@ mlp_create_problem_create_column (struct MLP_Problem *p, char *name, | |||
924 | return col; | 924 | return col; |
925 | } | 925 | } |
926 | 926 | ||
927 | static int | ||
928 | mlp_create_problem_create_constraint (struct MLP_Problem *p, char *name, | ||
929 | unsigned int bound, double lb, double ub) | ||
930 | { | ||
931 | char * op; | ||
932 | int row = glp_add_rows (p->prob, 1); | ||
933 | /* set row name */ | ||
934 | glp_set_row_name (p->prob, row, name); | ||
935 | /* set row bounds: <= 0 */ | ||
936 | glp_set_row_bnds (p->prob, row, bound, lb, ub); | ||
937 | switch (bound) { | ||
938 | case GLP_UP: | ||
939 | GNUNET_asprintf(&op, "-inf <= x <= %.2f", ub); | ||
940 | break; | ||
941 | case GLP_DB: | ||
942 | GNUNET_asprintf(&op, "%.2f <= x <= %.2f", lb, ub); | ||
943 | break; | ||
944 | case GLP_LO: | ||
945 | GNUNET_asprintf(&op, "%.2f <= x <= inf", lb); | ||
946 | break; | ||
947 | default: | ||
948 | GNUNET_asprintf(&op, "ERROR"); | ||
949 | break; | ||
950 | } | ||
951 | #if DEBUG_MLP_PROBLEM_CREATION | ||
952 | LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: Added row [%u] `%s': %s\n", | ||
953 | row, name, op); | ||
954 | #endif | ||
955 | GNUNET_free (op); | ||
956 | return row; | ||
957 | } | ||
958 | |||
927 | /** | 959 | /** |
928 | * Create the | 960 | * Create the |
929 | * - address columns b and n | 961 | * - address columns b and n |
@@ -939,7 +971,6 @@ mlp_create_problem_add_address_information (void *cls, const struct GNUNET_HashC | |||
939 | struct ATS_Address *address = value; | 971 | struct ATS_Address *address = value; |
940 | struct ATS_Peer *peer; | 972 | struct ATS_Peer *peer; |
941 | struct MLP_information *mlpi; | 973 | struct MLP_information *mlpi; |
942 | unsigned int col; | ||
943 | char *name; | 974 | char *name; |
944 | 975 | ||
945 | /* Check if we have to add this peer due to a pending request */ | 976 | /* Check if we have to add this peer due to a pending request */ |
@@ -969,18 +1000,10 @@ mlp_create_problem_add_address_information (void *cls, const struct GNUNET_HashC | |||
969 | /* Add constraint c1) bandwidth capping | 1000 | /* Add constraint c1) bandwidth capping |
970 | * b_t + (-M) * n_t <= 0 | 1001 | * b_t + (-M) * n_t <= 0 |
971 | * */ | 1002 | * */ |
972 | mlpi->r_c1 = glp_add_rows (p->prob, 1); | ||
973 | /* set row name */ | ||
974 | GNUNET_asprintf(&name, "c1_%s_%s", GNUNET_i2s(&address->peer), address->plugin); | 1003 | GNUNET_asprintf(&name, "c1_%s_%s", GNUNET_i2s(&address->peer), address->plugin); |
975 | glp_set_row_name (p->prob, mlpi->r_c1, name); | 1004 | mlpi->r_c1 = mlp_create_problem_create_constraint (p, name, GLP_LO, 0.0, 0.0); |
976 | /* set row bounds: <= 0 */ | ||
977 | glp_set_row_bnds (p->prob, mlpi->r_c1, GLP_UP, 0.0, 0.0); | ||
978 | #if DEBUG_MLP_PROBLEM_CREATION | ||
979 | LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: Added row [%u] `%s': %s %u\n", | ||
980 | mlpi->r_c1, name, | ||
981 | "<=", 0); | ||
982 | #endif | ||
983 | GNUNET_free (name); | 1005 | GNUNET_free (name); |
1006 | |||
984 | /* c1) set b = 1 coefficient */ | 1007 | /* c1) set b = 1 coefficient */ |
985 | mlp_create_problem_set_value (p, mlpi->r_c1, mlpi->c_b, 1); | 1008 | mlp_create_problem_set_value (p, mlpi->r_c1, mlpi->c_b, 1); |
986 | /* c1) set n = -M coefficient */ | 1009 | /* c1) set n = -M coefficient */ |
@@ -989,18 +1012,10 @@ mlp_create_problem_add_address_information (void *cls, const struct GNUNET_HashC | |||
989 | /* Add constraint c 3) minimum bandwidth | 1012 | /* Add constraint c 3) minimum bandwidth |
990 | * b_t + (-n_t * b_min) >= 0 | 1013 | * b_t + (-n_t * b_min) >= 0 |
991 | * */ | 1014 | * */ |
992 | mlpi->r_c3 = glp_add_rows (p->prob, 1); | ||
993 | /* set row name */ | ||
994 | GNUNET_asprintf(&name, "c3_%s_%s", GNUNET_i2s(&address->peer), address->plugin); | 1015 | GNUNET_asprintf(&name, "c3_%s_%s", GNUNET_i2s(&address->peer), address->plugin); |
995 | glp_set_row_name (p->prob, mlpi->r_c3, name); | 1016 | mlpi->r_c3 = mlp_create_problem_create_constraint (p, name, GLP_LO, 0.0, 0.0); |
996 | /* set row bounds: >= 0 */ | ||
997 | glp_set_row_bnds (p->prob, mlpi->r_c3, GLP_LO, 0.0, 0.0); | ||
998 | #if DEBUG_MLP_PROBLEM_CREATION | ||
999 | LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: Added row [%u] `%s': %s %u\n", | ||
1000 | mlpi->r_c3, name, | ||
1001 | "<=", 0); | ||
1002 | #endif | ||
1003 | GNUNET_free (name); | 1017 | GNUNET_free (name); |
1018 | |||
1004 | /* c3) set b = 1 coefficient */ | 1019 | /* c3) set b = 1 coefficient */ |
1005 | mlp_create_problem_set_value (p, mlpi->r_c3, mlpi->c_b, 1); | 1020 | mlp_create_problem_set_value (p, mlpi->r_c3, mlpi->c_b, 1); |
1006 | /* c3) set n = -b_min coefficient */ | 1021 | /* c3) set n = -b_min coefficient */ |