aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-02-25 13:08:49 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-02-25 13:08:49 +0000
commit5778894d72e28da8e1038e2002073c7b4b8d13e1 (patch)
tree2c762e3adb4481c1cacd74b35f3ee03247b9fa3e /src
parentc0edc2399fb6153df47c19445b502345524b935a (diff)
downloadgnunet-5778894d72e28da8e1038e2002073c7b4b8d13e1.tar.gz
gnunet-5778894d72e28da8e1038e2002073c7b4b8d13e1.zip
fixes
Diffstat (limited to 'src')
-rw-r--r--src/ats/gnunet-service-ats_addresses_mlp.c63
-rw-r--r--src/ats/test_ats_mlp.c6
2 files changed, 48 insertions, 21 deletions
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c
index 704062e07..f7273f8ee 100644
--- a/src/ats/gnunet-service-ats_addresses_mlp.c
+++ b/src/ats/gnunet-service-ats_addresses_mlp.c
@@ -136,8 +136,9 @@
136#define LOG(kind,...) GNUNET_log_from (kind, "ats-mlp",__VA_ARGS__) 136#define LOG(kind,...) GNUNET_log_from (kind, "ats-mlp",__VA_ARGS__)
137 137
138#define WRITE_MLP GNUNET_NO 138#define WRITE_MLP GNUNET_NO
139#define DEBUG_MLP_PROBLEM_CREATION GNUNET_YES 139#define DEBUG_MLP_PROBLEM_CREATION GNUNET_NO
140#define VERBOSE_GLPK GNUNET_NO 140#define VERBOSE_GLPK GNUNET_NO
141#define TEST_MAX_BW_ASSIGNMENT GNUNET_YES
141 142
142/** 143/**
143 * Intercept GLPK terminal output 144 * Intercept GLPK terminal output
@@ -918,7 +919,12 @@ mlp_create_problem_add_address_information (void *cls, const struct GNUNET_HashC
918 919
919 /* Add bandwidth column */ 920 /* Add bandwidth column */
920 GNUNET_asprintf (&name, "b_%s_%s", GNUNET_i2s (&address->peer), address->plugin); 921 GNUNET_asprintf (&name, "b_%s_%s", GNUNET_i2s (&address->peer), address->plugin);
922#if TEST_MAX_BW_ASSIGNMENT
923 mlpi->c_b = mlp_create_problem_create_column (p, name, GLP_CV, GLP_LO, 0.0, 0.0, 1.0);
924#else
921 mlpi->c_b = mlp_create_problem_create_column (p, name, GLP_CV, GLP_LO, 0.0, 0.0, 0.0); 925 mlpi->c_b = mlp_create_problem_create_column (p, name, GLP_CV, GLP_LO, 0.0, 0.0, 0.0);
926#endif
927
922 GNUNET_free (name); 928 GNUNET_free (name);
923 929
924 /* Add usage column */ 930 /* Add usage column */
@@ -1038,6 +1044,12 @@ mlp_create_problem_add_invariant_columns (struct GAS_MLP_Handle *mlp, struct MLP
1038 char *name; 1044 char *name;
1039 int c; 1045 int c;
1040 1046
1047#if TEST_MAX_BW_ASSIGNMENT
1048 mlp->pv.co_D = 0.0;
1049 mlp->pv.co_U = 0.0;
1050 mlp->pv.co_R = 0.0;
1051#endif
1052
1041 /* Diversity d column */ 1053 /* Diversity d column */
1042 p->c_d = mlp_create_problem_create_column (p, "d", GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_D); 1054 p->c_d = mlp_create_problem_create_column (p, "d", GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_D);
1043 1055
@@ -1045,13 +1057,17 @@ mlp_create_problem_add_invariant_columns (struct GAS_MLP_Handle *mlp, struct MLP
1045 p->c_u = mlp_create_problem_create_column (p, "u", GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_U); 1057 p->c_u = mlp_create_problem_create_column (p, "u", GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_U);
1046 1058
1047 /* Relativity r column */ 1059 /* Relativity r column */
1048 p->c_r = mlp_create_problem_create_column (p, "u", GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_R); 1060 p->c_r = mlp_create_problem_create_column (p, "r", GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_R);
1049 1061
1050 /* Quality metric columns */ 1062 /* Quality metric columns */
1051 for (c = 0; c < mlp->pv.m_q; c++) 1063 for (c = 0; c < mlp->pv.m_q; c++)
1052 { 1064 {
1053 GNUNET_asprintf (&name, "q_%u", mlp->pv.q[c]); 1065 GNUNET_asprintf (&name, "q_%u", mlp->pv.q[c]);
1066#if TEST_MAX_BW_ASSIGNMENT
1067 p->c_q[c] = mlp_create_problem_create_column (p, name, GLP_CV, GLP_LO, 0.0, 0.0, 0.0);
1068#else
1054 p->c_q[c] = mlp_create_problem_create_column (p, name, GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_Q[c]); 1069 p->c_q[c] = mlp_create_problem_create_column (p, name, GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_Q[c]);
1070#endif
1055 GNUNET_free (name); 1071 GNUNET_free (name);
1056 } 1072 }
1057} 1073}
@@ -1086,7 +1102,6 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHas
1086 p->num_elements = (10 * p->num_addresses + mlp->pv.m_q * p->num_addresses + mlp->pv.m_q + p->num_peers + 2 + 1); 1102 p->num_elements = (10 * p->num_addresses + mlp->pv.m_q * p->num_addresses + mlp->pv.m_q + p->num_peers + 2 + 1);
1087 LOG (GNUNET_ERROR_TYPE_DEBUG, "Rebuilding problem for %u peer(s) and %u addresse(s) and %u quality metrics == %u elements\n", 1103 LOG (GNUNET_ERROR_TYPE_DEBUG, "Rebuilding problem for %u peer(s) and %u addresse(s) and %u quality metrics == %u elements\n",
1088 p->num_peers, p->num_addresses, mlp->pv.m_q, p->num_elements); 1104 p->num_peers, p->num_addresses, mlp->pv.m_q, p->num_elements);
1089 LOG (GNUNET_ERROR_TYPE_DEBUG, "Rebuilding %u \n", mlp->pv.b_min);
1090 1105
1091 /* Set a problem name */ 1106 /* Set a problem name */
1092 glp_set_prob_name (p->prob, "GNUnet ATS bandwidth distribution"); 1107 glp_set_prob_name (p->prob, "GNUnet ATS bandwidth distribution");
@@ -1190,7 +1205,7 @@ mlp_solve_mlp_problem (struct GAS_MLP_Handle *mlp)
1190 case GLP_OPT: 1205 case GLP_OPT:
1191 /* solution is feasible */ 1206 /* solution is feasible */
1192 case GLP_FEAS: 1207 case GLP_FEAS:
1193 LOG (GNUNET_ERROR_TYPE_DEBUG, "Solving LP problem: %s\n", mlp_status_to_string(res)); 1208 LOG (GNUNET_ERROR_TYPE_DEBUG, "Solving MLP problem: %s\n", mlp_status_to_string(res));
1194 return GNUNET_OK; 1209 return GNUNET_OK;
1195 /* Problem was ill-defined, no way to handle that */ 1210 /* Problem was ill-defined, no way to handle that */
1196 default: 1211 default:
@@ -1212,13 +1227,12 @@ mlp_propagate_results (void *cls, const struct GNUNET_HashCode *key, void *value
1212 struct GAS_MLP_Handle *mlp = cls; 1227 struct GAS_MLP_Handle *mlp = cls;
1213 struct ATS_Address *address; 1228 struct ATS_Address *address;
1214 struct MLP_information *mlpi; 1229 struct MLP_information *mlpi;
1215 double mlp_bw; 1230 double mlp_bw = NaN;
1216 double mlp_use; 1231 double mlp_use = NaN;
1217 1232
1218 /* Check if we have to add this peer due to a pending request */ 1233 /* Check if we have to add this peer due to a pending request */
1219 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(mlp->peers, key)) 1234 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(mlp->peers, key))
1220 return GNUNET_OK; 1235 return GNUNET_OK;
1221
1222 address = value; 1236 address = value;
1223 GNUNET_assert (address->solver_information != NULL); 1237 GNUNET_assert (address->solver_information != NULL);
1224 mlpi = address->solver_information; 1238 mlpi = address->solver_information;
@@ -1229,14 +1243,16 @@ mlp_propagate_results (void *cls, const struct GNUNET_HashCode *key, void *value
1229 if ((GLP_YES == mlp_use) && (GNUNET_NO == address->active)) 1243 if ((GLP_YES == mlp_use) && (GNUNET_NO == address->active))
1230 { 1244 {
1231 /* Address switch: Activate address*/ 1245 /* Address switch: Activate address*/
1246 LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %f : enabling address\n", (1 == mlp_use) ? "[x]": "[ ]", mlp_bw);
1232 address->active = GNUNET_YES; 1247 address->active = GNUNET_YES;
1233 address->assigned_bw_in.value__ = htonl (0); 1248 address->assigned_bw_in.value__ = htonl (mlp_bw);
1234 address->assigned_bw_out.value__ = htonl (0); 1249 address->assigned_bw_out.value__ = htonl (mlp_bw);
1235 mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address); 1250 mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address);
1236 } 1251 }
1237 else if ((GLP_NO == mlp_use) && (GNUNET_YES == address->active)) 1252 else if ((GLP_NO == mlp_use) && (GNUNET_YES == address->active))
1238 { 1253 {
1239 /* Address switch: Disable address*/ 1254 /* Address switch: Disable address*/
1255 LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %f : disabling address\n", (1 == mlp_use) ? "[x]": "[ ]", mlp_bw);
1240 address->active = GNUNET_NO; 1256 address->active = GNUNET_NO;
1241 /* Set bandwidth to 0 */ 1257 /* Set bandwidth to 0 */
1242 address->assigned_bw_in.value__ = htonl (0); 1258 address->assigned_bw_in.value__ = htonl (0);
@@ -1247,10 +1263,15 @@ mlp_propagate_results (void *cls, const struct GNUNET_HashCode *key, void *value
1247 (mlp_bw != ntohl(address->assigned_bw_in.value__))) 1263 (mlp_bw != ntohl(address->assigned_bw_in.value__)))
1248 { 1264 {
1249 /* Bandwidth changed */ 1265 /* Bandwidth changed */
1266 LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %f : bandwidth changed\n", (1 == mlp_use) ? "[x]": "[ ]", mlp_bw);
1250 address->assigned_bw_in.value__ = htonl (mlp_bw); 1267 address->assigned_bw_in.value__ = htonl (mlp_bw);
1251 address->assigned_bw_out.value__ = htonl (mlp_bw); 1268 address->assigned_bw_out.value__ = htonl (mlp_bw);
1252 mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address); 1269 mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address);
1253 } 1270 }
1271 else
1272 {
1273 LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %f : no change\n", (1 == mlp_use) ? "[x]": "[ ]", mlp_bw);
1274 }
1254 1275
1255 return GNUNET_OK; 1276 return GNUNET_OK;
1256} 1277}
@@ -1297,32 +1318,36 @@ GAS_mlp_solve_problem (void *solver, struct GNUNET_CONTAINER_MultiHashMap * addr
1297 /* Run LP solver */ 1318 /* Run LP solver */
1298 LOG (GNUNET_ERROR_TYPE_DEBUG, "Running LP solver \n"); 1319 LOG (GNUNET_ERROR_TYPE_DEBUG, "Running LP solver \n");
1299 start_lp = GNUNET_TIME_absolute_get(); 1320 start_lp = GNUNET_TIME_absolute_get();
1300 mlp_solve_lp_problem (mlp); 1321 res = mlp_solve_lp_problem (mlp);
1301 duration_lp = GNUNET_TIME_absolute_get_duration (start_lp); 1322 duration_lp = GNUNET_TIME_absolute_get_duration (start_lp);
1302 1323
1303 /* Run LP solver */ 1324 /* Run LP solver */
1304 LOG (GNUNET_ERROR_TYPE_DEBUG, "Running MLP solver \n"); 1325 LOG (GNUNET_ERROR_TYPE_DEBUG, "Running MLP solver \n");
1305 start_mlp = GNUNET_TIME_absolute_get(); 1326 start_mlp = GNUNET_TIME_absolute_get();
1306 mlp_solve_lp_problem (mlp); 1327 res = mlp_solve_mlp_problem (mlp);
1307 duration_mlp = GNUNET_TIME_absolute_get_duration (start_mlp); 1328 duration_mlp = GNUNET_TIME_absolute_get_duration (start_mlp);
1308 LOG (GNUNET_ERROR_TYPE_DEBUG, "Solver took LP %llu ms, MLP %llu ms\n", 1329 LOG (GNUNET_ERROR_TYPE_DEBUG, "Solver took LP %llu ms, MLP %llu ms\n",
1309 (unsigned long long) duration_lp.rel_value, 1330 (unsigned long long) duration_lp.rel_value,
1310 (unsigned long long) duration_mlp.rel_value); 1331 (unsigned long long) duration_mlp.rel_value);
1311 1332
1312 /* Store LP */
1313#if DUMP_PROBLEM
1314 char *filename;
1315 GNUNET_asprintf (&filename, "problem_%llu.lp", GNUNET_TIME_absolute_get().abs_value);
1316 glp_write_lp (mlp->p.prob, 0, filename);
1317 GNUNET_free (filename);
1318#endif
1319
1320 /* Propagate result*/ 1333 /* Propagate result*/
1321 if (GNUNET_OK == res) 1334 if (GNUNET_OK == res)
1322 { 1335 {
1323 GNUNET_CONTAINER_multihashmap_iterate (addresses, &mlp_propagate_results, mlp); 1336 GNUNET_CONTAINER_multihashmap_iterate (addresses, &mlp_propagate_results, mlp);
1324 } 1337 }
1325 1338
1339 /* Store LP */
1340#if WRITE_MLP
1341 char *filename;
1342 struct GNUNET_TIME_Absolute time = GNUNET_TIME_absolute_get();
1343 GNUNET_asprintf (&filename, "problem_%llu.lp", time.abs_value);
1344 glp_write_prob (mlp->p.prob, 0, filename);
1345 GNUNET_free (filename);
1346 GNUNET_asprintf (&filename, "problem_%llu.sol", time.abs_value);
1347 glp_print_sol(mlp->p.prob, filename);
1348 GNUNET_free (filename);
1349#endif
1350
1326 /* Reset change and update marker */ 1351 /* Reset change and update marker */
1327 mlp->mlp_prob_updated = GNUNET_NO; 1352 mlp->mlp_prob_updated = GNUNET_NO;
1328 mlp->mlp_prob_changed = GNUNET_NO; 1353 mlp->mlp_prob_changed = GNUNET_NO;
diff --git a/src/ats/test_ats_mlp.c b/src/ats/test_ats_mlp.c
index c43f740c3..d564b0228 100644
--- a/src/ats/test_ats_mlp.c
+++ b/src/ats/test_ats_mlp.c
@@ -123,8 +123,10 @@ end_now (int res)
123static void 123static void
124bandwidth_changed_cb (void *cls, struct ATS_Address *address) 124bandwidth_changed_cb (void *cls, struct ATS_Address *address)
125{ 125{
126 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MLP tells suggests me for peer `%s' address `%s':`%s'\n", 126 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MLP suggests for peer `%s' address `%s':`%s' in %llu out %llu \n",
127 GNUNET_i2s(&address->peer), address->plugin, address->addr); 127 GNUNET_i2s(&address->peer), address->plugin, address->addr,
128 ntohl(address->assigned_bw_in.value__),
129 ntohl(address->assigned_bw_out.value__));
128 //end_now (0); 130 //end_now (0);
129} 131}
130 132