aboutsummaryrefslogtreecommitdiff
path: root/src/ats
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-01-19 14:50:40 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-01-19 14:50:40 +0000
commit9b41d405b9d318b6748b8c233c0b80a4e76bcf43 (patch)
treefbc2cca013601bce2134ef9bfee39ebb06d7a0e5 /src/ats
parent4a4d5fab309bb2c5a45c13f63e36415e04caf390 (diff)
downloadgnunet-9b41d405b9d318b6748b8c233c0b80a4e76bcf43.tar.gz
gnunet-9b41d405b9d318b6748b8c233c0b80a4e76bcf43.zip
- basic constraints working correct
Diffstat (limited to 'src/ats')
-rw-r--r--src/ats/gnunet-service-ats_addresses_mlp.c66
1 files changed, 32 insertions, 34 deletions
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c
index 798d8edc6..badad5588 100644
--- a/src/ats/gnunet-service-ats_addresses_mlp.c
+++ b/src/ats/gnunet-service-ats_addresses_mlp.c
@@ -31,8 +31,8 @@
31#include "gnunet_statistics_service.h" 31#include "gnunet_statistics_service.h"
32#include "glpk.h" 32#include "glpk.h"
33 33
34#define WRITE_MLP GNUNET_YES 34#define WRITE_MLP GNUNET_NO
35#define DEBUG_ATS GNUNET_YES 35#define DEBUG_ATS GNUNET_EXTRA_LOGGING
36 36
37/** 37/**
38 * Translate glpk solver error codes to text 38 * Translate glpk solver error codes to text
@@ -233,6 +233,7 @@ create_constraint_it (void *cls, const GNUNET_HashCode * key, void *value)
233 struct ATS_Address *address = value; 233 struct ATS_Address *address = value;
234 struct MLP_information *mlpi; 234 struct MLP_information *mlpi;
235 unsigned int row_index; 235 unsigned int row_index;
236 char *name;
236 237
237 GNUNET_assert (address->mlp_information != NULL); 238 GNUNET_assert (address->mlp_information != NULL);
238 mlpi = (struct MLP_information *) address->mlp_information; 239 mlpi = (struct MLP_information *) address->mlp_information;
@@ -242,6 +243,10 @@ create_constraint_it (void *cls, const GNUNET_HashCode * key, void *value)
242 */ 243 */
243 row_index = glp_add_rows (mlp->prob, 1); 244 row_index = glp_add_rows (mlp->prob, 1);
244 mlpi->r_c1 = row_index; 245 mlpi->r_c1 = row_index;
246 /* set row name */
247 GNUNET_asprintf(&name, "c1_%s_%s", GNUNET_i2s(&address->peer), address->plugin);
248 glp_set_row_name (mlp->prob, row_index, name);
249 GNUNET_free (name);
245 /* set row bounds: <= 0 */ 250 /* set row bounds: <= 0 */
246 glp_set_row_bnds (mlp->prob, row_index, GLP_UP, 0.0, 0.0); 251 glp_set_row_bnds (mlp->prob, row_index, GLP_UP, 0.0, 0.0);
247 mlp->ia[mlp->ci] = row_index; 252 mlp->ia[mlp->ci] = row_index;
@@ -259,10 +264,13 @@ create_constraint_it (void *cls, const GNUNET_HashCode * key, void *value)
259 */ 264 */
260 265
261 row_index = glp_add_rows (mlp->prob, 1); 266 row_index = glp_add_rows (mlp->prob, 1);
267 /* set row name */
268 GNUNET_asprintf(&name, "c3_%s_%s", GNUNET_i2s(&address->peer), address->plugin);
269 glp_set_row_name (mlp->prob, row_index, name);
270 GNUNET_free (name);
262 mlpi->r_c3 = row_index; 271 mlpi->r_c3 = row_index;
263 /* set row bounds: >= 0 */ 272 /* set row bounds: >= 0 */
264 glp_set_row_bnds (mlp->prob, row_index, GLP_LO, 0.0, 0.0); 273 glp_set_row_bnds (mlp->prob, row_index, GLP_LO, 0.0, 0.0);
265 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "ats-mlp", "bmin %i %f\n", mlp->b_min, mlp->BIG_M);
266 274
267 mlp->ia[mlp->ci] = row_index; 275 mlp->ia[mlp->ci] = row_index;
268 mlp->ja[mlp->ci] = mlpi->c_b; 276 mlp->ja[mlp->ci] = mlpi->c_b;
@@ -273,7 +281,7 @@ create_constraint_it (void *cls, const GNUNET_HashCode * key, void *value)
273 mlp->ja[mlp->ci] = mlpi->c_n; 281 mlp->ja[mlp->ci] = mlpi->c_n;
274 mlp->ar[mlp->ci] = - (double) mlp->b_min; 282 mlp->ar[mlp->ci] = - (double) mlp->b_min;
275 mlp->ci++; 283 mlp->ci++;
276#if 0 284
277 /* c 4) minimum connections 285 /* c 4) minimum connections
278 * (1)*n_1 + ... + (1)*n_m >= n_min 286 * (1)*n_1 + ... + (1)*n_m >= n_min
279 */ 287 */
@@ -289,7 +297,6 @@ create_constraint_it (void *cls, const GNUNET_HashCode * key, void *value)
289 mlp->ja[mlp->ci] = mlpi->c_n; 297 mlp->ja[mlp->ci] = mlpi->c_n;
290 mlp->ar[mlp->ci] = 1; 298 mlp->ar[mlp->ci] = 1;
291 mlp->ci++; 299 mlp->ci++;
292#endif
293 300
294 return GNUNET_OK; 301 return GNUNET_OK;
295} 302}
@@ -308,6 +315,7 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON
308 unsigned int n_addresses; 315 unsigned int n_addresses;
309 int row_index; 316 int row_index;
310 //int c; 317 //int c;
318 char *name;
311 319
312 /* Problem matrix*/ 320 /* Problem matrix*/
313 n_addresses = GNUNET_CONTAINER_multihashmap_size(addresses); 321 n_addresses = GNUNET_CONTAINER_multihashmap_size(addresses);
@@ -351,7 +359,7 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON
351 * #indices:|quality properties| + |n_addresses| 359 * #indices:|quality properties| + |n_addresses|
352 * */ 360 * */
353 361
354 int pi = ((7 * n_addresses) /*+ (2 * n_addresses + mlp->m_q + 1)*/); 362 int pi = ((7 * n_addresses) + (2 * n_addresses + mlp->m_q + 1));
355 mlp->cm_size = pi; 363 mlp->cm_size = pi;
356 mlp->ci = 1; 364 mlp->ci = 1;
357 365
@@ -380,12 +388,13 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON
380 int min = mlp->n_min; 388 int min = mlp->n_min;
381 if (mlp->n_min > mlp->c_p) 389 if (mlp->n_min > mlp->c_p)
382 min = mlp->c_p; 390 min = mlp->c_p;
383/* 391
384 mlp->r_c4 = glp_add_rows (mlp->prob, 1); 392 mlp->r_c4 = glp_add_rows (mlp->prob, 1);
385 glp_set_row_bnds (mlp->prob, mlp->r_c4, GLP_FX, min, min); 393 glp_set_row_name (mlp->prob, mlp->r_c4, "c4");
386*/ 394 glp_set_row_bnds (mlp->prob, mlp->r_c4, GLP_LO, min, min);
395
387 /* Add row for c6) */ 396 /* Add row for c6) */
388#if 0 397
389 mlp->r_c6 = glp_add_rows (mlp->prob, 1); 398 mlp->r_c6 = glp_add_rows (mlp->prob, 1);
390 /* Set type type to fix */ 399 /* Set type type to fix */
391 glp_set_row_bnds (mlp->prob, mlp->r_c6, GLP_FX, 0.0, 0.0); 400 glp_set_row_bnds (mlp->prob, mlp->r_c6, GLP_FX, 0.0, 0.0);
@@ -394,7 +403,7 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON
394 ja[mlp->ci] = mlp->c_d; 403 ja[mlp->ci] = mlp->c_d;
395 ar[mlp->ci] = -1; 404 ar[mlp->ci] = -1;
396 mlp->ci++; 405 mlp->ci++;
397#endif 406
398 GNUNET_CONTAINER_multihashmap_iterate (addresses, create_constraint_it, mlp); 407 GNUNET_CONTAINER_multihashmap_iterate (addresses, create_constraint_it, mlp);
399 408
400 /* Adding constraint rows 409 /* Adding constraint rows
@@ -404,7 +413,7 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON
404 * c 2) 1 address per peer 413 * c 2) 1 address per peer
405 * sum (n_p1_1 + ... + n_p1_n) = 1 414 * sum (n_p1_1 + ... + n_p1_n) = 1
406 */ 415 */
407return; 416
408 /* Adding rows for c 2) */ 417 /* Adding rows for c 2) */
409 row_index = glp_add_rows (mlp->prob, mlp->c_p); 418 row_index = glp_add_rows (mlp->prob, mlp->c_p);
410 419
@@ -412,18 +421,21 @@ return;
412 while (peer != NULL) 421 while (peer != NULL)
413 { 422 {
414 struct ATS_Address *addr = peer->head; 423 struct ATS_Address *addr = peer->head;
415 struct MLP_information *mlpi = (struct MLP_information *) addr->mlp_information; 424 struct MLP_information *mlpi = NULL;
416 /* Adding row for c 2) */ 425 /* Adding row for c 2) */
426 GNUNET_asprintf(&name, "c2_%s", GNUNET_i2s(&peer->id));
427 glp_set_row_name (mlp->prob, row_index, name);
428 GNUNET_free (name);
417 /* Set row bound == 1 */ 429 /* Set row bound == 1 */
418 glp_set_row_bnds (mlp->prob, row_index, GLP_FX, 1.0, 1.0); 430 glp_set_row_bnds (mlp->prob, row_index, GLP_FX, 1.0, 1.0);
419 431
420 while (addr != NULL) 432 while (addr != NULL)
421 { 433 {
434 mlpi = (struct MLP_information *) addr->mlp_information;
422 ia[mlp->ci] = row_index; 435 ia[mlp->ci] = row_index;
423 ja[mlp->ci] = mlpi->c_n; 436 ja[mlp->ci] = mlpi->c_n;
424 ar[mlp->ci] = 1; 437 ar[mlp->ci] = 1;
425 mlp->ci++; 438 mlp->ci++;
426
427 addr = addr->next; 439 addr = addr->next;
428 } 440 }
429 peer = peer->next; 441 peer = peer->next;
@@ -483,7 +495,7 @@ create_columns_it (void *cls, const GNUNET_HashCode * key, void *value)
483 /* Continuous value*/ 495 /* Continuous value*/
484 glp_set_col_kind (mlp->prob, mlpi->c_b , GLP_CV); 496 glp_set_col_kind (mlp->prob, mlpi->c_b , GLP_CV);
485 /* Objective function coefficient == 0 */ 497 /* Objective function coefficient == 0 */
486 glp_set_obj_coef (mlp->prob, mlpi->c_b , 1); 498 glp_set_obj_coef (mlp->prob, mlpi->c_b , 0);
487 499
488 500
489 /* Add usage column */ 501 /* Add usage column */
@@ -495,7 +507,7 @@ create_columns_it (void *cls, const GNUNET_HashCode * key, void *value)
495 /* Integer value*/ 507 /* Integer value*/
496 glp_set_col_kind (mlp->prob, mlpi->c_n, GLP_IV); 508 glp_set_col_kind (mlp->prob, mlpi->c_n, GLP_IV);
497 /* Objective function coefficient == 0 */ 509 /* Objective function coefficient == 0 */
498 glp_set_obj_coef (mlp->prob, mlpi->c_n, 1); 510 glp_set_obj_coef (mlp->prob, mlpi->c_n, 0);
499 511
500 return GNUNET_OK; 512 return GNUNET_OK;
501} 513}
@@ -512,8 +524,9 @@ static int
512mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses) 524mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses)
513{ 525{
514 int res = GNUNET_OK; 526 int res = GNUNET_OK;
515/* 527
516 int col; 528 int col;
529/*
517 int c; 530 int c;
518 char *name; 531 char *name;
519*/ 532*/
@@ -531,7 +544,7 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHas
531 /* Adding invariant columns */ 544 /* Adding invariant columns */
532 545
533 /* Diversity d column */ 546 /* Diversity d column */
534#if 0 547
535 col = glp_add_cols (mlp->prob, 1); 548 col = glp_add_cols (mlp->prob, 1);
536 mlp->c_d = col; 549 mlp->c_d = col;
537 /* Column name */ 550 /* Column name */
@@ -540,7 +553,7 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHas
540 glp_set_obj_coef (mlp->prob, col, mlp->co_D); 553 glp_set_obj_coef (mlp->prob, col, mlp->co_D);
541 /* Column lower bound = 0.0 */ 554 /* Column lower bound = 0.0 */
542 glp_set_col_bnds (mlp->prob, col, GLP_LO, 0.0, 0.0); 555 glp_set_col_bnds (mlp->prob, col, GLP_LO, 0.0, 0.0);
543 556#if 0
544 /* Utilization u column */ 557 /* Utilization u column */
545 558
546 col = glp_add_cols (mlp->prob, 1); 559 col = glp_add_cols (mlp->prob, 1);
@@ -819,8 +832,6 @@ mlp_solve_problem (struct GAS_MLP_Handle *mlp)
819 glp_print_mip (mlp->prob, name); 832 glp_print_mip (mlp->prob, name);
820 GNUNET_free (name); 833 GNUNET_free (name);
821# endif 834# endif
822
823
824 if (res != GNUNET_OK) 835 if (res != GNUNET_OK)
825 { 836 {
826#if DEBUG_ATS 837#if DEBUG_ATS
@@ -829,16 +840,6 @@ mlp_solve_problem (struct GAS_MLP_Handle *mlp)
829 return GNUNET_SYSERR; 840 return GNUNET_SYSERR;
830 } 841 }
831 842
832 res = glp_mip_status(mlp->prob);
833
834 if (res != GNUNET_OK)
835 {
836#if DEBUG_ATS
837 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "LP Problem solving failed\n");
838#endif
839 return GNUNET_SYSERR;
840 }
841
842#if DEBUG_ATS 843#if DEBUG_ATS
843 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Problem solved: %i %s\n", res, mlp_status_to_string(res)); 844 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Problem solved: %i %s\n", res, mlp_status_to_string(res));
844#endif 845#endif
@@ -1135,9 +1136,6 @@ GAS_mlp_address_delete (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult
1135 mlp_delete_problem (mlp); 1136 mlp_delete_problem (mlp);
1136 if ((GNUNET_CONTAINER_multihashmap_size (addresses) > 0) && (mlp->c_p > 0)) 1137 if ((GNUNET_CONTAINER_multihashmap_size (addresses) > 0) && (mlp->c_p > 0))
1137 { 1138 {
1138#if DEBUG_ATS
1139 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "mlp_create_problem %i\n",__LINE__);
1140#endif
1141 mlp_create_problem (mlp, addresses); 1139 mlp_create_problem (mlp, addresses);
1142 1140
1143 /* Recalculate */ 1141 /* Recalculate */