diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-02-22 14:28:56 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-02-22 14:28:56 +0000 |
commit | be143717676293b28b614659d4e322acb538dd24 (patch) | |
tree | b5e75ae33174450cb8f1ff4d0a2861be8e69632a | |
parent | 7d9b98003496df4a29d52d3ece51070e3c4c29b0 (diff) | |
download | gnunet-be143717676293b28b614659d4e322acb538dd24.tar.gz gnunet-be143717676293b28b614659d4e322acb538dd24.zip |
create set_value function
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.c | 60 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.h | 2 |
2 files changed, 28 insertions, 34 deletions
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c index 9ae812c97..3d9ac4d88 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.c +++ b/src/ats/gnunet-service-ats_addresses_mlp.c | |||
@@ -1095,6 +1095,23 @@ mlp_create_problem_add_address_information (struct GAS_MLP_Handle *mlp, struct M | |||
1095 | 1095 | ||
1096 | } | 1096 | } |
1097 | 1097 | ||
1098 | static void | ||
1099 | mlp_create_problem_set_value (struct MLP_Problem *p, int row, int col, double val) | ||
1100 | { | ||
1101 | if ((p->ci + 1) >= p->num_elements) | ||
1102 | { | ||
1103 | GNUNET_break (0); | ||
1104 | return; | ||
1105 | } | ||
1106 | p->ia[p->ci] = row ; | ||
1107 | p->ja[p->ci] = col; | ||
1108 | p->ar[p->ci] = val; | ||
1109 | #if DEBUG_MLP_PROBLEM_CREATION | ||
1110 | LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: Set value [%u,%u] == %.2f\n", | ||
1111 | p->ia[p->ci], p->ja[p->ci], p->ar[p->ci]); | ||
1112 | #endif | ||
1113 | p->ci++; | ||
1114 | } | ||
1098 | 1115 | ||
1099 | /** | 1116 | /** |
1100 | * Create the invariant columns c4, c6, c10, c8, c7 | 1117 | * Create the invariant columns c4, c6, c10, c8, c7 |
@@ -1132,15 +1149,7 @@ mlp_create_problem_add_invariant_rows (struct GAS_MLP_Handle *mlp, struct MLP_Pr | |||
1132 | "==", 0); | 1149 | "==", 0); |
1133 | #endif | 1150 | #endif |
1134 | /* c6 )Setting -D */ | 1151 | /* c6 )Setting -D */ |
1135 | p->ia[p->ci] = p->r_c6 ; | 1152 | mlp_create_problem_set_value (p, p->r_c6, p->c_d, -1); |
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 | |||
1144 | 1153 | ||
1145 | /* Add rows for c 10) */ | 1154 | /* Add rows for c 10) */ |
1146 | for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++) | 1155 | for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++) |
@@ -1171,15 +1180,7 @@ mlp_create_problem_add_invariant_rows (struct GAS_MLP_Handle *mlp, struct MLP_Pr | |||
1171 | "==", 0); | 1180 | "==", 0); |
1172 | #endif | 1181 | #endif |
1173 | /* -u */ | 1182 | /* -u */ |
1174 | p->ia[p->ci] = p->r_c8; | 1183 | mlp_create_problem_set_value (p, p->r_c8, p->c_u, -1); |
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 | |||
1183 | 1184 | ||
1184 | /* c 7) For all quality metrics */ | 1185 | /* c 7) For all quality metrics */ |
1185 | for (c = 0; c < mlp->pv.m_q; c++) | 1186 | for (c = 0; c < mlp->pv.m_q; c++) |
@@ -1195,14 +1196,7 @@ mlp_create_problem_add_invariant_rows (struct GAS_MLP_Handle *mlp, struct MLP_Pr | |||
1195 | "==", 0); | 1196 | "==", 0); |
1196 | #endif | 1197 | #endif |
1197 | GNUNET_free (name); | 1198 | GNUNET_free (name); |
1198 | p->ia[p->ci] = p->r_q[c]; | 1199 | mlp_create_problem_set_value (p, p->r_q[c], p->c_q[c], -1); |
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++; | ||
1206 | } | 1200 | } |
1207 | } | 1201 | } |
1208 | 1202 | ||
@@ -1289,7 +1283,6 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHas | |||
1289 | { | 1283 | { |
1290 | struct MLP_Problem *p = &mlp->p; | 1284 | struct MLP_Problem *p = &mlp->p; |
1291 | int res = GNUNET_OK; | 1285 | int res = GNUNET_OK; |
1292 | int elements; | ||
1293 | 1286 | ||
1294 | GNUNET_assert (p->prob == NULL); | 1287 | GNUNET_assert (p->prob == NULL); |
1295 | GNUNET_assert (p->ia == NULL); | 1288 | GNUNET_assert (p->ia == NULL); |
@@ -1302,9 +1295,9 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHas | |||
1302 | GNUNET_assert (NULL != p->prob); | 1295 | GNUNET_assert (NULL != p->prob); |
1303 | p->num_peers = GNUNET_CONTAINER_multihashmap_size (mlp->peers); | 1296 | p->num_peers = GNUNET_CONTAINER_multihashmap_size (mlp->peers); |
1304 | p->num_addresses = mlp_create_problem_count_addresses (addresses, mlp->peers); | 1297 | p->num_addresses = mlp_create_problem_count_addresses (addresses, mlp->peers); |
1305 | 1298 | p->num_elements = ((7 * p->num_addresses) + (5 * p->num_addresses + mlp->pv.m_q + p->num_peers + 2) + 1); | |
1306 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Rebuilding problem for %u peer(s) and %u addresse(s)\n", | 1299 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Rebuilding problem for %u peer(s) and %u addresse(s) == %u elements\n", |
1307 | p->num_peers, p->num_addresses); | 1300 | p->num_peers, p->num_addresses, p->num_elements); |
1308 | 1301 | ||
1309 | /* Set a problem name */ | 1302 | /* Set a problem name */ |
1310 | glp_set_prob_name (p->prob, "GNUnet ats bandwidth distribution"); | 1303 | glp_set_prob_name (p->prob, "GNUnet ats bandwidth distribution"); |
@@ -1313,16 +1306,15 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHas | |||
1313 | 1306 | ||
1314 | /* Create problem matrix */ | 1307 | /* Create problem matrix */ |
1315 | /* last +1 caused by glpk index starting with one: [1..elements]*/ | 1308 | /* 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; | 1309 | p->ci = 1; |
1318 | /* row index */ | 1310 | /* row index */ |
1319 | int *ia = GNUNET_malloc (elements * sizeof (int)); | 1311 | int *ia = GNUNET_malloc (p->num_elements * sizeof (int)); |
1320 | p->ia = ia; | 1312 | p->ia = ia; |
1321 | /* column index */ | 1313 | /* column index */ |
1322 | int *ja = GNUNET_malloc (elements * sizeof (int)); | 1314 | int *ja = GNUNET_malloc (p->num_elements * sizeof (int)); |
1323 | p->ja = ja; | 1315 | p->ja = ja; |
1324 | /* coefficient */ | 1316 | /* coefficient */ |
1325 | double *ar= GNUNET_malloc (elements * sizeof (double)); | 1317 | double *ar= GNUNET_malloc (p->num_elements * sizeof (double)); |
1326 | p->ar = ar; | 1318 | p->ar = ar; |
1327 | 1319 | ||
1328 | /* Adding invariant columns */ | 1320 | /* Adding invariant columns */ |
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.h b/src/ats/gnunet-service-ats_addresses_mlp.h index 04ead545e..ab6681b0b 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.h +++ b/src/ats/gnunet-service-ats_addresses_mlp.h | |||
@@ -104,6 +104,8 @@ struct MLP_Problem | |||
104 | unsigned int num_addresses; | 104 | unsigned int num_addresses; |
105 | /* Number of peers in problem */ | 105 | /* Number of peers in problem */ |
106 | unsigned int num_peers; | 106 | unsigned int num_peers; |
107 | /* Number of elements in problem matrix */ | ||
108 | unsigned int num_elements; | ||
107 | 109 | ||
108 | /* Row index constraint 2: */ | 110 | /* Row index constraint 2: */ |
109 | unsigned int r_c2; | 111 | unsigned int r_c2; |