diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-07-04 07:58:20 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-07-04 07:58:20 +0000 |
commit | 22d740193d80f0bd86035743a7804e84672bf54a (patch) | |
tree | 628be37c2cba89103253945c133bc7d568579fc6 | |
parent | 22ce2ce1b9941f585bfbac1acc0489d86a0b10a5 (diff) | |
download | gnunet-22d740193d80f0bd86035743a7804e84672bf54a.tar.gz gnunet-22d740193d80f0bd86035743a7804e84672bf54a.zip |
new function to update a value in the matrix
-rw-r--r-- | src/ats/gnunet-service-ats-solver_mlp.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/ats/gnunet-service-ats-solver_mlp.c b/src/ats/gnunet-service-ats-solver_mlp.c index 4b7548750..12687eac4 100644 --- a/src/ats/gnunet-service-ats-solver_mlp.c +++ b/src/ats/gnunet-service-ats-solver_mlp.c | |||
@@ -411,7 +411,76 @@ static int mlp_create_problem_count_addresses ( | |||
411 | } | 411 | } |
412 | 412 | ||
413 | 413 | ||
414 | /** | ||
415 | * Updates an existing value in the matrix | ||
416 | * | ||
417 | * Extract the row, updates the value and updates the row in the problem | ||
418 | * | ||
419 | * @param p the mlp problem | ||
420 | * @param row the row to create the value in | ||
421 | * @param col the column to create the value in | ||
422 | * @param val the value to set | ||
423 | * @param line calling line for debbuging | ||
424 | */ | ||
425 | static void | ||
426 | mlp_create_problem_update_value (struct MLP_Problem *p, | ||
427 | int row, int col, double val, | ||
428 | int line) | ||
429 | { | ||
430 | int c_cols; | ||
431 | int c_elems; | ||
432 | int c1; | ||
433 | double *val_array; | ||
434 | int *ind_array; | ||
435 | |||
436 | GNUNET_assert (NULL != p); | ||
437 | GNUNET_assert (NULL != p->prob); | ||
438 | |||
439 | /* Get number of columns and prepare data structure */ | ||
440 | c_cols = glp_get_num_cols(p->prob); | ||
441 | if (0 >= c_cols) | ||
442 | return; | ||
443 | |||
444 | val_array = GNUNET_malloc (c_cols * sizeof (double)); | ||
445 | GNUNET_assert (NULL != val_array); | ||
446 | ind_array = GNUNET_malloc (c_cols * sizeof (int)); | ||
447 | GNUNET_assert (NULL != ind_array); | ||
448 | /* Extract the row */ | ||
414 | 449 | ||
450 | if (0 == (c_elems = glp_get_mat_row (p->prob, row, ind_array, val_array))) | ||
451 | return; | ||
452 | |||
453 | /* Update the value */ | ||
454 | for (c1 = 0; c1 <= c_elems; c1++) | ||
455 | { | ||
456 | if (ind_array[c1] == row) | ||
457 | break; | ||
458 | } | ||
459 | if (c_elems == c1) | ||
460 | return; /* not found */ | ||
461 | |||
462 | /* Update value */ | ||
463 | val_array[c1] = val; | ||
464 | |||
465 | /* Update the row in the matrix */ | ||
466 | glp_set_mat_row (p->prob, row, c_elems, ind_array, val_array); | ||
467 | GNUNET_free (ind_array); | ||
468 | GNUNET_free (val_array); | ||
469 | //p-> = GNUNET_YES; | ||
470 | } | ||
471 | |||
472 | /** | ||
473 | * Creates a new value in the matrix | ||
474 | * | ||
475 | * Sets the row and column index in the problem array and increments the | ||
476 | * position field | ||
477 | * | ||
478 | * @param p the mlp problem | ||
479 | * @param row the row to create the value in | ||
480 | * @param col the column to create the value in | ||
481 | * @param val the value to set | ||
482 | * @param line calling line for debbuging | ||
483 | */ | ||
415 | static void | 484 | static void |
416 | mlp_create_problem_set_value (struct MLP_Problem *p, | 485 | mlp_create_problem_set_value (struct MLP_Problem *p, |
417 | int row, int col, double val, | 486 | int row, int col, double val, |