diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-01-18 13:28:03 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-01-18 13:28:03 +0000 |
commit | 7e5155c6686807af805491f7e7cfc68de91c1963 (patch) | |
tree | b31e28b1f1f09ceec4bddb3a93d0563eb47d6cf2 /src/ats | |
parent | 7c6b8edcc300e1be76803a9b80bfd720ddf0283a (diff) | |
download | gnunet-7e5155c6686807af805491f7e7cfc68de91c1963.tar.gz gnunet-7e5155c6686807af805491f7e7cfc68de91c1963.zip |
- constraint 1 & 3
Diffstat (limited to 'src/ats')
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.c | 71 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.h | 9 |
2 files changed, 78 insertions, 2 deletions
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c index a878ddd9e..54abd9d89 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.c +++ b/src/ats/gnunet-service-ats_addresses_mlp.c | |||
@@ -32,9 +32,12 @@ | |||
32 | #if HAVE_LIBGLPK | 32 | #if HAVE_LIBGLPK |
33 | #include "glpk.h" | 33 | #include "glpk.h" |
34 | #endif | 34 | #endif |
35 | #include "float.h" | ||
35 | 36 | ||
36 | #define DEBUG_ATS GNUNET_YES | 37 | #define DEBUG_ATS GNUNET_YES |
37 | #define VERY_BIG_DOUBLE_VALUE DBL_MAX | 38 | |
39 | /* A very big value */ | ||
40 | #define M DBL_MAX | ||
38 | 41 | ||
39 | /** | 42 | /** |
40 | * Translate glpk solver error codes to text | 43 | * Translate glpk solver error codes to text |
@@ -189,6 +192,68 @@ mlp_delete_problem (struct GAS_MLP_Handle *mlp) | |||
189 | } | 192 | } |
190 | 193 | ||
191 | /** | 194 | /** |
195 | * Add constraints that are iterating over "forall addresses" | ||
196 | * and collects all existing peers for "forall peers" constraints | ||
197 | * | ||
198 | * @param cls GAS_MLP_Handle | ||
199 | * @param key Hashcode | ||
200 | * @param value ATS_Address | ||
201 | * | ||
202 | * @return GNUNET_OK to continue | ||
203 | */ | ||
204 | static int | ||
205 | create_constraint_it (void *cls, const GNUNET_HashCode * key, void *value) | ||
206 | { | ||
207 | struct GAS_MLP_Handle *mlp = cls; | ||
208 | struct ATS_Address *address = value; | ||
209 | struct MLP_information *mlpi; | ||
210 | unsigned int row_index; | ||
211 | |||
212 | GNUNET_assert (address->mlp_information != NULL); | ||
213 | mlpi = (struct MLP_information *) address->mlp_information; | ||
214 | |||
215 | /* c 1) bandwidth capping | ||
216 | * b_t + (-M) * n_t <= 0 | ||
217 | */ | ||
218 | row_index = glp_add_rows (mlp->prob, 1); | ||
219 | mlpi->r_c1 = row_index; | ||
220 | /* set row bounds: <= 0 */ | ||
221 | glp_set_row_bnds (mlp->prob, row_index, GLP_UP, 0.0, 0.0); | ||
222 | |||
223 | mlp->ia[mlp->ci] = row_index; | ||
224 | mlp->ja[mlp->ci] = mlpi->c_b; | ||
225 | mlp->ar[mlp->ci] = 1; | ||
226 | mlp->ci++; | ||
227 | |||
228 | mlp->ia[mlp->ci] = row_index; | ||
229 | mlp->ja[mlp->ci] = mlpi->c_b; | ||
230 | mlp->ar[mlp->ci] = -M; | ||
231 | mlp->ci++; | ||
232 | |||
233 | /* c 3) minimum bandwidth | ||
234 | * b_t + (-n_t * b_min) >= 0 | ||
235 | */ | ||
236 | |||
237 | row_index = glp_add_rows (mlp->prob, 1); | ||
238 | mlpi->r_c3 = row_index; | ||
239 | /* set row bounds: >= 0 */ | ||
240 | glp_set_row_bnds (mlp->prob, row_index, GLP_LO, 0.0, 0.0); | ||
241 | |||
242 | mlp->ia[mlp->ci] = row_index; | ||
243 | mlp->ja[mlp->ci] = mlpi->c_b; | ||
244 | mlp->ar[mlp->ci] = 1; | ||
245 | mlp->ci++; | ||
246 | |||
247 | mlp->ia[mlp->ci] = row_index; | ||
248 | mlp->ja[mlp->ci] = mlpi->c_b; | ||
249 | mlp->ar[mlp->ci] = -mlp->b_min; | ||
250 | mlp->ci++; | ||
251 | |||
252 | return GNUNET_OK; | ||
253 | } | ||
254 | |||
255 | |||
256 | /** | ||
192 | * Adds the problem constraints for all addresses | 257 | * Adds the problem constraints for all addresses |
193 | * Required for problem recreation after address deletion | 258 | * Required for problem recreation after address deletion |
194 | * | 259 | * |
@@ -238,6 +303,7 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON | |||
238 | 303 | ||
239 | int pi = (7 * n_addresses); | 304 | int pi = (7 * n_addresses); |
240 | mlp->cm_size = pi; | 305 | mlp->cm_size = pi; |
306 | mlp->ci = 0; | ||
241 | 307 | ||
242 | /* row index */ | 308 | /* row index */ |
243 | int *ia = GNUNET_malloc (pi * sizeof (int)); | 309 | int *ia = GNUNET_malloc (pi * sizeof (int)); |
@@ -251,11 +317,12 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON | |||
251 | double *ar= GNUNET_malloc (pi * sizeof (double)); | 317 | double *ar= GNUNET_malloc (pi * sizeof (double)); |
252 | mlp->ar = ar; | 318 | mlp->ar = ar; |
253 | 319 | ||
254 | |||
255 | /* Adding constraint rows */ | 320 | /* Adding constraint rows */ |
256 | /* Feasibility constraints */ | 321 | /* Feasibility constraints */ |
257 | 322 | ||
258 | /* c 1) bandwidth capping */ | 323 | /* c 1) bandwidth capping */ |
324 | /* c 3) minimum bandwidth */ | ||
325 | GNUNET_CONTAINER_multihashmap_iterate (addresses, create_constraint_it, mlp); | ||
259 | 326 | ||
260 | } | 327 | } |
261 | 328 | ||
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.h b/src/ats/gnunet-service-ats_addresses_mlp.h index 56616ae85..bb86d2251 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.h +++ b/src/ats/gnunet-service-ats_addresses_mlp.h | |||
@@ -144,6 +144,7 @@ struct GAS_MLP_Handle | |||
144 | double *ar; | 144 | double *ar; |
145 | /* current size of the constraint matrix |indices| */ | 145 | /* current size of the constraint matrix |indices| */ |
146 | unsigned int cm_size; | 146 | unsigned int cm_size; |
147 | unsigned int ci; | ||
147 | 148 | ||
148 | /* column index Diversity (D) column */ | 149 | /* column index Diversity (D) column */ |
149 | int c_d; | 150 | int c_d; |
@@ -189,6 +190,14 @@ struct MLP_information | |||
189 | 190 | ||
190 | /* address usage column */ | 191 | /* address usage column */ |
191 | signed int c_n; | 192 | signed int c_n; |
193 | |||
194 | /* row indexes */ | ||
195 | |||
196 | /* constraint 1: bandwidth capping */ | ||
197 | unsigned int r_c1; | ||
198 | |||
199 | /* constraint 3: minimum bandwidth */ | ||
200 | unsigned int r_c3; | ||
192 | }; | 201 | }; |
193 | 202 | ||
194 | 203 | ||