aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_ats.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:46:35 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:46:35 +0000
commit502af2167f7c218366666ca4944bd7cc54b5b19a (patch)
treea91fec5cc9769d260640bd91c6633cb9cf395524 /src/transport/gnunet-service-transport_ats.c
parent03af5a603b7cc53432249d5854cd412aa90dde0d (diff)
downloadgnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz
gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip
indentation
Diffstat (limited to 'src/transport/gnunet-service-transport_ats.c')
-rw-r--r--src/transport/gnunet-service-transport_ats.c1826
1 files changed, 911 insertions, 915 deletions
diff --git a/src/transport/gnunet-service-transport_ats.c b/src/transport/gnunet-service-transport_ats.c
index df425bfb0..34d1791b9 100644
--- a/src/transport/gnunet-service-transport_ats.c
+++ b/src/transport/gnunet-service-transport_ats.c
@@ -41,133 +41,136 @@
41 41
42#ifndef GLP_PROB_DEFINED 42#ifndef GLP_PROB_DEFINED
43#define GLP_PROB_DEFINED 43#define GLP_PROB_DEFINED
44 typedef struct { double _opaque_prob[100]; } glp_prob; 44typedef struct
45{
46 double _opaque_prob[100];
47} glp_prob;
45#endif 48#endif
46 49
47typedef struct 50typedef struct
48{ /* integer optimizer control parameters */ 51{ /* integer optimizer control parameters */
49 int msg_lev; /* message level (see glp_smcp) */ 52 int msg_lev; /* message level (see glp_smcp) */
50 int br_tech; /* branching technique: */ 53 int br_tech; /* branching technique: */
51#define GLP_BR_FFV 1 /* first fractional variable */ 54#define GLP_BR_FFV 1 /* first fractional variable */
52#define GLP_BR_LFV 2 /* last fractional variable */ 55#define GLP_BR_LFV 2 /* last fractional variable */
53#define GLP_BR_MFV 3 /* most fractional variable */ 56#define GLP_BR_MFV 3 /* most fractional variable */
54#define GLP_BR_DTH 4 /* heuristic by Driebeck and Tomlin */ 57#define GLP_BR_DTH 4 /* heuristic by Driebeck and Tomlin */
55#define GLP_BR_PCH 5 /* hybrid pseudocost heuristic */ 58#define GLP_BR_PCH 5 /* hybrid pseudocost heuristic */
56 int bt_tech; /* backtracking technique: */ 59 int bt_tech; /* backtracking technique: */
57#define GLP_BT_DFS 1 /* depth first search */ 60#define GLP_BT_DFS 1 /* depth first search */
58#define GLP_BT_BFS 2 /* breadth first search */ 61#define GLP_BT_BFS 2 /* breadth first search */
59#define GLP_BT_BLB 3 /* best local bound */ 62#define GLP_BT_BLB 3 /* best local bound */
60#define GLP_BT_BPH 4 /* best projection heuristic */ 63#define GLP_BT_BPH 4 /* best projection heuristic */
61 double tol_int; /* mip.tol_int */ 64 double tol_int; /* mip.tol_int */
62 double tol_obj; /* mip.tol_obj */ 65 double tol_obj; /* mip.tol_obj */
63 int tm_lim; /* mip.tm_lim (milliseconds) */ 66 int tm_lim; /* mip.tm_lim (milliseconds) */
64 int out_frq; /* mip.out_frq (milliseconds) */ 67 int out_frq; /* mip.out_frq (milliseconds) */
65 int out_dly; /* mip.out_dly (milliseconds) */ 68 int out_dly; /* mip.out_dly (milliseconds) */
66 /* mip.cb_func */ 69 /* mip.cb_func */
67 void *cb_info; /* mip.cb_info */ 70 void *cb_info; /* mip.cb_info */
68 int cb_size; /* mip.cb_size */ 71 int cb_size; /* mip.cb_size */
69 int pp_tech; /* preprocessing technique: */ 72 int pp_tech; /* preprocessing technique: */
70#define GLP_PP_NONE 0 /* disable preprocessing */ 73#define GLP_PP_NONE 0 /* disable preprocessing */
71#define GLP_PP_ROOT 1 /* preprocessing only on root level */ 74#define GLP_PP_ROOT 1 /* preprocessing only on root level */
72#define GLP_PP_ALL 2 /* preprocessing on all levels */ 75#define GLP_PP_ALL 2 /* preprocessing on all levels */
73 double mip_gap; /* relative MIP gap tolerance */ 76 double mip_gap; /* relative MIP gap tolerance */
74 int mir_cuts; /* MIR cuts (GLP_ON/GLP_OFF) */ 77 int mir_cuts; /* MIR cuts (GLP_ON/GLP_OFF) */
75 int gmi_cuts; /* Gomory's cuts (GLP_ON/GLP_OFF) */ 78 int gmi_cuts; /* Gomory's cuts (GLP_ON/GLP_OFF) */
76 int cov_cuts; /* cover cuts (GLP_ON/GLP_OFF) */ 79 int cov_cuts; /* cover cuts (GLP_ON/GLP_OFF) */
77 int clq_cuts; /* clique cuts (GLP_ON/GLP_OFF) */ 80 int clq_cuts; /* clique cuts (GLP_ON/GLP_OFF) */
78 int presolve; /* enable/disable using MIP presolver */ 81 int presolve; /* enable/disable using MIP presolver */
79 int binarize; /* try to binarize integer variables */ 82 int binarize; /* try to binarize integer variables */
80 int fp_heur; /* feasibility pump heuristic */ 83 int fp_heur; /* feasibility pump heuristic */
81#if 1 /* 28/V-2010 */ 84#if 1 /* 28/V-2010 */
82 int alien; /* use alien solver */ 85 int alien; /* use alien solver */
83#endif 86#endif
84 double foo_bar[29]; /* (reserved) */ 87 double foo_bar[29]; /* (reserved) */
85} glp_iocp; 88} glp_iocp;
86 89
87typedef struct 90typedef struct
88{ /* simplex method control parameters */ 91{ /* simplex method control parameters */
89 int msg_lev; /* message level: */ 92 int msg_lev; /* message level: */
90#define GLP_MSG_OFF 0 /* no output */ 93#define GLP_MSG_OFF 0 /* no output */
91#define GLP_MSG_ERR 1 /* warning and error messages only */ 94#define GLP_MSG_ERR 1 /* warning and error messages only */
92#define GLP_MSG_ON 2 /* normal output */ 95#define GLP_MSG_ON 2 /* normal output */
93#define GLP_MSG_ALL 3 /* full output */ 96#define GLP_MSG_ALL 3 /* full output */
94#define GLP_MSG_DBG 4 /* debug output */ 97#define GLP_MSG_DBG 4 /* debug output */
95 int meth; /* simplex method option: */ 98 int meth; /* simplex method option: */
96#define GLP_PRIMAL 1 /* use primal simplex */ 99#define GLP_PRIMAL 1 /* use primal simplex */
97#define GLP_DUALP 2 /* use dual; if it fails, use primal */ 100#define GLP_DUALP 2 /* use dual; if it fails, use primal */
98#define GLP_DUAL 3 /* use dual simplex */ 101#define GLP_DUAL 3 /* use dual simplex */
99 int pricing; /* pricing technique: */ 102 int pricing; /* pricing technique: */
100#define GLP_PT_STD 0x11 /* standard (Dantzig rule) */ 103#define GLP_PT_STD 0x11 /* standard (Dantzig rule) */
101#define GLP_PT_PSE 0x22 /* projected steepest edge */ 104#define GLP_PT_PSE 0x22 /* projected steepest edge */
102 int r_test; /* ratio test technique: */ 105 int r_test; /* ratio test technique: */
103#define GLP_RT_STD 0x11 /* standard (textbook) */ 106#define GLP_RT_STD 0x11 /* standard (textbook) */
104#define GLP_RT_HAR 0x22 /* two-pass Harris' ratio test */ 107#define GLP_RT_HAR 0x22 /* two-pass Harris' ratio test */
105 double tol_bnd; /* spx.tol_bnd */ 108 double tol_bnd; /* spx.tol_bnd */
106 double tol_dj; /* spx.tol_dj */ 109 double tol_dj; /* spx.tol_dj */
107 double tol_piv; /* spx.tol_piv */ 110 double tol_piv; /* spx.tol_piv */
108 double obj_ll; /* spx.obj_ll */ 111 double obj_ll; /* spx.obj_ll */
109 double obj_ul; /* spx.obj_ul */ 112 double obj_ul; /* spx.obj_ul */
110 int it_lim; /* spx.it_lim */ 113 int it_lim; /* spx.it_lim */
111 int tm_lim; /* spx.tm_lim (milliseconds) */ 114 int tm_lim; /* spx.tm_lim (milliseconds) */
112 int out_frq; /* spx.out_frq */ 115 int out_frq; /* spx.out_frq */
113 int out_dly; /* spx.out_dly (milliseconds) */ 116 int out_dly; /* spx.out_dly (milliseconds) */
114 int presolve; /* enable/disable using LP presolver */ 117 int presolve; /* enable/disable using LP presolver */
115 double foo_bar[36]; /* (reserved) */ 118 double foo_bar[36]; /* (reserved) */
116} glp_smcp; 119} glp_smcp;
117 120
118/* optimization direction flag: */ 121/* optimization direction flag: */
119#define GLP_MIN 1 /* minimization */ 122#define GLP_MIN 1 /* minimization */
120#define GLP_MAX 2 /* maximization */ 123#define GLP_MAX 2 /* maximization */
121 124
122/* kind of structural variable: */ 125/* kind of structural variable: */
123#define GLP_CV 1 /* continuous variable */ 126#define GLP_CV 1 /* continuous variable */
124#define GLP_IV 2 /* integer variable */ 127#define GLP_IV 2 /* integer variable */
125#define GLP_BV 3 /* binary variable */ 128#define GLP_BV 3 /* binary variable */
126 129
127/* type of auxiliary/structural variable: */ 130/* type of auxiliary/structural variable: */
128#define GLP_FR 1 /* free variable */ 131#define GLP_FR 1 /* free variable */
129#define GLP_LO 2 /* variable with lower bound */ 132#define GLP_LO 2 /* variable with lower bound */
130#define GLP_UP 3 /* variable with upper bound */ 133#define GLP_UP 3 /* variable with upper bound */
131#define GLP_DB 4 /* double-bounded variable */ 134#define GLP_DB 4 /* double-bounded variable */
132#define GLP_FX 5 /* fixed variable */ 135#define GLP_FX 5 /* fixed variable */
133 136
134/* solution indicator: */ 137/* solution indicator: */
135#define GLP_SOL 1 /* basic solution */ 138#define GLP_SOL 1 /* basic solution */
136#define GLP_IPT 2 /* interior-point solution */ 139#define GLP_IPT 2 /* interior-point solution */
137#define GLP_MIP 3 /* mixed integer solution */ 140#define GLP_MIP 3 /* mixed integer solution */
138 141
139/* solution status: */ 142/* solution status: */
140#define GLP_UNDEF 1 /* solution is undefined */ 143#define GLP_UNDEF 1 /* solution is undefined */
141#define GLP_FEAS 2 /* solution is feasible */ 144#define GLP_FEAS 2 /* solution is feasible */
142#define GLP_INFEAS 3 /* solution is infeasible */ 145#define GLP_INFEAS 3 /* solution is infeasible */
143#define GLP_NOFEAS 4 /* no feasible solution exists */ 146#define GLP_NOFEAS 4 /* no feasible solution exists */
144#define GLP_OPT 5 /* solution is optimal */ 147#define GLP_OPT 5 /* solution is optimal */
145#define GLP_UNBND 6 /* solution is unbounded */ 148#define GLP_UNBND 6 /* solution is unbounded */
146 149
147/* return codes: */ 150/* return codes: */
148#define GLP_EBADB 0x01 /* invalid basis */ 151#define GLP_EBADB 0x01 /* invalid basis */
149#define GLP_ESING 0x02 /* singular matrix */ 152#define GLP_ESING 0x02 /* singular matrix */
150#define GLP_ECOND 0x03 /* ill-conditioned matrix */ 153#define GLP_ECOND 0x03 /* ill-conditioned matrix */
151#define GLP_EBOUND 0x04 /* invalid bounds */ 154#define GLP_EBOUND 0x04 /* invalid bounds */
152#define GLP_EFAIL 0x05 /* solver failed */ 155#define GLP_EFAIL 0x05 /* solver failed */
153#define GLP_EOBJLL 0x06 /* objective lower limit reached */ 156#define GLP_EOBJLL 0x06 /* objective lower limit reached */
154#define GLP_EOBJUL 0x07 /* objective upper limit reached */ 157#define GLP_EOBJUL 0x07 /* objective upper limit reached */
155#define GLP_EITLIM 0x08 /* iteration limit exceeded */ 158#define GLP_EITLIM 0x08 /* iteration limit exceeded */
156#define GLP_ETMLIM 0x09 /* time limit exceeded */ 159#define GLP_ETMLIM 0x09 /* time limit exceeded */
157#define GLP_ENOPFS 0x0A /* no primal feasible solution */ 160#define GLP_ENOPFS 0x0A /* no primal feasible solution */
158#define GLP_ENODFS 0x0B /* no dual feasible solution */ 161#define GLP_ENODFS 0x0B /* no dual feasible solution */
159#define GLP_EROOT 0x0C /* root LP optimum not provided */ 162#define GLP_EROOT 0x0C /* root LP optimum not provided */
160#define GLP_ESTOP 0x0D /* search terminated by application */ 163#define GLP_ESTOP 0x0D /* search terminated by application */
161#define GLP_EMIPGAP 0x0E /* relative mip gap tolerance reached */ 164#define GLP_EMIPGAP 0x0E /* relative mip gap tolerance reached */
162#define GLP_ENOFEAS 0x0F /* no primal/dual feasible solution */ 165#define GLP_ENOFEAS 0x0F /* no primal/dual feasible solution */
163#define GLP_ENOCVG 0x10 /* no convergence */ 166#define GLP_ENOCVG 0x10 /* no convergence */
164#define GLP_EINSTAB 0x11 /* numerical instability */ 167#define GLP_EINSTAB 0x11 /* numerical instability */
165#define GLP_EDATA 0x12 /* invalid data */ 168#define GLP_EDATA 0x12 /* invalid data */
166#define GLP_ERANGE 0x13 /* result out of range */ 169#define GLP_ERANGE 0x13 /* result out of range */
167 170
168/* enable/disable flag: */ 171/* enable/disable flag: */
169#define GLP_ON 1 /* enable something */ 172#define GLP_ON 1 /* enable something */
170#define GLP_OFF 0 /* disable something */ 173#define GLP_OFF 0 /* disable something */
171 174
172#endif 175#endif
173 176
@@ -176,10 +179,11 @@ typedef struct
176 */ 179 */
177 180
178 181
179void * _lp_create_prob ( void ) 182void *
183_lp_create_prob (void)
180{ 184{
181#if HAVE_LIBGLPK 185#if HAVE_LIBGLPK
182 return glp_create_prob( ); 186 return glp_create_prob ();
183#else 187#else
184 // Function not implemented 188 // Function not implemented
185 GNUNET_break (0); 189 GNUNET_break (0);
@@ -187,7 +191,8 @@ void * _lp_create_prob ( void )
187 return NULL; 191 return NULL;
188} 192}
189 193
190void _lp_set_obj_dir (glp_prob *P, int dir) 194void
195_lp_set_obj_dir (glp_prob *P, int dir)
191{ 196{
192#if HAVE_LIBGLPK 197#if HAVE_LIBGLPK
193 return glp_set_obj_dir (P, dir); 198 return glp_set_obj_dir (P, dir);
@@ -197,20 +202,22 @@ void _lp_set_obj_dir (glp_prob *P, int dir)
197#endif 202#endif
198} 203}
199 204
200void _lp_set_prob_name (glp_prob *P, const char *name) 205void
206_lp_set_prob_name (glp_prob *P, const char *name)
201{ 207{
202#if HAVE_LIBGLPK 208#if HAVE_LIBGLPK
203 glp_set_prob_name(P, name); 209 glp_set_prob_name (P, name);
204#else 210#else
205 // Function not implemented 211 // Function not implemented
206 GNUNET_break (0); 212 GNUNET_break (0);
207#endif 213#endif
208} 214}
209 215
210int _lp_add_cols (glp_prob *P, int ncs) 216int
217_lp_add_cols (glp_prob *P, int ncs)
211{ 218{
212#if HAVE_LIBGLPK 219#if HAVE_LIBGLPK
213 return glp_add_cols(P, ncs); 220 return glp_add_cols (P, ncs);
214#else 221#else
215 // Function not implemented 222 // Function not implemented
216 GNUNET_break (0); 223 GNUNET_break (0);
@@ -218,7 +225,8 @@ int _lp_add_cols (glp_prob *P, int ncs)
218 return 0; 225 return 0;
219} 226}
220 227
221int _lp_add_rows (glp_prob *P, int nrs) 228int
229_lp_add_rows (glp_prob *P, int nrs)
222{ 230{
223#if HAVE_LIBGLPK 231#if HAVE_LIBGLPK
224 return glp_add_rows (P, nrs); 232 return glp_add_rows (P, nrs);
@@ -230,27 +238,30 @@ int _lp_add_rows (glp_prob *P, int nrs)
230} 238}
231 239
232 240
233void _lp_set_row_bnds (glp_prob *P, int i, int type, double lb, double ub) 241void
242_lp_set_row_bnds (glp_prob *P, int i, int type, double lb, double ub)
234{ 243{
235#if HAVE_LIBGLPK 244#if HAVE_LIBGLPK
236 glp_set_row_bnds(P, i , type, lb, ub); 245 glp_set_row_bnds (P, i, type, lb, ub);
237#else 246#else
238 // Function not implemented 247 // Function not implemented
239 GNUNET_break (0); 248 GNUNET_break (0);
240#endif 249#endif
241} 250}
242 251
243void _lp_init_smcp (void * parm) 252void
253_lp_init_smcp (void *parm)
244{ 254{
245#if HAVE_LIBGLPK 255#if HAVE_LIBGLPK
246 glp_init_smcp(parm); 256 glp_init_smcp (parm);
247#else 257#else
248 // Function not implemented 258 // Function not implemented
249 GNUNET_break (0); 259 GNUNET_break (0);
250#endif 260#endif
251} 261}
252 262
253void _lp_set_col_name (glp_prob *P, int j, const char *name) 263void
264_lp_set_col_name (glp_prob *P, int j, const char *name)
254{ 265{
255#if HAVE_LIBGLPK 266#if HAVE_LIBGLPK
256 glp_set_col_name (P, j, name); 267 glp_set_col_name (P, j, name);
@@ -260,28 +271,30 @@ void _lp_set_col_name (glp_prob *P, int j, const char *name)
260#endif 271#endif
261} 272}
262 273
263void _lp_set_col_bnds (glp_prob *P, int j, int type, double lb, 274void
264 double ub) 275_lp_set_col_bnds (glp_prob *P, int j, int type, double lb, double ub)
265{ 276{
266#if HAVE_LIBGLPK 277#if HAVE_LIBGLPK
267 glp_set_col_bnds(P, j, type, lb, ub); 278 glp_set_col_bnds (P, j, type, lb, ub);
268#else 279#else
269 // Function not implemented 280 // Function not implemented
270 GNUNET_break (0); 281 GNUNET_break (0);
271#endif 282#endif
272} 283}
273 284
274void _lp_set_obj_coef(glp_prob *P, int j, double coef) 285void
286_lp_set_obj_coef (glp_prob *P, int j, double coef)
275{ 287{
276#if HAVE_LIBGLPK 288#if HAVE_LIBGLPK
277 glp_set_obj_coef(P, j, coef); 289 glp_set_obj_coef (P, j, coef);
278#else 290#else
279 // Function not implemented 291 // Function not implemented
280 GNUNET_break (0); 292 GNUNET_break (0);
281#endif 293#endif
282} 294}
283 295
284void _lp_delete_prob (void * P) 296void
297_lp_delete_prob (void *P)
285{ 298{
286#if HAVE_LIBGLPK 299#if HAVE_LIBGLPK
287 glp_delete_prob (P); 300 glp_delete_prob (P);
@@ -291,7 +304,8 @@ void _lp_delete_prob (void * P)
291#endif 304#endif
292} 305}
293 306
294static int _lp_simplex(glp_prob *P, void *parm) 307static int
308_lp_simplex (glp_prob *P, void *parm)
295{ 309{
296#if HAVE_LIBGLPK 310#if HAVE_LIBGLPK
297 return glp_simplex (P, parm); 311 return glp_simplex (P, parm);
@@ -302,19 +316,21 @@ static int _lp_simplex(glp_prob *P, void *parm)
302 return 0; 316 return 0;
303} 317}
304 318
305static void _lp_load_matrix (glp_prob *P, int ne, const int ia[], 319static void
306 const int ja[], const double ar[]) 320_lp_load_matrix (glp_prob *P, int ne, const int ia[],
321 const int ja[], const double ar[])
307{ 322{
308#if HAVE_LIBGLPK 323#if HAVE_LIBGLPK
309 glp_load_matrix(P, ne, ia, ja, ar); 324 glp_load_matrix (P, ne, ia, ja, ar);
310#else 325#else
311 // Function not implemented 326 // Function not implemented
312 GNUNET_break (0); 327 GNUNET_break (0);
313#endif 328#endif
314} 329}
315 330
316static void _lp_set_mat_row (glp_prob *P, int i, int len, const int ind[], 331static void
317 const double val[]) 332_lp_set_mat_row (glp_prob *P, int i, int len, const int ind[],
333 const double val[])
318{ 334{
319#if HAVE_LIBGLPK 335#if HAVE_LIBGLPK
320 glp_set_mat_row (P, i, len, ind, val); 336 glp_set_mat_row (P, i, len, ind, val);
@@ -324,10 +340,11 @@ static void _lp_set_mat_row (glp_prob *P, int i, int len, const int ind[],
324#endif 340#endif
325} 341}
326 342
327static int _lp_write_lp (glp_prob *P, const void *parm, const char *fname) 343static int
344_lp_write_lp (glp_prob *P, const void *parm, const char *fname)
328{ 345{
329#if HAVE_LIBGLPK 346#if HAVE_LIBGLPK
330 return glp_write_lp ( P, parm, fname); 347 return glp_write_lp (P, parm, fname);
331#else 348#else
332 // Function not implemented 349 // Function not implemented
333 GNUNET_break (0); 350 GNUNET_break (0);
@@ -335,7 +352,8 @@ static int _lp_write_lp (glp_prob *P, const void *parm, const char *fname)
335 return 0; 352 return 0;
336} 353}
337 354
338static void _lp_init_iocp (void *parm) 355static void
356_lp_init_iocp (void *parm)
339{ 357{
340#if HAVE_LIBGLPK 358#if HAVE_LIBGLPK
341 glp_init_iocp (parm); 359 glp_init_iocp (parm);
@@ -345,7 +363,8 @@ static void _lp_init_iocp (void *parm)
345#endif 363#endif
346} 364}
347 365
348static int _lp_intopt (glp_prob *P, const void *parm) 366static int
367_lp_intopt (glp_prob *P, const void *parm)
349{ 368{
350#if HAVE_LIBGLPK 369#if HAVE_LIBGLPK
351 return glp_intopt (P, parm); 370 return glp_intopt (P, parm);
@@ -356,7 +375,8 @@ static int _lp_intopt (glp_prob *P, const void *parm)
356 return 0; 375 return 0;
357} 376}
358 377
359static int _lp_get_status (glp_prob *P) 378static int
379_lp_get_status (glp_prob *P)
360{ 380{
361#if HAVE_LIBGLPK 381#if HAVE_LIBGLPK
362 return glp_get_status (P); 382 return glp_get_status (P);
@@ -367,7 +387,8 @@ static int _lp_get_status (glp_prob *P)
367 return 0; 387 return 0;
368} 388}
369 389
370static int _lp_mip_status (glp_prob *P) 390static int
391_lp_mip_status (glp_prob *P)
371{ 392{
372#if HAVE_LIBGLPK 393#if HAVE_LIBGLPK
373 return glp_mip_status (P); 394 return glp_mip_status (P);
@@ -378,7 +399,8 @@ static int _lp_mip_status (glp_prob *P)
378 return 0; 399 return 0;
379} 400}
380 401
381static void _lp_set_col_kind (glp_prob *P, int j, int kind) 402static void
403_lp_set_col_kind (glp_prob *P, int j, int kind)
382{ 404{
383#if HAVE_LIBGLPK 405#if HAVE_LIBGLPK
384 glp_set_col_kind (P, j, kind); 406 glp_set_col_kind (P, j, kind);
@@ -388,7 +410,8 @@ static void _lp_set_col_kind (glp_prob *P, int j, int kind)
388#endif 410#endif
389} 411}
390 412
391static void _lp_free_env (void) 413static void
414_lp_free_env (void)
392{ 415{
393#if HAVE_LIBGLPK 416#if HAVE_LIBGLPK
394 glp_free_env (); 417 glp_free_env ();
@@ -398,7 +421,8 @@ static void _lp_free_env (void)
398#endif 421#endif
399} 422}
400 423
401static const char * _lp_get_col_name ( glp_prob *P, int j) 424static const char *
425_lp_get_col_name (glp_prob *P, int j)
402{ 426{
403#if HAVE_LIBGLPK 427#if HAVE_LIBGLPK
404 return glp_get_col_name (P, j); 428 return glp_get_col_name (P, j);
@@ -409,7 +433,8 @@ static const char * _lp_get_col_name ( glp_prob *P, int j)
409 return NULL; 433 return NULL;
410} 434}
411 435
412static double _lp_mip_obj_val (glp_prob *P) 436static double
437_lp_mip_obj_val (glp_prob *P)
413{ 438{
414#if HAVE_LIBGLPK 439#if HAVE_LIBGLPK
415 return glp_mip_obj_val (P); 440 return glp_mip_obj_val (P);
@@ -421,10 +446,11 @@ static double _lp_mip_obj_val (glp_prob *P)
421} 446}
422 447
423 448
424static double _lp_get_col_prim (glp_prob *P, int j) 449static double
450_lp_get_col_prim (glp_prob *P, int j)
425{ 451{
426#if HAVE_LIBGLPK 452#if HAVE_LIBGLPK
427 return glp_get_col_prim (P , j); 453 return glp_get_col_prim (P, j);
428#else 454#else
429 // Function not implemented 455 // Function not implemented
430 GNUNET_break (0); 456 GNUNET_break (0);
@@ -432,7 +458,8 @@ static double _lp_get_col_prim (glp_prob *P, int j)
432 return 0.0; 458 return 0.0;
433} 459}
434 460
435static int _lp_print_sol(glp_prob *P, const char *fname) 461static int
462_lp_print_sol (glp_prob *P, const char *fname)
436{ 463{
437#if HAVE_LIBGLPK 464#if HAVE_LIBGLPK
438#else 465#else
@@ -447,24 +474,27 @@ static int _lp_print_sol(glp_prob *P, const char *fname)
447 */ 474 */
448 475
449static void _dummy2 (); 476static void _dummy2 ();
450static void _dummy () 477static void
478_dummy ()
451{ 479{
452 return; 480 return;
453 _lp_get_col_name (NULL, 0); 481 _lp_get_col_name (NULL, 0);
454 _lp_mip_obj_val (NULL); 482 _lp_mip_obj_val (NULL);
455 _lp_get_col_prim (NULL, 0); 483 _lp_get_col_prim (NULL, 0);
456 _lp_set_mat_row(NULL,0,0,NULL,NULL); 484 _lp_set_mat_row (NULL, 0, 0, NULL, NULL);
457 _dummy2(); 485 _dummy2 ();
458} 486}
459 487
460 488
461 489
462static void _dummy2 () 490static void
491_dummy2 ()
463{ 492{
464 ats_modify_problem_state (NULL, 0); 493 ats_modify_problem_state (NULL, 0);
465 qm[1].atis_index = 0; 494 qm[1].atis_index = 0;
466 _dummy(); 495 _dummy ();
467 int t = ATS_COST_UPDATED + ATS_MODIFIED + ATS_NEW; 496 int t = ATS_COST_UPDATED + ATS_MODIFIED + ATS_NEW;
497
468 t++; 498 t++;
469} 499}
470 500
@@ -479,19 +509,20 @@ static void _dummy2 ()
479 * @return 509 * @return
480 */ 510 */
481 511
482struct ATS_Handle * ats_init (double D, 512struct ATS_Handle *
483 double U, 513ats_init (double D,
484 double R, 514 double U,
485 int v_b_min, 515 double R,
486 int v_n_min, 516 int v_b_min,
487 int max_iterations, 517 int v_n_min,
488 struct GNUNET_TIME_Relative max_duration, 518 int max_iterations,
489 GNUNET_TRANSPORT_ATS_AddressNotification address_not, 519 struct GNUNET_TIME_Relative max_duration,
490 GNUNET_TRANSPORT_ATS_ResultCallback res_cb) 520 GNUNET_TRANSPORT_ATS_AddressNotification address_not,
521 GNUNET_TRANSPORT_ATS_ResultCallback res_cb)
491{ 522{
492 struct ATS_Handle * ats = NULL; 523 struct ATS_Handle *ats = NULL;
493 524
494 ats = GNUNET_malloc(sizeof (struct ATS_Handle)); 525 ats = GNUNET_malloc (sizeof (struct ATS_Handle));
495 526
496 ats->prob = NULL; 527 ats->prob = NULL;
497 528
@@ -507,7 +538,7 @@ struct ATS_Handle * ats_init (double D,
507 ats->v_b_min = v_b_min; 538 ats->v_b_min = v_b_min;
508 ats->v_n_min = v_n_min; 539 ats->v_n_min = v_n_min;
509 ats->dump_min_peers = 0; 540 ats->dump_min_peers = 0;
510 ats->dump_min_addr = 0; 541 ats->dump_min_addr = 0;
511 ats->dump_overwrite = GNUNET_NO; 542 ats->dump_overwrite = GNUNET_NO;
512 ats->mechanisms = NULL; 543 ats->mechanisms = NULL;
513 ats->peers = NULL; 544 ats->peers = NULL;
@@ -529,181 +560,165 @@ struct ATS_Handle * ats_init (double D,
529 * @param stat result struct 560 * @param stat result struct
530 * @return GNUNET_SYSERR if glpk is not available, number of mechanisms used 561 * @return GNUNET_SYSERR if glpk is not available, number of mechanisms used
531 */ 562 */
532int ats_create_problem (struct ATS_Handle *ats, 563int
533 struct ATS_internals *stat, 564ats_create_problem (struct ATS_Handle *ats,
534 struct ATS_peer *peers, 565 struct ATS_internals *stat,
535 int c_p, 566 struct ATS_peer *peers,
536 struct ATS_mechanism *mechanisms, 567 int c_p, struct ATS_mechanism *mechanisms, int c_m)
537 int c_m)
538{ 568{
539 if ((c_p == 0) || (c_m == 0)) 569 if ((c_p == 0) || (c_m == 0))
540 return GNUNET_SYSERR; 570 return GNUNET_SYSERR;
541 571
542 ats->prob = _lp_create_prob(); 572 ats->prob = _lp_create_prob ();
543 573
544 int c; 574 int c;
545 int c_c_ressources = available_ressources; 575 int c_c_ressources = available_ressources;
546 int c_q_metrics = available_quality_metrics; 576 int c_q_metrics = available_quality_metrics;
547 577
548 double M = VERY_BIG_DOUBLE_VALUE; 578 double M = VERY_BIG_DOUBLE_VALUE;
549 double Q[c_q_metrics+1]; 579 double Q[c_q_metrics + 1];
550 for (c=1; c<=c_q_metrics; c++) 580
581 for (c = 1; c <= c_q_metrics; c++)
551 { 582 {
552 Q[c] = 1; 583 Q[c] = 1;
553 } 584 }
554 585
555 if (ats->v_n_min > c_p) 586 if (ats->v_n_min > c_p)
556 ats->v_n_min = c_p; 587 ats->v_n_min = c_p;
557#if VERBOSE_ATS 588#if VERBOSE_ATS
558 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Creating problem with: %i peers, %i mechanisms, %i resource entries, %i quality metrics \n", 589 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
559 c_p, 590 "Creating problem with: %i peers, %i mechanisms, %i resource entries, %i quality metrics \n",
560 c_m, 591 c_p, c_m, c_c_ressources, c_q_metrics);
561 c_c_ressources,
562 c_q_metrics);
563#endif 592#endif
564 593
565 int size = 1 + 3 + 10 *c_m + c_p + 594 int size = 1 + 3 + 10 * c_m + c_p +
566 (c_q_metrics*c_m)+ c_q_metrics + c_c_ressources * c_m ; 595 (c_q_metrics * c_m) + c_q_metrics + c_c_ressources * c_m;
567 int row_index; 596 int row_index;
568 int array_index=1; 597 int array_index = 1;
569 int * ia = GNUNET_malloc (size * sizeof (int)); 598 int *ia = GNUNET_malloc (size * sizeof (int));
570 int * ja = GNUNET_malloc (size * sizeof (int)); 599 int *ja = GNUNET_malloc (size * sizeof (int));
571 double * ar = GNUNET_malloc(size* sizeof (double)); 600 double *ar = GNUNET_malloc (size * sizeof (double));
572 601
573 _lp_set_prob_name (ats->prob, "gnunet ats bandwidth distribution"); 602 _lp_set_prob_name (ats->prob, "gnunet ats bandwidth distribution");
574 _lp_set_obj_dir(ats->prob, GLP_MAX); 603 _lp_set_obj_dir (ats->prob, GLP_MAX);
575 604
576 /* adding columns */ 605 /* adding columns */
577 char * name; 606 char *name;
578 _lp_add_cols(ats->prob, 2 * c_m); 607
608 _lp_add_cols (ats->prob, 2 * c_m);
579 /* adding b_t cols */ 609 /* adding b_t cols */
580 for (c=1; c <= c_m; c++) 610 for (c = 1; c <= c_m; c++)
581 { 611 {
582 GNUNET_asprintf(&name, 612 GNUNET_asprintf (&name,
583 "p_%s_b%i",GNUNET_i2s(&(mechanisms[c].peer->peer)), c); 613 "p_%s_b%i", GNUNET_i2s (&(mechanisms[c].peer->peer)), c);
584 _lp_set_col_name(ats->prob, c, name); 614 _lp_set_col_name (ats->prob, c, name);
585 GNUNET_free (name); 615 GNUNET_free (name);
586 _lp_set_col_bnds(ats->prob, c, GLP_LO, 0.0, 0.0); 616 _lp_set_col_bnds (ats->prob, c, GLP_LO, 0.0, 0.0);
587 _lp_set_col_kind(ats->prob, c, GLP_CV); 617 _lp_set_col_kind (ats->prob, c, GLP_CV);
588 _lp_set_obj_coef(ats->prob, c, 0); 618 _lp_set_obj_coef (ats->prob, c, 0);
589 } 619 }
590 620
591 /* adding n_t cols */ 621 /* adding n_t cols */
592 for (c=c_m+1; c <= 2*c_m; c++) 622 for (c = c_m + 1; c <= 2 * c_m; c++)
593 { 623 {
594 GNUNET_asprintf(&name, 624 GNUNET_asprintf (&name,
595 "p_%s_n%i",GNUNET_i2s(&(mechanisms[c-c_m].peer->peer)),(c-c_m)); 625 "p_%s_n%i", GNUNET_i2s (&(mechanisms[c - c_m].peer->peer)),
596 _lp_set_col_name(ats->prob, c, name); 626 (c - c_m));
627 _lp_set_col_name (ats->prob, c, name);
597 GNUNET_free (name); 628 GNUNET_free (name);
598 _lp_set_col_bnds(ats->prob, c, GLP_DB, 0.0, 1.0); 629 _lp_set_col_bnds (ats->prob, c, GLP_DB, 0.0, 1.0);
599 _lp_set_col_kind(ats->prob, c, GLP_IV); 630 _lp_set_col_kind (ats->prob, c, GLP_IV);
600 _lp_set_obj_coef(ats->prob, c, 0); 631 _lp_set_obj_coef (ats->prob, c, 0);
601 } 632 }
602 633
603 /* feasibility constraints */ 634 /* feasibility constraints */
604 /* Constraint 1: one address per peer*/ 635 /* Constraint 1: one address per peer */
605 row_index = 1; 636 row_index = 1;
606 637
607 _lp_add_rows(ats->prob, c_p); 638 _lp_add_rows (ats->prob, c_p);
608 639
609 for (c=1; c<=c_p; c++) 640 for (c = 1; c <= c_p; c++)
610 { 641 {
611#if VERBOSE_ATS 642#if VERBOSE_ATS
612 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", 643 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", row_index);
613 row_index);
614#endif 644#endif
615 645
616 _lp_set_row_bnds(ats->prob, row_index, GLP_FX, 1.0, 1.0); 646 _lp_set_row_bnds (ats->prob, row_index, GLP_FX, 1.0, 1.0);
617 struct ATS_mechanism *m = peers[c].m_head; 647 struct ATS_mechanism *m = peers[c].m_head;
618 while (m!=NULL) 648
619 { 649 while (m != NULL)
620 ia[array_index] = row_index; 650 {
621 ja[array_index] = (c_m + m->col_index); 651 ia[array_index] = row_index;
622 ar[array_index] = 1; 652 ja[array_index] = (c_m + m->col_index);
653 ar[array_index] = 1;
623#if VERBOSE_ATS 654#if VERBOSE_ATS
624 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 655 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
625 array_index, 656 array_index,
626 ia[array_index], 657 ia[array_index], ja[array_index], ar[array_index]);
627 ja[array_index], 658#endif
628 ar[array_index]); 659 array_index++;
629#endif 660 m = m->next;
630 array_index++; 661 }
631 m = m->next; 662 row_index++;
632 }
633 row_index++;
634 } 663 }
635 664
636 /* Constraint 2: only active mechanism gets bandwidth assigned */ 665 /* Constraint 2: only active mechanism gets bandwidth assigned */
637 _lp_add_rows(ats->prob, c_m); 666 _lp_add_rows (ats->prob, c_m);
638 for (c=1; c<=c_m; c++) 667 for (c = 1; c <= c_m; c++)
639 { 668 {
640 /* b_t - n_t * M <= 0 */ 669 /* b_t - n_t * M <= 0 */
641#if VERBOSE_ATS 670#if VERBOSE_ATS
642 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", 671 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", row_index);
643 row_index);
644#endif 672#endif
645 _lp_set_row_bnds(ats->prob, row_index, GLP_UP, 0.0, 0.0); 673 _lp_set_row_bnds (ats->prob, row_index, GLP_UP, 0.0, 0.0);
646 ia[array_index] = row_index; 674 ia[array_index] = row_index;
647 ja[array_index] = mechanisms[c].col_index; 675 ja[array_index] = mechanisms[c].col_index;
648 ar[array_index] = 1; 676 ar[array_index] = 1;
649#if VERBOSE_ATS 677#if VERBOSE_ATS
650 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 678 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
651 array_index, 679 array_index, ia[array_index], ja[array_index], ar[array_index]);
652 ia[array_index], 680#endif
653 ja[array_index], 681 array_index++;
654 ar[array_index]); 682 ia[array_index] = row_index;
655#endif 683 ja[array_index] = c_m + mechanisms[c].col_index;
656 array_index++; 684 ar[array_index] = -M;
657 ia[array_index] = row_index;
658 ja[array_index] = c_m + mechanisms[c].col_index;
659 ar[array_index] = -M;
660#if VERBOSE_ATS 685#if VERBOSE_ATS
661 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 686 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
662 array_index, 687 array_index, ia[array_index], ja[array_index], ar[array_index]);
663 ia[array_index], 688#endif
664 ja[array_index], 689 array_index++;
665 ar[array_index]); 690 row_index++;
666#endif
667 array_index++;
668 row_index ++;
669 } 691 }
670 692
671 /* Constraint 3: minimum bandwidth*/ 693 /* Constraint 3: minimum bandwidth */
672 _lp_add_rows(ats->prob, c_m); 694 _lp_add_rows (ats->prob, c_m);
673 695
674 for (c=1; c<=c_m; c++) 696 for (c = 1; c <= c_m; c++)
675 { 697 {
676 /* b_t - n_t * b_min <= 0 */ 698 /* b_t - n_t * b_min <= 0 */
677#if VERBOSE_ATS 699#if VERBOSE_ATS
678 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", 700 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", row_index);
679 row_index);
680#endif 701#endif
681#if HAVE_LIBGLPK 702#if HAVE_LIBGLPK
682 _lp_set_row_bnds(ats->prob, row_index, GLP_LO, 0.0, 0.0); 703 _lp_set_row_bnds (ats->prob, row_index, GLP_LO, 0.0, 0.0);
683#endif 704#endif
684 ia[array_index] = row_index; 705 ia[array_index] = row_index;
685 ja[array_index] = mechanisms[c].col_index; 706 ja[array_index] = mechanisms[c].col_index;
686 ar[array_index] = 1; 707 ar[array_index] = 1;
687#if VERBOSE_ATS 708#if VERBOSE_ATS
688 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 709 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
689 array_index, 710 array_index, ia[array_index], ja[array_index], ar[array_index]);
690 ia[array_index], 711#endif
691 ja[array_index], 712 array_index++;
692 ar[array_index]); 713 ia[array_index] = row_index;
693#endif 714 ja[array_index] = c_m + mechanisms[c].col_index;
694 array_index++; 715 ar[array_index] = -ats->v_b_min;
695 ia[array_index] = row_index;
696 ja[array_index] = c_m + mechanisms[c].col_index;
697 ar[array_index] = -ats->v_b_min;
698#if VERBOSE_ATS 716#if VERBOSE_ATS
699 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 717 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
700 array_index, 718 array_index, ia[array_index], ja[array_index], ar[array_index]);
701 ia[array_index], 719#endif
702 ja[array_index], 720 array_index++;
703 ar[array_index]); 721 row_index++;
704#endif
705 array_index++;
706 row_index ++;
707 } 722 }
708 int c2; 723 int c2;
709 724
@@ -711,69 +726,63 @@ int ats_create_problem (struct ATS_Handle *ats,
711 /* V cr: bt * ct_r <= cr_max 726 /* V cr: bt * ct_r <= cr_max
712 * */ 727 * */
713 728
714 _lp_add_rows(ats->prob, available_ressources); 729 _lp_add_rows (ats->prob, available_ressources);
715 730
716 double ct_max = VERY_BIG_DOUBLE_VALUE; 731 double ct_max = VERY_BIG_DOUBLE_VALUE;
717 double ct_min = 0.0; 732 double ct_min = 0.0;
718 733
719 stat->begin_cr = array_index; 734 stat->begin_cr = array_index;
720 735
721 for (c=0; c<available_ressources; c++) 736 for (c = 0; c < available_ressources; c++)
722 { 737 {
723 ct_max = ressources[c].c_max; 738 ct_max = ressources[c].c_max;
724 ct_min = ressources[c].c_min; 739 ct_min = ressources[c].c_min;
725#if VERBOSE_ATS 740#if VERBOSE_ATS
726 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] %f..%f\n", 741 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] %f..%f\n",
727 row_index, 742 row_index, ct_min, ct_max);
728 ct_min,
729 ct_max);
730#endif 743#endif
731#if HAVE_LIBGLPK 744#if HAVE_LIBGLPK
732 _lp_set_row_bnds(ats->prob, row_index, GLP_DB, ct_min, ct_max); 745 _lp_set_row_bnds (ats->prob, row_index, GLP_DB, ct_min, ct_max);
733#endif 746#endif
734 for (c2=1; c2<=c_m; c2++) 747 for (c2 = 1; c2 <= c_m; c2++)
735 { 748 {
736 double value = 0; 749 double value = 0;
737 ia[array_index] = row_index; 750
738 ja[array_index] = c2; 751 ia[array_index] = row_index;
739 value = mechanisms[c2].ressources[c].c; 752 ja[array_index] = c2;
740 ar[array_index] = value; 753 value = mechanisms[c2].ressources[c].c;
754 ar[array_index] = value;
741#if VERBOSE_ATS 755#if VERBOSE_ATS
742 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 756 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
743 array_index, ia[array_index], 757 array_index, ia[array_index],
744 ja[array_index], 758 ja[array_index], ar[array_index]);
745 ar[array_index]);
746#endif 759#endif
747 array_index++; 760 array_index++;
748 } 761 }
749 row_index ++; 762 row_index++;
750 } 763 }
751 stat->end_cr = array_index--; 764 stat->end_cr = array_index--;
752 765
753 /* Constraint 5: min number of connections*/ 766 /* Constraint 5: min number of connections */
754 _lp_add_rows(ats->prob, 1); 767 _lp_add_rows (ats->prob, 1);
755 768
756 for (c=1; c<=c_m; c++) 769 for (c = 1; c <= c_m; c++)
757 { 770 {
758 // b_t - n_t * b_min >= 0 771 // b_t - n_t * b_min >= 0
759#if VERBOSE_ATS 772#if VERBOSE_ATS
760 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", 773 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", row_index);
761 row_index);
762#endif 774#endif
763 _lp_set_row_bnds(ats->prob, row_index, GLP_LO, ats->v_n_min, 0.0); 775 _lp_set_row_bnds (ats->prob, row_index, GLP_LO, ats->v_n_min, 0.0);
764 ia[array_index] = row_index; 776 ia[array_index] = row_index;
765 ja[array_index] = c_m + mechanisms[c].col_index; 777 ja[array_index] = c_m + mechanisms[c].col_index;
766 ar[array_index] = 1; 778 ar[array_index] = 1;
767#if VERBOSE_ATS 779#if VERBOSE_ATS
768 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 780 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
769 array_index, 781 array_index, ia[array_index], ja[array_index], ar[array_index]);
770 ia[array_index],
771 ja[array_index],
772 ar[array_index]);
773#endif 782#endif
774 array_index++; 783 array_index++;
775 } 784 }
776 row_index ++; 785 row_index++;
777 786
778 // optimisation constraints 787 // optimisation constraints
779 788
@@ -781,29 +790,27 @@ int ats_create_problem (struct ATS_Handle *ats,
781 790
782 // Constraint 6: optimize for diversity 791 // Constraint 6: optimize for diversity
783 int col_d; 792 int col_d;
784 col_d = _lp_add_cols(ats->prob, 1);
785 793
786 _lp_set_col_name(ats->prob, col_d, "d"); 794 col_d = _lp_add_cols (ats->prob, 1);
787 _lp_set_obj_coef(ats->prob, col_d, ats->D); 795
788 _lp_set_col_bnds(ats->prob, col_d, GLP_LO, 0.0, 0.0); 796 _lp_set_col_name (ats->prob, col_d, "d");
789 _lp_add_rows(ats->prob, 1); 797 _lp_set_obj_coef (ats->prob, col_d, ats->D);
790 _lp_set_row_bnds(ats->prob, row_index, GLP_FX, 0.0, 0.0); 798 _lp_set_col_bnds (ats->prob, col_d, GLP_LO, 0.0, 0.0);
799 _lp_add_rows (ats->prob, 1);
800 _lp_set_row_bnds (ats->prob, row_index, GLP_FX, 0.0, 0.0);
791 801
792 stat->col_d = col_d; 802 stat->col_d = col_d;
793#if VERBOSE_ATS 803#if VERBOSE_ATS
794 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",row_index); 804 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", row_index);
795#endif 805#endif
796 for (c=1; c<=c_m; c++) 806 for (c = 1; c <= c_m; c++)
797 { 807 {
798 ia[array_index] = row_index; 808 ia[array_index] = row_index;
799 ja[array_index] = c_m + mechanisms[c].col_index; 809 ja[array_index] = c_m + mechanisms[c].col_index;
800 ar[array_index] = 1; 810 ar[array_index] = 1;
801#if VERBOSE_ATS 811#if VERBOSE_ATS
802 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 812 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
803 array_index, 813 array_index, ia[array_index], ja[array_index], ar[array_index]);
804 ia[array_index],
805 ja[array_index],
806 ar[array_index]);
807#endif 814#endif
808 array_index++; 815 array_index++;
809 } 816 }
@@ -812,122 +819,120 @@ int ats_create_problem (struct ATS_Handle *ats,
812 ar[array_index] = -1; 819 ar[array_index] = -1;
813#if VERBOSE_ATS 820#if VERBOSE_ATS
814 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 821 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
815 array_index, 822 array_index, ia[array_index], ja[array_index], ar[array_index]);
816 ia[array_index],
817 ja[array_index],
818 ar[array_index]);
819#endif 823#endif
820 array_index++; 824 array_index++;
821 row_index ++; 825 row_index++;
822 826
823 // Constraint 7: optimize for quality 827 // Constraint 7: optimize for quality
824 int col_qm; 828 int col_qm;
825 col_qm = _lp_add_cols(ats->prob, c_q_metrics); 829
830 col_qm = _lp_add_cols (ats->prob, c_q_metrics);
826 831
827 stat->col_qm = col_qm; 832 stat->col_qm = col_qm;
828 //GNUNET_assert (col_qm == (2*c_mechs) + 3 + 1); 833 //GNUNET_assert (col_qm == (2*c_mechs) + 3 + 1);
829 for (c=0; c< c_q_metrics; c++) 834 for (c = 0; c < c_q_metrics; c++)
830 { 835 {
831 GNUNET_asprintf(&name, "Q_%s",qm[c].name); 836 GNUNET_asprintf (&name, "Q_%s", qm[c].name);
832 _lp_set_col_name (ats->prob, col_qm + c, name); 837 _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); 838 _lp_set_col_bnds (ats->prob, col_qm + c, GLP_LO, 0.0, 0.0);
834 GNUNET_free (name); 839 GNUNET_free (name);
835 _lp_set_obj_coef (ats->prob, col_qm + c, Q[c]); 840 _lp_set_obj_coef (ats->prob, col_qm + c, Q[c]);
836 } 841 }
837 842
838 _lp_add_rows(ats->prob, available_quality_metrics); 843 _lp_add_rows (ats->prob, available_quality_metrics);
839 844
840 stat->begin_qm = row_index; 845 stat->begin_qm = row_index;
841 for (c=1; c <= c_q_metrics; c++) 846 for (c = 1; c <= c_q_metrics; c++)
842 { 847 {
843#if VERBOSE_ATS 848#if VERBOSE_ATS
844 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", 849 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", row_index);
845 row_index);
846#endif 850#endif
847 double value = 1; 851 double value = 1;
848 _lp_set_row_bnds(ats->prob, row_index, GLP_FX, 0.0, 0.0); 852
849 for (c2=1; c2<=c_m; c2++) 853 _lp_set_row_bnds (ats->prob, row_index, GLP_FX, 0.0, 0.0);
854 for (c2 = 1; c2 <= c_m; c2++)
855 {
856 ia[array_index] = row_index;
857 ja[array_index] = c2;
858 if (qm[c - 1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY)
850 { 859 {
851 ia[array_index] = row_index; 860 double v0 = 0, v1 = 0, v2 = 0;
852 ja[array_index] = c2; 861
853 if (qm[c-1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY) 862 v0 = mechanisms[c2].quality[c - 1].values[0];
854 { 863 if (v1 < 1)
855 double v0 = 0, v1 = 0, v2 = 0; 864 v0 = 0.1;
856 v0 = mechanisms[c2].quality[c-1].values[0]; 865 v1 = mechanisms[c2].quality[c - 1].values[1];
857 if (v1 < 1) v0 = 0.1; 866 if (v1 < 1)
858 v1 = mechanisms[c2].quality[c-1].values[1]; 867 v0 = 0.1;
859 if (v1 < 1) v0 = 0.1; 868 v2 = mechanisms[c2].quality[c - 1].values[2];
860 v2 = mechanisms[c2].quality[c-1].values[2]; 869 if (v1 < 1)
861 if (v1 < 1) v0 = 0.1; 870 v0 = 0.1;
862 value = 100.0 / ((v0 + 2 * v1 + 3 * v2) / 6.0); 871 value = 100.0 / ((v0 + 2 * v1 + 3 * v2) / 6.0);
863 value = 1; 872 value = 1;
864 }
865 if (qm[c-1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE)
866 {
867 double v0 = 0, v1 = 0, v2 = 0;
868 v0 = mechanisms[c2].quality[c-1].values[0];
869 if (v0 < 1) v0 = 1;
870 v1 = mechanisms[c2].quality[c-1].values[1];
871 if (v1 < 1) v1 = 1;
872 v2 = mechanisms[c2].quality[c-1].values[2];
873 if (v2 < 1) v2 = 1;
874 value = (v0 + 2 * v1 + 3 * v2) / 6.0;
875 if (value >= 1)
876 value = (double) 10 / value;
877 else
878 value = 10;
879 }
880 ar[array_index] = (mechanisms[c2].peer->f) * value ;
881#if VERBOSE_ATS
882 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: %s [%i,%i]=%f \n",
883 array_index,
884 qm[c-1].name,
885 ia[array_index],
886 ja[array_index],
887 ar[array_index]);
888#endif
889 array_index++;
890 } 873 }
891 ia[array_index] = row_index; 874 if (qm[c - 1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE)
892 ja[array_index] = col_qm + c - 1; 875 {
893 ar[array_index] = -1; 876 double v0 = 0, v1 = 0, v2 = 0;
877
878 v0 = mechanisms[c2].quality[c - 1].values[0];
879 if (v0 < 1)
880 v0 = 1;
881 v1 = mechanisms[c2].quality[c - 1].values[1];
882 if (v1 < 1)
883 v1 = 1;
884 v2 = mechanisms[c2].quality[c - 1].values[2];
885 if (v2 < 1)
886 v2 = 1;
887 value = (v0 + 2 * v1 + 3 * v2) / 6.0;
888 if (value >= 1)
889 value = (double) 10 / value;
890 else
891 value = 10;
892 }
893 ar[array_index] = (mechanisms[c2].peer->f) * value;
894#if VERBOSE_ATS 894#if VERBOSE_ATS
895 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 895 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: %s [%i,%i]=%f \n",
896 array_index, 896 array_index,
897 ia[array_index], 897 qm[c - 1].name,
898 ja[array_index], 898 ia[array_index], ja[array_index], ar[array_index]);
899 ar[array_index]);
900#endif 899#endif
901 array_index++; 900 array_index++;
902 row_index++; 901 }
902 ia[array_index] = row_index;
903 ja[array_index] = col_qm + c - 1;
904 ar[array_index] = -1;
905#if VERBOSE_ATS
906 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
907 array_index, ia[array_index], ja[array_index], ar[array_index]);
908#endif
909 array_index++;
910 row_index++;
903 } 911 }
904 stat->end_qm = row_index-1; 912 stat->end_qm = row_index - 1;
905 913
906 // Constraint 8: optimize bandwidth utility 914 // Constraint 8: optimize bandwidth utility
907 int col_u; 915 int col_u;
908 916
909 col_u = _lp_add_cols(ats->prob, 1); 917 col_u = _lp_add_cols (ats->prob, 1);
910 918
911 _lp_set_col_name(ats->prob, col_u, "u"); 919 _lp_set_col_name (ats->prob, col_u, "u");
912 _lp_set_obj_coef(ats->prob, col_u, ats->U); 920 _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); 921 _lp_set_col_bnds (ats->prob, col_u, GLP_LO, 0.0, 0.0);
914 _lp_add_rows(ats->prob, 1); 922 _lp_add_rows (ats->prob, 1);
915 stat->col_u = col_u; 923 stat->col_u = col_u;
916#if VERBOSE_ATS 924#if VERBOSE_ATS
917 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",row_index); 925 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", row_index);
918#endif 926#endif
919 _lp_set_row_bnds(ats->prob, row_index, GLP_FX, 0.0, 0.0); 927 _lp_set_row_bnds (ats->prob, row_index, GLP_FX, 0.0, 0.0);
920 for (c=1; c<=c_m; c++) 928 for (c = 1; c <= c_m; c++)
921 { 929 {
922 ia[array_index] = row_index; 930 ia[array_index] = row_index;
923 ja[array_index] = c; 931 ja[array_index] = c;
924 ar[array_index] = mechanisms[c].peer->f; 932 ar[array_index] = mechanisms[c].peer->f;
925#if VERBOSE_ATS 933#if VERBOSE_ATS
926 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 934 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
927 array_index, 935 array_index, ia[array_index], ja[array_index], ar[array_index]);
928 ia[array_index],
929 ja[array_index],
930 ar[array_index]);
931#endif 936#endif
932 array_index++; 937 array_index++;
933 } 938 }
@@ -936,40 +941,37 @@ int ats_create_problem (struct ATS_Handle *ats,
936 ar[array_index] = -1; 941 ar[array_index] = -1;
937#if VERBOSE_ATS 942#if VERBOSE_ATS
938 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 943 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
939 array_index, ia[array_index], 944 array_index, ia[array_index], ja[array_index], ar[array_index]);
940 ja[array_index],
941 ar[array_index]);
942#endif 945#endif
943 946
944 array_index++; 947 array_index++;
945 row_index ++; 948 row_index++;
946 949
947 // Constraint 9: optimize relativity 950 // Constraint 9: optimize relativity
948 int col_r; 951 int col_r;
949 952
950 col_r = _lp_add_cols(ats->prob, 1); 953 col_r = _lp_add_cols (ats->prob, 1);
951 954
952 _lp_set_col_name(ats->prob, col_r, "r"); 955 _lp_set_col_name (ats->prob, col_r, "r");
953 _lp_set_obj_coef(ats->prob, col_r, ats->R); 956 _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); 957 _lp_set_col_bnds (ats->prob, col_r, GLP_LO, 0.0, 0.0);
955 _lp_add_rows(ats->prob, c_p); 958 _lp_add_rows (ats->prob, c_p);
956 959
957 stat->col_r = col_r; 960 stat->col_r = col_r;
958 for (c=1; c<=c_p; c++) 961 for (c = 1; c <= c_p; c++)
959 { 962 {
960 _lp_set_row_bnds(ats->prob, row_index, GLP_LO, 0.0, 0.0); 963 _lp_set_row_bnds (ats->prob, row_index, GLP_LO, 0.0, 0.0);
961 struct ATS_mechanism *m = peers[c].m_head; 964 struct ATS_mechanism *m = peers[c].m_head;
962 while (m!=NULL) 965
966 while (m != NULL)
963 { 967 {
964 ia[array_index] = row_index; 968 ia[array_index] = row_index;
965 ja[array_index] = m->col_index; 969 ja[array_index] = m->col_index;
966 ar[array_index] = 1 / mechanisms[c].peer->f; 970 ar[array_index] = 1 / mechanisms[c].peer->f;
967#if VERBOSE_ATS 971#if VERBOSE_ATS
968 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 972 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
969 array_index, 973 array_index,
970 ia[array_index], 974 ia[array_index], ja[array_index], ar[array_index]);
971 ja[array_index],
972 ar[array_index]);
973#endif 975#endif
974 array_index++; 976 array_index++;
975 m = m->next; 977 m = m->next;
@@ -979,17 +981,14 @@ int ats_create_problem (struct ATS_Handle *ats,
979 ar[array_index] = -1; 981 ar[array_index] = -1;
980#if VERBOSE_ATS 982#if VERBOSE_ATS
981 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 983 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
982 array_index, 984 array_index, ia[array_index], ja[array_index], ar[array_index]);
983 ia[array_index],
984 ja[array_index],
985 ar[array_index]);
986#endif 985#endif
987 array_index++; 986 array_index++;
988 row_index++; 987 row_index++;
989 } 988 }
990 989
991 /* Loading the matrix */ 990 /* Loading the matrix */
992 _lp_load_matrix(ats->prob, array_index-1, ia, ja, ar); 991 _lp_load_matrix (ats->prob, array_index - 1, ia, ja, ar);
993 992
994 stat->c_mechs = c_m; 993 stat->c_mechs = c_m;
995 stat->c_peers = c_p; 994 stat->c_peers = c_p;
@@ -1005,30 +1004,31 @@ int ats_create_problem (struct ATS_Handle *ats,
1005} 1004}
1006 1005
1007 1006
1008void ats_delete_problem (struct ATS_Handle * ats) 1007void
1008ats_delete_problem (struct ATS_Handle *ats)
1009{ 1009{
1010#if DEBUG_ATS 1010#if DEBUG_ATS
1011 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Deleting problem\n"); 1011 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Deleting problem\n");
1012#endif 1012#endif
1013 int c; 1013 int c;
1014 1014
1015 for (c=0; c< (ats->internal).c_mechs; c++) 1015 for (c = 0; c < (ats->internal).c_mechs; c++)
1016 GNUNET_free_non_null (ats->mechanisms[c].rc); 1016 GNUNET_free_non_null (ats->mechanisms[c].rc);
1017 if (ats->mechanisms!=NULL) 1017 if (ats->mechanisms != NULL)
1018 { 1018 {
1019 GNUNET_free(ats->mechanisms); 1019 GNUNET_free (ats->mechanisms);
1020 ats->mechanisms = NULL; 1020 ats->mechanisms = NULL;
1021 } 1021 }
1022 1022
1023 if (ats->peers!=NULL) 1023 if (ats->peers != NULL)
1024 { 1024 {
1025 GNUNET_free(ats->peers); 1025 GNUNET_free (ats->peers);
1026 ats->peers = NULL; 1026 ats->peers = NULL;
1027 } 1027 }
1028 1028
1029 if (ats->prob != NULL) 1029 if (ats->prob != NULL)
1030 { 1030 {
1031 _lp_delete_prob(ats->prob); 1031 _lp_delete_prob (ats->prob);
1032 ats->prob = NULL; 1032 ats->prob = NULL;
1033 } 1033 }
1034 1034
@@ -1042,13 +1042,14 @@ void ats_delete_problem (struct ATS_Handle * ats)
1042 ats->internal.valid = GNUNET_SYSERR; 1042 ats->internal.valid = GNUNET_SYSERR;
1043} 1043}
1044 1044
1045void ats_modify_problem_state (struct ATS_Handle * ats, enum ATS_problem_state s) 1045void
1046ats_modify_problem_state (struct ATS_Handle *ats, enum ATS_problem_state s)
1046{ 1047{
1047 if (ats == NULL) 1048 if (ats == NULL)
1048 return; 1049 return;
1049 switch (s) 1050 switch (s)
1050 { 1051 {
1051 case ATS_NEW : 1052 case ATS_NEW:
1052 ats->internal.recreate_problem = GNUNET_NO; 1053 ats->internal.recreate_problem = GNUNET_NO;
1053 ats->internal.modified_quality = GNUNET_NO; 1054 ats->internal.modified_quality = GNUNET_NO;
1054 ats->internal.modified_resources = GNUNET_NO; 1055 ats->internal.modified_resources = GNUNET_NO;
@@ -1056,10 +1057,10 @@ void ats_modify_problem_state (struct ATS_Handle * ats, enum ATS_problem_state s
1056 case ATS_MODIFIED: 1057 case ATS_MODIFIED:
1057 ats->internal.recreate_problem = GNUNET_YES; 1058 ats->internal.recreate_problem = GNUNET_YES;
1058 break; 1059 break;
1059 case ATS_QUALITY_UPDATED : 1060 case ATS_QUALITY_UPDATED:
1060 ats->internal.modified_quality = GNUNET_YES; 1061 ats->internal.modified_quality = GNUNET_YES;
1061 break; 1062 break;
1062 case ATS_COST_UPDATED : 1063 case ATS_COST_UPDATED:
1063 ats->internal.modified_resources = GNUNET_YES; 1064 ats->internal.modified_resources = GNUNET_YES;
1064 break; 1065 break;
1065 case ATS_QUALITY_COST_UPDATED: 1066 case ATS_QUALITY_COST_UPDATED:
@@ -1074,12 +1075,12 @@ void ats_modify_problem_state (struct ATS_Handle * ats, enum ATS_problem_state s
1074 1075
1075} 1076}
1076 1077
1077void ats_solve_problem (struct ATS_Handle * ats, 1078void
1078 unsigned int max_it, 1079ats_solve_problem (struct ATS_Handle *ats,
1079 unsigned int max_dur, 1080 unsigned int max_it,
1080 unsigned int c_peers, 1081 unsigned int max_dur,
1081 unsigned int c_mechs, 1082 unsigned int c_peers,
1082 struct ATS_internals *stat) 1083 unsigned int c_mechs, struct ATS_internals *stat)
1083{ 1084{
1084 int result = GNUNET_SYSERR; 1085 int result = GNUNET_SYSERR;
1085 int lp_solution = GNUNET_SYSERR; 1086 int lp_solution = GNUNET_SYSERR;
@@ -1088,7 +1089,8 @@ void ats_solve_problem (struct ATS_Handle * ats,
1088 // Solving simplex 1089 // Solving simplex
1089 1090
1090 glp_smcp opt_lp; 1091 glp_smcp opt_lp;
1091 _lp_init_smcp(&opt_lp); 1092
1093 _lp_init_smcp (&opt_lp);
1092#if VERBOSE_ATS 1094#if VERBOSE_ATS
1093 opt_lp.msg_lev = GLP_MSG_ALL; 1095 opt_lp.msg_lev = GLP_MSG_ALL;
1094#else 1096#else
@@ -1100,20 +1102,20 @@ void ats_solve_problem (struct ATS_Handle * ats,
1100 opt_lp.tm_lim = max_dur; 1102 opt_lp.tm_lim = max_dur;
1101 1103
1102 if (ats->internal.recreate_problem == GNUNET_YES) 1104 if (ats->internal.recreate_problem == GNUNET_YES)
1103 opt_lp.presolve = GLP_ON; 1105 opt_lp.presolve = GLP_ON;
1104 1106
1105 result = _lp_simplex(ats->prob, &opt_lp); 1107 result = _lp_simplex (ats->prob, &opt_lp);
1106 lp_solution = _lp_get_status (ats->prob); 1108 lp_solution = _lp_get_status (ats->prob);
1107 1109
1108 if ((result == GLP_ETMLIM) || (result == GLP_EITLIM)) 1110 if ((result == GLP_ETMLIM) || (result == GLP_EITLIM))
1109 { 1111 {
1110 ats->internal.valid = GNUNET_NO; 1112 ats->internal.valid = GNUNET_NO;
1111 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1113 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1112 "ATS exceeded time or iteration limit!\n"); 1114 "ATS exceeded time or iteration limit!\n");
1113 return; 1115 return;
1114 } 1116 }
1115 1117
1116 if (ats_evaluate_results(result, lp_solution, "LP") == GNUNET_YES) 1118 if (ats_evaluate_results (result, lp_solution, "LP") == GNUNET_YES)
1117 { 1119 {
1118 stat->valid = GNUNET_YES; 1120 stat->valid = GNUNET_YES;
1119 } 1121 }
@@ -1121,36 +1123,37 @@ void ats_solve_problem (struct ATS_Handle * ats,
1121 { 1123 {
1122 ats->internal.simplex_rerun_required = GNUNET_YES; 1124 ats->internal.simplex_rerun_required = GNUNET_YES;
1123 opt_lp.presolve = GLP_ON; 1125 opt_lp.presolve = GLP_ON;
1124 result = _lp_simplex(ats->prob, &opt_lp); 1126 result = _lp_simplex (ats->prob, &opt_lp);
1125 lp_solution = _lp_get_status (ats->prob); 1127 lp_solution = _lp_get_status (ats->prob);
1126 1128
1127 // TODO: Remove if this does not appear until release 1129 // TODO: Remove if this does not appear until release
1128 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "" 1130 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, ""
1129 "EXECUTED SIMPLEX WITH PRESOLVER! %i \n", 1131 "EXECUTED SIMPLEX WITH PRESOLVER! %i \n", lp_solution);
1130 lp_solution);
1131 1132
1132 if (ats_evaluate_results(result, lp_solution, "LP") != GNUNET_YES) 1133 if (ats_evaluate_results (result, lp_solution, "LP") != GNUNET_YES)
1133 { 1134 {
1134 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1135 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1135 "After execution simplex with presolver: STILL INVALID!\n"); 1136 "After execution simplex with presolver: STILL INVALID!\n");
1136 char * filename; 1137 char *filename;
1137 GNUNET_asprintf (&filename, 1138
1138 "ats_mlp_p%i_m%i_%llu.mlp", 1139 GNUNET_asprintf (&filename,
1139 ats->internal.c_peers, 1140 "ats_mlp_p%i_m%i_%llu.mlp",
1140 ats->internal.c_mechs, 1141 ats->internal.c_peers,
1141 GNUNET_TIME_absolute_get().abs_value); 1142 ats->internal.c_mechs,
1142 _lp_write_lp ((void *)ats->prob, NULL, filename); 1143 GNUNET_TIME_absolute_get ().abs_value);
1143 GNUNET_free (filename); 1144 _lp_write_lp ((void *) ats->prob, NULL, filename);
1144 stat->valid = GNUNET_NO; 1145 GNUNET_free (filename);
1145 ats->internal.recreate_problem = GNUNET_YES; 1146 stat->valid = GNUNET_NO;
1146 return; 1147 ats->internal.recreate_problem = GNUNET_YES;
1148 return;
1147 } 1149 }
1148 stat->valid = GNUNET_YES; 1150 stat->valid = GNUNET_YES;
1149 } 1151 }
1150 1152
1151 // Solving mlp 1153 // Solving mlp
1152 glp_iocp opt_mlp; 1154 glp_iocp opt_mlp;
1153 _lp_init_iocp(&opt_mlp); 1155
1156 _lp_init_iocp (&opt_mlp);
1154 // maximum duration 1157 // maximum duration
1155 opt_mlp.tm_lim = max_dur; 1158 opt_mlp.tm_lim = max_dur;
1156 // output level 1159 // output level
@@ -1161,342 +1164,351 @@ void ats_solve_problem (struct ATS_Handle * ats,
1161#endif 1164#endif
1162 1165
1163 result = _lp_intopt (ats->prob, &opt_mlp); 1166 result = _lp_intopt (ats->prob, &opt_mlp);
1164 mlp_solution = _lp_mip_status (ats->prob); 1167 mlp_solution = _lp_mip_status (ats->prob);
1165 stat->solution = mlp_solution; 1168 stat->solution = mlp_solution;
1166 1169
1167 if (ats_evaluate_results(result, mlp_solution, "MLP") == GNUNET_YES) 1170 if (ats_evaluate_results (result, mlp_solution, "MLP") == GNUNET_YES)
1168 { 1171 {
1169 stat->valid = GNUNET_YES; 1172 stat->valid = GNUNET_YES;
1170 } 1173 }
1171 else 1174 else
1172 { 1175 {
1173 // TODO: Remove if this does not appear until release 1176 // TODO: Remove if this does not appear until release
1174 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1177 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1175 "MLP solution for %i peers, %i mechs is invalid: %i\n", 1178 "MLP solution for %i peers, %i mechs is invalid: %i\n",
1176 ats->internal.c_peers, 1179 ats->internal.c_peers, ats->internal.c_mechs, mlp_solution);
1177 ats->internal.c_mechs, 1180 stat->valid = GNUNET_NO;
1178 mlp_solution);
1179 stat->valid = GNUNET_NO;
1180 } 1181 }
1181 1182
1182#if VERBOSE_ATS 1183#if VERBOSE_ATS
1183 if (_lp_get_col_prim(ats->prob,2*c_mechs+1) != 1) 1184 if (_lp_get_col_prim (ats->prob, 2 * c_mechs + 1) != 1)
1184 {
1185 int c;
1186 for (c=1; c<= available_quality_metrics; c++ )
1187 { 1185 {
1186 int c;
1187
1188 for (c = 1; c <= available_quality_metrics; c++)
1189 {
1190 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s %f\n",
1191 _lp_get_col_name (ats->prob, 2 * c_mechs + 3 + c),
1192 _lp_get_col_prim (ats->prob, 2 * c_mechs + 3 + c));
1193 }
1188 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s %f\n", 1194 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s %f\n",
1189 _lp_get_col_name(ats->prob,2*c_mechs+3+c), 1195 _lp_get_col_name (ats->prob, 2 * c_mechs + 1),
1190 _lp_get_col_prim(ats->prob,2*c_mechs+3+c)); 1196 _lp_get_col_prim (ats->prob, 2 * c_mechs + 1));
1191 } 1197 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s %f\n",
1192 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s %f\n", 1198 _lp_get_col_name (ats->prob, 2 * c_mechs + 2),
1193 _lp_get_col_name(ats->prob,2*c_mechs+1), 1199 _lp_get_col_prim (ats->prob, 2 * c_mechs + 2));
1194 _lp_get_col_prim(ats->prob,2*c_mechs+1)); 1200 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s %f\n",
1195 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s %f\n", 1201 _lp_get_col_name (ats->prob, 2 * c_mechs + 3),
1196 _lp_get_col_name(ats->prob,2*c_mechs+2), 1202 _lp_get_col_prim (ats->prob, 2 * c_mechs + 3));
1197 _lp_get_col_prim(ats->prob,2*c_mechs+2)); 1203 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "objective value: %f\n",
1198 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s %f\n", 1204 _lp_mip_obj_val (ats->prob));
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));
1203 } 1205 }
1204#endif 1206#endif
1205} 1207}
1206 1208
1207 1209
1208void ats_shutdown (struct ATS_Handle * ats) 1210void
1211ats_shutdown (struct ATS_Handle *ats)
1209{ 1212{
1210#if DEBUG_ATS 1213#if DEBUG_ATS
1211 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ATS shutdown\n"); 1214 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ATS shutdown\n");
1212#endif 1215#endif
1213 ats_delete_problem (ats); 1216 ats_delete_problem (ats);
1214 _lp_free_env(); 1217 _lp_free_env ();
1215 1218
1216 GNUNET_free (ats); 1219 GNUNET_free (ats);
1217} 1220}
1218 1221
1219void ats_update_problem_qm (struct ATS_Handle * ats) 1222void
1223ats_update_problem_qm (struct ATS_Handle *ats)
1220{ 1224{
1221 int array_index; 1225 int array_index;
1222 int row_index; 1226 int row_index;
1223 int c, c2; 1227 int c, c2;
1224 int c_q_metrics = available_quality_metrics; 1228 int c_q_metrics = available_quality_metrics;
1225 1229
1226 int *ja = GNUNET_malloc ((1 + ats->internal.c_mechs*2 + 3 + 1230 int *ja = GNUNET_malloc ((1 + ats->internal.c_mechs * 2 + 3 +
1227 available_quality_metrics) * sizeof (int)); 1231 available_quality_metrics) * sizeof (int));
1228 double *ar = GNUNET_malloc ((1 + ats->internal.c_mechs*2 + 3 + 1232 double *ar = GNUNET_malloc ((1 + ats->internal.c_mechs * 2 + 3 +
1229 available_quality_metrics) * sizeof (double)); 1233 available_quality_metrics) * sizeof (double));
1230#if DEBUG_ATS 1234#if DEBUG_ATS
1231 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updating problem quality metrics\n"); 1235 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updating problem quality metrics\n");
1232#endif 1236#endif
1233 row_index = ats->internal.begin_qm; 1237 row_index = ats->internal.begin_qm;
1238
1239 for (c = 1; c <= c_q_metrics; c++)
1240 {
1241 array_index = 1;
1242 double value = 1;
1234 1243
1235 for (c=1; c <= c_q_metrics; c++)
1236 {
1237 array_index = 1;
1238 double value = 1;
1239#if VERBOSE_ATS
1240 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",row_index);
1241#endif
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++)
1244 {
1245 ja[array_index] = c2;
1246 GNUNET_assert (ats->mechanisms[c2].addr != NULL);
1247 GNUNET_assert (ats->mechanisms[c2].peer != NULL);
1248
1249 if (qm[c-1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY)
1250 {
1251 double v0 = 0, v1 = 0, v2 = 0;
1252
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);
1260 //value = 1;
1261 }
1262 if (qm[c-1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE)
1263 {
1264 double v0 = 0, v1 = 0, v2 = 0;
1265 v0 = ats->mechanisms[c2].quality[c-1].values[0];
1266 if (v0 < 1) v0 = 1;
1267 v1 = ats->mechanisms[c2].quality[c-1].values[1];
1268 if (v1 < 1) v1 = 1;
1269 v2 = ats->mechanisms[c2].quality[c-1].values[2];
1270 if (v2 < 1) v2 = 1;
1271 value = (v0 + 2 * v1 + 3 * v2) / 6.0;
1272 if (value >= 1)
1273 value = (double) 10 / value;
1274 else
1275 value = 10;
1276 }
1277 ar[array_index] = (ats->mechanisms[c2].peer->f) * value;
1278#if VERBOSE_ATS 1244#if VERBOSE_ATS
1279 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: %s [%i,%i]=%f \n", 1245 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", row_index);
1280 array_index, 1246#endif
1281 qm[c-1].name, 1247 _lp_set_row_bnds (ats->prob, row_index, GLP_FX, 0.0, 0.0);
1282 row_index, 1248 for (c2 = 1; c2 <= ats->internal.c_mechs; c2++)
1283 ja[array_index], 1249 {
1284 ar[array_index]); 1250 ja[array_index] = c2;
1285#endif 1251 GNUNET_assert (ats->mechanisms[c2].addr != NULL);
1286 array_index++; 1252 GNUNET_assert (ats->mechanisms[c2].peer != NULL);
1287 }
1288 ja[array_index] = ats->internal.col_qm + c - 1;
1289 ar[array_index] = -1;
1290 1253
1254 if (qm[c - 1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY)
1255 {
1256 double v0 = 0, v1 = 0, v2 = 0;
1257
1258 v0 = ats->mechanisms[c2].quality[c - 1].values[0];
1259 if (v1 < 1)
1260 v0 = 0.1;
1261 v1 = ats->mechanisms[c2].quality[c - 1].values[1];
1262 if (v1 < 1)
1263 v0 = 0.1;
1264 v2 = ats->mechanisms[c2].quality[c - 1].values[2];
1265 if (v1 < 1)
1266 v0 = 0.1;
1267 value = 100.0 / ((v0 + 2 * v1 + 3 * v2) / 6.0);
1268 //value = 1;
1269 }
1270 if (qm[c - 1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE)
1271 {
1272 double v0 = 0, v1 = 0, v2 = 0;
1273
1274 v0 = ats->mechanisms[c2].quality[c - 1].values[0];
1275 if (v0 < 1)
1276 v0 = 1;
1277 v1 = ats->mechanisms[c2].quality[c - 1].values[1];
1278 if (v1 < 1)
1279 v1 = 1;
1280 v2 = ats->mechanisms[c2].quality[c - 1].values[2];
1281 if (v2 < 1)
1282 v2 = 1;
1283 value = (v0 + 2 * v1 + 3 * v2) / 6.0;
1284 if (value >= 1)
1285 value = (double) 10 / value;
1286 else
1287 value = 10;
1288 }
1289 ar[array_index] = (ats->mechanisms[c2].peer->f) * value;
1291#if VERBOSE_ATS 1290#if VERBOSE_ATS
1292 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 1291 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: %s [%i,%i]=%f \n",
1293 array_index, 1292 array_index,
1294 row_index, 1293 qm[c - 1].name, row_index, ja[array_index], ar[array_index]);
1295 ja[array_index], 1294#endif
1296 ar[array_index]); 1295 array_index++;
1297#endif
1298 _lp_set_mat_row (ats->prob, row_index, array_index, ja, ar);
1299 array_index = 1;
1300 row_index++;
1301 } 1296 }
1302 GNUNET_free_non_null (ja); 1297 ja[array_index] = ats->internal.col_qm + c - 1;
1303 GNUNET_free_non_null (ar); 1298 ar[array_index] = -1;
1299
1300#if VERBOSE_ATS
1301 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
1302 array_index, row_index, ja[array_index], ar[array_index]);
1303#endif
1304 _lp_set_mat_row (ats->prob, row_index, array_index, ja, ar);
1305 array_index = 1;
1306 row_index++;
1307 }
1308 GNUNET_free_non_null (ja);
1309 GNUNET_free_non_null (ar);
1304 1310
1305} 1311}
1306 1312
1307 1313
1308void 1314void
1309ats_calculate_bandwidth_distribution (struct ATS_Handle * ats) 1315ats_calculate_bandwidth_distribution (struct ATS_Handle *ats)
1310{ 1316{
1311 struct GNUNET_TIME_Absolute start; 1317 struct GNUNET_TIME_Absolute start;
1312 struct GNUNET_TIME_Relative creation; 1318 struct GNUNET_TIME_Relative creation;
1313 struct GNUNET_TIME_Relative solving; 1319 struct GNUNET_TIME_Relative solving;
1314 int c_m; 1320 int c_m;
1315 int c_p; 1321 int c_p;
1316 char *text = "unmodified"; 1322 char *text = "unmodified";
1317 1323
1318#if FIXME_WACHS 1324#if FIXME_WACHS
1319 int dur; 1325 int dur;
1320 if (INT_MAX < ats->max_exec_duration.rel_value) 1326
1321 dur = INT_MAX; 1327 if (INT_MAX < ats->max_exec_duration.rel_value)
1322 else 1328 dur = INT_MAX;
1323 dur = (int) ats->max_exec_duration.rel_value; 1329 else
1330 dur = (int) ats->max_exec_duration.rel_value;
1324#endif 1331#endif
1325 1332
1326 ats->internal.simplex_rerun_required = GNUNET_NO; 1333 ats->internal.simplex_rerun_required = GNUNET_NO;
1327 start = GNUNET_TIME_absolute_get(); 1334 start = GNUNET_TIME_absolute_get ();
1328 if ((ats->internal.recreate_problem == GNUNET_YES) || 1335 if ((ats->internal.recreate_problem == GNUNET_YES) ||
1329 (ats->prob==NULL) || 1336 (ats->prob == NULL) || (ats->internal.valid == GNUNET_NO))
1330 (ats->internal.valid == GNUNET_NO)) 1337 {
1331 { 1338 text = "new";
1332 text = "new"; 1339 ats->internal.recreate_problem = GNUNET_YES;
1333 ats->internal.recreate_problem = GNUNET_YES; 1340 ats_delete_problem (ats);
1334 ats_delete_problem (ats); 1341 ats->addr_notification (&ats->peers, &c_p, &ats->mechanisms, &c_m);
1335 ats->addr_notification(&ats->peers , &c_p, &ats->mechanisms, &c_m);
1336#if DEBUG_ATS 1342#if DEBUG_ATS
1337 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1343 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1338 "Service returned: %i peer, %i mechs\n", 1344 "Service returned: %i peer, %i mechs\n", c_p, c_m);
1339 c_p,
1340 c_m);
1341#endif 1345#endif
1342 ats_create_problem (ats, &ats->internal, ats->peers, c_p, ats->mechanisms, c_m); 1346 ats_create_problem (ats, &ats->internal, ats->peers, c_p, ats->mechanisms,
1347 c_m);
1343 1348
1344 1349
1345#if DEBUG_ATS 1350#if DEBUG_ATS
1346 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1351 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1347 "Peers/Addresses were modified... new problem: %i peer, %i mechs\n", 1352 "Peers/Addresses were modified... new problem: %i peer, %i mechs\n",
1348 ats->internal.c_peers, 1353 ats->internal.c_peers, ats->internal.c_mechs);
1349 ats->internal.c_mechs);
1350#endif 1354#endif
1351 } 1355 }
1352 1356
1353 else if ((ats->internal.recreate_problem == GNUNET_NO) && 1357 else if ((ats->internal.recreate_problem == GNUNET_NO) &&
1354 (ats->internal.modified_resources == GNUNET_YES) && 1358 (ats->internal.modified_resources == GNUNET_YES) &&
1355 (ats->internal.valid == GNUNET_YES)) 1359 (ats->internal.valid == GNUNET_YES))
1356 { 1360 {
1357 text = "modified resources"; 1361 text = "modified resources";
1358 ats_update_problem_cr (ats); 1362 ats_update_problem_cr (ats);
1359 } 1363 }
1360 else if ((ats->internal.recreate_problem == GNUNET_NO) && 1364 else if ((ats->internal.recreate_problem == GNUNET_NO) &&
1361 (ats->internal.modified_quality == GNUNET_YES) && 1365 (ats->internal.modified_quality == GNUNET_YES) &&
1362 (ats->internal.valid == GNUNET_YES)) 1366 (ats->internal.valid == GNUNET_YES))
1363 { 1367 {
1364 text = "modified quality"; 1368 text = "modified quality";
1365 ats_update_problem_qm (ats); 1369 ats_update_problem_qm (ats);
1366 //ats_update_problem_qm_TEST (); 1370 //ats_update_problem_qm_TEST ();
1367 } 1371 }
1368#if DEBUG_ATS 1372#if DEBUG_ATS
1369 else GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Problem is %s\n", text); 1373 else
1374 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Problem is %s\n", text);
1370#endif 1375#endif
1371 1376
1372 creation = GNUNET_TIME_absolute_get_difference(start,GNUNET_TIME_absolute_get()); 1377 creation =
1373 start = GNUNET_TIME_absolute_get(); 1378 GNUNET_TIME_absolute_get_difference (start, GNUNET_TIME_absolute_get ());
1379 start = GNUNET_TIME_absolute_get ();
1374 1380
1375 ats->internal.solution = GLP_UNDEF; 1381 ats->internal.solution = GLP_UNDEF;
1376 if (ats->internal.valid == GNUNET_YES) 1382 if (ats->internal.valid == GNUNET_YES)
1377 { 1383 {
1378 ats_solve_problem(ats, 1384 ats_solve_problem (ats,
1379 ats->max_iterations, 1385 ats->max_iterations,
1380 ats->max_exec_duration.rel_value, 1386 ats->max_exec_duration.rel_value,
1381 ats->internal.c_peers, 1387 ats->internal.c_peers,
1382 ats->internal.c_mechs, 1388 ats->internal.c_mechs, &ats->internal);
1383 &ats->internal); 1389 }
1384 } 1390 solving =
1385 solving = GNUNET_TIME_absolute_get_difference(start,GNUNET_TIME_absolute_get()); 1391 GNUNET_TIME_absolute_get_difference (start, GNUNET_TIME_absolute_get ());
1386 1392
1387 if (ats->internal.valid == GNUNET_YES) 1393 if (ats->internal.valid == GNUNET_YES)
1388 { 1394 {
1389 /* Telling about new distribution*/ 1395 /* Telling about new distribution */
1390 ats->result_cb (); 1396 ats->result_cb ();
1397
1398 int msg_type = GNUNET_ERROR_TYPE_DEBUG;
1391 1399
1392 int msg_type = GNUNET_ERROR_TYPE_DEBUG;
1393#if DEBUG_ATS 1400#if DEBUG_ATS
1394 msg_type = GNUNET_ERROR_TYPE_ERROR; 1401 msg_type = GNUNET_ERROR_TYPE_ERROR;
1395#endif 1402#endif
1396 GNUNET_log (msg_type, 1403 GNUNET_log (msg_type,
1397 "MLP %s: creation time: %llu, execution time: %llu, %i peers, %i mechanisms, simplex rerun: %s, solution %s\n", 1404 "MLP %s: creation time: %llu, execution time: %llu, %i peers, %i mechanisms, simplex rerun: %s, solution %s\n",
1398 text, 1405 text,
1399 creation.rel_value, 1406 creation.rel_value,
1400 solving.rel_value, 1407 solving.rel_value,
1401 ats->internal.c_peers, 1408 ats->internal.c_peers,
1402 ats->internal.c_mechs, 1409 ats->internal.c_mechs,
1403 (ats->internal.simplex_rerun_required == GNUNET_NO) ? "NO" : "YES", 1410 (ats->internal.simplex_rerun_required ==
1404 (ats->internal.solution == 5) ? "OPTIMAL" : "INVALID"); 1411 GNUNET_NO) ? "NO" : "YES",
1405 ats->successful_executions ++; 1412 (ats->internal.solution == 5) ? "OPTIMAL" : "INVALID");
1413 ats->successful_executions++;
1414 GNUNET_STATISTICS_set (ats->stats, "# ATS successful executions",
1415 ats->successful_executions, GNUNET_NO);
1416
1417 if ((ats->internal.recreate_problem == GNUNET_YES) || (ats->prob == NULL))
1418 GNUNET_STATISTICS_set (ats->stats, "ATS state", ATS_NEW, GNUNET_NO);
1419 else if ((ats->internal.modified_resources == GNUNET_YES) &&
1420 (ats->internal.modified_quality == GNUNET_NO))
1421 GNUNET_STATISTICS_set (ats->stats, "ATS state", ATS_COST_UPDATED,
1422 GNUNET_NO);
1423 else if ((ats->internal.modified_resources == GNUNET_NO) &&
1424 (ats->internal.modified_quality == GNUNET_YES) &&
1425 (ats->internal.simplex_rerun_required == GNUNET_NO))
1426 GNUNET_STATISTICS_set (ats->stats, "ATS state", ATS_QUALITY_UPDATED,
1427 GNUNET_NO);
1428 else if ((ats->internal.modified_resources == GNUNET_YES) &&
1429 (ats->internal.modified_quality == GNUNET_YES) &&
1430 (ats->internal.simplex_rerun_required == GNUNET_NO))
1431 GNUNET_STATISTICS_set (ats->stats, "ATS state", ATS_QUALITY_COST_UPDATED,
1432 GNUNET_NO);
1433 else if (ats->internal.simplex_rerun_required == GNUNET_NO)
1434 GNUNET_STATISTICS_set (ats->stats, "ATS state", ATS_UNMODIFIED,
1435 GNUNET_NO);
1436 }
1437 else
1438 {
1439 if (ats->internal.c_peers != 0)
1440 {
1441 ats->invalid_executions++;
1442 GNUNET_STATISTICS_set (ats->stats, "# ATS invalid executions",
1443 ats->invalid_executions, GNUNET_NO);
1444 }
1445 else
1446 {
1406 GNUNET_STATISTICS_set (ats->stats, "# ATS successful executions", 1447 GNUNET_STATISTICS_set (ats->stats, "# ATS successful executions",
1407 ats->successful_executions, 1448 ats->successful_executions, GNUNET_NO);
1408 GNUNET_NO); 1449 }
1409 1450 }
1410 if ((ats->internal.recreate_problem == GNUNET_YES) || (ats->prob==NULL)) 1451
1411 GNUNET_STATISTICS_set (ats->stats, "ATS state",ATS_NEW, GNUNET_NO); 1452 GNUNET_STATISTICS_set (ats->stats,
1412 else if ((ats->internal.modified_resources == GNUNET_YES) && 1453 "ATS duration", solving.rel_value + creation.rel_value,
1413 (ats->internal.modified_quality == GNUNET_NO)) 1454 GNUNET_NO);
1414 GNUNET_STATISTICS_set (ats->stats, "ATS state", ATS_COST_UPDATED, GNUNET_NO); 1455 GNUNET_STATISTICS_set (ats->stats, "ATS mechanisms", ats->internal.c_mechs,
1415 else if ((ats->internal.modified_resources == GNUNET_NO) && 1456 GNUNET_NO);
1416 (ats->internal.modified_quality == GNUNET_YES) && 1457 GNUNET_STATISTICS_set (ats->stats, "ATS peers", ats->internal.c_peers,
1417 (ats->internal.simplex_rerun_required == GNUNET_NO)) 1458 GNUNET_NO);
1418 GNUNET_STATISTICS_set (ats->stats, "ATS state", ATS_QUALITY_UPDATED, GNUNET_NO); 1459 GNUNET_STATISTICS_set (ats->stats, "ATS solution", ats->internal.solution,
1419 else if ((ats->internal.modified_resources == GNUNET_YES) && 1460 GNUNET_NO);
1420 (ats->internal.modified_quality == GNUNET_YES) && 1461 GNUNET_STATISTICS_set (ats->stats, "ATS timestamp", start.abs_value,
1421 (ats->internal.simplex_rerun_required == GNUNET_NO)) 1462 GNUNET_NO);
1422 GNUNET_STATISTICS_set (ats->stats, "ATS state", ATS_QUALITY_COST_UPDATED, GNUNET_NO); 1463
1423 else if (ats->internal.simplex_rerun_required == GNUNET_NO) 1464 if ((ats->save_mlp == GNUNET_YES) &&
1424 GNUNET_STATISTICS_set (ats->stats, "ATS state", ATS_UNMODIFIED, GNUNET_NO); 1465 (ats->internal.c_mechs >= ats->dump_min_peers) &&
1466 (ats->internal.c_mechs >= ats->dump_min_addr))
1467 {
1468 char *filename;
1469
1470 if (ats->dump_overwrite == GNUNET_NO)
1471 {
1472 GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i_%s_%llu.mlp",
1473 ats->internal.c_peers,
1474 ats->internal.c_mechs,
1475 text, GNUNET_TIME_absolute_get ().abs_value);
1476 _lp_write_lp ((void *) ats->prob, NULL, filename);
1425 } 1477 }
1426 else 1478 else
1427 { 1479 {
1428 if (ats->internal.c_peers != 0) 1480 GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i.mlp",
1429 { 1481 ats->internal.c_peers, ats->internal.c_mechs);
1430 ats->invalid_executions ++; 1482 _lp_write_lp ((void *) ats->prob, NULL, filename);
1431 GNUNET_STATISTICS_set (ats->stats, "# ATS invalid executions",
1432 ats->invalid_executions, GNUNET_NO);
1433 }
1434 else
1435 {
1436 GNUNET_STATISTICS_set (ats->stats, "# ATS successful executions",
1437 ats->successful_executions, GNUNET_NO);
1438 }
1439 } 1483 }
1484 GNUNET_free (filename);
1485 }
1486 if ((ats->save_solution == GNUNET_YES) &&
1487 (ats->internal.c_mechs >= ats->dump_min_peers) &&
1488 (ats->internal.c_mechs >= ats->dump_min_addr))
1489 {
1490 char *filename;
1440 1491
1441 GNUNET_STATISTICS_set (ats->stats, 1492 if (ats->dump_overwrite == GNUNET_NO)
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);
1451
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))
1455 { 1493 {
1456 char * filename; 1494 GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i_%s_%llu.sol",
1457 if (ats->dump_overwrite == GNUNET_NO) 1495 ats->internal.c_peers,
1458 { 1496 ats->internal.c_mechs,
1459 GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i_%s_%llu.mlp", 1497 text, GNUNET_TIME_absolute_get ().abs_value);
1460 ats->internal.c_peers, 1498 _lp_print_sol (ats->prob, filename);
1461 ats->internal.c_mechs,
1462 text,
1463 GNUNET_TIME_absolute_get().abs_value);
1464 _lp_write_lp ((void *) ats->prob, NULL, filename);
1465 }
1466 else
1467 {
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);
1471 }
1472 GNUNET_free (filename);
1473 } 1499 }
1474 if ((ats->save_solution == GNUNET_YES) && 1500 else
1475 (ats->internal.c_mechs >= ats->dump_min_peers) &&
1476 (ats->internal.c_mechs >= ats->dump_min_addr))
1477 { 1501 {
1478 char * filename; 1502 GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i.sol",
1479 if (ats->dump_overwrite == GNUNET_NO) 1503 ats->internal.c_peers, ats->internal.c_mechs);
1480 { 1504 _lp_print_sol (ats->prob, filename);
1481 GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i_%s_%llu.sol",
1482 ats->internal.c_peers,
1483 ats->internal.c_mechs,
1484 text,
1485 GNUNET_TIME_absolute_get().abs_value);
1486 _lp_print_sol (ats->prob, filename);
1487 }
1488 else
1489 {
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);
1493 }
1494 GNUNET_free (filename);
1495 } 1505 }
1506 GNUNET_free (filename);
1507 }
1496 1508
1497 ats->internal.recreate_problem = GNUNET_NO; 1509 ats->internal.recreate_problem = GNUNET_NO;
1498 ats->internal.modified_resources = GNUNET_NO; 1510 ats->internal.modified_resources = GNUNET_NO;
1499 ats->internal.modified_quality = GNUNET_NO; 1511 ats->internal.modified_quality = GNUNET_NO;
1500} 1512}
1501 1513
1502/** 1514/**
@@ -1508,198 +1520,188 @@ ats_calculate_bandwidth_distribution (struct ATS_Handle * ats)
1508 * valid 1520 * valid
1509 */ 1521 */
1510 1522
1511int ats_evaluate_results (int result, int solution, char * problem) 1523int
1524ats_evaluate_results (int result, int solution, char *problem)
1512{ 1525{
1513 int cont = GNUNET_NO; 1526 int cont = GNUNET_NO;
1527
1514#if DEBUG_ATS || VERBOSE_ATS 1528#if DEBUG_ATS || VERBOSE_ATS
1515 int error_kind = GNUNET_ERROR_TYPE_DEBUG; 1529 int error_kind = GNUNET_ERROR_TYPE_DEBUG;
1516#endif 1530#endif
1517#if VERBOSE_ATS 1531#if VERBOSE_ATS
1518 error_kind = GNUNET_ERROR_TYPE_ERROR; 1532 error_kind = GNUNET_ERROR_TYPE_ERROR;
1519#endif 1533#endif
1520 switch (result) { 1534 switch (result)
1521 case GNUNET_SYSERR : /* GNUNET problem, not GLPK related */ 1535 {
1536 case GNUNET_SYSERR: /* GNUNET problem, not GLPK related */
1522#if DEBUG_ATS || VERBOSE_ATS 1537#if DEBUG_ATS || VERBOSE_ATS
1523 GNUNET_log (error_kind, 1538 GNUNET_log (error_kind, "%s, GLPK solving not executed\n", problem);
1524 "%s, GLPK solving not executed\n", problem);
1525#endif 1539#endif
1526 break; 1540 break;
1527 case GLP_ESTOP : /* search terminated by application */ 1541 case GLP_ESTOP: /* search terminated by application */
1528#if DEBUG_ATS || VERBOSE_ATS 1542#if DEBUG_ATS || VERBOSE_ATS
1529 GNUNET_log (error_kind, 1543 GNUNET_log (error_kind, "%s , Search terminated by application\n", problem);
1530 "%s , Search terminated by application\n", problem);
1531#endif 1544#endif
1532 break; 1545 break;
1533 case GLP_EITLIM : /* iteration limit exceeded */ 1546 case GLP_EITLIM: /* iteration limit exceeded */
1534#if DEBUG_ATS || VERBOSE_ATS 1547#if DEBUG_ATS || VERBOSE_ATS
1535 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1548 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1536 "%s Iteration limit exceeded\n", problem); 1549 "%s Iteration limit exceeded\n", problem);
1537#endif 1550#endif
1538 break; 1551 break;
1539 case GLP_ETMLIM : /* time limit exceeded */ 1552 case GLP_ETMLIM: /* time limit exceeded */
1540#if DEBUG_ATS || VERBOSE_ATS 1553#if DEBUG_ATS || VERBOSE_ATS
1541 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1554 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s Time limit exceeded\n", problem);
1542 "%s Time limit exceeded\n", problem);
1543#endif 1555#endif
1544 break; 1556 break;
1545 case GLP_ENOPFS : /* no primal feasible solution */ 1557 case GLP_ENOPFS: /* no primal feasible solution */
1546 case GLP_ENODFS : /* no dual feasible solution */ 1558 case GLP_ENODFS: /* no dual feasible solution */
1547#if DEBUG_ATS || VERBOSE_ATS 1559#if DEBUG_ATS || VERBOSE_ATS
1548 GNUNET_log (error_kind, 1560 GNUNET_log (error_kind, "%s No feasible solution\n", problem);
1549 "%s No feasible solution\n", problem); 1561#endif
1550#endif 1562 break;
1551 break; 1563 case GLP_EBADB: /* invalid basis */
1552 case GLP_EBADB : /* invalid basis */ 1564 case GLP_ESING: /* singular matrix */
1553 case GLP_ESING : /* singular matrix */ 1565 case GLP_ECOND: /* ill-conditioned matrix */
1554 case GLP_ECOND : /* ill-conditioned matrix */ 1566 case GLP_EBOUND: /* invalid bounds */
1555 case GLP_EBOUND : /* invalid bounds */ 1567 case GLP_EFAIL: /* solver failed */
1556 case GLP_EFAIL : /* solver failed */ 1568 case GLP_EOBJLL: /* objective lower limit reached */
1557 case GLP_EOBJLL : /* objective lower limit reached */ 1569 case GLP_EOBJUL: /* objective upper limit reached */
1558 case GLP_EOBJUL : /* objective upper limit reached */ 1570 case GLP_EROOT: /* root LP optimum not provided */
1559 case GLP_EROOT : /* root LP optimum not provided */
1560#if DEBUG_ATS || VERBOSE_ATS 1571#if DEBUG_ATS || VERBOSE_ATS
1561 GNUNET_log (error_kind, 1572 GNUNET_log (error_kind, "%s Invalid Input data: %i\n", problem, result);
1562 "%s Invalid Input data: %i\n",
1563 problem, result);
1564#endif 1573#endif
1565 break; 1574 break;
1566 case 0: 1575 case 0:
1567#if DEBUG_ATS || VERBOSE_ATS 1576#if DEBUG_ATS || VERBOSE_ATS
1568 GNUNET_log (error_kind, 1577 GNUNET_log (error_kind, "%s Problem has been solved\n", problem);
1569 "%s Problem has been solved\n", problem);
1570#endif 1578#endif
1571 break; 1579 break;
1572 } 1580 }
1573 1581
1574 switch (solution) { 1582 switch (solution)
1575 case GLP_UNDEF: 1583 {
1584 case GLP_UNDEF:
1576#if DEBUG_ATS || VERBOSE_ATS 1585#if DEBUG_ATS || VERBOSE_ATS
1577 GNUNET_log (error_kind, 1586 GNUNET_log (error_kind, "%s solution is undefined\n", problem);
1578 "%s solution is undefined\n", problem);
1579#endif 1587#endif
1580 break; 1588 break;
1581 case GLP_OPT: 1589 case GLP_OPT:
1582#if DEBUG_ATS || VERBOSE_ATS 1590#if DEBUG_ATS || VERBOSE_ATS
1583 GNUNET_log (error_kind, 1591 GNUNET_log (error_kind, "%s solution is optimal\n", problem);
1584 "%s solution is optimal\n", problem);
1585#endif 1592#endif
1586 cont=GNUNET_YES; 1593 cont = GNUNET_YES;
1587 break; 1594 break;
1588 case GLP_FEAS: 1595 case GLP_FEAS:
1589#if DEBUG_ATS || VERBOSE_ATS 1596#if DEBUG_ATS || VERBOSE_ATS
1590 GNUNET_log (error_kind, 1597 GNUNET_log (error_kind,
1591 "%s solution is %s feasible, however, its optimality (or non-optimality) has not been proven\n", 1598 "%s solution is %s feasible, however, its optimality (or non-optimality) has not been proven\n",
1592 problem, (0==strcmp(problem,"LP")?"":"integer")); 1599 problem, (0 == strcmp (problem, "LP") ? "" : "integer"));
1593#endif 1600#endif
1594 cont=GNUNET_YES; 1601 cont = GNUNET_YES;
1595 break; 1602 break;
1596 case GLP_NOFEAS: 1603 case GLP_NOFEAS:
1597#if DEBUG_ATS || VERBOSE_ATS 1604#if DEBUG_ATS || VERBOSE_ATS
1598 GNUNET_log (error_kind, "%s problem has no %sfeasible solution\n", 1605 GNUNET_log (error_kind, "%s problem has no %sfeasible solution\n",
1599 problem, (0==strcmp(problem,"LP")?"":"integer ")); 1606 problem, (0 == strcmp (problem, "LP") ? "" : "integer "));
1600#endif 1607#endif
1601 break; 1608 break;
1602 case GLP_INFEAS: 1609 case GLP_INFEAS:
1603#if DEBUG_ATS || VERBOSE_ATS 1610#if DEBUG_ATS || VERBOSE_ATS
1604 GNUNET_log (error_kind, "%s problem is infeasible \n", problem); 1611 GNUNET_log (error_kind, "%s problem is infeasible \n", problem);
1605#endif 1612#endif
1606 break; 1613 break;
1607 case GLP_UNBND: 1614 case GLP_UNBND:
1608#if DEBUG_ATS || VERBOSE_ATS 1615#if DEBUG_ATS || VERBOSE_ATS
1609 GNUNET_log (error_kind, "%s problem is unbounded \n", problem); 1616 GNUNET_log (error_kind, "%s problem is unbounded \n", problem);
1610#endif 1617#endif
1611 default: 1618 default:
1612 break; 1619 break;
1613 } 1620 }
1614return cont; 1621 return cont;
1615} 1622}
1616 1623
1617void ats_update_problem_cr (struct ATS_Handle * ats) 1624void
1625ats_update_problem_cr (struct ATS_Handle *ats)
1618{ 1626{
1619 int array_index; 1627 int array_index;
1620 int row_index; 1628 int row_index;
1621 int c, c2; 1629 int c, c2;
1622 double ct_max, ct_min; 1630 double ct_max, ct_min;
1623
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));
1628
1629 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updating problem quality metrics\n");
1630 row_index = ats->internal.begin_cr;
1631 array_index = 1;
1632 1631
1633 for (c=0; c<available_ressources; c++) 1632 int *ja = GNUNET_malloc ((1 + ats->internal.c_mechs * 2 + 3 +
1634 { 1633 available_quality_metrics) * sizeof (int));
1635 ct_max = ressources[c].c_max; 1634 double *ar = GNUNET_malloc ((1 + ats->internal.c_mechs * 2 + 3 +
1636 ct_min = ressources[c].c_min; 1635 available_quality_metrics) * sizeof (double));
1636
1637 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updating problem quality metrics\n");
1638 row_index = ats->internal.begin_cr;
1639 array_index = 1;
1640
1641 for (c = 0; c < available_ressources; c++)
1642 {
1643 ct_max = ressources[c].c_max;
1644 ct_min = ressources[c].c_min;
1637#if VERBOSE_ATS 1645#if VERBOSE_ATS
1638 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] %f..%f\n", 1646 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] %f..%f\n",
1639 row_index, 1647 row_index, ct_min, ct_max);
1640 ct_min,
1641 ct_max);
1642#endif 1648#endif
1643 _lp_set_row_bnds(ats->prob, row_index, GLP_DB, ct_min, ct_max); 1649 _lp_set_row_bnds (ats->prob, row_index, GLP_DB, ct_min, ct_max);
1644 for (c2=1; c2<=ats->internal.c_mechs; c2++) 1650 for (c2 = 1; c2 <= ats->internal.c_mechs; c2++)
1645 { 1651 {
1646 double value = 0; 1652 double value = 0;
1647 GNUNET_assert (ats->mechanisms[c2].addr != NULL); 1653
1648 GNUNET_assert (ats->mechanisms[c2].peer != NULL); 1654 GNUNET_assert (ats->mechanisms[c2].addr != NULL);
1655 GNUNET_assert (ats->mechanisms[c2].peer != NULL);
1649 1656
1650 ja[array_index] = c2; 1657 ja[array_index] = c2;
1651 value = ats->mechanisms[c2].ressources[c].c; 1658 value = ats->mechanisms[c2].ressources[c].c;
1652 ar[array_index] = value; 1659 ar[array_index] = value;
1653#if VERBOSE_ATS 1660#if VERBOSE_ATS
1654 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 1661 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
1655 array_index, 1662 array_index, row_index, ja[array_index], ar[array_index]);
1656 row_index,
1657 ja[array_index],
1658 ar[array_index]);
1659#endif 1663#endif
1660 array_index++; 1664 array_index++;
1661 }
1662 _lp_set_mat_row (ats->prob, row_index, array_index, ja, ar);
1663 row_index ++;
1664 } 1665 }
1665 GNUNET_free_non_null (ja); 1666 _lp_set_mat_row (ats->prob, row_index, array_index, ja, ar);
1666 GNUNET_free_non_null (ar); 1667 row_index++;
1668 }
1669 GNUNET_free_non_null (ja);
1670 GNUNET_free_non_null (ar);
1667 1671
1668} 1672}
1669 1673
1670void ats_set_logging_options (struct ATS_Handle * ats, 1674void
1671 struct GNUNET_STATISTICS_Handle * stats, 1675ats_set_logging_options (struct ATS_Handle *ats,
1672 const struct GNUNET_CONFIGURATION_Handle *cfg) 1676 struct GNUNET_STATISTICS_Handle *stats,
1677 const struct GNUNET_CONFIGURATION_Handle *cfg)
1673{ 1678{
1674 int minimum_addresses; 1679 int minimum_addresses;
1675 int minimum_peers; 1680 int minimum_peers;
1676 int overwrite_dump; 1681 int overwrite_dump;
1677 int log_solution; 1682 int log_solution;
1678 int log_problem; 1683 int log_problem;
1679 unsigned long long value; 1684 unsigned long long value;
1680 1685
1681 if (ats == NULL) 1686 if (ats == NULL)
1682 return; 1687 return;
1683 log_problem = GNUNET_CONFIGURATION_get_value_yesno (cfg, 1688 log_problem = GNUNET_CONFIGURATION_get_value_yesno (cfg,
1684 "transport", 1689 "transport", "DUMP_MLP");
1685 "DUMP_MLP");
1686 log_solution = GNUNET_CONFIGURATION_get_value_yesno (cfg, 1690 log_solution = GNUNET_CONFIGURATION_get_value_yesno (cfg,
1687 "transport", 1691 "transport",
1688 "DUMP_SOLUTION"); 1692 "DUMP_SOLUTION");
1689 overwrite_dump = GNUNET_CONFIGURATION_get_value_yesno (cfg, 1693 overwrite_dump = GNUNET_CONFIGURATION_get_value_yesno (cfg,
1690 "transport", 1694 "transport",
1691 "DUMP_OVERWRITE"); 1695 "DUMP_OVERWRITE");
1692 if (GNUNET_OK == 1696 if (GNUNET_OK ==
1693 GNUNET_CONFIGURATION_get_value_number(cfg, 1697 GNUNET_CONFIGURATION_get_value_number (cfg,
1694 "transport", 1698 "transport",
1695 "DUMP_MIN_PEERS", 1699 "DUMP_MIN_PEERS", &value))
1696 &value))
1697 minimum_peers = (int) value; 1700 minimum_peers = (int) value;
1698 if (GNUNET_OK == 1701 if (GNUNET_OK ==
1699 GNUNET_CONFIGURATION_get_value_number(cfg, 1702 GNUNET_CONFIGURATION_get_value_number (cfg,
1700 "transport", 1703 "transport",
1701 "DUMP_MIN_ADDRS", 1704 "DUMP_MIN_ADDRS", &value))
1702 &value))
1703 minimum_addresses = (int) value; 1705 minimum_addresses = (int) value;
1704 1706
1705 1707
@@ -1712,64 +1714,58 @@ void ats_set_logging_options (struct ATS_Handle * ats,
1712} 1714}
1713 1715
1714#if 0 1716#if 0
1715static void ats_update_problem_qm_TEST () 1717static void
1718ats_update_problem_qm_TEST ()
1716{ 1719{
1717 int row_index; 1720 int row_index;
1718 int c 1721 int c int c2;
1719 int c2; 1722 int c_old;
1720 int c_old; 1723 int changed = 0;
1721 int changed = 0; 1724
1722 1725 int old_ja[ats->internal.c_mechs + 2];
1723 int old_ja[ats->internal.c_mechs + 2]; 1726 double old_ar[ats->internal.c_mechs + 2];
1724 double old_ar[ats->internal.c_mechs + 2]; 1727
1725 1728 int *ja = GNUNET_malloc ((1 + ats->internal.c_mechs * 2 + 3 +
1726 int *ja = GNUNET_malloc ((1 + ats->internal.c_mechs*2 + 3 + 1729 available_quality_metrics) * sizeof (int));
1727 available_quality_metrics) * sizeof (int)); 1730 double *ar = GNUNET_malloc ((1 + ats->internal.c_mechs * 2 + 3 +
1728 double *ar = GNUNET_malloc ((1 + ats->internal.c_mechs*2 + 3 + 1731 available_quality_metrics) * sizeof (double));
1729 available_quality_metrics) * sizeof (double));
1730#if DEBUG_ATS 1732#if DEBUG_ATS
1731 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1733 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1732 "Updating problem quality metrics TEST\n"); 1734 "Updating problem quality metrics TEST\n");
1733#endif 1735#endif
1734 if (ats->internal.begin_qm >0) 1736 if (ats->internal.begin_qm > 0)
1735 row_index = ats->internal.begin_qm; 1737 row_index = ats->internal.begin_qm;
1736 else 1738 else
1737 return; 1739 return;
1738 for (c=0; c<available_quality_metrics; c++) 1740 for (c = 0; c < available_quality_metrics; c++)
1741 {
1742 c_old = _lp_get_mat_row (ats->prob, row_index, old_ja, old_ar);
1743 _lp_set_row_bnds (ats->prob, row_index, GLP_FX, 0.0, 0.0);
1744 for (c2 = 1; c2 <= c_old; c2++)
1739 { 1745 {
1740 c_old = _lp_get_mat_row (ats->prob, row_index, old_ja, old_ar); 1746 ja[c2] = old_ja[c2];
1741 _lp_set_row_bnds(ats->prob, row_index, GLP_FX, 0.0, 0.0); 1747 if ((changed < 3) && (c2 > 2) && (old_ar[c2] != -1))
1742 for (c2=1; c2<=c_old; c2++)
1743 { 1748 {
1744 ja[c2] = old_ja[c2]; 1749 ar[c2] = old_ar[c2] + 5 - changed;
1745 if ((changed < 3) && (c2>2) && (old_ar[c2] != -1)) 1750 changed++;
1746 { 1751 }
1747 ar[c2] = old_ar[c2] + 5 - changed; 1752 else
1748 changed ++; 1753 ar[c2] = old_ar[c2];
1749 }
1750 else
1751 ar[c2] = old_ar[c2];
1752#if VERBOSE_ATS 1754#if VERBOSE_ATS
1753 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1755 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1754 "[index]=[%i]: old [%i,%i]=%f new [%i,%i]=%f\n", 1756 "[index]=[%i]: old [%i,%i]=%f new [%i,%i]=%f\n",
1755 c2, 1757 c2,
1756 row_index, 1758 row_index, old_ja[c2], old_ar[c2], row_index, ja[c2], ar[c2]);
1757 old_ja[c2], 1759#endif
1758 old_ar[c2],
1759 row_index,
1760 ja[c2],
1761 ar[c2]);
1762#endif
1763 }
1764 _lp_set_mat_row (ats->prob, row_index, c_old, ja, ar);
1765 row_index ++;
1766 } 1760 }
1767 GNUNET_free_non_null (ja); 1761 _lp_set_mat_row (ats->prob, row_index, c_old, ja, ar);
1768 GNUNET_free_non_null (ar); 1762 row_index++;
1763 }
1764 GNUNET_free_non_null (ja);
1765 GNUNET_free_non_null (ar);
1769} 1766}
1770#endif 1767#endif
1771 1768
1772 1769
1773 1770
1774/* end of transport_ats.c */ 1771/* end of transport_ats.c */
1775