aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-02-21 12:14:33 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-02-21 12:14:33 +0000
commit6989b0988146705e8ea5411a110a7d645b7cc459 (patch)
treef83b5097d27a8d2830f7c81d9939931f43fb13d8
parenta250da032ba65252d9da96e8429b22e265c69980 (diff)
downloadgnunet-6989b0988146705e8ea5411a110a7d645b7cc459.tar.gz
gnunet-6989b0988146705e8ea5411a110a7d645b7cc459.zip
changes
-rw-r--r--src/ats/gnunet-service-ats_addresses_mlp.c34
-rw-r--r--src/ats/gnunet-service-ats_addresses_mlp.h9
2 files changed, 26 insertions, 17 deletions
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c
index 607f9372c..3f3e3316b 100644
--- a/src/ats/gnunet-service-ats_addresses_mlp.c
+++ b/src/ats/gnunet-service-ats_addresses_mlp.c
@@ -549,7 +549,7 @@ mlp_scheduler (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
549 549
550 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Scheduled problem solving\n"); 550 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Scheduled problem solving\n");
551 551
552 if (mlp->addresses_in_problem != 0) 552 if (mlp->num_addresses != 0)
553 GAS_mlp_solve_problem(mlp, &ctx); 553 GAS_mlp_solve_problem(mlp, &ctx);
554} 554}
555 555
@@ -850,7 +850,7 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON
850 char *name; 850 char *name;
851 851
852 /* Problem matrix*/ 852 /* Problem matrix*/
853 n_addresses = p->addresses_in_problem; 853 n_addresses = p->num_addresses;
854 854
855 /* Required indices in the constrain matrix 855 /* Required indices in the constrain matrix
856 * 856 *
@@ -904,7 +904,7 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON
904 * */ 904 * */
905 905
906 /* last +1 caused by glpk index starting with one: [1..pi]*/ 906 /* last +1 caused by glpk index starting with one: [1..pi]*/
907 int pi = ((7 * n_addresses) + (5 * n_addresses + mlp->pv.m_q + mlp->c_p + 2) + 1); 907 int pi = ((7 * n_addresses) + (5 * n_addresses + mlp->pv.m_q + p->num_peers + 2) + 1);
908 mlp->cm_size = pi; 908 mlp->cm_size = pi;
909 p->ci = 1; 909 p->ci = 1;
910 910
@@ -935,8 +935,8 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON
935 name = "c4"; 935 name = "c4";
936 int min = mlp->pv.n_min; 936 int min = mlp->pv.n_min;
937 /* Number of minimum connections is min(|Peers|, n_min) */ 937 /* Number of minimum connections is min(|Peers|, n_min) */
938 if (mlp->pv.n_min > mlp->c_p) 938 if (mlp->pv.n_min > p->num_peers)
939 min = mlp->c_p; 939 min = p->num_peers;
940 p->r_c4 = glp_add_rows (p->prob, 1); 940 p->r_c4 = glp_add_rows (p->prob, 1);
941 glp_set_row_name (p->prob, p->r_c4, name); 941 glp_set_row_name (p->prob, p->r_c4, name);
942 glp_set_row_bnds (p->prob, p->r_c4, GLP_LO, min, min); 942 glp_set_row_bnds (p->prob, p->r_c4, GLP_LO, min, min);
@@ -1002,7 +1002,7 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON
1002 * */ 1002 * */
1003 1003
1004 /* Adding rows for c 8) */ 1004 /* Adding rows for c 8) */
1005 p->r_c8 = glp_add_rows (p->prob, mlp->c_p); 1005 p->r_c8 = glp_add_rows (p->prob, p->num_peers);
1006 name = "c8"; 1006 name = "c8";
1007 glp_set_row_name (p->prob, p->r_c8, "c8"); 1007 glp_set_row_name (p->prob, p->r_c8, "c8");
1008 /* Set row bound == 0 */ 1008 /* Set row bound == 0 */
@@ -1149,7 +1149,7 @@ mlp_create_address_columns_it (void *cls, const struct GNUNET_HashCode * key, vo
1149 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(mlp->peers, key)) 1149 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(mlp->peers, key))
1150 return GNUNET_OK; 1150 return GNUNET_OK;
1151 1151
1152 p->addresses_in_problem ++; 1152 p->num_addresses ++;
1153 mlpi = GNUNET_malloc (sizeof (struct MLP_information)); 1153 mlpi = GNUNET_malloc (sizeof (struct MLP_information));
1154 address->solver_information = mlpi; 1154 address->solver_information = mlpi;
1155 1155
@@ -1211,10 +1211,18 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHas
1211 GNUNET_CONTAINER_multihashmap_size(mlp->peers)); 1211 GNUNET_CONTAINER_multihashmap_size(mlp->peers));
1212 1212
1213 GNUNET_assert (p->prob == NULL); 1213 GNUNET_assert (p->prob == NULL);
1214 GNUNET_assert (p->ia == NULL);
1215 GNUNET_assert (p->ja == NULL);
1216 GNUNET_assert (p->ar == NULL);
1217
1218
1219 /* Reset MLP problem struct */
1220 p->num_addresses = 0;
1221 p->num_peers = GNUNET_CONTAINER_multihashmap_size (mlp->peers);
1214 1222
1215 /* create the glpk problem */ 1223 /* create the glpk problem */
1216 p->prob = glp_create_prob (); 1224 p->prob = glp_create_prob ();
1217 p->addresses_in_problem = 0;; 1225 p->num_addresses = 0;;
1218 GNUNET_assert (NULL != p->prob); 1226 GNUNET_assert (NULL != p->prob);
1219 1227
1220 /* Set a problem name */ 1228 /* Set a problem name */
@@ -1284,13 +1292,15 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHas
1284 1292
1285 /* Add columns for addresses */ 1293 /* Add columns for addresses */
1286 GNUNET_CONTAINER_multihashmap_iterate (addresses, mlp_create_address_columns_it, mlp); 1294 GNUNET_CONTAINER_multihashmap_iterate (addresses, mlp_create_address_columns_it, mlp);
1287 LOG (GNUNET_ERROR_TYPE_DEBUG, "Problems contains %u addresses, %u addresses skipped \n", 1295 LOG (GNUNET_ERROR_TYPE_DEBUG, "Problems contains %u peers, %u addresses, %u addresses skipped \n",
1288 p->addresses_in_problem, GNUNET_CONTAINER_multihashmap_size(addresses)- p->addresses_in_problem); 1296 GNUNET_CONTAINER_multihashmap_size(mlp->peers),
1297 p->num_addresses, GNUNET_CONTAINER_multihashmap_size(addresses)- p->num_addresses);
1289 1298
1290 /* Add constraints rows */ 1299 /* Add constraints rows */
1291 mlp_add_constraints_all_addresses (mlp, addresses); 1300 mlp_add_constraints_all_addresses (mlp, addresses);
1292 1301
1293 /* Load the matrix */ 1302 /* Load the matrix */
1303 LOG (GNUNET_ERROR_TYPE_DEBUG, "Loading matrix\n");
1294 //glp_load_matrix(mlp->prob, (mlp->ci-1), mlp->ia, mlp->ja, mlp->ar); 1304 //glp_load_matrix(mlp->prob, (mlp->ci-1), mlp->ia, mlp->ja, mlp->ar);
1295 1305
1296 return res; 1306 return res;
@@ -1576,7 +1586,7 @@ GAS_mlp_address_update (void *solver,
1576 } 1586 }
1577 1587
1578 address->solver_information = mlpi; 1588 address->solver_information = mlpi;
1579 mlp->addresses_in_problem ++; 1589 mlp->num_addresses ++;
1580 GNUNET_STATISTICS_update (mlp->stats, "# addresses in MLP", 1, GNUNET_NO); 1590 GNUNET_STATISTICS_update (mlp->stats, "# addresses in MLP", 1, GNUNET_NO);
1581 1591
1582 /* Check for and add peer */ 1592 /* Check for and add peer */
@@ -1692,7 +1702,7 @@ GAS_mlp_address_delete (void *solver,
1692 GNUNET_free (address->solver_information); 1702 GNUNET_free (address->solver_information);
1693 address->solver_information = NULL; 1703 address->solver_information = NULL;
1694 1704
1695 mlp->addresses_in_problem --; 1705 mlp->num_addresses --;
1696 GNUNET_STATISTICS_update (mlp->stats, "# addresses in MLP", -1, GNUNET_NO); 1706 GNUNET_STATISTICS_update (mlp->stats, "# addresses in MLP", -1, GNUNET_NO);
1697 } 1707 }
1698 1708
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.h b/src/ats/gnunet-service-ats_addresses_mlp.h
index bffdd08c9..c86960c59 100644
--- a/src/ats/gnunet-service-ats_addresses_mlp.h
+++ b/src/ats/gnunet-service-ats_addresses_mlp.h
@@ -92,7 +92,10 @@ struct MLP_Problem
92#else 92#else
93 void *prob; 93 void *prob;
94#endif 94#endif
95 unsigned int addresses_in_problem; 95 /* Number of addresses in problem */
96 unsigned int num_addresses;
97 /* Number of peers in problem */
98 unsigned int num_peers;
96 99
97 /* Row index constraint 2: */ 100 /* Row index constraint 2: */
98 unsigned int r_c2; 101 unsigned int r_c2;
@@ -325,10 +328,6 @@ struct GAS_MLP_Handle
325 struct ATS_Peer *peer_head; 328 struct ATS_Peer *peer_head;
326 struct ATS_Peer *peer_tail; 329 struct ATS_Peer *peer_tail;
327 330
328 /* Number of peers */
329 unsigned int c_p;
330
331
332 /* current size of the constraint matrix |indices| */ 331 /* current size of the constraint matrix |indices| */
333 unsigned int cm_size; 332 unsigned int cm_size;
334 333