aboutsummaryrefslogtreecommitdiff
path: root/src/ats
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-07-05 13:38:43 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-07-05 13:38:43 +0000
commit64f029eee70bc9c57eb674373b9d0ea78ec1f6be (patch)
tree868c81695865115698a4de21e9487077871e627c /src/ats
parentb536843b7b700223eed2028f678d8c9fab4e444e (diff)
downloadgnunet-64f029eee70bc9c57eb674373b9d0ea78ec1f6be.tar.gz
gnunet-64f029eee70bc9c57eb674373b9d0ea78ec1f6be.zip
improved value updating for unkown values
Diffstat (limited to 'src/ats')
-rw-r--r--src/ats/gnunet-service-ats-solver_mlp.c55
1 files changed, 29 insertions, 26 deletions
diff --git a/src/ats/gnunet-service-ats-solver_mlp.c b/src/ats/gnunet-service-ats-solver_mlp.c
index b93508406..27ff63ea3 100644
--- a/src/ats/gnunet-service-ats-solver_mlp.c
+++ b/src/ats/gnunet-service-ats-solver_mlp.c
@@ -433,6 +433,7 @@ mlp_create_problem_update_value (struct MLP_Problem *p,
433 int c_elems; 433 int c_elems;
434 int c1; 434 int c1;
435 int res; 435 int res;
436 int found;
436 double *val_array; 437 double *val_array;
437 int *ind_array; 438 int *ind_array;
438 439
@@ -450,42 +451,44 @@ mlp_create_problem_update_value (struct MLP_Problem *p,
450 GNUNET_assert (NULL != ind_array); 451 GNUNET_assert (NULL != ind_array);
451 /* Extract the row */ 452 /* Extract the row */
452 453
453 if (0 == (c_elems = glp_get_mat_row (p->prob, row, ind_array, val_array)))
454 {
455 ind_array[1] = col;
456 val_array[1] = val;
457 LOG (GNUNET_ERROR_TYPE_DEBUG, "[P] Updating value in [%s : %s] to `%.2f'\n",
458 glp_get_row_name (p->prob, row), glp_get_col_name (p->prob, col),
459 val);
460 glp_set_mat_row (p->prob, row, 1, ind_array, val_array);
461 return GNUNET_YES;
462 }
463
464 /* Update the value */ 454 /* Update the value */
455 c_elems = glp_get_mat_row (p->prob, row, ind_array, val_array);
456 found = GNUNET_NO;
465 for (c1 = 1; c1 < (c_elems+1); c1++) 457 for (c1 = 1; c1 < (c_elems+1); c1++)
466 { 458 {
467 if (ind_array[c1] == col) 459 if (ind_array[c1] == col)
460 {
461 found = GNUNET_YES;
468 break; 462 break;
463 }
469 } 464 }
470 if ((c_elems + 1)== c1) 465 if (GNUNET_NO == found)
471 { 466 {
472 GNUNET_free (ind_array); 467 ind_array[c_elems+1] = col;
473 GNUNET_free (val_array); 468 val_array[c_elems+1] = val;
474 GNUNET_break (0); 469 LOG (GNUNET_ERROR_TYPE_DEBUG, "[P] Setting value in [%s : %s] to `%.2f'\n",
475 return GNUNET_SYSERR; /* not found */ 470 glp_get_row_name (p->prob, row), glp_get_col_name (p->prob, col),
471 val);
472 glp_set_mat_row (p->prob, row, c_elems+1, ind_array, val_array);
473 GNUNET_free (ind_array);
474 GNUNET_free (val_array);
475 return GNUNET_YES;
476 } 476 }
477 /* Update value */
478 LOG (GNUNET_ERROR_TYPE_DEBUG, "[P] Updating value in [%s : %s] from `%.2f' to `%.2f'\n",
479 glp_get_row_name (p->prob, row), glp_get_col_name (p->prob, col),
480 val_array[c1], val);
481 if (val != val_array[c1])
482 res = GNUNET_YES;
483 else 477 else
484 res = GNUNET_NO; 478 {
485 val_array[c1] = val; 479 /* Update value */
480 LOG (GNUNET_ERROR_TYPE_DEBUG, "[P] Updating value in [%s : %s] from `%.2f' to `%.2f'\n",
481 glp_get_row_name (p->prob, row), glp_get_col_name (p->prob, col),
482 val_array[c1], val);
483 if (val != val_array[c1])
484 res = GNUNET_YES;
485 else
486 res = GNUNET_NO;
487 val_array[c1] = val;
488 /* Update the row in the matrix */
489 glp_set_mat_row (p->prob, row, c_elems, ind_array, val_array);
490 }
486 491
487 /* Update the row in the matrix */
488 glp_set_mat_row (p->prob, row, c_elems, ind_array, val_array);
489 GNUNET_free (ind_array); 492 GNUNET_free (ind_array);
490 GNUNET_free (val_array); 493 GNUNET_free (val_array);
491 return res; 494 return res;