2 This file is part of GNUnet.
3 (C) 2009, 2010 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file transport/transport_ats.c
23 * @brief automatic transport selection
24 * @author Matthias Wachs
29 #include "gnunet-service-transport_ats.h"
30 #include "gnunet_transport_service.h"
31 #include "gnunet_statistics_service.h"
32 #include "gnunet_container_lib.h"
38 /* LP/MIP problem object */
42 #ifndef GLP_PROB_DEFINED
43 #define GLP_PROB_DEFINED
44 typedef struct { double _opaque_prob[100]; } glp_prob;
48 { /* integer optimizer control parameters */
49 int msg_lev; /* message level (see glp_smcp) */
50 int br_tech; /* branching technique: */
51 #define GLP_BR_FFV 1 /* first fractional variable */
52 #define GLP_BR_LFV 2 /* last fractional variable */
53 #define GLP_BR_MFV 3 /* most fractional variable */
54 #define GLP_BR_DTH 4 /* heuristic by Driebeck and Tomlin */
55 #define GLP_BR_PCH 5 /* hybrid pseudocost heuristic */
56 int bt_tech; /* backtracking technique: */
57 #define GLP_BT_DFS 1 /* depth first search */
58 #define GLP_BT_BFS 2 /* breadth first search */
59 #define GLP_BT_BLB 3 /* best local bound */
60 #define GLP_BT_BPH 4 /* best projection heuristic */
61 double tol_int; /* mip.tol_int */
62 double tol_obj; /* mip.tol_obj */
63 int tm_lim; /* mip.tm_lim (milliseconds) */
64 int out_frq; /* mip.out_frq (milliseconds) */
65 int out_dly; /* mip.out_dly (milliseconds) */
67 void *cb_info; /* mip.cb_info */
68 int cb_size; /* mip.cb_size */
69 int pp_tech; /* preprocessing technique: */
70 #define GLP_PP_NONE 0 /* disable preprocessing */
71 #define GLP_PP_ROOT 1 /* preprocessing only on root level */
72 #define GLP_PP_ALL 2 /* preprocessing on all levels */
73 double mip_gap; /* relative MIP gap tolerance */
74 int mir_cuts; /* MIR cuts (GLP_ON/GLP_OFF) */
75 int gmi_cuts; /* Gomory's cuts (GLP_ON/GLP_OFF) */
76 int cov_cuts; /* cover cuts (GLP_ON/GLP_OFF) */
77 int clq_cuts; /* clique cuts (GLP_ON/GLP_OFF) */
78 int presolve; /* enable/disable using MIP presolver */
79 int binarize; /* try to binarize integer variables */
80 int fp_heur; /* feasibility pump heuristic */
82 int alien; /* use alien solver */
84 double foo_bar[29]; /* (reserved) */
88 { /* simplex method control parameters */
89 int msg_lev; /* message level: */
90 #define GLP_MSG_OFF 0 /* no output */
91 #define GLP_MSG_ERR 1 /* warning and error messages only */
92 #define GLP_MSG_ON 2 /* normal output */
93 #define GLP_MSG_ALL 3 /* full output */
94 #define GLP_MSG_DBG 4 /* debug output */
95 int meth; /* simplex method option: */
96 #define GLP_PRIMAL 1 /* use primal simplex */
97 #define GLP_DUALP 2 /* use dual; if it fails, use primal */
98 #define GLP_DUAL 3 /* use dual simplex */
99 int pricing; /* pricing technique: */
100 #define GLP_PT_STD 0x11 /* standard (Dantzig rule) */
101 #define GLP_PT_PSE 0x22 /* projected steepest edge */
102 int r_test; /* ratio test technique: */
103 #define GLP_RT_STD 0x11 /* standard (textbook) */
104 #define GLP_RT_HAR 0x22 /* two-pass Harris' ratio test */
105 double tol_bnd; /* spx.tol_bnd */
106 double tol_dj; /* spx.tol_dj */
107 double tol_piv; /* spx.tol_piv */
108 double obj_ll; /* spx.obj_ll */
109 double obj_ul; /* spx.obj_ul */
110 int it_lim; /* spx.it_lim */
111 int tm_lim; /* spx.tm_lim (milliseconds) */
112 int out_frq; /* spx.out_frq */
113 int out_dly; /* spx.out_dly (milliseconds) */
114 int presolve; /* enable/disable using LP presolver */
115 double foo_bar[36]; /* (reserved) */
118 /* optimization direction flag: */
119 #define GLP_MIN 1 /* minimization */
120 #define GLP_MAX 2 /* maximization */
122 /* kind of structural variable: */
123 #define GLP_CV 1 /* continuous variable */
124 #define GLP_IV 2 /* integer variable */
125 #define GLP_BV 3 /* binary variable */
127 /* type of auxiliary/structural variable: */
128 #define GLP_FR 1 /* free variable */
129 #define GLP_LO 2 /* variable with lower bound */
130 #define GLP_UP 3 /* variable with upper bound */
131 #define GLP_DB 4 /* double-bounded variable */
132 #define GLP_FX 5 /* fixed variable */
134 /* solution indicator: */
135 #define GLP_SOL 1 /* basic solution */
136 #define GLP_IPT 2 /* interior-point solution */
137 #define GLP_MIP 3 /* mixed integer solution */
139 /* solution status: */
140 #define GLP_UNDEF 1 /* solution is undefined */
141 #define GLP_FEAS 2 /* solution is feasible */
142 #define GLP_INFEAS 3 /* solution is infeasible */
143 #define GLP_NOFEAS 4 /* no feasible solution exists */
144 #define GLP_OPT 5 /* solution is optimal */
145 #define GLP_UNBND 6 /* solution is unbounded */
148 #define GLP_EBADB 0x01 /* invalid basis */
149 #define GLP_ESING 0x02 /* singular matrix */
150 #define GLP_ECOND 0x03 /* ill-conditioned matrix */
151 #define GLP_EBOUND 0x04 /* invalid bounds */
152 #define GLP_EFAIL 0x05 /* solver failed */
153 #define GLP_EOBJLL 0x06 /* objective lower limit reached */
154 #define GLP_EOBJUL 0x07 /* objective upper limit reached */
155 #define GLP_EITLIM 0x08 /* iteration limit exceeded */
156 #define GLP_ETMLIM 0x09 /* time limit exceeded */
157 #define GLP_ENOPFS 0x0A /* no primal feasible solution */
158 #define GLP_ENODFS 0x0B /* no dual feasible solution */
159 #define GLP_EROOT 0x0C /* root LP optimum not provided */
160 #define GLP_ESTOP 0x0D /* search terminated by application */
161 #define GLP_EMIPGAP 0x0E /* relative mip gap tolerance reached */
162 #define GLP_ENOFEAS 0x0F /* no primal/dual feasible solution */
163 #define GLP_ENOCVG 0x10 /* no convergence */
164 #define GLP_EINSTAB 0x11 /* numerical instability */
165 #define GLP_EDATA 0x12 /* invalid data */
166 #define GLP_ERANGE 0x13 /* result out of range */
168 /* enable/disable flag: */
169 #define GLP_ON 1 /* enable something */
170 #define GLP_OFF 0 /* disable something */
175 * Wrappers for GLPK Functions
179 void * _lp_create_prob ( void )
182 return glp_create_prob( );
184 // Function not implemented
190 void _lp_set_obj_dir (glp_prob *P, int dir)
193 return glp_set_obj_dir (P, dir);
195 // Function not implemented
200 void _lp_set_prob_name (glp_prob *P, const char *name)
203 glp_set_prob_name(P, name);
205 // Function not implemented
210 int _lp_add_cols (glp_prob *P, int ncs)
213 return glp_add_cols(P, ncs);
215 // Function not implemented
221 int _lp_add_rows (glp_prob *P, int nrs)
224 return glp_add_rows (P, nrs);
226 // Function not implemented
233 void _lp_set_row_bnds (glp_prob *P, int i, int type, double lb, double ub)
236 glp_set_row_bnds(P, i , type, lb, ub);
238 // Function not implemented
243 void _lp_init_smcp (void * parm)
248 // Function not implemented
253 void _lp_set_col_name (glp_prob *P, int j, const char *name)
256 glp_set_col_name (P, j, name);
258 // Function not implemented
263 void _lp_set_col_bnds (glp_prob *P, int j, int type, double lb,
267 glp_set_col_bnds(P, j, type, lb, ub);
269 // Function not implemented
274 void _lp_set_obj_coef(glp_prob *P, int j, double coef)
277 glp_set_obj_coef(P, j, coef);
279 // Function not implemented
284 void _lp_delete_prob (void * P)
289 // Function not implemented
294 static int _lp_simplex(glp_prob *P, void *parm)
297 return glp_simplex (P, parm);
299 // Function not implemented
305 static void _lp_load_matrix (glp_prob *P, int ne, const int ia[],
306 const int ja[], const double ar[])
309 glp_load_matrix(P, ne, ia, ja, ar);
311 // Function not implemented
316 static void _lp_set_mat_row (glp_prob *P, int i, int len, const int ind[],
320 glp_set_mat_row (P, i, len, ind, val);
322 // Function not implemented
327 static int _lp_write_lp (glp_prob *P, const void *parm, const char *fname)
330 return glp_write_lp ( P, parm, fname);
332 // Function not implemented
338 static void _lp_init_iocp (void *parm)
341 glp_init_iocp (parm);
343 // Function not implemented
348 static int _lp_intopt (glp_prob *P, const void *parm)
351 return glp_intopt (P, parm);
353 // Function not implemented
359 static int _lp_get_status (glp_prob *P)
362 return glp_get_status (P);
364 // Function not implemented
370 static int _lp_mip_status (glp_prob *P)
373 return glp_mip_status (P);
375 // Function not implemented
381 static void _lp_set_col_kind (glp_prob *P, int j, int kind)
384 glp_set_col_kind (P, j, kind);
386 // Function not implemented
391 static void _lp_free_env (void)
396 // Function not implemented
401 static const char * _lp_get_col_name ( glp_prob *P, int j)
404 return glp_get_col_name (P, j);
406 // Function not implemented
412 static double _lp_mip_obj_val (glp_prob *P)
415 return glp_mip_obj_val (P);
417 // Function not implemented
424 static double _lp_get_col_prim (glp_prob *P, int j)
427 return glp_get_col_prim (P , j);
429 // Function not implemented
435 static int _lp_print_sol(glp_prob *P, const char *fname)
439 // Function not implemented
446 * Dummy functions for CFLAGS
449 static void _dummy2 ();
450 static void _dummy ()
453 _lp_get_col_name (NULL, 0);
454 _lp_mip_obj_val (NULL);
455 _lp_get_col_prim (NULL, 0);
456 _lp_set_mat_row(NULL,0,0,NULL,NULL);
462 static void _dummy2 ()
464 ats_modify_problem_state (NULL, 0);
465 qm[1].atis_index = 0;
467 int t = ATS_COST_UPDATED + ATS_MODIFIED + ATS_NEW;
478 * @param cfg configuration handle to retrieve configuration (to be removed)
482 struct ATS_Handle * ats_init (double D,
488 struct GNUNET_TIME_Relative max_duration,
489 GNUNET_TRANSPORT_ATS_AddressNotification address_not,
490 GNUNET_TRANSPORT_ATS_ResultCallback res_cb)
492 struct ATS_Handle * ats = NULL;
494 ats = GNUNET_malloc(sizeof (struct ATS_Handle));
498 ats->addr_notification = address_not;
499 ats->result_cb = res_cb;
501 ats->max_iterations = max_iterations;
502 ats->max_exec_duration = max_duration;
507 ats->v_b_min = v_b_min;
508 ats->v_n_min = v_n_min;
509 ats->dump_min_peers = 0;
510 ats->dump_min_addr = 0;
511 ats->dump_overwrite = GNUNET_NO;
512 ats->mechanisms = NULL;
514 ats->successful_executions = 0;
515 ats->invalid_executions = 0;
521 /** solve the bandwidth distribution problem
522 * @param max_it maximum iterations
523 * @param max_dur maximum duration in ms
524 * @param D weight for diversity
525 * @param U weight for utility
526 * @param R weight for relativity
527 * @param v_b_min minimal bandwidth per peer
528 * @param v_n_min minimum number of connections
529 * @param stat result struct
530 * @return GNUNET_SYSERR if glpk is not available, number of mechanisms used
532 int ats_create_problem (struct ATS_Handle *ats,
533 struct ATS_internals *stat,
534 struct ATS_peer *peers,
536 struct ATS_mechanism *mechanisms,
539 if ((c_p == 0) || (c_m == 0))
540 return GNUNET_SYSERR;
542 ats->prob = _lp_create_prob();
545 int c_c_ressources = available_ressources;
546 int c_q_metrics = available_quality_metrics;
548 double M = VERY_BIG_DOUBLE_VALUE;
549 double Q[c_q_metrics+1];
550 for (c=1; c<=c_q_metrics; c++)
555 if (ats->v_n_min > c_p)
558 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Creating problem with: %i peers, %i mechanisms, %i resource entries, %i quality metrics \n",
565 int size = 1 + 3 + 10 *c_m + c_p +
566 (c_q_metrics*c_m)+ c_q_metrics + c_c_ressources * c_m ;
569 int * ia = GNUNET_malloc (size * sizeof (int));
570 int * ja = GNUNET_malloc (size * sizeof (int));
571 double * ar = GNUNET_malloc(size* sizeof (double));
573 _lp_set_prob_name (ats->prob, "gnunet ats bandwidth distribution");
574 _lp_set_obj_dir(ats->prob, GLP_MAX);
578 _lp_add_cols(ats->prob, 2 * c_m);
579 /* adding b_t cols */
580 for (c=1; c <= c_m; c++)
582 GNUNET_asprintf(&name,
583 "p_%s_b%i",GNUNET_i2s(&(mechanisms[c].peer->peer)), c);
584 _lp_set_col_name(ats->prob, c, name);
586 _lp_set_col_bnds(ats->prob, c, GLP_LO, 0.0, 0.0);
587 _lp_set_col_kind(ats->prob, c, GLP_CV);
588 _lp_set_obj_coef(ats->prob, c, 0);
591 /* adding n_t cols */
592 for (c=c_m+1; c <= 2*c_m; c++)
594 GNUNET_asprintf(&name,
595 "p_%s_n%i",GNUNET_i2s(&(mechanisms[c-c_m].peer->peer)),(c-c_m));
596 _lp_set_col_name(ats->prob, c, name);
598 _lp_set_col_bnds(ats->prob, c, GLP_DB, 0.0, 1.0);
599 _lp_set_col_kind(ats->prob, c, GLP_IV);
600 _lp_set_obj_coef(ats->prob, c, 0);
603 /* feasibility constraints */
604 /* Constraint 1: one address per peer*/
607 _lp_add_rows(ats->prob, c_p);
609 for (c=1; c<=c_p; c++)
612 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",
616 _lp_set_row_bnds(ats->prob, row_index, GLP_FX, 1.0, 1.0);
617 struct ATS_mechanism *m = peers[c].m_head;
620 ia[array_index] = row_index;
621 ja[array_index] = (c_m + m->col_index);
624 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
636 /* Constraint 2: only active mechanism gets bandwidth assigned */
637 _lp_add_rows(ats->prob, c_m);
638 for (c=1; c<=c_m; c++)
640 /* b_t - n_t * M <= 0 */
642 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",
645 _lp_set_row_bnds(ats->prob, row_index, GLP_UP, 0.0, 0.0);
646 ia[array_index] = row_index;
647 ja[array_index] = mechanisms[c].col_index;
650 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
657 ia[array_index] = row_index;
658 ja[array_index] = c_m + mechanisms[c].col_index;
659 ar[array_index] = -M;
661 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
671 /* Constraint 3: minimum bandwidth*/
672 _lp_add_rows(ats->prob, c_m);
674 for (c=1; c<=c_m; c++)
676 /* b_t - n_t * b_min <= 0 */
678 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",
682 _lp_set_row_bnds(ats->prob, row_index, GLP_LO, 0.0, 0.0);
684 ia[array_index] = row_index;
685 ja[array_index] = mechanisms[c].col_index;
688 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
695 ia[array_index] = row_index;
696 ja[array_index] = c_m + mechanisms[c].col_index;
697 ar[array_index] = -ats->v_b_min;
699 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
710 /* Constraint 4: max ressource capacity */
711 /* V cr: bt * ct_r <= cr_max
714 _lp_add_rows(ats->prob, available_ressources);
716 double ct_max = VERY_BIG_DOUBLE_VALUE;
719 stat->begin_cr = array_index;
721 for (c=0; c<available_ressources; c++)
723 ct_max = ressources[c].c_max;
724 ct_min = ressources[c].c_min;
726 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] %f..%f\n",
732 _lp_set_row_bnds(ats->prob, row_index, GLP_DB, ct_min, ct_max);
734 for (c2=1; c2<=c_m; c2++)
737 ia[array_index] = row_index;
738 ja[array_index] = c2;
739 value = mechanisms[c2].ressources[c].c;
740 ar[array_index] = value;
742 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
743 array_index, ia[array_index],
751 stat->end_cr = array_index--;
753 /* Constraint 5: min number of connections*/
754 _lp_add_rows(ats->prob, 1);
756 for (c=1; c<=c_m; c++)
758 // b_t - n_t * b_min >= 0
760 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",
763 _lp_set_row_bnds(ats->prob, row_index, GLP_LO, ats->v_n_min, 0.0);
764 ia[array_index] = row_index;
765 ja[array_index] = c_m + mechanisms[c].col_index;
768 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
778 // optimisation constraints
782 // Constraint 6: optimize for diversity
784 col_d = _lp_add_cols(ats->prob, 1);
786 _lp_set_col_name(ats->prob, col_d, "d");
787 _lp_set_obj_coef(ats->prob, col_d, ats->D);
788 _lp_set_col_bnds(ats->prob, col_d, GLP_LO, 0.0, 0.0);
789 _lp_add_rows(ats->prob, 1);
790 _lp_set_row_bnds(ats->prob, row_index, GLP_FX, 0.0, 0.0);
794 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",row_index);
796 for (c=1; c<=c_m; c++)
798 ia[array_index] = row_index;
799 ja[array_index] = c_m + mechanisms[c].col_index;
802 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
810 ia[array_index] = row_index;
811 ja[array_index] = col_d;
812 ar[array_index] = -1;
814 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
823 // Constraint 7: optimize for quality
825 col_qm = _lp_add_cols(ats->prob, c_q_metrics);
827 stat->col_qm = col_qm;
828 //GNUNET_assert (col_qm == (2*c_mechs) + 3 + 1);
829 for (c=0; c< c_q_metrics; c++)
831 GNUNET_asprintf(&name, "Q_%s",qm[c].name);
832 _lp_set_col_name (ats->prob, col_qm + c, name);
833 _lp_set_col_bnds (ats->prob, col_qm + c, GLP_LO, 0.0, 0.0);
835 _lp_set_obj_coef (ats->prob, col_qm + c, Q[c]);
838 _lp_add_rows(ats->prob, available_quality_metrics);
840 stat->begin_qm = row_index;
841 for (c=1; c <= c_q_metrics; c++)
844 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",
848 _lp_set_row_bnds(ats->prob, row_index, GLP_FX, 0.0, 0.0);
849 for (c2=1; c2<=c_m; c2++)
851 ia[array_index] = row_index;
852 ja[array_index] = c2;
853 if (qm[c-1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY)
855 double v0 = 0, v1 = 0, v2 = 0;
856 v0 = mechanisms[c2].quality[c-1].values[0];
857 if (v1 < 1) v0 = 0.1;
858 v1 = mechanisms[c2].quality[c-1].values[1];
859 if (v1 < 1) v0 = 0.1;
860 v2 = mechanisms[c2].quality[c-1].values[2];
861 if (v1 < 1) v0 = 0.1;
862 value = 100.0 / ((v0 + 2 * v1 + 3 * v2) / 6.0);
865 if (qm[c-1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE)
867 double v0 = 0, v1 = 0, v2 = 0;
868 v0 = mechanisms[c2].quality[c-1].values[0];
870 v1 = mechanisms[c2].quality[c-1].values[1];
872 v2 = mechanisms[c2].quality[c-1].values[2];
874 value = (v0 + 2 * v1 + 3 * v2) / 6.0;
876 value = (double) 10 / value;
880 ar[array_index] = (mechanisms[c2].peer->f) * value ;
882 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: %s [%i,%i]=%f \n",
891 ia[array_index] = row_index;
892 ja[array_index] = col_qm + c - 1;
893 ar[array_index] = -1;
895 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
904 stat->end_qm = row_index-1;
906 // Constraint 8: optimize bandwidth utility
909 col_u = _lp_add_cols(ats->prob, 1);
911 _lp_set_col_name(ats->prob, col_u, "u");
912 _lp_set_obj_coef(ats->prob, col_u, ats->U);
913 _lp_set_col_bnds(ats->prob, col_u, GLP_LO, 0.0, 0.0);
914 _lp_add_rows(ats->prob, 1);
917 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",row_index);
919 _lp_set_row_bnds(ats->prob, row_index, GLP_FX, 0.0, 0.0);
920 for (c=1; c<=c_m; c++)
922 ia[array_index] = row_index;
924 ar[array_index] = mechanisms[c].peer->f;
926 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
934 ia[array_index] = row_index;
935 ja[array_index] = col_u;
936 ar[array_index] = -1;
938 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
939 array_index, ia[array_index],
947 // Constraint 9: optimize relativity
950 col_r = _lp_add_cols(ats->prob, 1);
952 _lp_set_col_name(ats->prob, col_r, "r");
953 _lp_set_obj_coef(ats->prob, col_r, ats->R);
954 _lp_set_col_bnds(ats->prob, col_r, GLP_LO, 0.0, 0.0);
955 _lp_add_rows(ats->prob, c_p);
958 for (c=1; c<=c_p; c++)
960 _lp_set_row_bnds(ats->prob, row_index, GLP_LO, 0.0, 0.0);
961 struct ATS_mechanism *m = peers[c].m_head;
964 ia[array_index] = row_index;
965 ja[array_index] = m->col_index;
966 ar[array_index] = 1 / mechanisms[c].peer->f;
968 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
977 ia[array_index] = row_index;
978 ja[array_index] = col_r;
979 ar[array_index] = -1;
981 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
991 /* Loading the matrix */
992 _lp_load_matrix(ats->prob, array_index-1, ia, ja, ar);
997 stat->valid = GNUNET_YES;
1008 void ats_delete_problem (struct ATS_Handle * ats)
1011 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Deleting problem\n");
1015 for (c=0; c< (ats->internal).c_mechs; c++)
1016 GNUNET_free_non_null (ats->mechanisms[c].rc);
1017 if (ats->mechanisms!=NULL)
1019 GNUNET_free(ats->mechanisms);
1020 ats->mechanisms = NULL;
1023 if (ats->peers!=NULL)
1025 GNUNET_free(ats->peers);
1029 if (ats->prob != NULL)
1031 _lp_delete_prob(ats->prob);
1035 ats->internal.begin_cr = GNUNET_SYSERR;
1036 ats->internal.begin_qm = GNUNET_SYSERR;
1037 ats->internal.c_mechs = 0;
1038 ats->internal.c_peers = 0;
1039 ats->internal.end_cr = GNUNET_SYSERR;
1040 ats->internal.end_qm = GNUNET_SYSERR;
1041 ats->internal.solution = GNUNET_SYSERR;
1042 ats->internal.valid = GNUNET_SYSERR;
1045 void ats_modify_problem_state (struct ATS_Handle * ats, enum ATS_problem_state s)
1052 ats->internal.recreate_problem = GNUNET_NO;
1053 ats->internal.modified_quality = GNUNET_NO;
1054 ats->internal.modified_resources = GNUNET_NO;
1057 ats->internal.recreate_problem = GNUNET_YES;
1059 case ATS_QUALITY_UPDATED :
1060 ats->internal.modified_quality = GNUNET_YES;
1062 case ATS_COST_UPDATED :
1063 ats->internal.modified_resources = GNUNET_YES;
1065 case ATS_QUALITY_COST_UPDATED:
1066 ats->internal.modified_resources = GNUNET_YES;
1067 ats->internal.modified_quality = GNUNET_YES;
1077 void ats_solve_problem (struct ATS_Handle * ats,
1078 unsigned int max_it,
1079 unsigned int max_dur,
1080 unsigned int c_peers,
1081 unsigned int c_mechs,
1082 struct ATS_internals *stat)
1084 int result = GNUNET_SYSERR;
1085 int lp_solution = GNUNET_SYSERR;
1086 int mlp_solution = GNUNET_SYSERR;
1091 _lp_init_smcp(&opt_lp);
1093 opt_lp.msg_lev = GLP_MSG_ALL;
1095 opt_lp.msg_lev = GLP_MSG_OFF;
1097 // setting iteration limit
1098 opt_lp.it_lim = max_it;
1100 opt_lp.tm_lim = max_dur;
1102 if (ats->internal.recreate_problem == GNUNET_YES)
1103 opt_lp.presolve = GLP_ON;
1105 result = _lp_simplex(ats->prob, &opt_lp);
1106 lp_solution = _lp_get_status (ats->prob);
1108 if ((result == GLP_ETMLIM) || (result == GLP_EITLIM))
1110 ats->internal.valid = GNUNET_NO;
1111 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1112 "ATS exceeded time or iteration limit!\n");
1116 if (ats_evaluate_results(result, lp_solution, "LP") == GNUNET_YES)
1118 stat->valid = GNUNET_YES;
1122 ats->internal.simplex_rerun_required = GNUNET_YES;
1123 opt_lp.presolve = GLP_ON;
1124 result = _lp_simplex(ats->prob, &opt_lp);
1125 lp_solution = _lp_get_status (ats->prob);
1127 // TODO: Remove if this does not appear until release
1128 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, ""
1129 "EXECUTED SIMPLEX WITH PRESOLVER! %i \n",
1132 if (ats_evaluate_results(result, lp_solution, "LP") != GNUNET_YES)
1134 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1135 "After execution simplex with presolver: STILL INVALID!\n");
1137 GNUNET_asprintf (&filename,
1138 "ats_mlp_p%i_m%i_%llu.mlp",
1139 ats->internal.c_peers,
1140 ats->internal.c_mechs,
1141 GNUNET_TIME_absolute_get().abs_value);
1142 _lp_write_lp ((void *)ats->prob, NULL, filename);
1143 GNUNET_free (filename);
1144 stat->valid = GNUNET_NO;
1145 ats->internal.recreate_problem = GNUNET_YES;
1148 stat->valid = GNUNET_YES;
1153 _lp_init_iocp(&opt_mlp);
1155 opt_mlp.tm_lim = max_dur;
1158 opt_mlp.msg_lev = GLP_MSG_ALL;
1160 opt_mlp.msg_lev = GLP_MSG_OFF;
1163 result = _lp_intopt (ats->prob, &opt_mlp);
1164 mlp_solution = _lp_mip_status (ats->prob);
1165 stat->solution = mlp_solution;
1167 if (ats_evaluate_results(result, mlp_solution, "MLP") == GNUNET_YES)
1169 stat->valid = GNUNET_YES;
1173 // TODO: Remove if this does not appear until release
1174 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1175 "MLP solution for %i peers, %i mechs is invalid: %i\n",
1176 ats->internal.c_peers,
1177 ats->internal.c_mechs,
1179 stat->valid = GNUNET_NO;
1183 if (_lp_get_col_prim(ats->prob,2*c_mechs+1) != 1)
1186 for (c=1; c<= available_quality_metrics; c++ )
1188 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s %f\n",
1189 _lp_get_col_name(ats->prob,2*c_mechs+3+c),
1190 _lp_get_col_prim(ats->prob,2*c_mechs+3+c));
1192 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s %f\n",
1193 _lp_get_col_name(ats->prob,2*c_mechs+1),
1194 _lp_get_col_prim(ats->prob,2*c_mechs+1));
1195 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s %f\n",
1196 _lp_get_col_name(ats->prob,2*c_mechs+2),
1197 _lp_get_col_prim(ats->prob,2*c_mechs+2));
1198 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s %f\n",
1199 _lp_get_col_name(ats->prob,2*c_mechs+3),
1200 _lp_get_col_prim(ats->prob,2*c_mechs+3));
1201 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "objective value: %f\n",
1202 _lp_mip_obj_val(ats->prob));
1208 void ats_shutdown (struct ATS_Handle * ats)
1211 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ATS shutdown\n");
1213 ats_delete_problem (ats);
1219 void ats_update_problem_qm (struct ATS_Handle * ats)
1224 int c_q_metrics = available_quality_metrics;
1226 int *ja = GNUNET_malloc ((1 + ats->internal.c_mechs*2 + 3 +
1227 available_quality_metrics) * sizeof (int));
1228 double *ar = GNUNET_malloc ((1 + ats->internal.c_mechs*2 + 3 +
1229 available_quality_metrics) * sizeof (double));
1231 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updating problem quality metrics\n");
1233 row_index = ats->internal.begin_qm;
1235 for (c=1; c <= c_q_metrics; c++)
1240 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",row_index);
1242 _lp_set_row_bnds(ats->prob, row_index, GLP_FX, 0.0, 0.0);
1243 for (c2=1; c2<=ats->internal.c_mechs; c2++)
1245 ja[array_index] = c2;
1246 GNUNET_assert (ats->mechanisms[c2].addr != NULL);
1247 GNUNET_assert (ats->mechanisms[c2].peer != NULL);
1249 if (qm[c-1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY)
1251 double v0 = 0, v1 = 0, v2 = 0;
1253 v0 = ats->mechanisms[c2].quality[c-1].values[0];
1254 if (v1 < 1) v0 = 0.1;
1255 v1 = ats->mechanisms[c2].quality[c-1].values[1];
1256 if (v1 < 1) v0 = 0.1;
1257 v2 = ats->mechanisms[c2].quality[c-1].values[2];
1258 if (v1 < 1) v0 = 0.1;
1259 value = 100.0 / ((v0 + 2 * v1 + 3 * v2) / 6.0);
1262 if (qm[c-1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE)
1264 double v0 = 0, v1 = 0, v2 = 0;
1265 v0 = ats->mechanisms[c2].quality[c-1].values[0];
1267 v1 = ats->mechanisms[c2].quality[c-1].values[1];
1269 v2 = ats->mechanisms[c2].quality[c-1].values[2];
1271 value = (v0 + 2 * v1 + 3 * v2) / 6.0;
1273 value = (double) 10 / value;
1277 ar[array_index] = (ats->mechanisms[c2].peer->f) * value;
1279 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: %s [%i,%i]=%f \n",
1288 ja[array_index] = ats->internal.col_qm + c - 1;
1289 ar[array_index] = -1;
1292 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
1298 _lp_set_mat_row (ats->prob, row_index, array_index, ja, ar);
1302 GNUNET_free_non_null (ja);
1303 GNUNET_free_non_null (ar);
1309 ats_calculate_bandwidth_distribution (struct ATS_Handle * ats)
1311 struct GNUNET_TIME_Absolute start;
1312 struct GNUNET_TIME_Relative creation;
1313 struct GNUNET_TIME_Relative solving;
1316 char *text = "unmodified";
1320 if (INT_MAX < ats->max_exec_duration.rel_value)
1323 dur = (int) ats->max_exec_duration.rel_value;
1326 ats->internal.simplex_rerun_required = GNUNET_NO;
1327 start = GNUNET_TIME_absolute_get();
1328 if ((ats->internal.recreate_problem == GNUNET_YES) ||
1329 (ats->prob==NULL) ||
1330 (ats->internal.valid == GNUNET_NO))
1333 ats->internal.recreate_problem = GNUNET_YES;
1334 ats_delete_problem (ats);
1335 ats->addr_notification(&ats->peers , &c_p, &ats->mechanisms, &c_m);
1337 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1338 "Service returned: %i peer, %i mechs\n",
1342 ats_create_problem (ats, &ats->internal, ats->peers, c_p, ats->mechanisms, c_m);
1346 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1347 "Peers/Addresses were modified... new problem: %i peer, %i mechs\n",
1348 ats->internal.c_peers,
1349 ats->internal.c_mechs);
1353 else if ((ats->internal.recreate_problem == GNUNET_NO) &&
1354 (ats->internal.modified_resources == GNUNET_YES) &&
1355 (ats->internal.valid == GNUNET_YES))
1357 text = "modified resources";
1358 ats_update_problem_cr (ats);
1360 else if ((ats->internal.recreate_problem == GNUNET_NO) &&
1361 (ats->internal.modified_quality == GNUNET_YES) &&
1362 (ats->internal.valid == GNUNET_YES))
1364 text = "modified quality";
1365 ats_update_problem_qm (ats);
1366 //ats_update_problem_qm_TEST ();
1369 else GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Problem is %s\n", text);
1372 creation = GNUNET_TIME_absolute_get_difference(start,GNUNET_TIME_absolute_get());
1373 start = GNUNET_TIME_absolute_get();
1375 ats->internal.solution = GLP_UNDEF;
1376 if (ats->internal.valid == GNUNET_YES)
1378 ats_solve_problem(ats,
1379 ats->max_iterations,
1380 ats->max_exec_duration.rel_value,
1381 ats->internal.c_peers,
1382 ats->internal.c_mechs,
1385 solving = GNUNET_TIME_absolute_get_difference(start,GNUNET_TIME_absolute_get());
1387 if (ats->internal.valid == GNUNET_YES)
1389 /* Telling about new distribution*/
1392 int msg_type = GNUNET_ERROR_TYPE_DEBUG;
1394 msg_type = GNUNET_ERROR_TYPE_ERROR;
1396 GNUNET_log (msg_type,
1397 "MLP %s: creation time: %llu, execution time: %llu, %i peers, %i mechanisms, simplex rerun: %s, solution %s\n",
1401 ats->internal.c_peers,
1402 ats->internal.c_mechs,
1403 (ats->internal.simplex_rerun_required == GNUNET_NO) ? "NO" : "YES",
1404 (ats->internal.solution == 5) ? "OPTIMAL" : "INVALID");
1405 ats->successful_executions ++;
1406 GNUNET_STATISTICS_set (ats->stats, "# ATS successful executions",
1407 ats->successful_executions,
1410 if ((ats->internal.recreate_problem == GNUNET_YES) || (ats->prob==NULL))
1411 GNUNET_STATISTICS_set (ats->stats, "ATS state",ATS_NEW, GNUNET_NO);
1412 else if ((ats->internal.modified_resources == GNUNET_YES) &&
1413 (ats->internal.modified_quality == GNUNET_NO))
1414 GNUNET_STATISTICS_set (ats->stats, "ATS state", ATS_COST_UPDATED, GNUNET_NO);
1415 else if ((ats->internal.modified_resources == GNUNET_NO) &&
1416 (ats->internal.modified_quality == GNUNET_YES) &&
1417 (ats->internal.simplex_rerun_required == GNUNET_NO))
1418 GNUNET_STATISTICS_set (ats->stats, "ATS state", ATS_QUALITY_UPDATED, GNUNET_NO);
1419 else if ((ats->internal.modified_resources == GNUNET_YES) &&
1420 (ats->internal.modified_quality == GNUNET_YES) &&
1421 (ats->internal.simplex_rerun_required == GNUNET_NO))
1422 GNUNET_STATISTICS_set (ats->stats, "ATS state", ATS_QUALITY_COST_UPDATED, GNUNET_NO);
1423 else if (ats->internal.simplex_rerun_required == GNUNET_NO)
1424 GNUNET_STATISTICS_set (ats->stats, "ATS state", ATS_UNMODIFIED, GNUNET_NO);
1428 if (ats->internal.c_peers != 0)
1430 ats->invalid_executions ++;
1431 GNUNET_STATISTICS_set (ats->stats, "# ATS invalid executions",
1432 ats->invalid_executions, GNUNET_NO);
1436 GNUNET_STATISTICS_set (ats->stats, "# ATS successful executions",
1437 ats->successful_executions, GNUNET_NO);
1441 GNUNET_STATISTICS_set (ats->stats,
1442 "ATS duration", solving.rel_value + creation.rel_value, GNUNET_NO);
1443 GNUNET_STATISTICS_set (ats->stats,
1444 "ATS mechanisms", ats->internal.c_mechs, GNUNET_NO);
1445 GNUNET_STATISTICS_set (ats->stats,
1446 "ATS peers", ats->internal.c_peers, GNUNET_NO);
1447 GNUNET_STATISTICS_set (ats->stats,
1448 "ATS solution", ats->internal.solution, GNUNET_NO);
1449 GNUNET_STATISTICS_set (ats->stats,
1450 "ATS timestamp", start.abs_value, GNUNET_NO);
1452 if ((ats->save_mlp == GNUNET_YES) &&
1453 (ats->internal.c_mechs >= ats->dump_min_peers) &&
1454 (ats->internal.c_mechs >= ats->dump_min_addr))
1457 if (ats->dump_overwrite == GNUNET_NO)
1459 GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i_%s_%llu.mlp",
1460 ats->internal.c_peers,
1461 ats->internal.c_mechs,
1463 GNUNET_TIME_absolute_get().abs_value);
1464 _lp_write_lp ((void *) ats->prob, NULL, filename);
1468 GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i.mlp",
1469 ats->internal.c_peers, ats->internal.c_mechs );
1470 _lp_write_lp ((void *) ats->prob, NULL, filename);
1472 GNUNET_free (filename);
1474 if ((ats->save_solution == GNUNET_YES) &&
1475 (ats->internal.c_mechs >= ats->dump_min_peers) &&
1476 (ats->internal.c_mechs >= ats->dump_min_addr))
1479 if (ats->dump_overwrite == GNUNET_NO)
1481 GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i_%s_%llu.sol",
1482 ats->internal.c_peers,
1483 ats->internal.c_mechs,
1485 GNUNET_TIME_absolute_get().abs_value);
1486 _lp_print_sol (ats->prob, filename);
1490 GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i.sol",
1491 ats->internal.c_peers, ats->internal.c_mechs);
1492 _lp_print_sol (ats->prob, filename);
1494 GNUNET_free (filename);
1497 ats->internal.recreate_problem = GNUNET_NO;
1498 ats->internal.modified_resources = GNUNET_NO;
1499 ats->internal.modified_quality = GNUNET_NO;
1503 * Evaluate the result of the last simplex or mlp solving
1504 * @param result return value returned by the solver
1505 * @param solution solution state
1506 * @param problem mlp or lp
1507 * @return GNUNET_NO if solution is invalid, GNUNET_YES if solution is
1511 int ats_evaluate_results (int result, int solution, char * problem)
1513 int cont = GNUNET_NO;
1514 #if DEBUG_ATS || VERBOSE_ATS
1515 int error_kind = GNUNET_ERROR_TYPE_DEBUG;
1518 error_kind = GNUNET_ERROR_TYPE_ERROR;
1521 case GNUNET_SYSERR : /* GNUNET problem, not GLPK related */
1522 #if DEBUG_ATS || VERBOSE_ATS
1523 GNUNET_log (error_kind,
1524 "%s, GLPK solving not executed\n", problem);
1527 case GLP_ESTOP : /* search terminated by application */
1528 #if DEBUG_ATS || VERBOSE_ATS
1529 GNUNET_log (error_kind,
1530 "%s , Search terminated by application\n", problem);
1533 case GLP_EITLIM : /* iteration limit exceeded */
1534 #if DEBUG_ATS || VERBOSE_ATS
1535 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1536 "%s Iteration limit exceeded\n", problem);
1539 case GLP_ETMLIM : /* time limit exceeded */
1540 #if DEBUG_ATS || VERBOSE_ATS
1541 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1542 "%s Time limit exceeded\n", problem);
1545 case GLP_ENOPFS : /* no primal feasible solution */
1546 case GLP_ENODFS : /* no dual feasible solution */
1547 #if DEBUG_ATS || VERBOSE_ATS
1548 GNUNET_log (error_kind,
1549 "%s No feasible solution\n", problem);
1552 case GLP_EBADB : /* invalid basis */
1553 case GLP_ESING : /* singular matrix */
1554 case GLP_ECOND : /* ill-conditioned matrix */
1555 case GLP_EBOUND : /* invalid bounds */
1556 case GLP_EFAIL : /* solver failed */
1557 case GLP_EOBJLL : /* objective lower limit reached */
1558 case GLP_EOBJUL : /* objective upper limit reached */
1559 case GLP_EROOT : /* root LP optimum not provided */
1560 #if DEBUG_ATS || VERBOSE_ATS
1561 GNUNET_log (error_kind,
1562 "%s Invalid Input data: %i\n",
1567 #if DEBUG_ATS || VERBOSE_ATS
1568 GNUNET_log (error_kind,
1569 "%s Problem has been solved\n", problem);
1576 #if DEBUG_ATS || VERBOSE_ATS
1577 GNUNET_log (error_kind,
1578 "%s solution is undefined\n", problem);
1582 #if DEBUG_ATS || VERBOSE_ATS
1583 GNUNET_log (error_kind,
1584 "%s solution is optimal\n", problem);
1589 #if DEBUG_ATS || VERBOSE_ATS
1590 GNUNET_log (error_kind,
1591 "%s solution is %s feasible, however, its optimality (or non-optimality) has not been proven\n",
1592 problem, (0==strcmp(problem,"LP")?"":"integer"));
1597 #if DEBUG_ATS || VERBOSE_ATS
1598 GNUNET_log (error_kind, "%s problem has no %sfeasible solution\n",
1599 problem, (0==strcmp(problem,"LP")?"":"integer "));
1603 #if DEBUG_ATS || VERBOSE_ATS
1604 GNUNET_log (error_kind, "%s problem is infeasible \n", problem);
1608 #if DEBUG_ATS || VERBOSE_ATS
1609 GNUNET_log (error_kind, "%s problem is unbounded \n", problem);
1617 void ats_update_problem_cr (struct ATS_Handle * ats)
1622 double ct_max, ct_min;
1624 int *ja = GNUNET_malloc ((1 + ats->internal.c_mechs*2 + 3 +
1625 available_quality_metrics) * sizeof (int));
1626 double *ar = GNUNET_malloc ((1 + ats->internal.c_mechs*2 + 3 +
1627 available_quality_metrics) * sizeof (double));
1629 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updating problem quality metrics\n");
1630 row_index = ats->internal.begin_cr;
1633 for (c=0; c<available_ressources; c++)
1635 ct_max = ressources[c].c_max;
1636 ct_min = ressources[c].c_min;
1638 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] %f..%f\n",
1643 _lp_set_row_bnds(ats->prob, row_index, GLP_DB, ct_min, ct_max);
1644 for (c2=1; c2<=ats->internal.c_mechs; c2++)
1647 GNUNET_assert (ats->mechanisms[c2].addr != NULL);
1648 GNUNET_assert (ats->mechanisms[c2].peer != NULL);
1650 ja[array_index] = c2;
1651 value = ats->mechanisms[c2].ressources[c].c;
1652 ar[array_index] = value;
1654 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
1662 _lp_set_mat_row (ats->prob, row_index, array_index, ja, ar);
1665 GNUNET_free_non_null (ja);
1666 GNUNET_free_non_null (ar);
1670 void ats_set_logging_options (struct ATS_Handle * ats,
1671 struct GNUNET_STATISTICS_Handle * stats,
1672 const struct GNUNET_CONFIGURATION_Handle *cfg)
1674 int minimum_addresses;
1679 unsigned long long value;
1683 log_problem = GNUNET_CONFIGURATION_get_value_yesno (cfg,
1686 log_solution = GNUNET_CONFIGURATION_get_value_yesno (cfg,
1689 overwrite_dump = GNUNET_CONFIGURATION_get_value_yesno (cfg,
1693 GNUNET_CONFIGURATION_get_value_number(cfg,
1697 minimum_peers = (int) value;
1699 GNUNET_CONFIGURATION_get_value_number(cfg,
1703 minimum_addresses = (int) value;
1707 ats->dump_min_addr = minimum_addresses;
1708 ats->dump_min_peers = minimum_peers;
1709 ats->dump_overwrite = overwrite_dump;
1710 ats->save_mlp = log_problem;
1711 ats->save_solution = log_solution;
1715 static void ats_update_problem_qm_TEST ()
1723 int old_ja[ats->internal.c_mechs + 2];
1724 double old_ar[ats->internal.c_mechs + 2];
1726 int *ja = GNUNET_malloc ((1 + ats->internal.c_mechs*2 + 3 +
1727 available_quality_metrics) * sizeof (int));
1728 double *ar = GNUNET_malloc ((1 + ats->internal.c_mechs*2 + 3 +
1729 available_quality_metrics) * sizeof (double));
1731 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1732 "Updating problem quality metrics TEST\n");
1734 if (ats->internal.begin_qm >0)
1735 row_index = ats->internal.begin_qm;
1738 for (c=0; c<available_quality_metrics; c++)
1740 c_old = _lp_get_mat_row (ats->prob, row_index, old_ja, old_ar);
1741 _lp_set_row_bnds(ats->prob, row_index, GLP_FX, 0.0, 0.0);
1742 for (c2=1; c2<=c_old; c2++)
1744 ja[c2] = old_ja[c2];
1745 if ((changed < 3) && (c2>2) && (old_ar[c2] != -1))
1747 ar[c2] = old_ar[c2] + 5 - changed;
1751 ar[c2] = old_ar[c2];
1753 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1754 "[index]=[%i]: old [%i,%i]=%f new [%i,%i]=%f\n",
1764 _lp_set_mat_row (ats->prob, row_index, c_old, ja, ar);
1767 GNUNET_free_non_null (ja);
1768 GNUNET_free_non_null (ar);
1774 /* end of transport_ats.c */