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