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