summaryrefslogtreecommitdiff
path: root/src/ats/plugin_ats_mlp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ats/plugin_ats_mlp.c')
-rw-r--r--src/ats/plugin_ats_mlp.c2260
1 files changed, 1154 insertions, 1106 deletions
diff --git a/src/ats/plugin_ats_mlp.c b/src/ats/plugin_ats_mlp.c
index 0f3a727a7..8d3c9e23a 100644
--- a/src/ats/plugin_ats_mlp.c
+++ b/src/ats/plugin_ats_mlp.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file ats/plugin_ats_mlp.c 22 * @file ats/plugin_ats_mlp.c
@@ -34,7 +34,7 @@
34#include <glpk.h> 34#include <glpk.h>
35 35
36 36
37#define BIG_M_VALUE (UINT32_MAX) /10 37#define BIG_M_VALUE (UINT32_MAX) / 10
38#define BIG_M_STRING "unlimited" 38#define BIG_M_STRING "unlimited"
39 39
40#define MLP_AVERAGING_QUEUE_LENGTH 3 40#define MLP_AVERAGING_QUEUE_LENGTH 3
@@ -54,16 +54,14 @@
54#define GLP_YES 1.0 54#define GLP_YES 1.0
55#define GLP_NO 0.0 55#define GLP_NO 0.0
56 56
57enum MLP_Output_Format 57enum MLP_Output_Format {
58{
59 MLP_MPS, 58 MLP_MPS,
60 MLP_CPLEX, 59 MLP_CPLEX,
61 MLP_GLPK 60 MLP_GLPK
62}; 61};
63 62
64 63
65enum QualityMetrics 64enum QualityMetrics {
66{
67 RQ_QUALITY_METRIC_DELAY = 0, 65 RQ_QUALITY_METRIC_DELAY = 0,
68 RQ_QUALITY_METRIC_DISTANCE = 1, 66 RQ_QUALITY_METRIC_DISTANCE = 1,
69 RQ_QUALITY_METRIC_COUNT = 2 67 RQ_QUALITY_METRIC_COUNT = 2
@@ -71,22 +69,24 @@ enum QualityMetrics
71 69
72 70
73static const char * 71static const char *
74print_quality_type (enum QualityMetrics qm) 72print_quality_type(enum QualityMetrics qm)
75{ 73{
76 switch (qm){ 74 switch (qm)
77 case RQ_QUALITY_METRIC_DELAY: 75 {
78 return "delay"; 76 case RQ_QUALITY_METRIC_DELAY:
79 case RQ_QUALITY_METRIC_DISTANCE: 77 return "delay";
80 return "distance"; 78
81 default: 79 case RQ_QUALITY_METRIC_DISTANCE:
82 GNUNET_break (0); 80 return "distance";
83 return NULL; 81
84 } 82 default:
83 GNUNET_break(0);
84 return NULL;
85 }
85} 86}
86 87
87 88
88struct MLP_Solution 89struct MLP_Solution {
89{
90 int lp_res; 90 int lp_res;
91 int lp_presolv; 91 int lp_presolv;
92 int mip_res; 92 int mip_res;
@@ -103,11 +103,9 @@ struct MLP_Solution
103 103
104 int n_peers; 104 int n_peers;
105 int n_addresses; 105 int n_addresses;
106
107}; 106};
108 107
109struct ATS_Peer 108struct ATS_Peer {
110{
111 struct GNUNET_PeerIdentity id; 109 struct GNUNET_PeerIdentity id;
112 110
113 /* Was this peer already added to the current problem? */ 111 /* Was this peer already added to the current problem? */
@@ -123,8 +121,7 @@ struct ATS_Peer
123 double f; 121 double f;
124}; 122};
125 123
126struct MLP_Problem 124struct MLP_Problem {
127{
128 /** 125 /**
129 * GLPK (MLP) problem object 126 * GLPK (MLP) problem object
130 */ 127 */
@@ -170,11 +167,9 @@ struct MLP_Problem
170 int *ja; 167 int *ja;
171 /* Column index value */ 168 /* Column index value */
172 double *ar; 169 double *ar;
173
174}; 170};
175 171
176struct MLP_Variables 172struct MLP_Variables {
177{
178 /* Big M value for bandwidth capping */ 173 /* Big M value for bandwidth capping */
179 double BIG_M; 174 double BIG_M;
180 175
@@ -225,14 +220,12 @@ struct MLP_Variables
225 * contains mapping to GNUNET_ATS_Property 220 * contains mapping to GNUNET_ATS_Property
226 * */ 221 * */
227 int rc[RQ_QUALITY_METRIC_COUNT]; 222 int rc[RQ_QUALITY_METRIC_COUNT];
228
229}; 223};
230 224
231/** 225/**
232 * MLP Handle 226 * MLP Handle
233 */ 227 */
234struct GAS_MLP_Handle 228struct GAS_MLP_Handle {
235{
236 struct GNUNET_ATS_PluginEnvironment *env; 229 struct GNUNET_ATS_PluginEnvironment *env;
237 230
238 /** 231 /**
@@ -367,9 +360,7 @@ struct GAS_MLP_Handle
367/** 360/**
368 * Address specific MLP information 361 * Address specific MLP information
369 */ 362 */
370struct MLP_information 363struct MLP_information {
371{
372
373 /** 364 /**
374 * Bandwidth assigned outbound 365 * Bandwidth assigned outbound
375 */ 366 */
@@ -512,7 +503,7 @@ struct MLP_information
512 503
513 */ 504 */
514 505
515#define LOG(kind,...) GNUNET_log_from (kind, "ats-mlp",__VA_ARGS__) 506#define LOG(kind, ...) GNUNET_log_from(kind, "ats-mlp", __VA_ARGS__)
516 507
517/** 508/**
518 * Print debug output for mlp problem creation 509 * Print debug output for mlp problem creation
@@ -527,12 +518,12 @@ struct MLP_information
527 * @return 0: glpk prints output on terminal, 0 != surpress output 518 * @return 0: glpk prints output on terminal, 0 != surpress output
528 */ 519 */
529static int 520static int
530mlp_term_hook (void *info, const char *s) 521mlp_term_hook(void *info, const char *s)
531{ 522{
532 struct GAS_MLP_Handle *mlp = info; 523 struct GAS_MLP_Handle *mlp = info;
533 524
534 if (mlp->opt_dbg_glpk_verbose) 525 if (mlp->opt_dbg_glpk_verbose)
535 LOG (GNUNET_ERROR_TYPE_ERROR, "%s", s); 526 LOG(GNUNET_ERROR_TYPE_ERROR, "%s", s);
536 return 1; 527 return 1;
537} 528}
538 529
@@ -546,14 +537,15 @@ mlp_term_hook (void *info, const char *s)
546 * @return #GNUNET_OK 537 * @return #GNUNET_OK
547 */ 538 */
548static int 539static int
549reset_peers (void *cls, 540reset_peers(void *cls,
550 const struct GNUNET_PeerIdentity *key, 541 const struct GNUNET_PeerIdentity *key,
551 void *value) 542 void *value)
552 { 543{
553 struct ATS_Peer *peer = value; 544 struct ATS_Peer *peer = value;
554 peer->processed = GNUNET_NO; 545
555 return GNUNET_OK; 546 peer->processed = GNUNET_NO;
556 } 547 return GNUNET_OK;
548}
557 549
558/** 550/**
559 * Delete the MLP problem and free the constrain matrix 551 * Delete the MLP problem and free the constrain matrix
@@ -561,37 +553,38 @@ reset_peers (void *cls,
561 * @param mlp the MLP handle 553 * @param mlp the MLP handle
562 */ 554 */
563static void 555static void
564mlp_delete_problem (struct GAS_MLP_Handle *mlp) 556mlp_delete_problem(struct GAS_MLP_Handle *mlp)
565{ 557{
566 int c; 558 int c;
559
567 if (mlp == NULL) 560 if (mlp == NULL)
568 return; 561 return;
569 if (mlp->p.prob != NULL) 562 if (mlp->p.prob != NULL)
570 { 563 {
571 glp_delete_prob(mlp->p.prob); 564 glp_delete_prob(mlp->p.prob);
572 mlp->p.prob = NULL; 565 mlp->p.prob = NULL;
573 } 566 }
574 567
575 /* delete row index */ 568 /* delete row index */
576 if (mlp->p.ia != NULL) 569 if (mlp->p.ia != NULL)
577 { 570 {
578 GNUNET_free (mlp->p.ia); 571 GNUNET_free(mlp->p.ia);
579 mlp->p.ia = NULL; 572 mlp->p.ia = NULL;
580 } 573 }
581 574
582 /* delete column index */ 575 /* delete column index */
583 if (mlp->p.ja != NULL) 576 if (mlp->p.ja != NULL)
584 { 577 {
585 GNUNET_free (mlp->p.ja); 578 GNUNET_free(mlp->p.ja);
586 mlp->p.ja = NULL; 579 mlp->p.ja = NULL;
587 } 580 }
588 581
589 /* delete coefficients */ 582 /* delete coefficients */
590 if (mlp->p.ar != NULL) 583 if (mlp->p.ar != NULL)
591 { 584 {
592 GNUNET_free (mlp->p.ar); 585 GNUNET_free(mlp->p.ar);
593 mlp->p.ar = NULL; 586 mlp->p.ar = NULL;
594 } 587 }
595 mlp->p.ci = 0; 588 mlp->p.ci = 0;
596 mlp->p.prob = NULL; 589 mlp->p.prob = NULL;
597 590
@@ -601,15 +594,15 @@ mlp_delete_problem (struct GAS_MLP_Handle *mlp)
601 mlp->p.r_c4 = MLP_UNDEFINED; 594 mlp->p.r_c4 = MLP_UNDEFINED;
602 mlp->p.r_c6 = MLP_UNDEFINED; 595 mlp->p.r_c6 = MLP_UNDEFINED;
603 mlp->p.r_c9 = MLP_UNDEFINED; 596 mlp->p.r_c9 = MLP_UNDEFINED;
604 for (c = 0; c < RQ_QUALITY_METRIC_COUNT ; c ++) 597 for (c = 0; c < RQ_QUALITY_METRIC_COUNT; c++)
605 mlp->p.r_q[c] = MLP_UNDEFINED; 598 mlp->p.r_q[c] = MLP_UNDEFINED;
606 for (c = 0; c < GNUNET_NT_COUNT; c ++) 599 for (c = 0; c < GNUNET_NT_COUNT; c++)
607 mlp->p.r_quota[c] = MLP_UNDEFINED; 600 mlp->p.r_quota[c] = MLP_UNDEFINED;
608 mlp->p.ci = MLP_UNDEFINED; 601 mlp->p.ci = MLP_UNDEFINED;
609 602
610 603
611 GNUNET_CONTAINER_multipeermap_iterate (mlp->requested_peers, 604 GNUNET_CONTAINER_multipeermap_iterate(mlp->requested_peers,
612 &reset_peers, NULL); 605 &reset_peers, NULL);
613} 606}
614 607
615 608
@@ -619,25 +612,32 @@ mlp_delete_problem (struct GAS_MLP_Handle *mlp)
619 * @return string with result 612 * @return string with result
620 */ 613 */
621static const char * 614static const char *
622mlp_status_to_string (int retcode) 615mlp_status_to_string(int retcode)
623{ 616{
624 switch (retcode) { 617 switch (retcode)
618 {
625 case GLP_UNDEF: 619 case GLP_UNDEF:
626 return "solution is undefined"; 620 return "solution is undefined";
621
627 case GLP_FEAS: 622 case GLP_FEAS:
628 return "solution is feasible"; 623 return "solution is feasible";
624
629 case GLP_INFEAS: 625 case GLP_INFEAS:
630 return "solution is infeasible"; 626 return "solution is infeasible";
627
631 case GLP_NOFEAS: 628 case GLP_NOFEAS:
632 return "no feasible solution exists"; 629 return "no feasible solution exists";
630
633 case GLP_OPT: 631 case GLP_OPT:
634 return "solution is optimal"; 632 return "solution is optimal";
633
635 case GLP_UNBND: 634 case GLP_UNBND:
636 return "solution is unbounded"; 635 return "solution is unbounded";
636
637 default: 637 default:
638 GNUNET_break (0); 638 GNUNET_break(0);
639 return "unknown error"; 639 return "unknown error";
640 } 640 }
641} 641}
642 642
643 643
@@ -647,114 +647,134 @@ mlp_status_to_string (int retcode)
647 * @return string with result 647 * @return string with result
648 */ 648 */
649static const char * 649static const char *
650mlp_solve_to_string (int retcode) 650mlp_solve_to_string(int retcode)
651{ 651{
652 switch (retcode) { 652 switch (retcode)
653 {
653 case 0: 654 case 0:
654 return "ok"; 655 return "ok";
656
655 case GLP_EBADB: 657 case GLP_EBADB:
656 return "invalid basis"; 658 return "invalid basis";
659
657 case GLP_ESING: 660 case GLP_ESING:
658 return "singular matrix"; 661 return "singular matrix";
662
659 case GLP_ECOND: 663 case GLP_ECOND:
660 return "ill-conditioned matrix"; 664 return "ill-conditioned matrix";
665
661 case GLP_EBOUND: 666 case GLP_EBOUND:
662 return "invalid bounds"; 667 return "invalid bounds";
668
663 case GLP_EFAIL: 669 case GLP_EFAIL:
664 return "solver failed"; 670 return "solver failed";
671
665 case GLP_EOBJLL: 672 case GLP_EOBJLL:
666 return "objective lower limit reached"; 673 return "objective lower limit reached";
674
667 case GLP_EOBJUL: 675 case GLP_EOBJUL:
668 return "objective upper limit reached"; 676 return "objective upper limit reached";
677
669 case GLP_EITLIM: 678 case GLP_EITLIM:
670 return "iteration limit exceeded"; 679 return "iteration limit exceeded";
680
671 case GLP_ETMLIM: 681 case GLP_ETMLIM:
672 return "time limit exceeded"; 682 return "time limit exceeded";
683
673 case GLP_ENOPFS: 684 case GLP_ENOPFS:
674 return "no primal feasible solution"; 685 return "no primal feasible solution";
686
675 case GLP_ENODFS: 687 case GLP_ENODFS:
676 return "no dual feasible solution"; 688 return "no dual feasible solution";
689
677 case GLP_EROOT: 690 case GLP_EROOT:
678 return "root LP optimum not provided"; 691 return "root LP optimum not provided";
692
679 case GLP_ESTOP: 693 case GLP_ESTOP:
680 return "search terminated by application"; 694 return "search terminated by application";
695
681 case GLP_EMIPGAP: 696 case GLP_EMIPGAP:
682 return "relative mip gap tolerance reached"; 697 return "relative mip gap tolerance reached";
698
683 case GLP_ENOFEAS: 699 case GLP_ENOFEAS:
684 return "no dual feasible solution"; 700 return "no dual feasible solution";
701
685 case GLP_ENOCVG: 702 case GLP_ENOCVG:
686 return "no convergence"; 703 return "no convergence";
704
687 case GLP_EINSTAB: 705 case GLP_EINSTAB:
688 return "numerical instability"; 706 return "numerical instability";
707
689 case GLP_EDATA: 708 case GLP_EDATA:
690 return "invalid data"; 709 return "invalid data";
710
691 case GLP_ERANGE: 711 case GLP_ERANGE:
692 return "result out of range"; 712 return "result out of range";
713
693 default: 714 default:
694 GNUNET_break (0); 715 GNUNET_break(0);
695 return "unknown error"; 716 return "unknown error";
696 } 717 }
697} 718}
698 719
699 720
700struct CountContext 721struct CountContext {
701{
702 const struct GNUNET_CONTAINER_MultiPeerMap *map; 722 const struct GNUNET_CONTAINER_MultiPeerMap *map;
703 int result; 723 int result;
704}; 724};
705 725
706static int 726static int
707mlp_create_problem_count_addresses_it (void *cls, 727mlp_create_problem_count_addresses_it(void *cls,
708 const struct GNUNET_PeerIdentity *key, 728 const struct GNUNET_PeerIdentity *key,
709 void *value) 729 void *value)
710{ 730{
711 struct CountContext *cctx = cls; 731 struct CountContext *cctx = cls;
712 732
713 /* Check if we have to add this peer due to a pending request */ 733 /* Check if we have to add this peer due to a pending request */
714 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (cctx->map, key)) 734 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains(cctx->map, key))
715 cctx->result++; 735 cctx->result++;
716 return GNUNET_OK; 736 return GNUNET_OK;
717} 737}
718 738
719 739
720static int 740static int
721mlp_create_problem_count_addresses (const struct GNUNET_CONTAINER_MultiPeerMap *requested_peers, 741mlp_create_problem_count_addresses(const struct GNUNET_CONTAINER_MultiPeerMap *requested_peers,
722 const struct GNUNET_CONTAINER_MultiPeerMap *addresses) 742 const struct GNUNET_CONTAINER_MultiPeerMap *addresses)
723{ 743{
724 struct CountContext cctx; 744 struct CountContext cctx;
725 745
726 cctx.map = requested_peers; 746 cctx.map = requested_peers;
727 cctx.result = 0; 747 cctx.result = 0;
728 GNUNET_CONTAINER_multipeermap_iterate (addresses, 748 GNUNET_CONTAINER_multipeermap_iterate(addresses,
729 &mlp_create_problem_count_addresses_it, &cctx); 749 &mlp_create_problem_count_addresses_it, &cctx);
730 return cctx.result; 750 return cctx.result;
731} 751}
732 752
733 753
734static int 754static int
735mlp_create_problem_count_peers_it (void *cls, 755mlp_create_problem_count_peers_it(void *cls,
736 const struct GNUNET_PeerIdentity *key, 756 const struct GNUNET_PeerIdentity *key,
737 void *value) 757 void *value)
738{ 758{
739 struct CountContext *cctx = cls; 759 struct CountContext *cctx = cls;
740 760
741 /* Check if we have to addresses for the requested peer */ 761 /* Check if we have to addresses for the requested peer */
742 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (cctx->map, key)) 762 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains(cctx->map, key))
743 cctx->result++; 763 cctx->result++;
744 return GNUNET_OK; 764 return GNUNET_OK;
745} 765}
746 766
747 767
748static int 768static int
749mlp_create_problem_count_peers (const struct GNUNET_CONTAINER_MultiPeerMap *requested_peers, 769mlp_create_problem_count_peers(const struct GNUNET_CONTAINER_MultiPeerMap *requested_peers,
750 const struct GNUNET_CONTAINER_MultiPeerMap *addresses) 770 const struct GNUNET_CONTAINER_MultiPeerMap *addresses)
751{ 771{
752 struct CountContext cctx; 772 struct CountContext cctx;
753 773
754 cctx.map = addresses; 774 cctx.map = addresses;
755 cctx.result = 0; 775 cctx.result = 0;
756 GNUNET_CONTAINER_multipeermap_iterate (requested_peers, 776 GNUNET_CONTAINER_multipeermap_iterate(requested_peers,
757 &mlp_create_problem_count_peers_it, &cctx); 777 &mlp_create_problem_count_peers_it, &cctx);
758 return cctx.result; 778 return cctx.result;
759} 779}
760 780
@@ -773,9 +793,9 @@ mlp_create_problem_count_peers (const struct GNUNET_CONTAINER_MultiPeerMap *requ
773 * on error 793 * on error
774 */ 794 */
775static int 795static int
776mlp_create_problem_update_value (struct MLP_Problem *p, 796mlp_create_problem_update_value(struct MLP_Problem *p,
777 int row, int col, double val, 797 int row, int col, double val,
778 int line) 798 int line)
779{ 799{
780 int c_cols; 800 int c_cols;
781 int c_elems; 801 int c_elems;
@@ -785,59 +805,59 @@ mlp_create_problem_update_value (struct MLP_Problem *p,
785 double *val_array; 805 double *val_array;
786 int *ind_array; 806 int *ind_array;
787 807
788 GNUNET_assert (NULL != p->prob); 808 GNUNET_assert(NULL != p->prob);
789 809
790 /* Get number of columns and prepare data structure */ 810 /* Get number of columns and prepare data structure */
791 c_cols = glp_get_num_cols(p->prob); 811 c_cols = glp_get_num_cols(p->prob);
792 if (0 >= c_cols) 812 if (0 >= c_cols)
793 return GNUNET_SYSERR; 813 return GNUNET_SYSERR;
794 814
795 val_array = GNUNET_malloc ((c_cols +1)* sizeof (double)); 815 val_array = GNUNET_malloc((c_cols + 1) * sizeof(double));
796 GNUNET_assert (NULL != val_array); 816 GNUNET_assert(NULL != val_array);
797 ind_array = GNUNET_malloc ((c_cols+1) * sizeof (int)); 817 ind_array = GNUNET_malloc((c_cols + 1) * sizeof(int));
798 GNUNET_assert (NULL != ind_array); 818 GNUNET_assert(NULL != ind_array);
799 /* Extract the row */ 819 /* Extract the row */
800 820
801 /* Update the value */ 821 /* Update the value */
802 c_elems = glp_get_mat_row (p->prob, row, ind_array, val_array); 822 c_elems = glp_get_mat_row(p->prob, row, ind_array, val_array);
803 found = GNUNET_NO; 823 found = GNUNET_NO;
804 for (c1 = 1; c1 < (c_elems+1); c1++) 824 for (c1 = 1; c1 < (c_elems + 1); c1++)
805 {
806 if (ind_array[c1] == col)
807 { 825 {
808 found = GNUNET_YES; 826 if (ind_array[c1] == col)
809 break; 827 {
828 found = GNUNET_YES;
829 break;
830 }
810 } 831 }
811 }
812 if (GNUNET_NO == found) 832 if (GNUNET_NO == found)
813 { 833 {
814 ind_array[c_elems+1] = col; 834 ind_array[c_elems + 1] = col;
815 val_array[c_elems+1] = val; 835 val_array[c_elems + 1] = val;
816 LOG (GNUNET_ERROR_TYPE_DEBUG, "[P] Setting value in [%s : %s] to `%.2f'\n", 836 LOG(GNUNET_ERROR_TYPE_DEBUG, "[P] Setting value in [%s : %s] to `%.2f'\n",
817 glp_get_row_name (p->prob, row), glp_get_col_name (p->prob, col), 837 glp_get_row_name(p->prob, row), glp_get_col_name(p->prob, col),
818 val); 838 val);
819 glp_set_mat_row (p->prob, row, c_elems+1, ind_array, val_array); 839 glp_set_mat_row(p->prob, row, c_elems + 1, ind_array, val_array);
820 GNUNET_free (ind_array); 840 GNUNET_free(ind_array);
821 GNUNET_free (val_array); 841 GNUNET_free(val_array);
822 return GNUNET_YES; 842 return GNUNET_YES;
823 } 843 }
824 else 844 else
825 { 845 {
826 /* Update value */ 846 /* Update value */
827 LOG (GNUNET_ERROR_TYPE_DEBUG, "[P] Updating value in [%s : %s] from `%.2f' to `%.2f'\n", 847 LOG(GNUNET_ERROR_TYPE_DEBUG, "[P] Updating value in [%s : %s] from `%.2f' to `%.2f'\n",
828 glp_get_row_name (p->prob, row), glp_get_col_name (p->prob, col), 848 glp_get_row_name(p->prob, row), glp_get_col_name(p->prob, col),
829 val_array[c1], val); 849 val_array[c1], val);
830 if (val != val_array[c1]) 850 if (val != val_array[c1])
831 res = GNUNET_YES; 851 res = GNUNET_YES;
832 else 852 else
833 res = GNUNET_NO; 853 res = GNUNET_NO;
834 val_array[c1] = val; 854 val_array[c1] = val;
835 /* Update the row in the matrix */ 855 /* Update the row in the matrix */
836 glp_set_mat_row (p->prob, row, c_elems, ind_array, val_array); 856 glp_set_mat_row(p->prob, row, c_elems, ind_array, val_array);
837 } 857 }
838 858
839 GNUNET_free (ind_array); 859 GNUNET_free(ind_array);
840 GNUNET_free (val_array); 860 GNUNET_free(val_array);
841 return res; 861 return res;
842} 862}
843 863
@@ -854,83 +874,89 @@ mlp_create_problem_update_value (struct MLP_Problem *p,
854 * @param line calling line for debbuging 874 * @param line calling line for debbuging
855 */ 875 */
856static void 876static void
857mlp_create_problem_set_value (struct MLP_Problem *p, 877mlp_create_problem_set_value(struct MLP_Problem *p,
858 int row, int col, double val, 878 int row, int col, double val,
859 int line) 879 int line)
860{ 880{
861 if ((p->ci) >= p->num_elements) 881 if ((p->ci) >= p->num_elements)
862 { 882 {
863 LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: line %u: Request for index %u bigger than array size of %u\n", 883 LOG(GNUNET_ERROR_TYPE_DEBUG, "[P]: line %u: Request for index %u bigger than array size of %u\n",
864 line, p->ci + 1, p->num_elements); 884 line, p->ci + 1, p->num_elements);
865 GNUNET_break (0); 885 GNUNET_break(0);
866 return; 886 return;
867 } 887 }
868 if ((0 == row) || (0 == col)) 888 if ((0 == row) || (0 == col))
869 { 889 {
870 GNUNET_break (0); 890 GNUNET_break(0);
871 LOG (GNUNET_ERROR_TYPE_ERROR, "[P]: Invalid call from line %u: row = %u, col = %u\n", 891 LOG(GNUNET_ERROR_TYPE_ERROR, "[P]: Invalid call from line %u: row = %u, col = %u\n",
872 line, row, col); 892 line, row, col);
873 } 893 }
874 p->ia[p->ci] = row ; 894 p->ia[p->ci] = row;
875 p->ja[p->ci] = col; 895 p->ja[p->ci] = col;
876 p->ar[p->ci] = val; 896 p->ar[p->ci] = val;
877#if DEBUG_MLP_PROBLEM_CREATION 897#if DEBUG_MLP_PROBLEM_CREATION
878 LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: line %u: Set value [%u,%u] in index %u == %.2f\n", 898 LOG(GNUNET_ERROR_TYPE_DEBUG, "[P]: line %u: Set value [%u,%u] in index %u == %.2f\n",
879 line, p->ia[p->ci], p->ja[p->ci], p->ci, p->ar[p->ci]); 899 line, p->ia[p->ci], p->ja[p->ci], p->ci, p->ar[p->ci]);
880#endif 900#endif
881 p->ci++; 901 p->ci++;
882} 902}
883 903
884static int 904static int
885mlp_create_problem_create_column (struct MLP_Problem *p, char *name, 905mlp_create_problem_create_column(struct MLP_Problem *p, char *name,
886 unsigned int type, unsigned int bound, double lb, double ub, 906 unsigned int type, unsigned int bound, double lb, double ub,
887 double coef) 907 double coef)
888{ 908{
889 int col = glp_add_cols (p->prob, 1); 909 int col = glp_add_cols(p->prob, 1);
890 glp_set_col_name (p->prob, col, name); 910
891 glp_set_col_bnds (p->prob, col, bound, lb, ub); 911 glp_set_col_name(p->prob, col, name);
892 glp_set_col_kind (p->prob, col, type); 912 glp_set_col_bnds(p->prob, col, bound, lb, ub);
893 glp_set_obj_coef (p->prob, col, coef); 913 glp_set_col_kind(p->prob, col, type);
914 glp_set_obj_coef(p->prob, col, coef);
894#if DEBUG_MLP_PROBLEM_CREATION 915#if DEBUG_MLP_PROBLEM_CREATION
895 LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: Added column [%u] `%s': %.2f\n", 916 LOG(GNUNET_ERROR_TYPE_DEBUG, "[P]: Added column [%u] `%s': %.2f\n",
896 col, name, coef); 917 col, name, coef);
897#endif 918#endif
898 return col; 919 return col;
899} 920}
900 921
901static int 922static int
902mlp_create_problem_create_constraint (struct MLP_Problem *p, char *name, 923mlp_create_problem_create_constraint(struct MLP_Problem *p, char *name,
903 unsigned int bound, double lb, double ub) 924 unsigned int bound, double lb, double ub)
904{ 925{
905 char * op; 926 char * op;
906 int row = glp_add_rows (p->prob, 1); 927 int row = glp_add_rows(p->prob, 1);
928
907 /* set row name */ 929 /* set row name */
908 glp_set_row_name (p->prob, row, name); 930 glp_set_row_name(p->prob, row, name);
909 /* set row bounds: <= 0 */ 931 /* set row bounds: <= 0 */
910 glp_set_row_bnds (p->prob, row, bound, lb, ub); 932 glp_set_row_bnds(p->prob, row, bound, lb, ub);
911 switch (bound) 933 switch (bound)
912 { 934 {
913 case GLP_UP: 935 case GLP_UP:
914 GNUNET_asprintf(&op, "-inf <= x <= %.2f", ub); 936 GNUNET_asprintf(&op, "-inf <= x <= %.2f", ub);
915 break; 937 break;
938
916 case GLP_DB: 939 case GLP_DB:
917 GNUNET_asprintf(&op, "%.2f <= x <= %.2f", lb, ub); 940 GNUNET_asprintf(&op, "%.2f <= x <= %.2f", lb, ub);
918 break; 941 break;
942
919 case GLP_FX: 943 case GLP_FX:
920 GNUNET_asprintf(&op, "%.2f == x == %.2f", lb, ub); 944 GNUNET_asprintf(&op, "%.2f == x == %.2f", lb, ub);
921 break; 945 break;
946
922 case GLP_LO: 947 case GLP_LO:
923 GNUNET_asprintf(&op, "%.2f <= x <= inf", lb); 948 GNUNET_asprintf(&op, "%.2f <= x <= inf", lb);
924 break; 949 break;
950
925 default: 951 default:
926 GNUNET_asprintf(&op, "ERROR"); 952 GNUNET_asprintf(&op, "ERROR");
927 break; 953 break;
928 } 954 }
929#if DEBUG_MLP_PROBLEM_CREATION 955#if DEBUG_MLP_PROBLEM_CREATION
930 LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: Added row [%u] `%s': %s\n", 956 LOG(GNUNET_ERROR_TYPE_DEBUG, "[P]: Added row [%u] `%s': %s\n",
931 row, name, op); 957 row, name, op);
932#endif 958#endif
933 GNUNET_free (op); 959 GNUNET_free(op);
934 return row; 960 return row;
935} 961}
936 962
@@ -942,9 +968,9 @@ mlp_create_problem_create_constraint (struct MLP_Problem *p, char *name,
942 * - Set address dependent entries in problem matrix as well 968 * - Set address dependent entries in problem matrix as well
943 */ 969 */
944static int 970static int
945mlp_create_problem_add_address_information (void *cls, 971mlp_create_problem_add_address_information(void *cls,
946 const struct GNUNET_PeerIdentity *key, 972 const struct GNUNET_PeerIdentity *key,
947 void *value) 973 void *value)
948{ 974{
949 struct GAS_MLP_Handle *mlp = cls; 975 struct GAS_MLP_Handle *mlp = cls;
950 struct MLP_Problem *p = &mlp->p; 976 struct MLP_Problem *p = &mlp->p;
@@ -964,63 +990,63 @@ mlp_create_problem_add_address_information (void *cls,
964 990
965 mlpi = address->solver_information; 991 mlpi = address->solver_information;
966 if (NULL == mlpi) 992 if (NULL == mlpi)
967 { 993 {
968 fprintf (stderr, "%s %p\n",GNUNET_i2s (&address->peer), address); 994 fprintf(stderr, "%s %p\n", GNUNET_i2s(&address->peer), address);
969 GNUNET_break (0); 995 GNUNET_break(0);
970 return GNUNET_OK; 996 return GNUNET_OK;
971 } 997 }
972 998
973 addr_net = address->properties.scope; 999 addr_net = address->properties.scope;
974 for (addr_net_index = 0; addr_net_index < GNUNET_NT_COUNT; addr_net_index++) 1000 for (addr_net_index = 0; addr_net_index < GNUNET_NT_COUNT; addr_net_index++)
975 { 1001 {
976 if (mlp->pv.quota_index[addr_net_index] == addr_net) 1002 if (mlp->pv.quota_index[addr_net_index] == addr_net)
977 break; 1003 break;
978 } 1004 }
979 1005
980 if (addr_net_index >= GNUNET_NT_COUNT) 1006 if (addr_net_index >= GNUNET_NT_COUNT)
981 { 1007 {
982 GNUNET_break (0); 1008 GNUNET_break(0);
983 return GNUNET_OK; 1009 return GNUNET_OK;
984 } 1010 }
985 1011
986 max_quota = 0; 1012 max_quota = 0;
987 for (c = 0; c < GNUNET_NT_COUNT; c++) 1013 for (c = 0; c < GNUNET_NT_COUNT; c++)
988 { 1014 {
989 if (mlp->pv.quota_out[c] > max_quota) 1015 if (mlp->pv.quota_out[c] > max_quota)
990 max_quota = mlp->pv.quota_out[c]; 1016 max_quota = mlp->pv.quota_out[c];
991 if (mlp->pv.quota_in[c] > max_quota) 1017 if (mlp->pv.quota_in[c] > max_quota)
992 max_quota = mlp->pv.quota_in[c]; 1018 max_quota = mlp->pv.quota_in[c];
993 } 1019 }
994 if (max_quota > mlp->pv.BIG_M) 1020 if (max_quota > mlp->pv.BIG_M)
995 cur_bigm = (double) mlp->pv.BIG_M; 1021 cur_bigm = (double)mlp->pv.BIG_M;
996 else 1022 else
997 cur_bigm = max_quota; 1023 cur_bigm = max_quota;
998 1024
999 1025
1000 /* Get peer */ 1026 /* Get peer */
1001 peer = GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, key); 1027 peer = GNUNET_CONTAINER_multipeermap_get(mlp->requested_peers, key);
1002 GNUNET_assert (NULL != peer); 1028 GNUNET_assert(NULL != peer);
1003 if (peer->processed == GNUNET_NO) 1029 if (peer->processed == GNUNET_NO)
1004 { 1030 {
1005 /* Add peer dependent constraints */ 1031 /* Add peer dependent constraints */
1006 /* Add c2) One address active per peer */ 1032 /* Add c2) One address active per peer */
1007 GNUNET_asprintf(&name, "c2_%s", GNUNET_i2s(&address->peer)); 1033 GNUNET_asprintf(&name, "c2_%s", GNUNET_i2s(&address->peer));
1008 peer->r_c2 = mlp_create_problem_create_constraint (p, name, GLP_FX, 1.0, 1.0); 1034 peer->r_c2 = mlp_create_problem_create_constraint(p, name, GLP_FX, 1.0, 1.0);
1009 GNUNET_free (name); 1035 GNUNET_free(name);
1010 if (GNUNET_NO == mlp->opt_dbg_feasibility_only) 1036 if (GNUNET_NO == mlp->opt_dbg_feasibility_only)
1011 {
1012 if (GNUNET_YES == mlp->opt_dbg_optimize_relativity)
1013 { 1037 {
1014 /* Add c9) Relativity */ 1038 if (GNUNET_YES == mlp->opt_dbg_optimize_relativity)
1015 GNUNET_asprintf(&name, "c9_%s", GNUNET_i2s(&address->peer)); 1039 {
1016 peer->r_c9 = mlp_create_problem_create_constraint (p, name, GLP_LO, 0.0, 0.0); 1040 /* Add c9) Relativity */
1017 GNUNET_free (name); 1041 GNUNET_asprintf(&name, "c9_%s", GNUNET_i2s(&address->peer));
1018 /* c9) set coefficient */ 1042 peer->r_c9 = mlp_create_problem_create_constraint(p, name, GLP_LO, 0.0, 0.0);
1019 mlp_create_problem_set_value (p, peer->r_c9, p->c_r, -peer->f , __LINE__); 1043 GNUNET_free(name);
1044 /* c9) set coefficient */
1045 mlp_create_problem_set_value(p, peer->r_c9, p->c_r, -peer->f, __LINE__);
1046 }
1020 } 1047 }
1021 }
1022 peer->processed = GNUNET_YES; 1048 peer->processed = GNUNET_YES;
1023 } 1049 }
1024 1050
1025 /* Reset addresses' solver information */ 1051 /* Reset addresses' solver information */
1026 mlpi->c_b = 0; 1052 mlpi->c_b = 0;
@@ -1030,47 +1056,47 @@ mlp_create_problem_add_address_information (void *cls,
1030 mlpi->r_c3 = 0; 1056 mlpi->r_c3 = 0;
1031 1057
1032 /* Add bandwidth column */ 1058 /* Add bandwidth column */
1033 GNUNET_asprintf (&name, "b_%s_%s_%p", GNUNET_i2s (&address->peer), address->plugin, address); 1059 GNUNET_asprintf(&name, "b_%s_%s_%p", GNUNET_i2s(&address->peer), address->plugin, address);
1034 if (GNUNET_NO == mlp->opt_dbg_feasibility_only) 1060 if (GNUNET_NO == mlp->opt_dbg_feasibility_only)
1035 { 1061 {
1036 mlpi->c_b = mlp_create_problem_create_column (p, name, GLP_CV, GLP_LO, 0.0, 0.0, 0.0); 1062 mlpi->c_b = mlp_create_problem_create_column(p, name, GLP_CV, GLP_LO, 0.0, 0.0, 0.0);
1037 } 1063 }
1038 else 1064 else
1039 { 1065 {
1040 /* Maximize for bandwidth assignment in feasibility testing */ 1066 /* Maximize for bandwidth assignment in feasibility testing */
1041 mlpi->c_b = mlp_create_problem_create_column (p, name, GLP_CV, GLP_LO, 0.0, 0.0, 1.0); 1067 mlpi->c_b = mlp_create_problem_create_column(p, name, GLP_CV, GLP_LO, 0.0, 0.0, 1.0);
1042 } 1068 }
1043 GNUNET_free (name); 1069 GNUNET_free(name);
1044 1070
1045 /* Add address active column */ 1071 /* Add address active column */
1046 GNUNET_asprintf (&name, "n_%s_%s_%p", GNUNET_i2s (&address->peer), address->plugin, address); 1072 GNUNET_asprintf(&name, "n_%s_%s_%p", GNUNET_i2s(&address->peer), address->plugin, address);
1047 mlpi->c_n = mlp_create_problem_create_column (p, name, GLP_IV, GLP_DB, 0.0, 1.0, 0.0); 1073 mlpi->c_n = mlp_create_problem_create_column(p, name, GLP_IV, GLP_DB, 0.0, 1.0, 0.0);
1048 GNUNET_free (name); 1074 GNUNET_free(name);
1049 1075
1050 /* Add address dependent constraints */ 1076 /* Add address dependent constraints */
1051 /* Add c1) bandwidth capping: b_t + (-M) * n_t <= 0 */ 1077 /* Add c1) bandwidth capping: b_t + (-M) * n_t <= 0 */
1052 GNUNET_asprintf(&name, "c1_%s_%s_%p", GNUNET_i2s(&address->peer), address->plugin, address); 1078 GNUNET_asprintf(&name, "c1_%s_%s_%p", GNUNET_i2s(&address->peer), address->plugin, address);
1053 mlpi->r_c1 = mlp_create_problem_create_constraint (p, name, GLP_UP, 0.0, 0.0); 1079 mlpi->r_c1 = mlp_create_problem_create_constraint(p, name, GLP_UP, 0.0, 0.0);
1054 GNUNET_free (name); 1080 GNUNET_free(name);
1055 /* c1) set b = 1 coefficient */ 1081 /* c1) set b = 1 coefficient */
1056 mlp_create_problem_set_value (p, mlpi->r_c1, mlpi->c_b, 1, __LINE__); 1082 mlp_create_problem_set_value(p, mlpi->r_c1, mlpi->c_b, 1, __LINE__);
1057 /* c1) set n = - min (M, quota) coefficient */ 1083 /* c1) set n = - min (M, quota) coefficient */
1058 cur_bigm = (double) mlp->pv.quota_out[addr_net_index]; 1084 cur_bigm = (double)mlp->pv.quota_out[addr_net_index];
1059 if (cur_bigm > mlp->pv.BIG_M) 1085 if (cur_bigm > mlp->pv.BIG_M)
1060 cur_bigm = (double) mlp->pv.BIG_M; 1086 cur_bigm = (double)mlp->pv.BIG_M;
1061 mlp_create_problem_set_value (p, mlpi->r_c1, mlpi->c_n, -cur_bigm, __LINE__); 1087 mlp_create_problem_set_value(p, mlpi->r_c1, mlpi->c_n, -cur_bigm, __LINE__);
1062 1088
1063 /* Add constraint c 3) minimum bandwidth 1089 /* Add constraint c 3) minimum bandwidth
1064 * b_t + (-n_t * b_min) >= 0 1090 * b_t + (-n_t * b_min) >= 0
1065 * */ 1091 * */
1066 GNUNET_asprintf(&name, "c3_%s_%s_%p", GNUNET_i2s(&address->peer), address->plugin, address); 1092 GNUNET_asprintf(&name, "c3_%s_%s_%p", GNUNET_i2s(&address->peer), address->plugin, address);
1067 mlpi->r_c3 = mlp_create_problem_create_constraint (p, name, GLP_LO, 0.0, 0.0); 1093 mlpi->r_c3 = mlp_create_problem_create_constraint(p, name, GLP_LO, 0.0, 0.0);
1068 GNUNET_free (name); 1094 GNUNET_free(name);
1069 1095
1070 /* c3) set b = 1 coefficient */ 1096 /* c3) set b = 1 coefficient */
1071 mlp_create_problem_set_value (p, mlpi->r_c3, mlpi->c_b, 1, __LINE__); 1097 mlp_create_problem_set_value(p, mlpi->r_c3, mlpi->c_b, 1, __LINE__);
1072 /* c3) set n = -b_min coefficient */ 1098 /* c3) set n = -b_min coefficient */
1073 mlp_create_problem_set_value (p, mlpi->r_c3, mlpi->c_n, - ((double )mlp->pv.b_min), __LINE__); 1099 mlp_create_problem_set_value(p, mlpi->r_c3, mlpi->c_n, -((double )mlp->pv.b_min), __LINE__);
1074 1100
1075 1101
1076 /* Set coefficient entries in invariant rows */ 1102 /* Set coefficient entries in invariant rows */
@@ -1078,41 +1104,41 @@ mlp_create_problem_add_address_information (void *cls,
1078 /* Feasbility */ 1104 /* Feasbility */
1079 1105
1080 /* c 4) minimum connections */ 1106 /* c 4) minimum connections */
1081 mlp_create_problem_set_value (p, p->r_c4, mlpi->c_n, 1, __LINE__); 1107 mlp_create_problem_set_value(p, p->r_c4, mlpi->c_n, 1, __LINE__);
1082 /* c 2) 1 address peer peer */ 1108 /* c 2) 1 address peer peer */
1083 mlp_create_problem_set_value (p, peer->r_c2, mlpi->c_n, 1, __LINE__); 1109 mlp_create_problem_set_value(p, peer->r_c2, mlpi->c_n, 1, __LINE__);
1084 /* c 10) obey network specific quotas 1110 /* c 10) obey network specific quotas
1085 * (1)*b_1 + ... + (1)*b_m <= quota_n 1111 * (1)*b_1 + ... + (1)*b_m <= quota_n
1086 */ 1112 */
1087 mlp_create_problem_set_value (p, p->r_quota[addr_net_index], mlpi->c_b, 1, __LINE__); 1113 mlp_create_problem_set_value(p, p->r_quota[addr_net_index], mlpi->c_b, 1, __LINE__);
1088 1114
1089 /* Optimality */ 1115 /* Optimality */
1090 if (GNUNET_NO == mlp->opt_dbg_feasibility_only) 1116 if (GNUNET_NO == mlp->opt_dbg_feasibility_only)
1091 { 1117 {
1092 /* c 6) maximize diversity */ 1118 /* c 6) maximize diversity */
1093 mlp_create_problem_set_value (p, p->r_c6, mlpi->c_n, 1, __LINE__); 1119 mlp_create_problem_set_value(p, p->r_c6, mlpi->c_n, 1, __LINE__);
1094 /* c 9) relativity */ 1120 /* c 9) relativity */
1095 if (GNUNET_YES == mlp->opt_dbg_optimize_relativity) 1121 if (GNUNET_YES == mlp->opt_dbg_optimize_relativity)
1096 mlp_create_problem_set_value (p, peer->r_c9, mlpi->c_b, 1, __LINE__); 1122 mlp_create_problem_set_value(p, peer->r_c9, mlpi->c_b, 1, __LINE__);
1097 /* c 8) utility */ 1123 /* c 8) utility */
1098 if (GNUNET_YES == mlp->opt_dbg_optimize_utility) 1124 if (GNUNET_YES == mlp->opt_dbg_optimize_utility)
1099 mlp_create_problem_set_value (p, p->r_c8, mlpi->c_b, 1, __LINE__); 1125 mlp_create_problem_set_value(p, p->r_c8, mlpi->c_b, 1, __LINE__);
1100 /* c 7) Optimize quality */ 1126 /* c 7) Optimize quality */
1101 /* For all quality metrics, set quality of this address */ 1127 /* For all quality metrics, set quality of this address */
1102 if (GNUNET_YES == mlp->opt_dbg_optimize_quality) 1128 if (GNUNET_YES == mlp->opt_dbg_optimize_quality)
1103 { 1129 {
1104 mlp_create_problem_set_value (p, 1130 mlp_create_problem_set_value(p,
1105 p->r_q[RQ_QUALITY_METRIC_DELAY], 1131 p->r_q[RQ_QUALITY_METRIC_DELAY],
1106 mlpi->c_b, 1132 mlpi->c_b,
1107 address->norm_delay.norm, 1133 address->norm_delay.norm,
1108 __LINE__); 1134 __LINE__);
1109 mlp_create_problem_set_value (p, 1135 mlp_create_problem_set_value(p,
1110 p->r_q[RQ_QUALITY_METRIC_DISTANCE], 1136 p->r_q[RQ_QUALITY_METRIC_DISTANCE],
1111 mlpi->c_b, 1137 mlpi->c_b,
1112 address->norm_distance.norm, 1138 address->norm_distance.norm,
1113 __LINE__); 1139 __LINE__);
1114 } 1140 }
1115 } 1141 }
1116 1142
1117 return GNUNET_OK; 1143 return GNUNET_OK;
1118} 1144}
@@ -1122,7 +1148,7 @@ mlp_create_problem_add_address_information (void *cls,
1122 * Create the invariant columns c4, c6, c10, c8, c7 1148 * Create the invariant columns c4, c6, c10, c8, c7
1123 */ 1149 */
1124static void 1150static void
1125mlp_create_problem_add_invariant_rows (struct GAS_MLP_Handle *mlp, struct MLP_Problem *p) 1151mlp_create_problem_add_invariant_rows(struct GAS_MLP_Handle *mlp, struct MLP_Problem *p)
1126{ 1152{
1127 int c; 1153 int c;
1128 1154
@@ -1130,55 +1156,55 @@ mlp_create_problem_add_invariant_rows (struct GAS_MLP_Handle *mlp, struct MLP_Pr
1130 1156
1131 /* Row for c4) minimum connection */ 1157 /* Row for c4) minimum connection */
1132 /* Number of minimum connections is min(|Peers|, n_min) */ 1158 /* Number of minimum connections is min(|Peers|, n_min) */
1133 p->r_c4 = mlp_create_problem_create_constraint (p, "c4", GLP_LO, (mlp->pv.n_min > p->num_peers) ? p->num_peers : mlp->pv.n_min, 0.0); 1159 p->r_c4 = mlp_create_problem_create_constraint(p, "c4", GLP_LO, (mlp->pv.n_min > p->num_peers) ? p->num_peers : mlp->pv.n_min, 0.0);
1134 1160
1135 /* Rows for c 10) Enforce network quotas */ 1161 /* Rows for c 10) Enforce network quotas */
1136 for (c = 0; c < GNUNET_NT_COUNT; c++) 1162 for (c = 0; c < GNUNET_NT_COUNT; c++)
1137 { 1163 {
1138 char * text; 1164 char * text;
1139 GNUNET_asprintf(&text, "c10_quota_ats_%s", 1165 GNUNET_asprintf(&text, "c10_quota_ats_%s",
1140 GNUNET_NT_to_string(mlp->pv.quota_index[c])); 1166 GNUNET_NT_to_string(mlp->pv.quota_index[c]));
1141 p->r_quota[c] = mlp_create_problem_create_constraint (p, text, GLP_DB, 0.0, mlp->pv.quota_out[c]); 1167 p->r_quota[c] = mlp_create_problem_create_constraint(p, text, GLP_DB, 0.0, mlp->pv.quota_out[c]);
1142 GNUNET_free (text); 1168 GNUNET_free(text);
1143 } 1169 }
1144 1170
1145 /* Optimality */ 1171 /* Optimality */
1146 if (GNUNET_NO == mlp->opt_dbg_feasibility_only) 1172 if (GNUNET_NO == mlp->opt_dbg_feasibility_only)
1147 {
1148 char *name;
1149 /* Add row for c6) Maximize for diversity */
1150 if (GNUNET_YES == mlp->opt_dbg_optimize_diversity)
1151 { 1173 {
1152 p->r_c6 = mlp_create_problem_create_constraint (p, "c6", GLP_FX, 0.0, 0.0); 1174 char *name;
1153 /* Set c6 ) Setting -D */ 1175 /* Add row for c6) Maximize for diversity */
1154 mlp_create_problem_set_value (p, p->r_c6, p->c_d, -1, __LINE__); 1176 if (GNUNET_YES == mlp->opt_dbg_optimize_diversity)
1155 } 1177 {
1178 p->r_c6 = mlp_create_problem_create_constraint(p, "c6", GLP_FX, 0.0, 0.0);
1179 /* Set c6 ) Setting -D */
1180 mlp_create_problem_set_value(p, p->r_c6, p->c_d, -1, __LINE__);
1181 }
1156 1182
1157 /* Adding rows for c 8) Maximize utility */ 1183 /* Adding rows for c 8) Maximize utility */
1158 if (GNUNET_YES == mlp->opt_dbg_optimize_utility) 1184 if (GNUNET_YES == mlp->opt_dbg_optimize_utility)
1159 { 1185 {
1160 p->r_c8 = mlp_create_problem_create_constraint (p, "c8", GLP_FX, 0.0, 0.0); 1186 p->r_c8 = mlp_create_problem_create_constraint(p, "c8", GLP_FX, 0.0, 0.0);
1161 /* -u */ 1187 /* -u */
1162 mlp_create_problem_set_value (p, p->r_c8, p->c_u, -1, __LINE__); 1188 mlp_create_problem_set_value(p, p->r_c8, p->c_u, -1, __LINE__);
1163 } 1189 }
1164 1190
1165 /* For all quality metrics: 1191 /* For all quality metrics:
1166 * c 7) Maximize quality, austerity */ 1192 * c 7) Maximize quality, austerity */
1167 if (GNUNET_YES == mlp->opt_dbg_optimize_quality) 1193 if (GNUNET_YES == mlp->opt_dbg_optimize_quality)
1168 { 1194 {
1169 for (c = 0; c < mlp->pv.m_q; c++) 1195 for (c = 0; c < mlp->pv.m_q; c++)
1170 { 1196 {
1171 GNUNET_asprintf (&name, 1197 GNUNET_asprintf(&name,
1172 "c7_q%i_%s", c, 1198 "c7_q%i_%s", c,
1173 print_quality_type (c)); 1199 print_quality_type(c));
1174 p->r_q[c] = mlp_create_problem_create_constraint (p, name, GLP_FX, 0.0, 0.0); 1200 p->r_q[c] = mlp_create_problem_create_constraint(p, name, GLP_FX, 0.0, 0.0);
1175 GNUNET_free (name); 1201 GNUNET_free(name);
1176 mlp_create_problem_set_value (p, 1202 mlp_create_problem_set_value(p,
1177 p->r_q[c], 1203 p->r_q[c],
1178 p->c_q[c], -1, __LINE__); 1204 p->c_q[c], -1, __LINE__);
1179 } 1205 }
1206 }
1180 } 1207 }
1181 }
1182} 1208}
1183 1209
1184 1210
@@ -1186,36 +1212,36 @@ mlp_create_problem_add_invariant_rows (struct GAS_MLP_Handle *mlp, struct MLP_Pr
1186 * Create the invariant columns d, u, r, q0 ... qm 1212 * Create the invariant columns d, u, r, q0 ... qm
1187 */ 1213 */
1188static void 1214static void
1189mlp_create_problem_add_invariant_columns (struct GAS_MLP_Handle *mlp, struct MLP_Problem *p) 1215mlp_create_problem_add_invariant_columns(struct GAS_MLP_Handle *mlp, struct MLP_Problem *p)
1190{ 1216{
1191 if (GNUNET_NO == mlp->opt_dbg_feasibility_only) 1217 if (GNUNET_NO == mlp->opt_dbg_feasibility_only)
1192 { 1218 {
1193 char *name; 1219 char *name;
1194 int c; 1220 int c;
1195 1221
1196 /* Diversity d column */ 1222 /* Diversity d column */
1197 if (GNUNET_YES == mlp->opt_dbg_optimize_diversity) 1223 if (GNUNET_YES == mlp->opt_dbg_optimize_diversity)
1198 p->c_d = mlp_create_problem_create_column (p, "d", GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_D); 1224 p->c_d = mlp_create_problem_create_column(p, "d", GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_D);
1199 1225
1200 /* Utilization u column */ 1226 /* Utilization u column */
1201 if (GNUNET_YES == mlp->opt_dbg_optimize_utility) 1227 if (GNUNET_YES == mlp->opt_dbg_optimize_utility)
1202 p->c_u = mlp_create_problem_create_column (p, "u", GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_U); 1228 p->c_u = mlp_create_problem_create_column(p, "u", GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_U);
1203 1229
1204 /* Relativity r column */ 1230 /* Relativity r column */
1205 if (GNUNET_YES == mlp->opt_dbg_optimize_relativity) 1231 if (GNUNET_YES == mlp->opt_dbg_optimize_relativity)
1206 p->c_r = mlp_create_problem_create_column (p, "r", GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_R); 1232 p->c_r = mlp_create_problem_create_column(p, "r", GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_R);
1207 1233
1208 /* Quality metric columns */ 1234 /* Quality metric columns */
1209 if (GNUNET_YES == mlp->opt_dbg_optimize_quality) 1235 if (GNUNET_YES == mlp->opt_dbg_optimize_quality)
1210 { 1236 {
1211 for (c = 0; c < mlp->pv.m_q; c++) 1237 for (c = 0; c < mlp->pv.m_q; c++)
1212 { 1238 {
1213 GNUNET_asprintf (&name, "q_%u", c); 1239 GNUNET_asprintf(&name, "q_%u", c);
1214 p->c_q[c] = mlp_create_problem_create_column (p, name, GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_Q[c]); 1240 p->c_q[c] = mlp_create_problem_create_column(p, name, GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_Q[c]);
1215 GNUNET_free (name); 1241 GNUNET_free(name);
1216 } 1242 }
1243 }
1217 } 1244 }
1218 }
1219} 1245}
1220 1246
1221 1247
@@ -1226,73 +1252,73 @@ mlp_create_problem_add_invariant_columns (struct GAS_MLP_Handle *mlp, struct MLP
1226 * @return #GNUNET_OK or #GNUNET_SYSERR 1252 * @return #GNUNET_OK or #GNUNET_SYSERR
1227 */ 1253 */
1228static int 1254static int
1229mlp_create_problem (struct GAS_MLP_Handle *mlp) 1255mlp_create_problem(struct GAS_MLP_Handle *mlp)
1230{ 1256{
1231 struct MLP_Problem *p = &mlp->p; 1257 struct MLP_Problem *p = &mlp->p;
1232 int res = GNUNET_OK; 1258 int res = GNUNET_OK;
1233 1259
1234 GNUNET_assert (p->prob == NULL); 1260 GNUNET_assert(p->prob == NULL);
1235 GNUNET_assert (p->ia == NULL); 1261 GNUNET_assert(p->ia == NULL);
1236 GNUNET_assert (p->ja == NULL); 1262 GNUNET_assert(p->ja == NULL);
1237 GNUNET_assert (p->ar == NULL); 1263 GNUNET_assert(p->ar == NULL);
1238 /* Reset MLP problem struct */ 1264 /* Reset MLP problem struct */
1239 1265
1240 /* create the glpk problem */ 1266 /* create the glpk problem */
1241 p->prob = glp_create_prob (); 1267 p->prob = glp_create_prob();
1242 GNUNET_assert (NULL != p->prob); 1268 GNUNET_assert(NULL != p->prob);
1243 p->num_peers = mlp_create_problem_count_peers (mlp->requested_peers, mlp->env->addresses); 1269 p->num_peers = mlp_create_problem_count_peers(mlp->requested_peers, mlp->env->addresses);
1244 p->num_addresses = mlp_create_problem_count_addresses (mlp->requested_peers, 1270 p->num_addresses = mlp_create_problem_count_addresses(mlp->requested_peers,
1245 mlp->env->addresses); 1271 mlp->env->addresses);
1246 1272
1247 /* Create problem matrix: 10 * #addresses + #q * #addresses + #q, + #peer + 2 + 1 */ 1273 /* Create problem matrix: 10 * #addresses + #q * #addresses + #q, + #peer + 2 + 1 */
1248 p->num_elements = (10 * p->num_addresses + mlp->pv.m_q * p->num_addresses + 1274 p->num_elements = (10 * p->num_addresses + mlp->pv.m_q * p->num_addresses +
1249 mlp->pv.m_q + p->num_peers + 2 + 1); 1275 mlp->pv.m_q + p->num_peers + 2 + 1);
1250 LOG (GNUNET_ERROR_TYPE_DEBUG, 1276 LOG(GNUNET_ERROR_TYPE_DEBUG,
1251 "Rebuilding problem for %u peer(s) and %u addresse(s) and %u quality metrics == %u elements\n", 1277 "Rebuilding problem for %u peer(s) and %u addresse(s) and %u quality metrics == %u elements\n",
1252 p->num_peers, 1278 p->num_peers,
1253 p->num_addresses, 1279 p->num_addresses,
1254 mlp->pv.m_q, 1280 mlp->pv.m_q,
1255 p->num_elements); 1281 p->num_elements);
1256 1282
1257 /* Set a problem name */ 1283 /* Set a problem name */
1258 glp_set_prob_name (p->prob, "GNUnet ATS bandwidth distribution"); 1284 glp_set_prob_name(p->prob, "GNUnet ATS bandwidth distribution");
1259 /* Set optimization direction to maximize */ 1285 /* Set optimization direction to maximize */
1260 glp_set_obj_dir (p->prob, GLP_MAX); 1286 glp_set_obj_dir(p->prob, GLP_MAX);
1261 1287
1262 /* Create problem matrix */ 1288 /* Create problem matrix */
1263 /* last +1 caused by glpk index starting with one: [1..elements]*/ 1289 /* last +1 caused by glpk index starting with one: [1..elements]*/
1264 p->ci = 1; 1290 p->ci = 1;
1265 /* row index */ 1291 /* row index */
1266 p->ia = GNUNET_malloc (p->num_elements * sizeof (int)); 1292 p->ia = GNUNET_malloc(p->num_elements * sizeof(int));
1267 /* column index */ 1293 /* column index */
1268 p->ja = GNUNET_malloc (p->num_elements * sizeof (int)); 1294 p->ja = GNUNET_malloc(p->num_elements * sizeof(int));
1269 /* coefficient */ 1295 /* coefficient */
1270 p->ar = GNUNET_malloc (p->num_elements * sizeof (double)); 1296 p->ar = GNUNET_malloc(p->num_elements * sizeof(double));
1271 1297
1272 if ((NULL == p->ia) || (NULL == p->ja) || (NULL == p->ar)) 1298 if ((NULL == p->ia) || (NULL == p->ja) || (NULL == p->ar))
1273 { 1299 {
1274 LOG (GNUNET_ERROR_TYPE_ERROR, _("Problem size too large, cannot allocate memory!\n")); 1300 LOG(GNUNET_ERROR_TYPE_ERROR, _("Problem size too large, cannot allocate memory!\n"));
1275 return GNUNET_SYSERR; 1301 return GNUNET_SYSERR;
1276 } 1302 }
1277 1303
1278 /* Adding invariant columns */ 1304 /* Adding invariant columns */
1279 mlp_create_problem_add_invariant_columns (mlp, p); 1305 mlp_create_problem_add_invariant_columns(mlp, p);
1280 1306
1281 /* Adding address independent constraint rows */ 1307 /* Adding address independent constraint rows */
1282 mlp_create_problem_add_invariant_rows (mlp, p); 1308 mlp_create_problem_add_invariant_rows(mlp, p);
1283 1309
1284 /* Adding address dependent columns constraint rows */ 1310 /* Adding address dependent columns constraint rows */
1285 GNUNET_CONTAINER_multipeermap_iterate (mlp->env->addresses, 1311 GNUNET_CONTAINER_multipeermap_iterate(mlp->env->addresses,
1286 &mlp_create_problem_add_address_information, 1312 &mlp_create_problem_add_address_information,
1287 mlp); 1313 mlp);
1288 1314
1289 /* Load the matrix */ 1315 /* Load the matrix */
1290 LOG (GNUNET_ERROR_TYPE_DEBUG, "Loading matrix\n"); 1316 LOG(GNUNET_ERROR_TYPE_DEBUG, "Loading matrix\n");
1291 glp_load_matrix(p->prob, (p->ci)-1, p->ia, p->ja, p->ar); 1317 glp_load_matrix(p->prob, (p->ci) - 1, p->ia, p->ja, p->ar);
1292 if (GNUNET_YES == mlp->opt_dbg_autoscale_problem) 1318 if (GNUNET_YES == mlp->opt_dbg_autoscale_problem)
1293 { 1319 {
1294 glp_scale_prob (p->prob, GLP_SF_AUTO); 1320 glp_scale_prob(p->prob, GLP_SF_AUTO);
1295 } 1321 }
1296 1322
1297 return res; 1323 return res;
1298} 1324}
@@ -1305,34 +1331,37 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp)
1305 * @return #GNUNET_OK if could be solved, #GNUNET_SYSERR on failure 1331 * @return #GNUNET_OK if could be solved, #GNUNET_SYSERR on failure
1306 */ 1332 */
1307static int 1333static int
1308mlp_solve_lp_problem (struct GAS_MLP_Handle *mlp) 1334mlp_solve_lp_problem(struct GAS_MLP_Handle *mlp)
1309{ 1335{
1310 int res = 0; 1336 int res = 0;
1311 int res_status = 0; 1337 int res_status = 0;
1338
1312 res = glp_simplex(mlp->p.prob, &mlp->control_param_lp); 1339 res = glp_simplex(mlp->p.prob, &mlp->control_param_lp);
1313 if (0 == res) 1340 if (0 == res)
1314 LOG(GNUNET_ERROR_TYPE_DEBUG, "Solving LP problem: %s\n", 1341 LOG(GNUNET_ERROR_TYPE_DEBUG, "Solving LP problem: %s\n",
1315 mlp_solve_to_string (res)); 1342 mlp_solve_to_string(res));
1316 else 1343 else
1317 LOG(GNUNET_ERROR_TYPE_DEBUG, "Solving LP problem failed: %s\n", 1344 LOG(GNUNET_ERROR_TYPE_DEBUG, "Solving LP problem failed: %s\n",
1318 mlp_solve_to_string (res)); 1345 mlp_solve_to_string(res));
1319 1346
1320 /* Analyze problem status */ 1347 /* Analyze problem status */
1321 res_status = glp_get_status (mlp->p.prob); 1348 res_status = glp_get_status(mlp->p.prob);
1322 switch (res_status) { 1349 switch (res_status)
1350 {
1323 case GLP_OPT: /* solution is optimal */ 1351 case GLP_OPT: /* solution is optimal */
1324 LOG (GNUNET_ERROR_TYPE_INFO, 1352 LOG(GNUNET_ERROR_TYPE_INFO,
1325 "Solving LP problem: %s, %s\n", 1353 "Solving LP problem: %s, %s\n",
1326 mlp_solve_to_string(res), 1354 mlp_solve_to_string(res),
1327 mlp_status_to_string(res_status)); 1355 mlp_status_to_string(res_status));
1328 return GNUNET_OK; 1356 return GNUNET_OK;
1357
1329 default: 1358 default:
1330 LOG (GNUNET_ERROR_TYPE_ERROR, 1359 LOG(GNUNET_ERROR_TYPE_ERROR,
1331 "Solving LP problem failed: %s %s\n", 1360 "Solving LP problem failed: %s %s\n",
1332 mlp_solve_to_string(res), 1361 mlp_solve_to_string(res),
1333 mlp_status_to_string(res_status)); 1362 mlp_status_to_string(res_status));
1334 return GNUNET_SYSERR; 1363 return GNUNET_SYSERR;
1335 } 1364 }
1336} 1365}
1337 1366
1338 1367
@@ -1345,9 +1374,9 @@ mlp_solve_lp_problem (struct GAS_MLP_Handle *mlp)
1345 * @return #GNUNET_OK to continue 1374 * @return #GNUNET_OK to continue
1346 */ 1375 */
1347static int 1376static int
1348mlp_propagate_results (void *cls, 1377mlp_propagate_results(void *cls,
1349 const struct GNUNET_PeerIdentity *key, 1378 const struct GNUNET_PeerIdentity *key,
1350 void *value) 1379 void *value)
1351{ 1380{
1352 struct GAS_MLP_Handle *mlp = cls; 1381 struct GAS_MLP_Handle *mlp = cls;
1353 struct ATS_Address *address; 1382 struct ATS_Address *address;
@@ -1357,27 +1386,27 @@ mlp_propagate_results (void *cls,
1357 double mlp_use = MLP_NaN; 1386 double mlp_use = MLP_NaN;
1358 1387
1359 /* Check if we have to add this peer due to a pending request */ 1388 /* Check if we have to add this peer due to a pending request */
1360 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (mlp->requested_peers, 1389 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(mlp->requested_peers,
1361 key)) 1390 key))
1362 { 1391 {
1363 return GNUNET_OK; 1392 return GNUNET_OK;
1364 } 1393 }
1365 address = value; 1394 address = value;
1366 GNUNET_assert (address->solver_information != NULL); 1395 GNUNET_assert(address->solver_information != NULL);
1367 mlpi = address->solver_information; 1396 mlpi = address->solver_information;
1368 1397
1369 mlp_bw_in = glp_mip_col_val(mlp->p.prob, mlpi->c_b);/* FIXME */ 1398 mlp_bw_in = glp_mip_col_val(mlp->p.prob, mlpi->c_b);/* FIXME */
1370 if (mlp_bw_in > (double) UINT32_MAX) 1399 if (mlp_bw_in > (double)UINT32_MAX)
1371 { 1400 {
1372 LOG (GNUNET_ERROR_TYPE_DEBUG, "Overflow in assigned bandwidth, reducing ...\n" ); 1401 LOG(GNUNET_ERROR_TYPE_DEBUG, "Overflow in assigned bandwidth, reducing ...\n");
1373 mlp_bw_in = (double) UINT32_MAX; 1402 mlp_bw_in = (double)UINT32_MAX;
1374 } 1403 }
1375 mlp_bw_out = glp_mip_col_val(mlp->p.prob, mlpi->c_b); 1404 mlp_bw_out = glp_mip_col_val(mlp->p.prob, mlpi->c_b);
1376 if (mlp_bw_out > (double) UINT32_MAX) 1405 if (mlp_bw_out > (double)UINT32_MAX)
1377 { 1406 {
1378 LOG (GNUNET_ERROR_TYPE_DEBUG, "Overflow in assigned bandwidth, reducing ...\n" ); 1407 LOG(GNUNET_ERROR_TYPE_DEBUG, "Overflow in assigned bandwidth, reducing ...\n");
1379 mlp_bw_out = (double) UINT32_MAX; 1408 mlp_bw_out = (double)UINT32_MAX;
1380 } 1409 }
1381 mlp_use = glp_mip_col_val(mlp->p.prob, mlpi->c_n); 1410 mlp_use = glp_mip_col_val(mlp->p.prob, mlpi->c_n);
1382 1411
1383 /* 1412 /*
@@ -1388,147 +1417,154 @@ mlp_propagate_results (void *cls,
1388 */ 1417 */
1389 1418
1390 if (GLP_YES == mlp_use) 1419 if (GLP_YES == mlp_use)
1391 {
1392 /* This address was selected by the solver to be used */
1393 mlpi->n = GNUNET_YES;
1394 if (GNUNET_NO == address->active)
1395 {
1396 /* Address was not used before, enabling address */
1397 LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : enabling address\n",
1398 (1 == mlp_use) ? "[x]": "[ ]", mlp_bw_out);
1399 address->active = GNUNET_YES;
1400 address->assigned_bw_in = mlp_bw_in;
1401 mlpi->b_in = mlp_bw_in;
1402 address->assigned_bw_out = mlp_bw_out;
1403 mlpi->b_out = mlp_bw_out;
1404 if ((NULL == mlp->exclude_peer) || (0 != GNUNET_memcmp (&address->peer, mlp->exclude_peer)))
1405 mlp->env->bandwidth_changed_cb (mlp->env->cls, address);
1406 return GNUNET_OK;
1407 }
1408 else if (GNUNET_YES == address->active)
1409 { 1420 {
1410 /* Address was used before, check for bandwidth change */ 1421 /* This address was selected by the solver to be used */
1411 if ((mlp_bw_out != address->assigned_bw_out) || 1422 mlpi->n = GNUNET_YES;
1412 (mlp_bw_in != address->assigned_bw_in)) 1423 if (GNUNET_NO == address->active)
1413 { 1424 {
1414 LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : bandwidth changed\n", 1425 /* Address was not used before, enabling address */
1415 (1 == mlp_use) ? "[x]": "[ ]", mlp_bw_out); 1426 LOG(GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : enabling address\n",
1427 (1 == mlp_use) ? "[x]" : "[ ]", mlp_bw_out);
1428 address->active = GNUNET_YES;
1416 address->assigned_bw_in = mlp_bw_in; 1429 address->assigned_bw_in = mlp_bw_in;
1417 mlpi->b_in = mlp_bw_in; 1430 mlpi->b_in = mlp_bw_in;
1418 address->assigned_bw_out = mlp_bw_out; 1431 address->assigned_bw_out = mlp_bw_out;
1419 mlpi->b_out = mlp_bw_out; 1432 mlpi->b_out = mlp_bw_out;
1420 if ((NULL == mlp->exclude_peer) || (0 != GNUNET_memcmp (&address->peer, mlp->exclude_peer))) 1433 if ((NULL == mlp->exclude_peer) || (0 != GNUNET_memcmp(&address->peer, mlp->exclude_peer)))
1421 mlp->env->bandwidth_changed_cb (mlp->env->cls, address); 1434 mlp->env->bandwidth_changed_cb(mlp->env->cls, address);
1422 return GNUNET_OK; 1435 return GNUNET_OK;
1423 } 1436 }
1437 else if (GNUNET_YES == address->active)
1438 {
1439 /* Address was used before, check for bandwidth change */
1440 if ((mlp_bw_out != address->assigned_bw_out) ||
1441 (mlp_bw_in != address->assigned_bw_in))
1442 {
1443 LOG(GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : bandwidth changed\n",
1444 (1 == mlp_use) ? "[x]" : "[ ]", mlp_bw_out);
1445 address->assigned_bw_in = mlp_bw_in;
1446 mlpi->b_in = mlp_bw_in;
1447 address->assigned_bw_out = mlp_bw_out;
1448 mlpi->b_out = mlp_bw_out;
1449 if ((NULL == mlp->exclude_peer) || (0 != GNUNET_memcmp(&address->peer, mlp->exclude_peer)))
1450 mlp->env->bandwidth_changed_cb(mlp->env->cls, address);
1451 return GNUNET_OK;
1452 }
1453 }
1454 else
1455 GNUNET_break(0);
1424 } 1456 }
1425 else
1426 GNUNET_break (0);
1427 }
1428 else if (GLP_NO == mlp_use) 1457 else if (GLP_NO == mlp_use)
1429 { 1458 {
1430 /* This address was selected by the solver to be not used */ 1459 /* This address was selected by the solver to be not used */
1431 mlpi->n = GNUNET_NO; 1460 mlpi->n = GNUNET_NO;
1432 if (GNUNET_NO == address->active) 1461 if (GNUNET_NO == address->active)
1433 { 1462 {
1434 /* Address was not used before, nothing to do */ 1463 /* Address was not used before, nothing to do */
1435 LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : no change\n", 1464 LOG(GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : no change\n",
1436 (1 == mlp_use) ? "[x]": "[ ]", mlp_bw_out); 1465 (1 == mlp_use) ? "[x]" : "[ ]", mlp_bw_out);
1437 return GNUNET_OK; 1466 return GNUNET_OK;
1438 } 1467 }
1439 else if (GNUNET_YES == address->active) 1468 else if (GNUNET_YES == address->active)
1440 { 1469 {
1441 /* Address was used before, disabling address */ 1470 /* Address was used before, disabling address */
1442 LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : disabling address\n", 1471 LOG(GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : disabling address\n",
1443 (1 == mlp_use) ? "[x]": "[ ]", mlp_bw_out); 1472 (1 == mlp_use) ? "[x]" : "[ ]", mlp_bw_out);
1444 address->active = GNUNET_NO; 1473 address->active = GNUNET_NO;
1445 /* Set bandwidth to 0 */ 1474 /* Set bandwidth to 0 */
1446 address->assigned_bw_in = 0; 1475 address->assigned_bw_in = 0;
1447 mlpi->b_in = 0; 1476 mlpi->b_in = 0;
1448 address->assigned_bw_out = 0; 1477 address->assigned_bw_out = 0;
1449 mlpi->b_out = 0; 1478 mlpi->b_out = 0;
1450 return GNUNET_OK; 1479 return GNUNET_OK;
1480 }
1481 else
1482 GNUNET_break(0);
1451 } 1483 }
1452 else
1453 GNUNET_break (0);
1454 }
1455 else 1484 else
1456 GNUNET_break (0); 1485 GNUNET_break(0);
1457 1486
1458 return GNUNET_OK; 1487 return GNUNET_OK;
1459} 1488}
1460 1489
1461 1490
1462static void 1491static void
1463notify (struct GAS_MLP_Handle *mlp, 1492notify(struct GAS_MLP_Handle *mlp,
1464 enum GAS_Solver_Operation op, 1493 enum GAS_Solver_Operation op,
1465 enum GAS_Solver_Status stat, 1494 enum GAS_Solver_Status stat,
1466 enum GAS_Solver_Additional_Information add) 1495 enum GAS_Solver_Additional_Information add)
1467{ 1496{
1468 mlp->env->info_cb (mlp->env->cls, 1497 mlp->env->info_cb(mlp->env->cls,
1469 op, 1498 op,
1470 stat, 1499 stat,
1471 add); 1500 add);
1472} 1501}
1473 1502
1474 1503
1475static void 1504static void
1476mlp_branch_and_cut_cb (glp_tree *tree, void *info) 1505mlp_branch_and_cut_cb(glp_tree *tree, void *info)
1477{ 1506{
1478 struct GAS_MLP_Handle *mlp = info; 1507 struct GAS_MLP_Handle *mlp = info;
1479 double mlp_obj = 0; 1508 double mlp_obj = 0;
1480 1509
1481 switch (glp_ios_reason (tree)) 1510 switch (glp_ios_reason(tree))
1482 { 1511 {
1483 case GLP_ISELECT: 1512 case GLP_ISELECT:
1484 /* Do nothing here */ 1513 /* Do nothing here */
1485 break; 1514 break;
1515
1486 case GLP_IPREPRO: 1516 case GLP_IPREPRO:
1487 /* Do nothing here */ 1517 /* Do nothing here */
1488 break; 1518 break;
1519
1489 case GLP_IROWGEN: 1520 case GLP_IROWGEN:
1490 /* Do nothing here */ 1521 /* Do nothing here */
1491 break; 1522 break;
1523
1492 case GLP_IHEUR: 1524 case GLP_IHEUR:
1493 /* Do nothing here */ 1525 /* Do nothing here */
1494 break; 1526 break;
1527
1495 case GLP_ICUTGEN: 1528 case GLP_ICUTGEN:
1496 /* Do nothing here */ 1529 /* Do nothing here */
1497 break; 1530 break;
1531
1498 case GLP_IBRANCH: 1532 case GLP_IBRANCH:
1499 /* Do nothing here */ 1533 /* Do nothing here */
1500 break; 1534 break;
1535
1501 case GLP_IBINGO: 1536 case GLP_IBINGO:
1502 /* A better solution was found */ 1537 /* A better solution was found */
1503 mlp->ps.mlp_gap = glp_ios_mip_gap (tree); 1538 mlp->ps.mlp_gap = glp_ios_mip_gap(tree);
1504 mlp_obj = glp_mip_obj_val (mlp->p.prob); 1539 mlp_obj = glp_mip_obj_val(mlp->p.prob);
1505 mlp->ps.lp_mlp_gap = (abs(mlp_obj - mlp->ps.lp_objective_value)) / (abs(mlp_obj) + DBL_EPSILON); 1540 mlp->ps.lp_mlp_gap = (abs(mlp_obj - mlp->ps.lp_objective_value)) / (abs(mlp_obj) + DBL_EPSILON);
1506 1541
1507 LOG (GNUNET_ERROR_TYPE_INFO, 1542 LOG(GNUNET_ERROR_TYPE_INFO,
1508 "Found better integer solution, current gaps: %.3f <= %.3f, %.3f <= %.3f\n", 1543 "Found better integer solution, current gaps: %.3f <= %.3f, %.3f <= %.3f\n",
1509 mlp->ps.mlp_gap, mlp->pv.mip_gap, 1544 mlp->ps.mlp_gap, mlp->pv.mip_gap,
1510 mlp->ps.lp_mlp_gap, mlp->pv.lp_mip_gap); 1545 mlp->ps.lp_mlp_gap, mlp->pv.lp_mip_gap);
1511 1546
1512 if (mlp->ps.mlp_gap <= mlp->pv.mip_gap) 1547 if (mlp->ps.mlp_gap <= mlp->pv.mip_gap)
1513 { 1548 {
1514 LOG (GNUNET_ERROR_TYPE_INFO, 1549 LOG(GNUNET_ERROR_TYPE_INFO,
1515 "Current LP/MLP gap of %.3f smaller than tolerated gap of %.3f, terminating search\n", 1550 "Current LP/MLP gap of %.3f smaller than tolerated gap of %.3f, terminating search\n",
1516 mlp->ps.lp_mlp_gap, mlp->pv.lp_mip_gap); 1551 mlp->ps.lp_mlp_gap, mlp->pv.lp_mip_gap);
1517 glp_ios_terminate (tree); 1552 glp_ios_terminate(tree);
1518 } 1553 }
1519 1554
1520 if (mlp->ps.lp_mlp_gap <= mlp->pv.lp_mip_gap) 1555 if (mlp->ps.lp_mlp_gap <= mlp->pv.lp_mip_gap)
1521 { 1556 {
1522 LOG (GNUNET_ERROR_TYPE_INFO, 1557 LOG(GNUNET_ERROR_TYPE_INFO,
1523 "Current LP/MLP gap of %.3f smaller than tolerated gap of %.3f, terminating search\n", 1558 "Current LP/MLP gap of %.3f smaller than tolerated gap of %.3f, terminating search\n",
1524 mlp->ps.lp_mlp_gap, mlp->pv.lp_mip_gap); 1559 mlp->ps.lp_mlp_gap, mlp->pv.lp_mip_gap);
1525 glp_ios_terminate (tree); 1560 glp_ios_terminate(tree);
1526 } 1561 }
1527 1562
1528 break; 1563 break;
1564
1529 default: 1565 default:
1530 break; 1566 break;
1531 } 1567 }
1532 //GNUNET_break (0); 1568 //GNUNET_break (0);
1533} 1569}
1534 1570
@@ -1540,7 +1576,7 @@ mlp_branch_and_cut_cb (glp_tree *tree, void *info)
1540 * @return #GNUNET_OK if could be solved, #GNUNET_SYSERR on failure 1576 * @return #GNUNET_OK if could be solved, #GNUNET_SYSERR on failure
1541 */ 1577 */
1542static int 1578static int
1543GAS_mlp_solve_problem (void *solver) 1579GAS_mlp_solve_problem(void *solver)
1544{ 1580{
1545 struct GAS_MLP_Handle *mlp = solver; 1581 struct GAS_MLP_Handle *mlp = solver;
1546 char *filename; 1582 char *filename;
@@ -1556,7 +1592,7 @@ GAS_mlp_solve_problem (void *solver)
1556 struct GNUNET_TIME_Relative dur_mlp; 1592 struct GNUNET_TIME_Relative dur_mlp;
1557 1593
1558 GNUNET_assert(NULL != solver); 1594 GNUNET_assert(NULL != solver);
1559 dur_lp = GNUNET_TIME_UNIT_ZERO; 1595 dur_lp = GNUNET_TIME_UNIT_ZERO;
1560 1596
1561 if (GNUNET_YES == mlp->stat_bulk_lock) 1597 if (GNUNET_YES == mlp->stat_bulk_lock)
1562 { 1598 {
@@ -1564,7 +1600,7 @@ GAS_mlp_solve_problem (void *solver)
1564 return GNUNET_NO; 1600 return GNUNET_NO;
1565 } 1601 }
1566 notify(mlp, GAS_OP_SOLVE_START, GAS_STAT_SUCCESS, 1602 notify(mlp, GAS_OP_SOLVE_START, GAS_STAT_SUCCESS,
1567 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED); 1603 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED);
1568 start_total = GNUNET_TIME_absolute_get(); 1604 start_total = GNUNET_TIME_absolute_get();
1569 1605
1570 if (0 == GNUNET_CONTAINER_multipeermap_size(mlp->requested_peers)) 1606 if (0 == GNUNET_CONTAINER_multipeermap_size(mlp->requested_peers))
@@ -1586,32 +1622,32 @@ GAS_mlp_solve_problem (void *solver)
1586 return GNUNET_OK; 1622 return GNUNET_OK;
1587 } 1623 }
1588 if (GNUNET_YES == mlp->stat_mlp_prob_changed) 1624 if (GNUNET_YES == mlp->stat_mlp_prob_changed)
1589 { 1625 {
1590 LOG(GNUNET_ERROR_TYPE_DEBUG, "Problem size changed, rebuilding\n"); 1626 LOG(GNUNET_ERROR_TYPE_DEBUG, "Problem size changed, rebuilding\n");
1591 notify(mlp, GAS_OP_SOLVE_SETUP_START, GAS_STAT_SUCCESS, GAS_INFO_FULL); 1627 notify(mlp, GAS_OP_SOLVE_SETUP_START, GAS_STAT_SUCCESS, GAS_INFO_FULL);
1592 mlp_delete_problem (mlp); 1628 mlp_delete_problem(mlp);
1593 if (GNUNET_SYSERR == mlp_create_problem (mlp)) 1629 if (GNUNET_SYSERR == mlp_create_problem(mlp))
1594 { 1630 {
1595 notify(mlp, GAS_OP_SOLVE_SETUP_STOP, GAS_STAT_FAIL, GAS_INFO_FULL); 1631 notify(mlp, GAS_OP_SOLVE_SETUP_STOP, GAS_STAT_FAIL, GAS_INFO_FULL);
1596 return GNUNET_SYSERR; 1632 return GNUNET_SYSERR;
1597 } 1633 }
1598 notify(mlp, GAS_OP_SOLVE_SETUP_STOP, GAS_STAT_SUCCESS, GAS_INFO_FULL); 1634 notify(mlp, GAS_OP_SOLVE_SETUP_STOP, GAS_STAT_SUCCESS, GAS_INFO_FULL);
1599 if (GNUNET_NO == mlp->opt_dbg_intopt_presolver) 1635 if (GNUNET_NO == mlp->opt_dbg_intopt_presolver)
1600 { 1636 {
1601 mlp->control_param_lp.presolve = GLP_YES; /* LP presolver, we need lp solution */ 1637 mlp->control_param_lp.presolve = GLP_YES; /* LP presolver, we need lp solution */
1602 mlp->control_param_mlp.presolve = GNUNET_NO; /* No presolver, we have LP solution */ 1638 mlp->control_param_mlp.presolve = GNUNET_NO; /* No presolver, we have LP solution */
1603 } 1639 }
1604 else 1640 else
1605 { 1641 {
1606 mlp->control_param_lp.presolve = GNUNET_NO; /* LP presolver, we need lp solution */ 1642 mlp->control_param_lp.presolve = GNUNET_NO; /* LP presolver, we need lp solution */
1607 mlp->control_param_mlp.presolve = GLP_YES; /* No presolver, we have LP solution */ 1643 mlp->control_param_mlp.presolve = GLP_YES; /* No presolver, we have LP solution */
1608 dur_lp = GNUNET_TIME_UNIT_ZERO; 1644 dur_lp = GNUNET_TIME_UNIT_ZERO;
1609 } 1645 }
1610 } 1646 }
1611 else 1647 else
1612 { 1648 {
1613 LOG(GNUNET_ERROR_TYPE_DEBUG, "Problem was updated, resolving\n"); 1649 LOG(GNUNET_ERROR_TYPE_DEBUG, "Problem was updated, resolving\n");
1614 } 1650 }
1615 1651
1616 /* Reset solution info */ 1652 /* Reset solution info */
1617 mlp->ps.lp_objective_value = 0.0; 1653 mlp->ps.lp_objective_value = 0.0;
@@ -1619,156 +1655,160 @@ GAS_mlp_solve_problem (void *solver)
1619 mlp->ps.mlp_objective_value = 0.0; 1655 mlp->ps.mlp_objective_value = 0.0;
1620 mlp->ps.lp_mlp_gap = 0.0; 1656 mlp->ps.lp_mlp_gap = 0.0;
1621 1657
1622 dur_setup = GNUNET_TIME_absolute_get_duration (start_total); 1658 dur_setup = GNUNET_TIME_absolute_get_duration(start_total);
1623 1659
1624 /* Run LP solver */ 1660 /* Run LP solver */
1625 if (GNUNET_NO == mlp->opt_dbg_intopt_presolver) 1661 if (GNUNET_NO == mlp->opt_dbg_intopt_presolver)
1626 { 1662 {
1627 notify(mlp, GAS_OP_SOLVE_MLP_LP_START, GAS_STAT_SUCCESS, 1663 notify(mlp, GAS_OP_SOLVE_MLP_LP_START, GAS_STAT_SUCCESS,
1628 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED); 1664 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED);
1629 LOG(GNUNET_ERROR_TYPE_DEBUG, 1665 LOG(GNUNET_ERROR_TYPE_DEBUG,
1630 "Running LP solver %s\n", 1666 "Running LP solver %s\n",
1631 (GLP_YES == mlp->control_param_lp.presolve)? "with presolver": "without presolver"); 1667 (GLP_YES == mlp->control_param_lp.presolve) ? "with presolver" : "without presolver");
1632 start_cur_op = GNUNET_TIME_absolute_get(); 1668 start_cur_op = GNUNET_TIME_absolute_get();
1633 1669
1634 /* Solve LP */ 1670 /* Solve LP */
1635 /* Only for debugging: 1671 /* Only for debugging:
1636 * Always use LP presolver: 1672 * Always use LP presolver:
1637 * mlp->control_param_lp.presolve = GLP_YES; */ 1673 * mlp->control_param_lp.presolve = GLP_YES; */
1638 res_lp = mlp_solve_lp_problem(mlp); 1674 res_lp = mlp_solve_lp_problem(mlp);
1639 if (GNUNET_OK == res_lp) 1675 if (GNUNET_OK == res_lp)
1640 { 1676 {
1641 mlp->ps.lp_objective_value = glp_get_obj_val (mlp->p.prob); 1677 mlp->ps.lp_objective_value = glp_get_obj_val(mlp->p.prob);
1642 LOG (GNUNET_ERROR_TYPE_DEBUG, 1678 LOG(GNUNET_ERROR_TYPE_DEBUG,
1643 "LP solution was: %.3f\n", 1679 "LP solution was: %.3f\n",
1644 mlp->ps.lp_objective_value); 1680 mlp->ps.lp_objective_value);
1645 } 1681 }
1646 1682
1647 dur_lp = GNUNET_TIME_absolute_get_duration (start_cur_op); 1683 dur_lp = GNUNET_TIME_absolute_get_duration(start_cur_op);
1648 notify(mlp, GAS_OP_SOLVE_MLP_LP_STOP, 1684 notify(mlp, GAS_OP_SOLVE_MLP_LP_STOP,
1649 (GNUNET_OK == res_lp) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL, 1685 (GNUNET_OK == res_lp) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL,
1650 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED); 1686 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED);
1651 } 1687 }
1652 1688
1653 if (GNUNET_YES == mlp->opt_dbg_intopt_presolver) 1689 if (GNUNET_YES == mlp->opt_dbg_intopt_presolver)
1654 res_lp = GNUNET_OK; 1690 res_lp = GNUNET_OK;
1655 1691
1656 /* Run MLP solver */ 1692 /* Run MLP solver */
1657 if ((GNUNET_OK == res_lp) || (GNUNET_YES == mlp->opt_dbg_intopt_presolver)) 1693 if ((GNUNET_OK == res_lp) || (GNUNET_YES == mlp->opt_dbg_intopt_presolver))
1658 { 1694 {
1659 LOG(GNUNET_ERROR_TYPE_DEBUG, "Running MLP solver \n"); 1695 LOG(GNUNET_ERROR_TYPE_DEBUG, "Running MLP solver \n");
1660 notify(mlp, GAS_OP_SOLVE_MLP_MLP_START, GAS_STAT_SUCCESS, 1696 notify(mlp, GAS_OP_SOLVE_MLP_MLP_START, GAS_STAT_SUCCESS,
1661 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED); 1697 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED);
1662 start_cur_op = GNUNET_TIME_absolute_get(); 1698 start_cur_op = GNUNET_TIME_absolute_get();
1663 1699
1664 /* Solve MIP */ 1700 /* Solve MIP */
1665 1701
1666 /* Only for debugging, always use LP presolver */ 1702 /* Only for debugging, always use LP presolver */
1667 if (GNUNET_YES == mlp->opt_dbg_intopt_presolver) 1703 if (GNUNET_YES == mlp->opt_dbg_intopt_presolver)
1668 mlp->control_param_mlp.presolve = GNUNET_YES; 1704 mlp->control_param_mlp.presolve = GNUNET_YES;
1669 1705
1670 mip_res = glp_intopt (mlp->p.prob, &mlp->control_param_mlp); 1706 mip_res = glp_intopt(mlp->p.prob, &mlp->control_param_mlp);
1671 switch (mip_res) 1707 switch (mip_res)
1672 { 1708 {
1673 case 0: 1709 case 0:
1674 /* Successful */ 1710 /* Successful */
1675 LOG (GNUNET_ERROR_TYPE_INFO, 1711 LOG(GNUNET_ERROR_TYPE_INFO,
1676 "Solving MLP problem: %s\n", 1712 "Solving MLP problem: %s\n",
1677 mlp_solve_to_string (mip_res)); 1713 mlp_solve_to_string(mip_res));
1678 break; 1714 break;
1715
1679 case GLP_ETMLIM: /* Time limit reached */ 1716 case GLP_ETMLIM: /* Time limit reached */
1680 case GLP_EMIPGAP: /* MIP gap tolerance limit reached */ 1717 case GLP_EMIPGAP: /* MIP gap tolerance limit reached */
1681 case GLP_ESTOP: /* Solver was instructed to stop*/ 1718 case GLP_ESTOP: /* Solver was instructed to stop*/
1682 /* Semi-successful */ 1719 /* Semi-successful */
1683 LOG (GNUNET_ERROR_TYPE_INFO, 1720 LOG(GNUNET_ERROR_TYPE_INFO,
1684 "Solving MLP problem solution was interupted: %s\n", 1721 "Solving MLP problem solution was interupted: %s\n",
1685 mlp_solve_to_string (mip_res)); 1722 mlp_solve_to_string(mip_res));
1686 break; 1723 break;
1724
1687 case GLP_EBOUND: 1725 case GLP_EBOUND:
1688 case GLP_EROOT: 1726 case GLP_EROOT:
1689 case GLP_ENOPFS: 1727 case GLP_ENOPFS:
1690 case GLP_ENODFS: 1728 case GLP_ENODFS:
1691 case GLP_EFAIL: 1729 case GLP_EFAIL:
1692 default: 1730 default:
1693 /* Fail */ 1731 /* Fail */
1694 LOG (GNUNET_ERROR_TYPE_INFO, 1732 LOG(GNUNET_ERROR_TYPE_INFO,
1695 "Solving MLP problem failed: %s\n", 1733 "Solving MLP problem failed: %s\n",
1696 mlp_solve_to_string (mip_res)); 1734 mlp_solve_to_string(mip_res));
1697 break; 1735 break;
1698 } 1736 }
1699
1700 /* Analyze problem status */
1701 mip_status = glp_mip_status(mlp->p.prob);
1702 switch (mip_status)
1703 {
1704 case GLP_OPT: /* solution is optimal */
1705 LOG (GNUNET_ERROR_TYPE_WARNING,
1706 "Solution of MLP problem is optimal: %s, %s\n",
1707 mlp_solve_to_string (mip_res),
1708 mlp_status_to_string (mip_status));
1709 mip_res = GNUNET_OK;
1710 break;
1711 case GLP_FEAS: /* solution is feasible but not proven optimal */
1712 1737
1713 if ( (mlp->ps.mlp_gap <= mlp->pv.mip_gap) || 1738 /* Analyze problem status */
1714 (mlp->ps.lp_mlp_gap <= mlp->pv.lp_mip_gap) ) 1739 mip_status = glp_mip_status(mlp->p.prob);
1740 switch (mip_status)
1715 { 1741 {
1716 LOG (GNUNET_ERROR_TYPE_INFO, 1742 case GLP_OPT: /* solution is optimal */
1717 "Solution of MLP problem is feasible and solution within gap constraints: %s, %s\n", 1743 LOG(GNUNET_ERROR_TYPE_WARNING,
1718 mlp_solve_to_string (mip_res), 1744 "Solution of MLP problem is optimal: %s, %s\n",
1719 mlp_status_to_string (mip_status)); 1745 mlp_solve_to_string(mip_res),
1746 mlp_status_to_string(mip_status));
1720 mip_res = GNUNET_OK; 1747 mip_res = GNUNET_OK;
1721 } 1748 break;
1722 else 1749
1723 { 1750 case GLP_FEAS: /* solution is feasible but not proven optimal */
1724 LOG (GNUNET_ERROR_TYPE_WARNING, 1751
1725 "Solution of MLP problem is feasible but solution not within gap constraints: %s, %s\n", 1752 if ((mlp->ps.mlp_gap <= mlp->pv.mip_gap) ||
1726 mlp_solve_to_string (mip_res), 1753 (mlp->ps.lp_mlp_gap <= mlp->pv.lp_mip_gap))
1727 mlp_status_to_string (mip_status)); 1754 {
1755 LOG(GNUNET_ERROR_TYPE_INFO,
1756 "Solution of MLP problem is feasible and solution within gap constraints: %s, %s\n",
1757 mlp_solve_to_string(mip_res),
1758 mlp_status_to_string(mip_status));
1759 mip_res = GNUNET_OK;
1760 }
1761 else
1762 {
1763 LOG(GNUNET_ERROR_TYPE_WARNING,
1764 "Solution of MLP problem is feasible but solution not within gap constraints: %s, %s\n",
1765 mlp_solve_to_string(mip_res),
1766 mlp_status_to_string(mip_status));
1767 mip_res = GNUNET_SYSERR;
1768 }
1769 break;
1770
1771 case GLP_UNDEF: /* Solution undefined */
1772 case GLP_NOFEAS: /* No feasible solution */
1773 default:
1774 LOG(GNUNET_ERROR_TYPE_ERROR,
1775 "Solving MLP problem failed: %s %s\n",
1776 mlp_solve_to_string(mip_res),
1777 mlp_status_to_string(mip_status));
1728 mip_res = GNUNET_SYSERR; 1778 mip_res = GNUNET_SYSERR;
1779 break;
1729 } 1780 }
1730 break;
1731 case GLP_UNDEF: /* Solution undefined */
1732 case GLP_NOFEAS: /* No feasible solution */
1733 default:
1734 LOG (GNUNET_ERROR_TYPE_ERROR,
1735 "Solving MLP problem failed: %s %s\n",
1736 mlp_solve_to_string (mip_res),
1737 mlp_status_to_string (mip_status));
1738 mip_res = GNUNET_SYSERR;
1739 break;
1740 }
1741 1781
1742 dur_mlp = GNUNET_TIME_absolute_get_duration (start_cur_op); 1782 dur_mlp = GNUNET_TIME_absolute_get_duration(start_cur_op);
1743 dur_total = GNUNET_TIME_absolute_get_duration (start_total); 1783 dur_total = GNUNET_TIME_absolute_get_duration(start_total);
1744 1784
1745 notify(mlp, GAS_OP_SOLVE_MLP_MLP_STOP, 1785 notify(mlp, GAS_OP_SOLVE_MLP_MLP_STOP,
1746 (GNUNET_OK == mip_res) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL, 1786 (GNUNET_OK == mip_res) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL,
1747 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED); 1787 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED);
1748 } 1788 }
1749 else 1789 else
1750 { 1790 {
1751 /* Do not execute mip solver since lp solution is invalid */ 1791 /* Do not execute mip solver since lp solution is invalid */
1752 dur_mlp = GNUNET_TIME_UNIT_ZERO; 1792 dur_mlp = GNUNET_TIME_UNIT_ZERO;
1753 dur_total = GNUNET_TIME_absolute_get_duration (start_total); 1793 dur_total = GNUNET_TIME_absolute_get_duration(start_total);
1754 1794
1755 notify(mlp, GAS_OP_SOLVE_MLP_MLP_STOP, GAS_STAT_FAIL, 1795 notify(mlp, GAS_OP_SOLVE_MLP_MLP_STOP, GAS_STAT_FAIL,
1756 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED); 1796 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED);
1757 mip_res = GNUNET_SYSERR; 1797 mip_res = GNUNET_SYSERR;
1758 } 1798 }
1759 1799
1760 /* Notify about end */ 1800 /* Notify about end */
1761 notify(mlp, GAS_OP_SOLVE_STOP, 1801 notify(mlp, GAS_OP_SOLVE_STOP,
1762 ((GNUNET_OK == mip_res) && (GNUNET_OK == mip_res)) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL, 1802 ((GNUNET_OK == mip_res) && (GNUNET_OK == mip_res)) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL,
1763 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED); 1803 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED);
1764 1804
1765 LOG (GNUNET_ERROR_TYPE_DEBUG, 1805 LOG(GNUNET_ERROR_TYPE_DEBUG,
1766 "Execution time for %s solve: (total/setup/lp/mlp) : %llu %llu %llu %llu\n", 1806 "Execution time for %s solve: (total/setup/lp/mlp) : %llu %llu %llu %llu\n",
1767 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? "full" : "updated", 1807 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? "full" : "updated",
1768 (unsigned long long) dur_total.rel_value_us, 1808 (unsigned long long)dur_total.rel_value_us,
1769 (unsigned long long) dur_setup.rel_value_us, 1809 (unsigned long long)dur_setup.rel_value_us,
1770 (unsigned long long) dur_lp.rel_value_us, 1810 (unsigned long long)dur_lp.rel_value_us,
1771 (unsigned long long) dur_mlp.rel_value_us); 1811 (unsigned long long)dur_mlp.rel_value_us);
1772 1812
1773 /* Save stats */ 1813 /* Save stats */
1774 mlp->ps.lp_res = res_lp; 1814 mlp->ps.lp_res = res_lp;
@@ -1780,55 +1820,59 @@ GAS_mlp_solve_problem (void *solver)
1780 mlp->ps.p_elements = mlp->p.num_elements; 1820 mlp->ps.p_elements = mlp->p.num_elements;
1781 1821
1782 /* Propagate result*/ 1822 /* Propagate result*/
1783 notify (mlp, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START, 1823 notify(mlp, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START,
1784 (GNUNET_OK == res_lp) && (GNUNET_OK == mip_res) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL, 1824 (GNUNET_OK == res_lp) && (GNUNET_OK == mip_res) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL,
1785 GAS_INFO_NONE); 1825 GAS_INFO_NONE);
1786 if ((GNUNET_OK == res_lp) && (GNUNET_OK == mip_res)) 1826 if ((GNUNET_OK == res_lp) && (GNUNET_OK == mip_res))
1787 { 1827 {
1788 GNUNET_CONTAINER_multipeermap_iterate(mlp->env->addresses, 1828 GNUNET_CONTAINER_multipeermap_iterate(mlp->env->addresses,
1789 &mlp_propagate_results, mlp); 1829 &mlp_propagate_results, mlp);
1790 } 1830 }
1791 notify (mlp, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP, 1831 notify(mlp, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP,
1792 (GNUNET_OK == res_lp) && (GNUNET_OK == mip_res) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL, 1832 (GNUNET_OK == res_lp) && (GNUNET_OK == mip_res) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL,
1793 GAS_INFO_NONE); 1833 GAS_INFO_NONE);
1794 1834
1795 struct GNUNET_TIME_Absolute time = GNUNET_TIME_absolute_get(); 1835 struct GNUNET_TIME_Absolute time = GNUNET_TIME_absolute_get();
1796 if ( (GNUNET_YES == mlp->opt_dump_problem_all) || 1836 if ((GNUNET_YES == mlp->opt_dump_problem_all) ||
1797 (mlp->opt_dump_problem_on_fail && ((GNUNET_OK != res_lp) || (GNUNET_OK != mip_res))) ) 1837 (mlp->opt_dump_problem_on_fail && ((GNUNET_OK != res_lp) || (GNUNET_OK != mip_res))))
1798 { 1838 {
1799 /* Write problem to disk */ 1839 /* Write problem to disk */
1800 switch (mlp->opt_log_format) { 1840 switch (mlp->opt_log_format)
1841 {
1801 case MLP_CPLEX: 1842 case MLP_CPLEX:
1802 GNUNET_asprintf(&filename, "problem_p_%u_a%u_%llu.cplex", mlp->p.num_peers, 1843 GNUNET_asprintf(&filename, "problem_p_%u_a%u_%llu.cplex", mlp->p.num_peers,
1803 mlp->p.num_addresses, time.abs_value_us); 1844 mlp->p.num_addresses, time.abs_value_us);
1804 glp_write_lp (mlp->p.prob, NULL, filename); 1845 glp_write_lp(mlp->p.prob, NULL, filename);
1805 break; 1846 break;
1847
1806 case MLP_GLPK: 1848 case MLP_GLPK:
1807 GNUNET_asprintf(&filename, "problem_p_%u_a%u_%llu.glpk", mlp->p.num_peers, 1849 GNUNET_asprintf(&filename, "problem_p_%u_a%u_%llu.glpk", mlp->p.num_peers,
1808 mlp->p.num_addresses, time.abs_value_us); 1850 mlp->p.num_addresses, time.abs_value_us);
1809 glp_write_prob (mlp->p.prob, 0, filename); 1851 glp_write_prob(mlp->p.prob, 0, filename);
1810 break; 1852 break;
1853
1811 case MLP_MPS: 1854 case MLP_MPS:
1812 GNUNET_asprintf(&filename, "problem_p_%u_a%u_%llu.mps", mlp->p.num_peers, 1855 GNUNET_asprintf(&filename, "problem_p_%u_a%u_%llu.mps", mlp->p.num_peers,
1813 mlp->p.num_addresses, time.abs_value_us); 1856 mlp->p.num_addresses, time.abs_value_us);
1814 glp_write_mps (mlp->p.prob, GLP_MPS_FILE, NULL, filename); 1857 glp_write_mps(mlp->p.prob, GLP_MPS_FILE, NULL, filename);
1815 break; 1858 break;
1859
1816 default: 1860 default:
1817 break; 1861 break;
1818 } 1862 }
1819 LOG(GNUNET_ERROR_TYPE_ERROR, "Dumped problem to file: `%s' \n", filename); 1863 LOG(GNUNET_ERROR_TYPE_ERROR, "Dumped problem to file: `%s' \n", filename);
1820 GNUNET_free(filename); 1864 GNUNET_free(filename);
1821 } 1865 }
1822 if ( (mlp->opt_dump_solution_all) || 1866 if ((mlp->opt_dump_solution_all) ||
1823 (mlp->opt_dump_solution_on_fail && ((GNUNET_OK != res_lp) || (GNUNET_OK != mip_res))) ) 1867 (mlp->opt_dump_solution_on_fail && ((GNUNET_OK != res_lp) || (GNUNET_OK != mip_res))))
1824 { 1868 {
1825 /* Write solution to disk */ 1869 /* Write solution to disk */
1826 GNUNET_asprintf(&filename, "problem_p_%u_a%u_%llu.sol", mlp->p.num_peers, 1870 GNUNET_asprintf(&filename, "problem_p_%u_a%u_%llu.sol", mlp->p.num_peers,
1827 mlp->p.num_addresses, time.abs_value_us); 1871 mlp->p.num_addresses, time.abs_value_us);
1828 glp_print_mip(mlp->p.prob, filename); 1872 glp_print_mip(mlp->p.prob, filename);
1829 LOG(GNUNET_ERROR_TYPE_ERROR, "Dumped solution to file: `%s' \n", filename); 1873 LOG(GNUNET_ERROR_TYPE_ERROR, "Dumped solution to file: `%s' \n", filename);
1830 GNUNET_free(filename); 1874 GNUNET_free(filename);
1831 } 1875 }
1832 1876
1833 /* Reset change and update marker */ 1877 /* Reset change and update marker */
1834 mlp->control_param_lp.presolve = GLP_NO; 1878 mlp->control_param_lp.presolve = GLP_NO;
@@ -1849,46 +1893,46 @@ GAS_mlp_solve_problem (void *solver)
1849 * @param network network type of this address 1893 * @param network network type of this address
1850 */ 1894 */
1851static void 1895static void
1852GAS_mlp_address_add (void *solver, 1896GAS_mlp_address_add(void *solver,
1853 struct ATS_Address *address, 1897 struct ATS_Address *address,
1854 uint32_t network) 1898 uint32_t network)
1855{ 1899{
1856 struct GAS_MLP_Handle *mlp = solver; 1900 struct GAS_MLP_Handle *mlp = solver;
1857 1901
1858 if (GNUNET_NT_COUNT <= network) 1902 if (GNUNET_NT_COUNT <= network)
1859 { 1903 {
1860 GNUNET_break (0); 1904 GNUNET_break(0);
1861 return; 1905 return;
1862 } 1906 }
1863 1907
1864 if (NULL == address->solver_information) 1908 if (NULL == address->solver_information)
1865 { 1909 {
1866 address->solver_information = GNUNET_new (struct MLP_information); 1910 address->solver_information = GNUNET_new(struct MLP_information);
1867 } 1911 }
1868 else 1912 else
1869 LOG (GNUNET_ERROR_TYPE_ERROR, 1913 LOG(GNUNET_ERROR_TYPE_ERROR,
1870 _("Adding address for peer `%s' multiple times\n"), 1914 _("Adding address for peer `%s' multiple times\n"),
1871 GNUNET_i2s(&address->peer)); 1915 GNUNET_i2s(&address->peer));
1872 1916
1873 /* Is this peer included in the problem? */ 1917 /* Is this peer included in the problem? */
1874 if (NULL == 1918 if (NULL ==
1875 GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, 1919 GNUNET_CONTAINER_multipeermap_get(mlp->requested_peers,
1876 &address->peer)) 1920 &address->peer))
1877 { 1921 {
1878 /* FIXME: should this be an error? */ 1922 /* FIXME: should this be an error? */
1879 LOG (GNUNET_ERROR_TYPE_DEBUG, 1923 LOG(GNUNET_ERROR_TYPE_DEBUG,
1880 "Adding address for peer `%s' without address request\n", 1924 "Adding address for peer `%s' without address request\n",
1881 GNUNET_i2s(&address->peer)); 1925 GNUNET_i2s(&address->peer));
1882 return; 1926 return;
1883 } 1927 }
1884 1928
1885 LOG (GNUNET_ERROR_TYPE_DEBUG, 1929 LOG(GNUNET_ERROR_TYPE_DEBUG,
1886 "Adding address for peer `%s' with address request \n", 1930 "Adding address for peer `%s' with address request \n",
1887 GNUNET_i2s(&address->peer)); 1931 GNUNET_i2s(&address->peer));
1888 /* Problem size changed: new address for peer with pending request */ 1932 /* Problem size changed: new address for peer with pending request */
1889 mlp->stat_mlp_prob_changed = GNUNET_YES; 1933 mlp->stat_mlp_prob_changed = GNUNET_YES;
1890 if (GNUNET_YES == mlp->opt_mlp_auto_solve) 1934 if (GNUNET_YES == mlp->opt_mlp_auto_solve)
1891 GAS_mlp_solve_problem (solver); 1935 GAS_mlp_solve_problem(solver);
1892} 1936}
1893 1937
1894 1938
@@ -1899,8 +1943,8 @@ GAS_mlp_address_add (void *solver,
1899 * @param address the address 1943 * @param address the address
1900 */ 1944 */
1901static void 1945static void
1902GAS_mlp_address_property_changed (void *solver, 1946GAS_mlp_address_property_changed(void *solver,
1903 struct ATS_Address *address) 1947 struct ATS_Address *address)
1904{ 1948{
1905 struct MLP_information *mlpi = address->solver_information; 1949 struct MLP_information *mlpi = address->solver_information;
1906 struct GAS_MLP_Handle *mlp = solver; 1950 struct GAS_MLP_Handle *mlp = solver;
@@ -1909,47 +1953,46 @@ GAS_mlp_address_property_changed (void *solver,
1909 return; /* There is no MLP problem to update yet */ 1953 return; /* There is no MLP problem to update yet */
1910 1954
1911 if (NULL == mlpi) 1955 if (NULL == mlpi)
1912 { 1956 {
1913 LOG (GNUNET_ERROR_TYPE_INFO, 1957 LOG(GNUNET_ERROR_TYPE_INFO,
1914 _("Updating address property for peer `%s' %p not added before\n"), 1958 _("Updating address property for peer `%s' %p not added before\n"),
1915 GNUNET_i2s (&address->peer), 1959 GNUNET_i2s(&address->peer),
1916 address); 1960 address);
1917 GNUNET_break (0); 1961 GNUNET_break(0);
1918 return; 1962 return;
1919 } 1963 }
1920 if (NULL == 1964 if (NULL ==
1921 GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, 1965 GNUNET_CONTAINER_multipeermap_get(mlp->requested_peers,
1922 &address->peer)) 1966 &address->peer))
1923 { 1967 {
1924 /* Peer is not requested, so no need to update problem */ 1968 /* Peer is not requested, so no need to update problem */
1925 return; 1969 return;
1926 } 1970 }
1927 LOG (GNUNET_ERROR_TYPE_DEBUG, 1971 LOG(GNUNET_ERROR_TYPE_DEBUG,
1928 "Updating properties for peer `%s'\n", 1972 "Updating properties for peer `%s'\n",
1929 GNUNET_i2s(&address->peer)); 1973 GNUNET_i2s(&address->peer));
1930 1974
1931 if (GNUNET_YES == mlp->opt_dbg_feasibility_only) 1975 if (GNUNET_YES == mlp->opt_dbg_feasibility_only)
1932 return; 1976 return;
1933 1977
1934 /* Update c7) [r_q[index]][c_b] = f_q * q_averaged[type_index] */ 1978 /* Update c7) [r_q[index]][c_b] = f_q * q_averaged[type_index] */
1935 if ( (GNUNET_YES == 1979 if ((GNUNET_YES ==
1936 mlp_create_problem_update_value (&mlp->p, 1980 mlp_create_problem_update_value(&mlp->p,
1937 mlp->p.r_q[RQ_QUALITY_METRIC_DELAY], 1981 mlp->p.r_q[RQ_QUALITY_METRIC_DELAY],
1938 mlpi->c_b, 1982 mlpi->c_b,
1939 address->norm_delay.norm, 1983 address->norm_delay.norm,
1940 __LINE__)) || 1984 __LINE__)) ||
1941 (GNUNET_YES == 1985 (GNUNET_YES ==
1942 mlp_create_problem_update_value (&mlp->p, 1986 mlp_create_problem_update_value(&mlp->p,
1943 mlp->p.r_q[RQ_QUALITY_METRIC_DISTANCE], 1987 mlp->p.r_q[RQ_QUALITY_METRIC_DISTANCE],
1944 mlpi->c_b, 1988 mlpi->c_b,
1945 address->norm_distance.norm, 1989 address->norm_distance.norm,
1946 __LINE__)) ) 1990 __LINE__)))
1947 { 1991 {
1948 mlp->stat_mlp_prob_updated = GNUNET_YES; 1992 mlp->stat_mlp_prob_updated = GNUNET_YES;
1949 if (GNUNET_YES == mlp->opt_mlp_auto_solve) 1993 if (GNUNET_YES == mlp->opt_mlp_auto_solve)
1950 GAS_mlp_solve_problem (solver); 1994 GAS_mlp_solve_problem(solver);
1951 } 1995 }
1952
1953} 1996}
1954 1997
1955 1998
@@ -1961,9 +2004,9 @@ GAS_mlp_address_property_changed (void *solver,
1961 * @return #GNUNET_OK 2004 * @return #GNUNET_OK
1962 */ 2005 */
1963static int 2006static int
1964mlp_get_preferred_address_it (void *cls, 2007mlp_get_preferred_address_it(void *cls,
1965 const struct GNUNET_PeerIdentity *key, 2008 const struct GNUNET_PeerIdentity *key,
1966 void *value) 2009 void *value)
1967{ 2010{
1968 static int counter = 0; 2011 static int counter = 0;
1969 struct ATS_Address **aa = cls; 2012 struct ATS_Address **aa = cls;
@@ -1983,41 +2026,40 @@ mlp_get_preferred_address_it (void *cls,
1983 */ 2026 */
1984 2027
1985 if (GNUNET_YES == mlpi->n) 2028 if (GNUNET_YES == mlpi->n)
1986 { 2029 {
1987 2030 (*aa) = addr;
1988 (*aa) = addr; 2031 (*aa)->assigned_bw_in = mlpi->b_in;
1989 (*aa)->assigned_bw_in = mlpi->b_in; 2032 (*aa)->assigned_bw_out = mlpi->b_out;
1990 (*aa)->assigned_bw_out = mlpi->b_out; 2033 return GNUNET_NO;
1991 return GNUNET_NO; 2034 }
1992 }
1993 counter++; 2035 counter++;
1994 return GNUNET_YES; 2036 return GNUNET_YES;
1995} 2037}
1996 2038
1997 2039
1998static double 2040static double
1999get_peer_pref_value (struct GAS_MLP_Handle *mlp, 2041get_peer_pref_value(struct GAS_MLP_Handle *mlp,
2000 const struct GNUNET_PeerIdentity *peer) 2042 const struct GNUNET_PeerIdentity *peer)
2001{ 2043{
2002 double res; 2044 double res;
2003 const double *preferences; 2045 const double *preferences;
2004 int c; 2046 int c;
2005 2047
2006 preferences = mlp->env->get_preferences (mlp->env->cls, peer); 2048 preferences = mlp->env->get_preferences(mlp->env->cls, peer);
2007 res = 0.0; 2049 res = 0.0;
2008 for (c = 0; c < GNUNET_ATS_PREFERENCE_END; c++) 2050 for (c = 0; c < GNUNET_ATS_PREFERENCE_END; c++)
2009 { 2051 {
2010 /* fprintf (stderr, "VALUE[%u] %s %.3f \n", 2052 /* fprintf (stderr, "VALUE[%u] %s %.3f \n",
2011 * c, GNUNET_i2s (&cur->addr->peer), t[c]); */ 2053 * c, GNUNET_i2s (&cur->addr->peer), t[c]); */
2012 res += preferences[c]; 2054 res += preferences[c];
2013 } 2055 }
2014 2056
2015 res /= GNUNET_ATS_PREFERENCE_END; 2057 res /= GNUNET_ATS_PREFERENCE_END;
2016 res += 1.0; 2058 res += 1.0;
2017 2059
2018 LOG (GNUNET_ERROR_TYPE_DEBUG, 2060 LOG(GNUNET_ERROR_TYPE_DEBUG,
2019 "Peer preference for peer `%s' == %.2f\n", 2061 "Peer preference for peer `%s' == %.2f\n",
2020 GNUNET_i2s(peer), res); 2062 GNUNET_i2s(peer), res);
2021 2063
2022 return res; 2064 return res;
2023} 2065}
@@ -2030,51 +2072,51 @@ get_peer_pref_value (struct GAS_MLP_Handle *mlp,
2030 * @param peer the peer 2072 * @param peer the peer
2031 */ 2073 */
2032static void 2074static void
2033GAS_mlp_get_preferred_address (void *solver, 2075GAS_mlp_get_preferred_address(void *solver,
2034 const struct GNUNET_PeerIdentity *peer) 2076 const struct GNUNET_PeerIdentity *peer)
2035{ 2077{
2036 struct GAS_MLP_Handle *mlp = solver; 2078 struct GAS_MLP_Handle *mlp = solver;
2037 struct ATS_Peer *p; 2079 struct ATS_Peer *p;
2038 struct ATS_Address *res; 2080 struct ATS_Address *res;
2039 2081
2040 LOG (GNUNET_ERROR_TYPE_DEBUG, 2082 LOG(GNUNET_ERROR_TYPE_DEBUG,
2041 "Getting preferred address for `%s'\n", 2083 "Getting preferred address for `%s'\n",
2042 GNUNET_i2s (peer)); 2084 GNUNET_i2s(peer));
2043 2085
2044 /* Is this peer included in the problem? */ 2086 /* Is this peer included in the problem? */
2045 if (NULL == 2087 if (NULL ==
2046 GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, 2088 GNUNET_CONTAINER_multipeermap_get(mlp->requested_peers,
2047 peer)) 2089 peer))
2048 { 2090 {
2049 LOG (GNUNET_ERROR_TYPE_INFO, "Adding peer `%s' to list of requested_peers with requests\n", 2091 LOG(GNUNET_ERROR_TYPE_INFO, "Adding peer `%s' to list of requested_peers with requests\n",
2050 GNUNET_i2s (peer)); 2092 GNUNET_i2s(peer));
2051 2093
2052 p = GNUNET_new (struct ATS_Peer); 2094 p = GNUNET_new(struct ATS_Peer);
2053 p->id = (*peer); 2095 p->id = (*peer);
2054 p->f = get_peer_pref_value (mlp, peer); 2096 p->f = get_peer_pref_value(mlp, peer);
2055 GNUNET_CONTAINER_multipeermap_put (mlp->requested_peers, 2097 GNUNET_CONTAINER_multipeermap_put(mlp->requested_peers,
2056 peer, p, 2098 peer, p,
2057 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 2099 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
2058 2100
2059 /* Added new peer, we have to rebuild problem before solving */ 2101 /* Added new peer, we have to rebuild problem before solving */
2060 mlp->stat_mlp_prob_changed = GNUNET_YES; 2102 mlp->stat_mlp_prob_changed = GNUNET_YES;
2061 2103
2062 if ((GNUNET_YES == mlp->opt_mlp_auto_solve)&& 2104 if ((GNUNET_YES == mlp->opt_mlp_auto_solve) &&
2063 (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains(mlp->env->addresses, 2105 (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains(mlp->env->addresses,
2064 peer))) 2106 peer)))
2065 { 2107 {
2066 mlp->exclude_peer = peer; 2108 mlp->exclude_peer = peer;
2067 GAS_mlp_solve_problem (mlp); 2109 GAS_mlp_solve_problem(mlp);
2068 mlp->exclude_peer = NULL; 2110 mlp->exclude_peer = NULL;
2069 } 2111 }
2070 } 2112 }
2071 /* Get prefered address */ 2113 /* Get prefered address */
2072 res = NULL; 2114 res = NULL;
2073 GNUNET_CONTAINER_multipeermap_get_multiple (mlp->env->addresses, peer, 2115 GNUNET_CONTAINER_multipeermap_get_multiple(mlp->env->addresses, peer,
2074 &mlp_get_preferred_address_it, &res); 2116 &mlp_get_preferred_address_it, &res);
2075 if (NULL != res) 2117 if (NULL != res)
2076 mlp->env->bandwidth_changed_cb (mlp->env->cls, 2118 mlp->env->bandwidth_changed_cb(mlp->env->cls,
2077 res); 2119 res);
2078} 2120}
2079 2121
2080 2122
@@ -2087,8 +2129,8 @@ GAS_mlp_get_preferred_address (void *solver,
2087 * @param address the address to delete 2129 * @param address the address to delete
2088 */ 2130 */
2089static void 2131static void
2090GAS_mlp_address_delete (void *solver, 2132GAS_mlp_address_delete(void *solver,
2091 struct ATS_Address *address) 2133 struct ATS_Address *address)
2092{ 2134{
2093 struct GAS_MLP_Handle *mlp = solver; 2135 struct GAS_MLP_Handle *mlp = solver;
2094 struct MLP_information *mlpi; 2136 struct MLP_information *mlpi;
@@ -2097,11 +2139,11 @@ GAS_mlp_address_delete (void *solver,
2097 2139
2098 mlpi = address->solver_information; 2140 mlpi = address->solver_information;
2099 if (NULL != mlpi) 2141 if (NULL != mlpi)
2100 { 2142 {
2101 /* Remove full address */ 2143 /* Remove full address */
2102 GNUNET_free (mlpi); 2144 GNUNET_free(mlpi);
2103 address->solver_information = NULL; 2145 address->solver_information = NULL;
2104 } 2146 }
2105 was_active = address->active; 2147 was_active = address->active;
2106 address->active = GNUNET_NO; 2148 address->active = GNUNET_NO;
2107 address->assigned_bw_in = 0; 2149 address->assigned_bw_in = 0;
@@ -2109,38 +2151,38 @@ GAS_mlp_address_delete (void *solver,
2109 2151
2110 /* Is this peer included in the problem? */ 2152 /* Is this peer included in the problem? */
2111 if (NULL == 2153 if (NULL ==
2112 GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, 2154 GNUNET_CONTAINER_multipeermap_get(mlp->requested_peers,
2113 &address->peer)) 2155 &address->peer))
2114 { 2156 {
2115 LOG (GNUNET_ERROR_TYPE_INFO, 2157 LOG(GNUNET_ERROR_TYPE_INFO,
2116 "Deleting address for peer `%s' without address request \n", 2158 "Deleting address for peer `%s' without address request \n",
2117 GNUNET_i2s(&address->peer)); 2159 GNUNET_i2s(&address->peer));
2118 return; 2160 return;
2119 } 2161 }
2120 LOG (GNUNET_ERROR_TYPE_INFO, 2162 LOG(GNUNET_ERROR_TYPE_INFO,
2121 "Deleting address for peer `%s' with address request \n", 2163 "Deleting address for peer `%s' with address request \n",
2122 GNUNET_i2s (&address->peer)); 2164 GNUNET_i2s(&address->peer));
2123 2165
2124 /* Problem size changed: new address for peer with pending request */ 2166 /* Problem size changed: new address for peer with pending request */
2125 mlp->stat_mlp_prob_changed = GNUNET_YES; 2167 mlp->stat_mlp_prob_changed = GNUNET_YES;
2126 if (GNUNET_YES == mlp->opt_mlp_auto_solve) 2168 if (GNUNET_YES == mlp->opt_mlp_auto_solve)
2127 { 2169 {
2128 GAS_mlp_solve_problem (solver); 2170 GAS_mlp_solve_problem(solver);
2129 } 2171 }
2130 if (GNUNET_YES == was_active) 2172 if (GNUNET_YES == was_active)
2131 { 2173 {
2132 GAS_mlp_get_preferred_address (solver, &address->peer); 2174 GAS_mlp_get_preferred_address(solver, &address->peer);
2133 res = NULL; 2175 res = NULL;
2134 GNUNET_CONTAINER_multipeermap_get_multiple (mlp->env->addresses, 2176 GNUNET_CONTAINER_multipeermap_get_multiple(mlp->env->addresses,
2135 &address->peer, 2177 &address->peer,
2136 &mlp_get_preferred_address_it, 2178 &mlp_get_preferred_address_it,
2137 &res); 2179 &res);
2138 if (NULL == res) 2180 if (NULL == res)
2139 { 2181 {
2140 /* No alternative address, disconnecting peer */ 2182 /* No alternative address, disconnecting peer */
2141 mlp->env->bandwidth_changed_cb (mlp->env->cls, address); 2183 mlp->env->bandwidth_changed_cb(mlp->env->cls, address);
2142 } 2184 }
2143 } 2185 }
2144} 2186}
2145 2187
2146 2188
@@ -2150,38 +2192,38 @@ GAS_mlp_address_delete (void *solver,
2150 * @param solver the solver 2192 * @param solver the solver
2151 */ 2193 */
2152static void 2194static void
2153GAS_mlp_bulk_start (void *solver) 2195GAS_mlp_bulk_start(void *solver)
2154{ 2196{
2155 struct GAS_MLP_Handle *s = solver; 2197 struct GAS_MLP_Handle *s = solver;
2156 2198
2157 LOG (GNUNET_ERROR_TYPE_DEBUG, 2199 LOG(GNUNET_ERROR_TYPE_DEBUG,
2158 "Locking solver for bulk operation ...\n"); 2200 "Locking solver for bulk operation ...\n");
2159 GNUNET_assert (NULL != solver); 2201 GNUNET_assert(NULL != solver);
2160 s->stat_bulk_lock ++; 2202 s->stat_bulk_lock++;
2161} 2203}
2162 2204
2163 2205
2164static void 2206static void
2165GAS_mlp_bulk_stop (void *solver) 2207GAS_mlp_bulk_stop(void *solver)
2166{ 2208{
2167 struct GAS_MLP_Handle *s = solver; 2209 struct GAS_MLP_Handle *s = solver;
2168 2210
2169 LOG (GNUNET_ERROR_TYPE_DEBUG, 2211 LOG(GNUNET_ERROR_TYPE_DEBUG,
2170 "Unlocking solver from bulk operation ...\n"); 2212 "Unlocking solver from bulk operation ...\n");
2171 GNUNET_assert (NULL != solver); 2213 GNUNET_assert(NULL != solver);
2172 2214
2173 if (s->stat_bulk_lock < 1) 2215 if (s->stat_bulk_lock < 1)
2174 { 2216 {
2175 GNUNET_break (0); 2217 GNUNET_break(0);
2176 return; 2218 return;
2177 } 2219 }
2178 s->stat_bulk_lock --; 2220 s->stat_bulk_lock--;
2179 2221
2180 if (0 < s->stat_bulk_requests) 2222 if (0 < s->stat_bulk_requests)
2181 { 2223 {
2182 GAS_mlp_solve_problem (solver); 2224 GAS_mlp_solve_problem(solver);
2183 s->stat_bulk_requests= 0; 2225 s->stat_bulk_requests = 0;
2184 } 2226 }
2185} 2227}
2186 2228
2187 2229
@@ -2193,26 +2235,26 @@ GAS_mlp_bulk_stop (void *solver)
2193 * @param peer the peer 2235 * @param peer the peer
2194 */ 2236 */
2195static void 2237static void
2196GAS_mlp_stop_get_preferred_address (void *solver, 2238GAS_mlp_stop_get_preferred_address(void *solver,
2197 const struct GNUNET_PeerIdentity *peer) 2239 const struct GNUNET_PeerIdentity *peer)
2198{ 2240{
2199 struct GAS_MLP_Handle *mlp = solver; 2241 struct GAS_MLP_Handle *mlp = solver;
2200 struct ATS_Peer *p = NULL; 2242 struct ATS_Peer *p = NULL;
2201 2243
2202 GNUNET_assert (NULL != solver); 2244 GNUNET_assert(NULL != solver);
2203 GNUNET_assert (NULL != peer); 2245 GNUNET_assert(NULL != peer);
2204 if (NULL != (p = GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, peer))) 2246 if (NULL != (p = GNUNET_CONTAINER_multipeermap_get(mlp->requested_peers, peer)))
2205 {
2206 GNUNET_assert (GNUNET_YES ==
2207 GNUNET_CONTAINER_multipeermap_remove (mlp->requested_peers, peer, p));
2208 GNUNET_free (p);
2209
2210 mlp->stat_mlp_prob_changed = GNUNET_YES;
2211 if (GNUNET_YES == mlp->opt_mlp_auto_solve)
2212 { 2247 {
2213 GAS_mlp_solve_problem (solver); 2248 GNUNET_assert(GNUNET_YES ==
2249 GNUNET_CONTAINER_multipeermap_remove(mlp->requested_peers, peer, p));
2250 GNUNET_free(p);
2251
2252 mlp->stat_mlp_prob_changed = GNUNET_YES;
2253 if (GNUNET_YES == mlp->opt_mlp_auto_solve)
2254 {
2255 GAS_mlp_solve_problem(solver);
2256 }
2214 } 2257 }
2215 }
2216} 2258}
2217 2259
2218 2260
@@ -2225,48 +2267,48 @@ GAS_mlp_stop_get_preferred_address (void *solver,
2225 * @param pref_rel the relative score 2267 * @param pref_rel the relative score
2226 */ 2268 */
2227static void 2269static void
2228GAS_mlp_address_change_preference (void *solver, 2270GAS_mlp_address_change_preference(void *solver,
2229 const struct GNUNET_PeerIdentity *peer, 2271 const struct GNUNET_PeerIdentity *peer,
2230 enum GNUNET_ATS_PreferenceKind kind, 2272 enum GNUNET_ATS_PreferenceKind kind,
2231 double pref_rel) 2273 double pref_rel)
2232{ 2274{
2233 struct GAS_MLP_Handle *mlp = solver; 2275 struct GAS_MLP_Handle *mlp = solver;
2234 struct ATS_Peer *p; 2276 struct ATS_Peer *p;
2235 2277
2236 LOG (GNUNET_ERROR_TYPE_DEBUG, 2278 LOG(GNUNET_ERROR_TYPE_DEBUG,
2237 "Changing preference for address for peer `%s' to %.2f\n", 2279 "Changing preference for address for peer `%s' to %.2f\n",
2238 GNUNET_i2s(peer), 2280 GNUNET_i2s(peer),
2239 pref_rel); 2281 pref_rel);
2240 2282
2241 GNUNET_STATISTICS_update (mlp->env->stats, 2283 GNUNET_STATISTICS_update(mlp->env->stats,
2242 "# LP address preference changes", 1, GNUNET_NO); 2284 "# LP address preference changes", 1, GNUNET_NO);
2243 /* Update the constraints with changed preferences */ 2285 /* Update the constraints with changed preferences */
2244 2286
2245 2287
2246 2288
2247 /* Update relativity constraint c9 */ 2289 /* Update relativity constraint c9 */
2248 if (NULL == (p = GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, peer))) 2290 if (NULL == (p = GNUNET_CONTAINER_multipeermap_get(mlp->requested_peers, peer)))
2249 { 2291 {
2250 LOG (GNUNET_ERROR_TYPE_INFO, 2292 LOG(GNUNET_ERROR_TYPE_INFO,
2251 "Updating preference for unknown peer `%s'\n", 2293 "Updating preference for unknown peer `%s'\n",
2252 GNUNET_i2s(peer)); 2294 GNUNET_i2s(peer));
2253 return; 2295 return;
2254 } 2296 }
2255 2297
2256 if (GNUNET_NO == mlp->opt_dbg_feasibility_only) 2298 if (GNUNET_NO == mlp->opt_dbg_feasibility_only)
2257 { 2299 {
2258 p->f = get_peer_pref_value (mlp, peer); 2300 p->f = get_peer_pref_value(mlp, peer);
2259 mlp_create_problem_update_value (&mlp->p, 2301 mlp_create_problem_update_value(&mlp->p,
2260 p->r_c9, 2302 p->r_c9,
2261 mlp->p.c_r, 2303 mlp->p.c_r,
2262 - p->f, 2304 -p->f,
2263 __LINE__); 2305 __LINE__);
2264 2306
2265 /* Problem size changed: new address for peer with pending request */ 2307 /* Problem size changed: new address for peer with pending request */
2266 mlp->stat_mlp_prob_updated = GNUNET_YES; 2308 mlp->stat_mlp_prob_updated = GNUNET_YES;
2267 if (GNUNET_YES == mlp->opt_mlp_auto_solve) 2309 if (GNUNET_YES == mlp->opt_mlp_auto_solve)
2268 GAS_mlp_solve_problem (solver); 2310 GAS_mlp_solve_problem(solver);
2269 } 2311 }
2270} 2312}
2271 2313
2272 2314
@@ -2281,31 +2323,31 @@ GAS_mlp_address_change_preference (void *solver,
2281 * @param score the score 2323 * @param score the score
2282 */ 2324 */
2283static void 2325static void
2284GAS_mlp_address_preference_feedback (void *solver, 2326GAS_mlp_address_preference_feedback(void *solver,
2285 struct GNUNET_SERVICE_Client *application, 2327 struct GNUNET_SERVICE_Client *application,
2286 const struct GNUNET_PeerIdentity *peer, 2328 const struct GNUNET_PeerIdentity *peer,
2287 const struct GNUNET_TIME_Relative scope, 2329 const struct GNUNET_TIME_Relative scope,
2288 enum GNUNET_ATS_PreferenceKind kind, 2330 enum GNUNET_ATS_PreferenceKind kind,
2289 double score) 2331 double score)
2290{ 2332{
2291 struct GAS_PROPORTIONAL_Handle *s = solver; 2333 struct GAS_PROPORTIONAL_Handle *s = solver;
2292 2334
2293 GNUNET_assert (NULL != solver); 2335 GNUNET_assert(NULL != solver);
2294 GNUNET_assert (NULL != peer); 2336 GNUNET_assert(NULL != peer);
2295 GNUNET_assert (NULL != s); 2337 GNUNET_assert(NULL != s);
2296} 2338}
2297 2339
2298 2340
2299static int 2341static int
2300mlp_free_peers (void *cls, 2342mlp_free_peers(void *cls,
2301 const struct GNUNET_PeerIdentity *key, void *value) 2343 const struct GNUNET_PeerIdentity *key, void *value)
2302{ 2344{
2303 struct GNUNET_CONTAINER_MultiPeerMap *map = cls; 2345 struct GNUNET_CONTAINER_MultiPeerMap *map = cls;
2304 struct ATS_Peer *p = value; 2346 struct ATS_Peer *p = value;
2305 2347
2306 GNUNET_assert (GNUNET_YES == 2348 GNUNET_assert(GNUNET_YES ==
2307 GNUNET_CONTAINER_multipeermap_remove (map, key, value)); 2349 GNUNET_CONTAINER_multipeermap_remove(map, key, value));
2308 GNUNET_free (p); 2350 GNUNET_free(p);
2309 2351
2310 return GNUNET_OK; 2352 return GNUNET_OK;
2311} 2353}
@@ -2318,36 +2360,36 @@ mlp_free_peers (void *cls,
2318 * @return NULL 2360 * @return NULL
2319 */ 2361 */
2320void * 2362void *
2321libgnunet_plugin_ats_mlp_done (void *cls) 2363libgnunet_plugin_ats_mlp_done(void *cls)
2322{ 2364{
2323 struct GNUNET_ATS_SolverFunctions *sf = cls; 2365 struct GNUNET_ATS_SolverFunctions *sf = cls;
2324 struct GAS_MLP_Handle *mlp = sf->cls; 2366 struct GAS_MLP_Handle *mlp = sf->cls;
2325 2367
2326 LOG (GNUNET_ERROR_TYPE_DEBUG, 2368 LOG(GNUNET_ERROR_TYPE_DEBUG,
2327 "Shutting down mlp solver\n"); 2369 "Shutting down mlp solver\n");
2328 mlp_delete_problem (mlp); 2370 mlp_delete_problem(mlp);
2329 GNUNET_CONTAINER_multipeermap_iterate (mlp->requested_peers, 2371 GNUNET_CONTAINER_multipeermap_iterate(mlp->requested_peers,
2330 &mlp_free_peers, 2372 &mlp_free_peers,
2331 mlp->requested_peers); 2373 mlp->requested_peers);
2332 GNUNET_CONTAINER_multipeermap_destroy (mlp->requested_peers); 2374 GNUNET_CONTAINER_multipeermap_destroy(mlp->requested_peers);
2333 mlp->requested_peers = NULL; 2375 mlp->requested_peers = NULL;
2334 2376
2335 /* Clean up GLPK environment */ 2377 /* Clean up GLPK environment */
2336 glp_free_env(); 2378 glp_free_env();
2337 GNUNET_free (mlp); 2379 GNUNET_free(mlp);
2338 2380
2339 LOG (GNUNET_ERROR_TYPE_DEBUG, 2381 LOG(GNUNET_ERROR_TYPE_DEBUG,
2340 "Shutdown down of mlp solver complete\n"); 2382 "Shutdown down of mlp solver complete\n");
2341 return NULL; 2383 return NULL;
2342} 2384}
2343 2385
2344 2386
2345void * 2387void *
2346libgnunet_plugin_ats_mlp_init (void *cls) 2388libgnunet_plugin_ats_mlp_init(void *cls)
2347{ 2389{
2348 static struct GNUNET_ATS_SolverFunctions sf; 2390 static struct GNUNET_ATS_SolverFunctions sf;
2349 struct GNUNET_ATS_PluginEnvironment *env = cls; 2391 struct GNUNET_ATS_PluginEnvironment *env = cls;
2350 struct GAS_MLP_Handle * mlp = GNUNET_new (struct GAS_MLP_Handle); 2392 struct GAS_MLP_Handle * mlp = GNUNET_new(struct GAS_MLP_Handle);
2351 float f_tmp; 2393 float f_tmp;
2352 unsigned long long tmp; 2394 unsigned long long tmp;
2353 unsigned int b_min; 2395 unsigned int b_min;
@@ -2360,349 +2402,355 @@ libgnunet_plugin_ats_mlp_init (void *cls)
2360 2402
2361 /* Init GLPK environment */ 2403 /* Init GLPK environment */
2362 int res = glp_init_env(); 2404 int res = glp_init_env();
2363 switch (res) { 2405
2406 switch (res)
2407 {
2364 case 0: 2408 case 0:
2365 LOG (GNUNET_ERROR_TYPE_DEBUG, "GLPK: `%s'\n", 2409 LOG(GNUNET_ERROR_TYPE_DEBUG, "GLPK: `%s'\n",
2366 "initialization successful"); 2410 "initialization successful");
2367 break; 2411 break;
2412
2368 case 1: 2413 case 1:
2369 LOG (GNUNET_ERROR_TYPE_DEBUG, "GLPK: `%s'\n", 2414 LOG(GNUNET_ERROR_TYPE_DEBUG, "GLPK: `%s'\n",
2370 "environment is already initialized"); 2415 "environment is already initialized");
2371 break; 2416 break;
2417
2372 case 2: 2418 case 2:
2373 LOG (GNUNET_ERROR_TYPE_ERROR, "Could not init GLPK: `%s'\n", 2419 LOG(GNUNET_ERROR_TYPE_ERROR, "Could not init GLPK: `%s'\n",
2374 "initialization failed (insufficient memory)"); 2420 "initialization failed (insufficient memory)");
2375 GNUNET_free(mlp); 2421 GNUNET_free(mlp);
2376 return NULL; 2422 return NULL;
2377 break; 2423 break;
2424
2378 case 3: 2425 case 3:
2379 LOG (GNUNET_ERROR_TYPE_ERROR, "Could not init GLPK: `%s'\n", 2426 LOG(GNUNET_ERROR_TYPE_ERROR, "Could not init GLPK: `%s'\n",
2380 "initialization failed (unsupported programming model)"); 2427 "initialization failed (unsupported programming model)");
2381 GNUNET_free(mlp); 2428 GNUNET_free(mlp);
2382 return NULL; 2429 return NULL;
2383 break; 2430 break;
2431
2384 default: 2432 default:
2385 break; 2433 break;
2386 } 2434 }
2387 2435
2388 mlp->opt_dump_problem_all = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 2436 mlp->opt_dump_problem_all = GNUNET_CONFIGURATION_get_value_yesno(env->cfg,
2389 "ats", "MLP_DUMP_PROBLEM_ALL"); 2437 "ats", "MLP_DUMP_PROBLEM_ALL");
2390 if (GNUNET_SYSERR == mlp->opt_dump_problem_all) 2438 if (GNUNET_SYSERR == mlp->opt_dump_problem_all)
2391 mlp->opt_dump_problem_all = GNUNET_NO; 2439 mlp->opt_dump_problem_all = GNUNET_NO;
2392 2440
2393 mlp->opt_dump_solution_all = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 2441 mlp->opt_dump_solution_all = GNUNET_CONFIGURATION_get_value_yesno(env->cfg,
2394 "ats", "MLP_DUMP_SOLUTION_ALL"); 2442 "ats", "MLP_DUMP_SOLUTION_ALL");
2395 if (GNUNET_SYSERR == mlp->opt_dump_solution_all) 2443 if (GNUNET_SYSERR == mlp->opt_dump_solution_all)
2396 mlp->opt_dump_solution_all = GNUNET_NO; 2444 mlp->opt_dump_solution_all = GNUNET_NO;
2397 2445
2398 mlp->opt_dump_problem_on_fail = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 2446 mlp->opt_dump_problem_on_fail = GNUNET_CONFIGURATION_get_value_yesno(env->cfg,
2399 "ats", "MLP_DUMP_PROBLEM_ON_FAIL"); 2447 "ats", "MLP_DUMP_PROBLEM_ON_FAIL");
2400 if (GNUNET_SYSERR == mlp->opt_dump_problem_on_fail) 2448 if (GNUNET_SYSERR == mlp->opt_dump_problem_on_fail)
2401 mlp->opt_dump_problem_on_fail = GNUNET_NO; 2449 mlp->opt_dump_problem_on_fail = GNUNET_NO;
2402 2450
2403 mlp->opt_dump_solution_on_fail = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 2451 mlp->opt_dump_solution_on_fail = GNUNET_CONFIGURATION_get_value_yesno(env->cfg,
2404 "ats", "MLP_DUMP_SOLUTION_ON_FAIL"); 2452 "ats", "MLP_DUMP_SOLUTION_ON_FAIL");
2405 if (GNUNET_SYSERR == mlp->opt_dump_solution_on_fail) 2453 if (GNUNET_SYSERR == mlp->opt_dump_solution_on_fail)
2406 mlp->opt_dump_solution_on_fail = GNUNET_NO; 2454 mlp->opt_dump_solution_on_fail = GNUNET_NO;
2407 2455
2408 mlp->opt_dbg_glpk_verbose = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 2456 mlp->opt_dbg_glpk_verbose = GNUNET_CONFIGURATION_get_value_yesno(env->cfg,
2409 "ats", "MLP_DBG_GLPK_VERBOSE"); 2457 "ats", "MLP_DBG_GLPK_VERBOSE");
2410 if (GNUNET_SYSERR == mlp->opt_dbg_glpk_verbose) 2458 if (GNUNET_SYSERR == mlp->opt_dbg_glpk_verbose)
2411 mlp->opt_dbg_glpk_verbose = GNUNET_NO; 2459 mlp->opt_dbg_glpk_verbose = GNUNET_NO;
2412 2460
2413 mlp->opt_dbg_feasibility_only = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 2461 mlp->opt_dbg_feasibility_only = GNUNET_CONFIGURATION_get_value_yesno(env->cfg,
2414 "ats", "MLP_DBG_FEASIBILITY_ONLY"); 2462 "ats", "MLP_DBG_FEASIBILITY_ONLY");
2415 if (GNUNET_SYSERR == mlp->opt_dbg_feasibility_only) 2463 if (GNUNET_SYSERR == mlp->opt_dbg_feasibility_only)
2416 mlp->opt_dbg_feasibility_only = GNUNET_NO; 2464 mlp->opt_dbg_feasibility_only = GNUNET_NO;
2417 if (GNUNET_YES == mlp->opt_dbg_feasibility_only) 2465 if (GNUNET_YES == mlp->opt_dbg_feasibility_only)
2418 LOG (GNUNET_ERROR_TYPE_WARNING, 2466 LOG(GNUNET_ERROR_TYPE_WARNING,
2419 "MLP solver is configured to check feasibility only!\n"); 2467 "MLP solver is configured to check feasibility only!\n");
2420 2468
2421 mlp->opt_dbg_autoscale_problem = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 2469 mlp->opt_dbg_autoscale_problem = GNUNET_CONFIGURATION_get_value_yesno(env->cfg,
2422 "ats", "MLP_DBG_AUTOSCALE_PROBLEM"); 2470 "ats", "MLP_DBG_AUTOSCALE_PROBLEM");
2423 if (GNUNET_SYSERR == mlp->opt_dbg_autoscale_problem) 2471 if (GNUNET_SYSERR == mlp->opt_dbg_autoscale_problem)
2424 mlp->opt_dbg_autoscale_problem = GNUNET_NO; 2472 mlp->opt_dbg_autoscale_problem = GNUNET_NO;
2425 if (GNUNET_YES == mlp->opt_dbg_autoscale_problem) 2473 if (GNUNET_YES == mlp->opt_dbg_autoscale_problem)
2426 LOG (GNUNET_ERROR_TYPE_WARNING, 2474 LOG(GNUNET_ERROR_TYPE_WARNING,
2427 "MLP solver is configured automatically scale the problem!\n"); 2475 "MLP solver is configured automatically scale the problem!\n");
2428 2476
2429 mlp->opt_dbg_intopt_presolver = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 2477 mlp->opt_dbg_intopt_presolver = GNUNET_CONFIGURATION_get_value_yesno(env->cfg,
2430 "ats", "MLP_DBG_INTOPT_PRESOLVE"); 2478 "ats", "MLP_DBG_INTOPT_PRESOLVE");
2431 if (GNUNET_SYSERR == mlp->opt_dbg_intopt_presolver) 2479 if (GNUNET_SYSERR == mlp->opt_dbg_intopt_presolver)
2432 mlp->opt_dbg_intopt_presolver = GNUNET_NO; 2480 mlp->opt_dbg_intopt_presolver = GNUNET_NO;
2433 if (GNUNET_YES == mlp->opt_dbg_intopt_presolver) 2481 if (GNUNET_YES == mlp->opt_dbg_intopt_presolver)
2434 LOG (GNUNET_ERROR_TYPE_WARNING, 2482 LOG(GNUNET_ERROR_TYPE_WARNING,
2435 "MLP solver is configured use the mlp presolver\n"); 2483 "MLP solver is configured use the mlp presolver\n");
2436 2484
2437 mlp->opt_dbg_optimize_diversity = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 2485 mlp->opt_dbg_optimize_diversity = GNUNET_CONFIGURATION_get_value_yesno(env->cfg,
2438 "ats", "MLP_DBG_OPTIMIZE_DIVERSITY"); 2486 "ats", "MLP_DBG_OPTIMIZE_DIVERSITY");
2439 if (GNUNET_SYSERR == mlp->opt_dbg_optimize_diversity) 2487 if (GNUNET_SYSERR == mlp->opt_dbg_optimize_diversity)
2440 mlp->opt_dbg_optimize_diversity = GNUNET_YES; 2488 mlp->opt_dbg_optimize_diversity = GNUNET_YES;
2441 if (GNUNET_NO == mlp->opt_dbg_optimize_diversity) 2489 if (GNUNET_NO == mlp->opt_dbg_optimize_diversity)
2442 LOG (GNUNET_ERROR_TYPE_WARNING, 2490 LOG(GNUNET_ERROR_TYPE_WARNING,
2443 "MLP solver is not optimizing for diversity\n"); 2491 "MLP solver is not optimizing for diversity\n");
2444 2492
2445 mlp->opt_dbg_optimize_relativity= GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 2493 mlp->opt_dbg_optimize_relativity = GNUNET_CONFIGURATION_get_value_yesno(env->cfg,
2446 "ats", "MLP_DBG_OPTIMIZE_RELATIVITY"); 2494 "ats", "MLP_DBG_OPTIMIZE_RELATIVITY");
2447 if (GNUNET_SYSERR == mlp->opt_dbg_optimize_relativity) 2495 if (GNUNET_SYSERR == mlp->opt_dbg_optimize_relativity)
2448 mlp->opt_dbg_optimize_relativity = GNUNET_YES; 2496 mlp->opt_dbg_optimize_relativity = GNUNET_YES;
2449 if (GNUNET_NO == mlp->opt_dbg_optimize_relativity) 2497 if (GNUNET_NO == mlp->opt_dbg_optimize_relativity)
2450 LOG (GNUNET_ERROR_TYPE_WARNING, 2498 LOG(GNUNET_ERROR_TYPE_WARNING,
2451 "MLP solver is not optimizing for relativity\n"); 2499 "MLP solver is not optimizing for relativity\n");
2452 2500
2453 mlp->opt_dbg_optimize_quality = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 2501 mlp->opt_dbg_optimize_quality = GNUNET_CONFIGURATION_get_value_yesno(env->cfg,
2454 "ats", "MLP_DBG_OPTIMIZE_QUALITY"); 2502 "ats", "MLP_DBG_OPTIMIZE_QUALITY");
2455 if (GNUNET_SYSERR == mlp->opt_dbg_optimize_quality) 2503 if (GNUNET_SYSERR == mlp->opt_dbg_optimize_quality)
2456 mlp->opt_dbg_optimize_quality = GNUNET_YES; 2504 mlp->opt_dbg_optimize_quality = GNUNET_YES;
2457 if (GNUNET_NO == mlp->opt_dbg_optimize_quality) 2505 if (GNUNET_NO == mlp->opt_dbg_optimize_quality)
2458 LOG (GNUNET_ERROR_TYPE_WARNING, 2506 LOG(GNUNET_ERROR_TYPE_WARNING,
2459 "MLP solver is not optimizing for quality\n"); 2507 "MLP solver is not optimizing for quality\n");
2460 2508
2461 mlp->opt_dbg_optimize_utility = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 2509 mlp->opt_dbg_optimize_utility = GNUNET_CONFIGURATION_get_value_yesno(env->cfg,
2462 "ats", "MLP_DBG_OPTIMIZE_UTILITY"); 2510 "ats", "MLP_DBG_OPTIMIZE_UTILITY");
2463 if (GNUNET_SYSERR == mlp->opt_dbg_optimize_utility) 2511 if (GNUNET_SYSERR == mlp->opt_dbg_optimize_utility)
2464 mlp->opt_dbg_optimize_utility = GNUNET_YES; 2512 mlp->opt_dbg_optimize_utility = GNUNET_YES;
2465 if (GNUNET_NO == mlp->opt_dbg_optimize_utility) 2513 if (GNUNET_NO == mlp->opt_dbg_optimize_utility)
2466 LOG (GNUNET_ERROR_TYPE_WARNING, 2514 LOG(GNUNET_ERROR_TYPE_WARNING,
2467 "MLP solver is not optimizing for utility\n"); 2515 "MLP solver is not optimizing for utility\n");
2468 2516
2469 if ( (GNUNET_NO == mlp->opt_dbg_optimize_utility) && 2517 if ((GNUNET_NO == mlp->opt_dbg_optimize_utility) &&
2470 (GNUNET_NO == mlp->opt_dbg_optimize_quality) && 2518 (GNUNET_NO == mlp->opt_dbg_optimize_quality) &&
2471 (GNUNET_NO == mlp->opt_dbg_optimize_relativity) && 2519 (GNUNET_NO == mlp->opt_dbg_optimize_relativity) &&
2472 (GNUNET_NO == mlp->opt_dbg_optimize_utility) && 2520 (GNUNET_NO == mlp->opt_dbg_optimize_utility) &&
2473 (GNUNET_NO == mlp->opt_dbg_feasibility_only)) 2521 (GNUNET_NO == mlp->opt_dbg_feasibility_only))
2474 {
2475 LOG (GNUNET_ERROR_TYPE_ERROR,
2476 _("MLP solver is not optimizing for anything, changing to feasibility check\n"));
2477 mlp->opt_dbg_feasibility_only = GNUNET_YES;
2478 }
2479
2480 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (env->cfg,
2481 "ats", "MLP_LOG_FORMAT", &outputformat))
2482 mlp->opt_log_format = MLP_CPLEX;
2483 else
2484 {
2485 GNUNET_STRINGS_utf8_toupper(outputformat, outputformat);
2486 if (0 == strcmp (outputformat, "MPS"))
2487 {
2488 mlp->opt_log_format = MLP_MPS;
2489 }
2490 else if (0 == strcmp (outputformat, "CPLEX"))
2491 { 2522 {
2492 mlp->opt_log_format = MLP_CPLEX; 2523 LOG(GNUNET_ERROR_TYPE_ERROR,
2524 _("MLP solver is not optimizing for anything, changing to feasibility check\n"));
2525 mlp->opt_dbg_feasibility_only = GNUNET_YES;
2493 } 2526 }
2494 else if (0 == strcmp (outputformat, "GLPK")) 2527
2495 { 2528 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(env->cfg,
2496 mlp->opt_log_format = MLP_GLPK; 2529 "ats", "MLP_LOG_FORMAT", &outputformat))
2497 } 2530 mlp->opt_log_format = MLP_CPLEX;
2498 else 2531 else
2499 { 2532 {
2500 LOG (GNUNET_ERROR_TYPE_WARNING, 2533 GNUNET_STRINGS_utf8_toupper(outputformat, outputformat);
2501 "Invalid log format `%s' in configuration, using CPLEX!\n", 2534 if (0 == strcmp(outputformat, "MPS"))
2502 outputformat); 2535 {
2503 mlp->opt_log_format = MLP_CPLEX; 2536 mlp->opt_log_format = MLP_MPS;
2537 }
2538 else if (0 == strcmp(outputformat, "CPLEX"))
2539 {
2540 mlp->opt_log_format = MLP_CPLEX;
2541 }
2542 else if (0 == strcmp(outputformat, "GLPK"))
2543 {
2544 mlp->opt_log_format = MLP_GLPK;
2545 }
2546 else
2547 {
2548 LOG(GNUNET_ERROR_TYPE_WARNING,
2549 "Invalid log format `%s' in configuration, using CPLEX!\n",
2550 outputformat);
2551 mlp->opt_log_format = MLP_CPLEX;
2552 }
2553 GNUNET_free(outputformat);
2504 } 2554 }
2505 GNUNET_free (outputformat);
2506 }
2507 2555
2508 mlp->pv.BIG_M = (double) BIG_M_VALUE; 2556 mlp->pv.BIG_M = (double)BIG_M_VALUE;
2509 2557
2510 mlp->pv.mip_gap = (double) 0.0; 2558 mlp->pv.mip_gap = (double)0.0;
2511 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", 2559 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats",
2512 "MLP_MAX_MIP_GAP", &f_tmp)) 2560 "MLP_MAX_MIP_GAP", &f_tmp))
2513 {
2514 if ((f_tmp < 0.0) || (f_tmp > 1.0))
2515 {
2516 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
2517 "MIP gap", f_tmp);
2518 }
2519 else
2520 { 2561 {
2521 mlp->pv.mip_gap = f_tmp; 2562 if ((f_tmp < 0.0) || (f_tmp > 1.0))
2522 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", 2563 {
2523 "MIP gap", f_tmp); 2564 LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
2565 "MIP gap", f_tmp);
2566 }
2567 else
2568 {
2569 mlp->pv.mip_gap = f_tmp;
2570 LOG(GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
2571 "MIP gap", f_tmp);
2572 }
2524 } 2573 }
2525 }
2526 2574
2527 mlp->pv.lp_mip_gap = (double) 0.0; 2575 mlp->pv.lp_mip_gap = (double)0.0;
2528 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", 2576 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats",
2529 "MLP_MAX_LP_MIP_GAP", &f_tmp)) 2577 "MLP_MAX_LP_MIP_GAP", &f_tmp))
2530 {
2531 if ((f_tmp < 0.0) || (f_tmp > 1.0))
2532 {
2533 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
2534 "LP/MIP", f_tmp);
2535 }
2536 else
2537 { 2578 {
2538 mlp->pv.lp_mip_gap = f_tmp; 2579 if ((f_tmp < 0.0) || (f_tmp > 1.0))
2539 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s gap of %.3f\n", 2580 {
2540 "LP/MIP", f_tmp); 2581 LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
2582 "LP/MIP", f_tmp);
2583 }
2584 else
2585 {
2586 mlp->pv.lp_mip_gap = f_tmp;
2587 LOG(GNUNET_ERROR_TYPE_INFO, "Using %s gap of %.3f\n",
2588 "LP/MIP", f_tmp);
2589 }
2541 } 2590 }
2542 }
2543 2591
2544 /* Get timeout for iterations */ 2592 /* Get timeout for iterations */
2545 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time(env->cfg, "ats", 2593 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time(env->cfg, "ats",
2546 "MLP_MAX_DURATION", &max_duration)) 2594 "MLP_MAX_DURATION", &max_duration))
2547 { 2595 {
2548 max_duration = MLP_MAX_EXEC_DURATION; 2596 max_duration = MLP_MAX_EXEC_DURATION;
2549 } 2597 }
2550 2598
2551 /* Get maximum number of iterations */ 2599 /* Get maximum number of iterations */
2552 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_size(env->cfg, "ats", 2600 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_size(env->cfg, "ats",
2553 "MLP_MAX_ITERATIONS", &max_iterations)) 2601 "MLP_MAX_ITERATIONS", &max_iterations))
2554 { 2602 {
2555 max_iterations = MLP_MAX_ITERATIONS; 2603 max_iterations = MLP_MAX_ITERATIONS;
2556 } 2604 }
2557 2605
2558 /* Get diversity coefficient from configuration */ 2606 /* Get diversity coefficient from configuration */
2559 mlp->pv.co_D = MLP_DEFAULT_D; 2607 mlp->pv.co_D = MLP_DEFAULT_D;
2560 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", 2608 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats",
2561 "MLP_COEFFICIENT_D", &f_tmp)) 2609 "MLP_COEFFICIENT_D", &f_tmp))
2562 {
2563 if ((f_tmp < 0.0))
2564 {
2565 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
2566 "MLP_COEFFICIENT_D", f_tmp);
2567 }
2568 else
2569 { 2610 {
2570 mlp->pv.co_D = f_tmp; 2611 if ((f_tmp < 0.0))
2571 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s gap of %.3f\n", 2612 {
2572 "MLP_COEFFICIENT_D", f_tmp); 2613 LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
2614 "MLP_COEFFICIENT_D", f_tmp);
2615 }
2616 else
2617 {
2618 mlp->pv.co_D = f_tmp;
2619 LOG(GNUNET_ERROR_TYPE_INFO, "Using %s gap of %.3f\n",
2620 "MLP_COEFFICIENT_D", f_tmp);
2621 }
2573 } 2622 }
2574 }
2575 2623
2576 /* Get relativity coefficient from configuration */ 2624 /* Get relativity coefficient from configuration */
2577 mlp->pv.co_R = MLP_DEFAULT_R; 2625 mlp->pv.co_R = MLP_DEFAULT_R;
2578 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", 2626 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats",
2579 "MLP_COEFFICIENT_R", &f_tmp)) 2627 "MLP_COEFFICIENT_R", &f_tmp))
2580 {
2581 if ((f_tmp < 0.0))
2582 {
2583 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
2584 "MLP_COEFFICIENT_R", f_tmp);
2585 }
2586 else
2587 { 2628 {
2588 mlp->pv.co_R = f_tmp; 2629 if ((f_tmp < 0.0))
2589 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s gap of %.3f\n", 2630 {
2590 "MLP_COEFFICIENT_R", f_tmp); 2631 LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
2632 "MLP_COEFFICIENT_R", f_tmp);
2633 }
2634 else
2635 {
2636 mlp->pv.co_R = f_tmp;
2637 LOG(GNUNET_ERROR_TYPE_INFO, "Using %s gap of %.3f\n",
2638 "MLP_COEFFICIENT_R", f_tmp);
2639 }
2591 } 2640 }
2592 }
2593 2641
2594 2642
2595 /* Get utilization coefficient from configuration */ 2643 /* Get utilization coefficient from configuration */
2596 mlp->pv.co_U = MLP_DEFAULT_U; 2644 mlp->pv.co_U = MLP_DEFAULT_U;
2597 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", 2645 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats",
2598 "MLP_COEFFICIENT_U", &f_tmp)) 2646 "MLP_COEFFICIENT_U", &f_tmp))
2599 {
2600 if ((f_tmp < 0.0))
2601 {
2602 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
2603 "MLP_COEFFICIENT_U", f_tmp);
2604 }
2605 else
2606 { 2647 {
2607 mlp->pv.co_U = f_tmp; 2648 if ((f_tmp < 0.0))
2608 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s gap of %.3f\n", 2649 {
2609 "MLP_COEFFICIENT_U", f_tmp); 2650 LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
2651 "MLP_COEFFICIENT_U", f_tmp);
2652 }
2653 else
2654 {
2655 mlp->pv.co_U = f_tmp;
2656 LOG(GNUNET_ERROR_TYPE_INFO, "Using %s gap of %.3f\n",
2657 "MLP_COEFFICIENT_U", f_tmp);
2658 }
2610 } 2659 }
2611 }
2612 2660
2613 /* Get quality metric coefficients from configuration */ 2661 /* Get quality metric coefficients from configuration */
2614 for (c = 0; c < RQ_QUALITY_METRIC_COUNT; c++) 2662 for (c = 0; c < RQ_QUALITY_METRIC_COUNT; c++)
2615 { 2663 {
2616 /* initialize quality coefficients with default value 1.0 */ 2664 /* initialize quality coefficients with default value 1.0 */
2617 mlp->pv.co_Q[c] = MLP_DEFAULT_QUALITY; 2665 mlp->pv.co_Q[c] = MLP_DEFAULT_QUALITY;
2618 } 2666 }
2619 2667
2620 2668
2621 if (GNUNET_OK == 2669 if (GNUNET_OK ==
2622 GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats", 2670 GNUNET_CONFIGURATION_get_value_size(env->cfg, "ats",
2623 "MLP_COEFFICIENT_QUALITY_DELAY", 2671 "MLP_COEFFICIENT_QUALITY_DELAY",
2624 &tmp)) 2672 &tmp))
2625 mlp->pv.co_Q[RQ_QUALITY_METRIC_DELAY] = (double) tmp / 100; 2673 mlp->pv.co_Q[RQ_QUALITY_METRIC_DELAY] = (double)tmp / 100;
2626 else 2674 else
2627 mlp->pv.co_Q[RQ_QUALITY_METRIC_DELAY] = MLP_DEFAULT_QUALITY; 2675 mlp->pv.co_Q[RQ_QUALITY_METRIC_DELAY] = MLP_DEFAULT_QUALITY;
2628 2676
2629 if (GNUNET_OK == 2677 if (GNUNET_OK ==
2630 GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats", 2678 GNUNET_CONFIGURATION_get_value_size(env->cfg, "ats",
2631 "MLP_COEFFICIENT_QUALITY_DISTANCE", 2679 "MLP_COEFFICIENT_QUALITY_DISTANCE",
2632 &tmp)) 2680 &tmp))
2633 mlp->pv.co_Q[RQ_QUALITY_METRIC_DISTANCE] = (double) tmp / 100; 2681 mlp->pv.co_Q[RQ_QUALITY_METRIC_DISTANCE] = (double)tmp / 100;
2634 else 2682 else
2635 mlp->pv.co_Q[RQ_QUALITY_METRIC_DISTANCE] = MLP_DEFAULT_QUALITY; 2683 mlp->pv.co_Q[RQ_QUALITY_METRIC_DISTANCE] = MLP_DEFAULT_QUALITY;
2636 2684
2637 /* Get minimum bandwidth per used address from configuration */ 2685 /* Get minimum bandwidth per used address from configuration */
2638 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats", 2686 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size(env->cfg, "ats",
2639 "MLP_MIN_BANDWIDTH", 2687 "MLP_MIN_BANDWIDTH",
2640 &tmp)) 2688 &tmp))
2641 b_min = tmp; 2689 b_min = tmp;
2642 else 2690 else
2643 { 2691 {
2644 b_min = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__); 2692 b_min = ntohl(GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
2645 } 2693 }
2646 2694
2647 /* Get minimum number of connections from configuration */ 2695 /* Get minimum number of connections from configuration */
2648 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats", 2696 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size(env->cfg, "ats",
2649 "MLP_MIN_CONNECTIONS", 2697 "MLP_MIN_CONNECTIONS",
2650 &tmp)) 2698 &tmp))
2651 n_min = tmp; 2699 n_min = tmp;
2652 else 2700 else
2653 n_min = MLP_DEFAULT_MIN_CONNECTIONS; 2701 n_min = MLP_DEFAULT_MIN_CONNECTIONS;
2654 2702
2655 /* Init network quotas */ 2703 /* Init network quotas */
2656 for (c = 0; c < GNUNET_NT_COUNT; c++) 2704 for (c = 0; c < GNUNET_NT_COUNT; c++)
2657 { 2705 {
2658 mlp->pv.quota_index[c] = c; 2706 mlp->pv.quota_index[c] = c;
2659 mlp->pv.quota_out[c] = env->out_quota[c]; 2707 mlp->pv.quota_out[c] = env->out_quota[c];
2660 mlp->pv.quota_in[c] = env->in_quota[c]; 2708 mlp->pv.quota_in[c] = env->in_quota[c];
2661 2709
2662 LOG (GNUNET_ERROR_TYPE_INFO, 2710 LOG(GNUNET_ERROR_TYPE_INFO,
2663 "Quota for network `%s' (in/out) %llu/%llu\n", 2711 "Quota for network `%s' (in/out) %llu/%llu\n",
2664 GNUNET_NT_to_string (c), 2712 GNUNET_NT_to_string(c),
2665 mlp->pv.quota_out[c], 2713 mlp->pv.quota_out[c],
2666 mlp->pv.quota_in[c]); 2714 mlp->pv.quota_in[c]);
2667 /* Check if defined quota could make problem unsolvable */ 2715 /* Check if defined quota could make problem unsolvable */
2668 if ((n_min * b_min) > mlp->pv.quota_out[c]) 2716 if ((n_min * b_min) > mlp->pv.quota_out[c])
2669 { 2717 {
2670 LOG (GNUNET_ERROR_TYPE_INFO, 2718 LOG(GNUNET_ERROR_TYPE_INFO,
2671 _("Adjusting inconsistent outbound quota configuration for network `%s', is %llu must be at least %llu\n"), 2719 _("Adjusting inconsistent outbound quota configuration for network `%s', is %llu must be at least %llu\n"),
2672 GNUNET_NT_to_string(mlp->pv.quota_index[c]), 2720 GNUNET_NT_to_string(mlp->pv.quota_index[c]),
2673 mlp->pv.quota_out[c], 2721 mlp->pv.quota_out[c],
2674 (n_min * b_min)); 2722 (n_min * b_min));
2675 mlp->pv.quota_out[c] = (n_min * b_min); 2723 mlp->pv.quota_out[c] = (n_min * b_min);
2676 } 2724 }
2677 if ((n_min * b_min) > mlp->pv.quota_in[c]) 2725 if ((n_min * b_min) > mlp->pv.quota_in[c])
2678 { 2726 {
2679 LOG (GNUNET_ERROR_TYPE_INFO, 2727 LOG(GNUNET_ERROR_TYPE_INFO,
2680 _("Adjusting inconsistent inbound quota configuration for network `%s', is %llu must be at least %llu\n"), 2728 _("Adjusting inconsistent inbound quota configuration for network `%s', is %llu must be at least %llu\n"),
2681 GNUNET_NT_to_string(mlp->pv.quota_index[c]), 2729 GNUNET_NT_to_string(mlp->pv.quota_index[c]),
2682 mlp->pv.quota_in[c], 2730 mlp->pv.quota_in[c],
2683 (n_min * b_min)); 2731 (n_min * b_min));
2684 mlp->pv.quota_in[c] = (n_min * b_min); 2732 mlp->pv.quota_in[c] = (n_min * b_min);
2685 } 2733 }
2686 /* Check if bandwidth is too big to make problem solvable */ 2734 /* Check if bandwidth is too big to make problem solvable */
2687 if (mlp->pv.BIG_M < mlp->pv.quota_out[c]) 2735 if (mlp->pv.BIG_M < mlp->pv.quota_out[c])
2688 { 2736 {
2689 LOG (GNUNET_ERROR_TYPE_INFO, 2737 LOG(GNUNET_ERROR_TYPE_INFO,
2690 _("Adjusting outbound quota configuration for network `%s'from %llu to %.0f\n"), 2738 _("Adjusting outbound quota configuration for network `%s'from %llu to %.0f\n"),
2691 GNUNET_NT_to_string(mlp->pv.quota_index[c]), 2739 GNUNET_NT_to_string(mlp->pv.quota_index[c]),
2692 mlp->pv.quota_out[c], 2740 mlp->pv.quota_out[c],
2693 mlp->pv.BIG_M); 2741 mlp->pv.BIG_M);
2694 mlp->pv.quota_out[c] = mlp->pv.BIG_M ; 2742 mlp->pv.quota_out[c] = mlp->pv.BIG_M;
2695 } 2743 }
2696 if (mlp->pv.BIG_M < mlp->pv.quota_in[c]) 2744 if (mlp->pv.BIG_M < mlp->pv.quota_in[c])
2697 { 2745 {
2698 LOG (GNUNET_ERROR_TYPE_INFO, 2746 LOG(GNUNET_ERROR_TYPE_INFO,
2699 _("Adjusting inbound quota configuration for network `%s' from %llu to %.0f\n"), 2747 _("Adjusting inbound quota configuration for network `%s' from %llu to %.0f\n"),
2700 GNUNET_NT_to_string(mlp->pv.quota_index[c]), 2748 GNUNET_NT_to_string(mlp->pv.quota_index[c]),
2701 mlp->pv.quota_in[c], 2749 mlp->pv.quota_in[c],
2702 mlp->pv.BIG_M); 2750 mlp->pv.BIG_M);
2703 mlp->pv.quota_in[c] = mlp->pv.BIG_M ; 2751 mlp->pv.quota_in[c] = mlp->pv.BIG_M;
2704 } 2752 }
2705 } 2753 }
2706 mlp->env = env; 2754 mlp->env = env;
2707 sf.cls = mlp; 2755 sf.cls = mlp;
2708 sf.s_add = &GAS_mlp_address_add; 2756 sf.s_add = &GAS_mlp_address_add;
@@ -2722,13 +2770,13 @@ libgnunet_plugin_ats_mlp_init (void *cls)
2722 mlp->stat_mlp_prob_changed = GNUNET_NO; 2770 mlp->stat_mlp_prob_changed = GNUNET_NO;
2723 mlp->stat_mlp_prob_updated = GNUNET_NO; 2771 mlp->stat_mlp_prob_updated = GNUNET_NO;
2724 mlp->opt_mlp_auto_solve = GNUNET_YES; 2772 mlp->opt_mlp_auto_solve = GNUNET_YES;
2725 mlp->requested_peers = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); 2773 mlp->requested_peers = GNUNET_CONTAINER_multipeermap_create(10, GNUNET_NO);
2726 mlp->stat_bulk_requests = 0; 2774 mlp->stat_bulk_requests = 0;
2727 mlp->stat_bulk_lock = 0; 2775 mlp->stat_bulk_lock = 0;
2728 2776
2729 /* Setup GLPK */ 2777 /* Setup GLPK */
2730 /* Redirect GLPK output to GNUnet logging */ 2778 /* Redirect GLPK output to GNUnet logging */
2731 glp_term_hook (&mlp_term_hook, (void *) mlp); 2779 glp_term_hook(&mlp_term_hook, (void *)mlp);
2732 2780
2733 /* Init LP solving parameters */ 2781 /* Init LP solving parameters */
2734 glp_init_smcp(&mlp->control_param_lp); 2782 glp_init_smcp(&mlp->control_param_lp);
@@ -2750,7 +2798,7 @@ libgnunet_plugin_ats_mlp_init (void *cls)
2750 mlp->control_param_mlp.msg_lev = GLP_MSG_ALL; 2798 mlp->control_param_mlp.msg_lev = GLP_MSG_ALL;
2751 mlp->control_param_mlp.tm_lim = max_duration.rel_value_us / 1000LL; 2799 mlp->control_param_mlp.tm_lim = max_duration.rel_value_us / 1000LL;
2752 2800
2753 LOG (GNUNET_ERROR_TYPE_DEBUG, "solver ready\n"); 2801 LOG(GNUNET_ERROR_TYPE_DEBUG, "solver ready\n");
2754 2802
2755 return &sf; 2803 return &sf;
2756} 2804}