diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-02-22 14:17:57 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-02-22 14:17:57 +0000 |
commit | 7d9b98003496df4a29d52d3ece51070e3c4c29b0 (patch) | |
tree | 350343b2cd7655ebd598bf8880b430eed86482be /src | |
parent | bffcd22f748a25a90fb3140bf5a820879e8d93ab (diff) | |
download | gnunet-7d9b98003496df4a29d52d3ece51070e3c4c29b0.tar.gz gnunet-7d9b98003496df4a29d52d3ece51070e3c4c29b0.zip |
changes
Diffstat (limited to 'src')
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.c | 132 |
1 files changed, 97 insertions, 35 deletions
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c index 943b2883b..9ae812c97 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.c +++ b/src/ats/gnunet-service-ats_addresses_mlp.c | |||
@@ -815,15 +815,6 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON | |||
815 | */ | 815 | */ |
816 | 816 | ||
817 | 817 | ||
818 | /* Setting -D */ | ||
819 | ia[p->ci] = p->r_c6 ; | ||
820 | ja[p->ci] = p->c_d; | ||
821 | ar[p->ci] = -1; | ||
822 | #if DEBUG_MLP_PROBLEM_CREATION | ||
823 | LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: Set value [%u,%u] == %.2f\n", | ||
824 | ia[p->ci], ja[p->ci], ar[p->ci]); | ||
825 | #endif | ||
826 | p->ci++; | ||
827 | 818 | ||
828 | GNUNET_CONTAINER_multihashmap_iterate (addresses, mlp_create_constraint_it, mlp); | 819 | GNUNET_CONTAINER_multihashmap_iterate (addresses, mlp_create_constraint_it, mlp); |
829 | 820 | ||
@@ -841,16 +832,6 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON | |||
841 | * V p : sum (bt_1 + ... +bt_n) - f_p * r = 0 | 832 | * V p : sum (bt_1 + ... +bt_n) - f_p * r = 0 |
842 | * */ | 833 | * */ |
843 | 834 | ||
844 | /* -u */ | ||
845 | ia[p->ci] = p->r_c8; | ||
846 | ja[p->ci] = p->c_u; | ||
847 | ar[p->ci] = -1; | ||
848 | #if DEBUG_MLP_PROBLEM_CREATION | ||
849 | LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: Set value [%u,%u] == %.2f\n", | ||
850 | ia[p->ci], ja[p->ci], ar[p->ci]); | ||
851 | #endif | ||
852 | p->ci++; | ||
853 | |||
854 | #if 0 | 835 | #if 0 |
855 | struct ATS_Peer * peer = mlp->peer_head; | 836 | struct ATS_Peer * peer = mlp->peer_head; |
856 | /* For all peers */ | 837 | /* For all peers */ |
@@ -1064,12 +1045,53 @@ mlp_create_address_columns_it (void *cls, const struct GNUNET_HashCode * key, vo | |||
1064 | } | 1045 | } |
1065 | #endif | 1046 | #endif |
1066 | 1047 | ||
1048 | |||
1049 | struct CountContext | ||
1050 | { | ||
1051 | struct GNUNET_CONTAINER_MultiHashMap * peers; | ||
1052 | int result; | ||
1053 | }; | ||
1054 | |||
1055 | static int | ||
1056 | mlp_create_problem_count_addresses_it (void *cls, const struct GNUNET_HashCode *key, void *value) | ||
1057 | { | ||
1058 | struct CountContext *cctx = cls; | ||
1059 | /* Check if we have to add this peer due to a pending request */ | ||
1060 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(cctx->peers, key)) | ||
1061 | cctx->result++; | ||
1062 | return GNUNET_OK; | ||
1063 | } | ||
1064 | |||
1065 | static int mlp_create_problem_count_addresses ( | ||
1066 | struct GNUNET_CONTAINER_MultiHashMap * peers, | ||
1067 | struct GNUNET_CONTAINER_MultiHashMap * addresses) | ||
1068 | { | ||
1069 | struct CountContext cctx; | ||
1070 | cctx.peers = peers; | ||
1071 | cctx.result = 0; | ||
1072 | GNUNET_CONTAINER_multihashmap_iterate (addresses, &mlp_create_problem_count_addresses_it, &cctx); | ||
1073 | return cctx.result; | ||
1074 | } | ||
1075 | |||
1076 | |||
1067 | /** | 1077 | /** |
1068 | * Create the invariant columns c4, c6, c10, c8, c7 | 1078 | * Create the |
1079 | * - address columns b and n | ||
1080 | * - address dependent constraint rows c1, c3 | ||
1081 | * - peer dependent rows c2 and c9 | ||
1082 | * - Set address dependent entries in problem matrix as well | ||
1069 | */ | 1083 | */ |
1070 | static void | 1084 | static void |
1071 | mlp_create_problem_add_address_information (struct GAS_MLP_Handle *mlp, struct MLP_Problem *p) | 1085 | mlp_create_problem_add_address_information (struct GAS_MLP_Handle *mlp, struct MLP_Problem *p) |
1072 | { | 1086 | { |
1087 | /* Add peer dependent constraints */ | ||
1088 | /* Add constraint c2 */ | ||
1089 | /* Add constraint c9 */ | ||
1090 | |||
1091 | /* Add address dependent constraints */ | ||
1092 | /* Add constraint c1 */ | ||
1093 | /* Add constraint c3 */ | ||
1094 | |||
1073 | 1095 | ||
1074 | } | 1096 | } |
1075 | 1097 | ||
@@ -1109,6 +1131,16 @@ mlp_create_problem_add_invariant_rows (struct GAS_MLP_Handle *mlp, struct MLP_Pr | |||
1109 | p->r_c6, name, | 1131 | p->r_c6, name, |
1110 | "==", 0); | 1132 | "==", 0); |
1111 | #endif | 1133 | #endif |
1134 | /* c6 )Setting -D */ | ||
1135 | p->ia[p->ci] = p->r_c6 ; | ||
1136 | p->ja[p->ci] = p->c_d; | ||
1137 | p->ar[p->ci] = -1; | ||
1138 | #if DEBUG_MLP_PROBLEM_CREATION | ||
1139 | LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: Set value [%u,%u] == %.2f\n", | ||
1140 | p->ia[p->ci], p->ja[p->ci], p->ar[p->ci]); | ||
1141 | #endif | ||
1142 | p->ci++; | ||
1143 | |||
1112 | 1144 | ||
1113 | /* Add rows for c 10) */ | 1145 | /* Add rows for c 10) */ |
1114 | for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++) | 1146 | for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++) |
@@ -1138,6 +1170,16 @@ mlp_create_problem_add_invariant_rows (struct GAS_MLP_Handle *mlp, struct MLP_Pr | |||
1138 | p->r_c8, name, | 1170 | p->r_c8, name, |
1139 | "==", 0); | 1171 | "==", 0); |
1140 | #endif | 1172 | #endif |
1173 | /* -u */ | ||
1174 | p->ia[p->ci] = p->r_c8; | ||
1175 | p->ja[p->ci] = p->c_u; | ||
1176 | p->ar[p->ci] = -1; | ||
1177 | #if DEBUG_MLP_PROBLEM_CREATION | ||
1178 | LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: Set value [%u,%u] == %.2f\n", | ||
1179 | p->ia[p->ci], p->ja[p->ci], p->ar[p->ci]); | ||
1180 | #endif | ||
1181 | p->ci++; | ||
1182 | |||
1141 | 1183 | ||
1142 | /* c 7) For all quality metrics */ | 1184 | /* c 7) For all quality metrics */ |
1143 | for (c = 0; c < mlp->pv.m_q; c++) | 1185 | for (c = 0; c < mlp->pv.m_q; c++) |
@@ -1150,9 +1192,17 @@ mlp_create_problem_add_invariant_rows (struct GAS_MLP_Handle *mlp, struct MLP_Pr | |||
1150 | #if DEBUG_MLP_PROBLEM_CREATION | 1192 | #if DEBUG_MLP_PROBLEM_CREATION |
1151 | LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: Added row [%u] `%s': %s %u\n", | 1193 | LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: Added row [%u] `%s': %s %u\n", |
1152 | p->r_q[c], name, | 1194 | p->r_q[c], name, |
1153 | "<=", 0); | 1195 | "==", 0); |
1154 | #endif | 1196 | #endif |
1155 | GNUNET_free (name); | 1197 | GNUNET_free (name); |
1198 | p->ia[p->ci] = p->r_q[c]; | ||
1199 | p->ja[p->ci] = p->c_q[c]; | ||
1200 | p->ar[p->ci] = -1; | ||
1201 | #if DEBUG_MLP_PROBLEM_CREATION | ||
1202 | LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: Set value [%u,%u] == %.2f\n", | ||
1203 | p->ia[p->ci], p->ja[p->ci], p->ar[p->ci]); | ||
1204 | #endif | ||
1205 | p->ci++; | ||
1156 | } | 1206 | } |
1157 | } | 1207 | } |
1158 | 1208 | ||
@@ -1239,30 +1289,42 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHas | |||
1239 | { | 1289 | { |
1240 | struct MLP_Problem *p = &mlp->p; | 1290 | struct MLP_Problem *p = &mlp->p; |
1241 | int res = GNUNET_OK; | 1291 | int res = GNUNET_OK; |
1242 | 1292 | int elements; | |
1243 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Rebuilding problem for %u peer(s) \n", | ||
1244 | GNUNET_CONTAINER_multihashmap_size(mlp->peers)); | ||
1245 | 1293 | ||
1246 | GNUNET_assert (p->prob == NULL); | 1294 | GNUNET_assert (p->prob == NULL); |
1247 | GNUNET_assert (p->ia == NULL); | 1295 | GNUNET_assert (p->ia == NULL); |
1248 | GNUNET_assert (p->ja == NULL); | 1296 | GNUNET_assert (p->ja == NULL); |
1249 | GNUNET_assert (p->ar == NULL); | 1297 | GNUNET_assert (p->ar == NULL); |
1250 | |||
1251 | |||
1252 | /* Reset MLP problem struct */ | 1298 | /* Reset MLP problem struct */ |
1253 | p->num_addresses = 0; | ||
1254 | p->num_peers = GNUNET_CONTAINER_multihashmap_size (mlp->peers); | ||
1255 | 1299 | ||
1256 | /* create the glpk problem */ | 1300 | /* create the glpk problem */ |
1257 | p->prob = glp_create_prob (); | 1301 | p->prob = glp_create_prob (); |
1258 | p->num_addresses = 0;; | ||
1259 | GNUNET_assert (NULL != p->prob); | 1302 | GNUNET_assert (NULL != p->prob); |
1303 | p->num_peers = GNUNET_CONTAINER_multihashmap_size (mlp->peers); | ||
1304 | p->num_addresses = mlp_create_problem_count_addresses (addresses, mlp->peers); | ||
1305 | |||
1306 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Rebuilding problem for %u peer(s) and %u addresse(s)\n", | ||
1307 | p->num_peers, p->num_addresses); | ||
1260 | 1308 | ||
1261 | /* Set a problem name */ | 1309 | /* Set a problem name */ |
1262 | glp_set_prob_name (p->prob, "GNUnet ats bandwidth distribution"); | 1310 | glp_set_prob_name (p->prob, "GNUnet ats bandwidth distribution"); |
1263 | /* Set optimization direction to maximize */ | 1311 | /* Set optimization direction to maximize */ |
1264 | glp_set_obj_dir (p->prob, GLP_MAX); | 1312 | glp_set_obj_dir (p->prob, GLP_MAX); |
1265 | 1313 | ||
1314 | /* Create problem matrix */ | ||
1315 | /* last +1 caused by glpk index starting with one: [1..elements]*/ | ||
1316 | elements = ((7 * p->num_addresses) + (5 * p->num_addresses + mlp->pv.m_q + p->num_peers + 2) + 1); | ||
1317 | p->ci = 1; | ||
1318 | /* row index */ | ||
1319 | int *ia = GNUNET_malloc (elements * sizeof (int)); | ||
1320 | p->ia = ia; | ||
1321 | /* column index */ | ||
1322 | int *ja = GNUNET_malloc (elements * sizeof (int)); | ||
1323 | p->ja = ja; | ||
1324 | /* coefficient */ | ||
1325 | double *ar= GNUNET_malloc (elements * sizeof (double)); | ||
1326 | p->ar = ar; | ||
1327 | |||
1266 | /* Adding invariant columns */ | 1328 | /* Adding invariant columns */ |
1267 | mlp_create_problem_add_invariant_columns (mlp, p); | 1329 | mlp_create_problem_add_invariant_columns (mlp, p); |
1268 | 1330 | ||
@@ -1274,13 +1336,13 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHas | |||
1274 | 1336 | ||
1275 | #if 0 | 1337 | #if 0 |
1276 | /* Add columns for addresses */ | 1338 | /* Add columns for addresses */ |
1277 | GNUNET_CONTAINER_multihashmap_iterate (addresses, mlp_create_address_columns_it, mlp); | 1339 | GNUNET_CONTAINER_multihashmap_iterate (peers, mlp_create_address_columns_it, mlp); |
1278 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Problems contains %u peers, %u addresses, %u addresses skipped \n", | 1340 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Problems contains %u peers, %u addresses, %u addresses skipped \n", |
1279 | GNUNET_CONTAINER_multihashmap_size(mlp->peers), | 1341 | GNUNET_CONTAINER_multihashmap_size(mlp->peers), |
1280 | p->num_addresses, GNUNET_CONTAINER_multihashmap_size(addresses)- p->num_addresses); | 1342 | p->num_addresses, GNUNET_CONTAINER_multihashmap_size(peers)- p->num_addresses); |
1281 | 1343 | ||
1282 | /* Add constraints rows */ | 1344 | /* Add constraints rows */ |
1283 | mlp_add_constraints_all_addresses (mlp, addresses); | 1345 | mlp_add_constraints_all_addresses (mlp, peers); |
1284 | # endif | 1346 | # endif |
1285 | 1347 | ||
1286 | /* Load the matrix */ | 1348 | /* Load the matrix */ |
@@ -1786,7 +1848,7 @@ GAS_mlp_address_update (void *solver, | |||
1786 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Recreating problem: new address\n"); | 1848 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Recreating problem: new address\n"); |
1787 | 1849 | ||
1788 | mlp_delete_problem (mlp); | 1850 | mlp_delete_problem (mlp); |
1789 | mlp_create_problem (mlp, addresses); | 1851 | mlp_create_problem (mlp, peers); |
1790 | mlp->presolver_required = GNUNET_YES; | 1852 | mlp->presolver_required = GNUNET_YES; |
1791 | } | 1853 | } |
1792 | if (mlp->auto_solve == GNUNET_YES) | 1854 | if (mlp->auto_solve == GNUNET_YES) |
@@ -1876,9 +1938,9 @@ GAS_mlp_address_delete (void *solver, | |||
1876 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Recreating problem: new address\n"); | 1938 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Recreating problem: new address\n"); |
1877 | 1939 | ||
1878 | mlp_delete_problem (mlp); | 1940 | mlp_delete_problem (mlp); |
1879 | if ((GNUNET_CONTAINER_multihashmap_size (addresses) > 0) && (mlp->c_p > 0)) | 1941 | if ((GNUNET_CONTAINER_multihashmap_size (peers) > 0) && (mlp->c_p > 0)) |
1880 | { | 1942 | { |
1881 | mlp_create_problem (mlp, addresses); | 1943 | mlp_create_problem (mlp, peers); |
1882 | 1944 | ||
1883 | /* Recalculate */ | 1945 | /* Recalculate */ |
1884 | mlp->presolver_required = GNUNET_YES; | 1946 | mlp->presolver_required = GNUNET_YES; |