2 This file is part of GNUnet.
3 (C) 2011 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file ats/plugin_ats_mlp.c
23 * @brief ats mlp problem solver
24 * @author Matthias Wachs
25 * @author Christian Grothoff
28 #include "plugin_ats_mlp.h"
33 * NOTE: Do not modify this documentation. This documentation is based on
34 * gnunet.org:/vcs/fsnsg/ats-paper.git/tech-doku/ats-tech-guide.tex
35 * use build_txt.sh to generate plaintext output
37 * The MLP solver (mlp) tries to finds an optimal bandwidth assignmentby
38 * optimizing an mixed integer programming problem. The MLP solver uses a
39 * number of constraints to find the best adddress for a peer and an optimal
40 * bandwidth assignment. mlp uses the GNU Linear Programming Kit to solve the
43 * We defined a constraint system to find an optimal bandwidth assignment.
44 * This constraint system uses as an input data addresses, bandwidth quotas,
45 * preferences and quality values. This constraint system is stored in an
46 * matrix based equotation system.
50 * A (M)LP problem consists of a target function to optimizes, constraints
51 * and rows and columns. FIXME GLP uses three arrays to index the matrix: two
52 * integer arrays storing the row and column indices in the matrix and an
53 * float array to store the coeeficient.
55 * To solve the problem we first find an initial solution for the LP problem
56 * using the LP solver and then find an MLP solution based on this solution
57 * using the MLP solver.
59 * Solving (M)LP problems has the property that finding an initial solution
60 * for the LP problem is computationally expensive and finding the MLP
61 * solution is cheaper. This is especially interesting an existing LP
62 * solution can be reused if only coefficients in the matrix have changed
63 * (addresses updated). Only when the problem size changes (addresses added
64 * or deleted) a new LP solution has to be found.
67 * The mlp solver solves the bandwidth assignment problem only on demand when
68 * an address suggestion is requested. When an address is requested mlp the
69 * solves the mlp problem and if the active address or the bandwidth assigned
70 * changes it calls the callback to addresses. The mlp solver gets notified
71 * about new addresses (adding sessions), removed addresses (address
72 * deletions) and address updates. To benefit from the mlp properties
73 * mentioned in section 5 the solver rembers if since the last solution
74 * addresses were added or deleted (problem size changed, problem has to be
75 * rebuild and solved from sratch) or if addresses were updated and the
76 * existing solution can be reused.
80 * The quotas for each network segment are passed by addresses. MLP can be
81 * adapted using configuration settings and uses the following parameters:
83 * Maximum duration for a MLP solution procees (default: 3 sec.)
84 * * MLP_MAX_ITERATIONS:
85 * Maximum number of iterations for a MLP solution process (default:
87 * * MLP_MIN_CONNECTIONS:
88 * Minimum number of desired connections (default: 4)
89 * * MLP_MIN_BANDWIDTH:
90 * Minimum amount of bandwidth assigned to an address (default: 1024)
91 * * MLP_COEFFICIENT_D:
92 * Diversity coefficient (default: 1.0)
93 * * MLP_COEFFICIENT_R:
94 * Relativity coefficient (default: 1.0)
95 * * MLP_COEFFICIENT_U:
96 * Utilization coefficient (default: 1.0)
97 * * MLP_COEFFICIENT_D:
98 * Diversity coefficient (default: 1.0)
99 * * MLP_COEFFICIENT_QUALITY_DELAY:
100 * Quality delay coefficient (default: 1.0)
101 * * MLP_COEFFICIENT_QUALITY_DISTANCE:
102 * Quality distance coefficient (default: 1.0)
103 * * MLP_COEFFICIENT_QUALITY_DISTANCE:
104 * Quality distance coefficient (default: 1.0)
105 * * MLP_COEFFICIENT_QUALITY_DISTANCE:
106 * Quality distance coefficient (default: 1.0)
107 * * MLP_COEFFICIENT_QUALITY_DISTANCE:
108 * Quality distance coefficient (default: 1.0)
110 * 5.2 Data structures used
112 * mlp has for each known peer a struct ATS_Peer containing information about
113 * a specific peer. The address field solver_information contains information
114 * about the mlp properties of this address.
118 * During initialization mlp initializes the GLPK libray used to solve the
119 * MLP problem: it initializes the glpk environment and creates an initial LP
120 * problem. Next it loads the configuration values from the configuration or
121 * uses the default values configured in -addresses_mlp.h. The quotas used
122 * are given by addresses but may have to be adjusted. mlp uses a upper limit
123 * for the bandwidth assigned called BIG M and a minimum amount of bandwidth
124 * an address gets assigned as well as a minium desired number of
125 * connections. If the configured quota is bigger than BIG M, it is reduced
126 * to BIG M. If the configured quota is smaller than MLP_MIN_CONNECTIONS
127 * *MLP_MIN_BANDWIDTH it is increased to this value.
133 #define LOG(kind,...) GNUNET_log_from (kind, "ats-mlp",__VA_ARGS__)
136 * Print debug output for mlp problem creation
138 #define DEBUG_MLP_PROBLEM_CREATION GNUNET_NO
142 * Maximize bandwidth assigned
144 * This option can be used to test if problem can be solved at all without
145 * optimizing for utility, diversity or relativity
148 #define MAXIMIZE_FOR_BANDWIDTH_ASSIGNED GNUNET_NO
151 * Intercept GLPK terminal output
152 * @param info the mlp handle
153 * @param s the string to print
154 * @return 0: glpk prints output on terminal, 0 != surpress output
157 mlp_term_hook (void *info, const char *s)
159 /* Not needed atm struct MLP_information *mlp = info; */
160 LOG (GNUNET_ERROR_TYPE_ERROR, "%s", s);
166 * Reset peers for next problem creation
168 * @param cls not used
170 * @param value ATS_Peer
174 reset_peers (void *cls,
175 const struct GNUNET_PeerIdentity *key,
178 struct ATS_Peer *peer = value;
179 peer->processed = GNUNET_NO;
184 * Delete the MLP problem and free the constrain matrix
186 * @param mlp the MLP handle
189 mlp_delete_problem (struct GAS_MLP_Handle *mlp)
194 if (mlp->p.prob != NULL)
196 glp_delete_prob(mlp->p.prob);
200 /* delete row index */
201 if (mlp->p.ia != NULL)
203 GNUNET_free (mlp->p.ia);
207 /* delete column index */
208 if (mlp->p.ja != NULL)
210 GNUNET_free (mlp->p.ja);
214 /* delete coefficients */
215 if (mlp->p.ar != NULL)
217 GNUNET_free (mlp->p.ar);
223 mlp->p.c_d = MLP_UNDEFINED;
224 mlp->p.c_r = MLP_UNDEFINED;
225 mlp->p.r_c2 = MLP_UNDEFINED;
226 mlp->p.r_c4 = MLP_UNDEFINED;
227 mlp->p.r_c6 = MLP_UNDEFINED;
228 mlp->p.r_c9 = MLP_UNDEFINED;
229 for (c = 0; c < mlp->pv.m_q ; c ++)
230 mlp->p.r_q[c] = MLP_UNDEFINED;
231 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c ++)
232 mlp->p.r_quota[c] = MLP_UNDEFINED;
233 mlp->p.ci = MLP_UNDEFINED;
236 GNUNET_CONTAINER_multipeermap_iterate (mlp->requested_peers,
242 * Translate ATS properties to text
243 * Just intended for debugging
245 * @param ats_index the ATS index
246 * @return string with result
249 mlp_ats_to_string (int ats_index)
252 case GNUNET_ATS_ARRAY_TERMINATOR:
253 return "GNUNET_ATS_ARRAY_TERMINATOR";
254 case GNUNET_ATS_UTILIZATION_OUT:
255 return "GNUNET_ATS_UTILIZATION_OUT";
256 case GNUNET_ATS_UTILIZATION_IN:
257 return "GNUNET_ATS_UTILIZATION_IN";
258 case GNUNET_ATS_UTILIZATION_PAYLOAD_OUT:
259 return "GNUNET_ATS_UTILIZATION_PAYLOAD_OUT";
260 case GNUNET_ATS_UTILIZATION_PAYLOAD_IN:
261 return "GNUNET_ATS_UTILIZATION_PAYLOAD_IN";
262 case GNUNET_ATS_COST_LAN:
263 return "GNUNET_ATS_COST_LAN";
264 case GNUNET_ATS_COST_WAN:
265 return "GNUNET_ATS_COST_LAN";
266 case GNUNET_ATS_COST_WLAN:
267 return "GNUNET_ATS_COST_WLAN";
268 case GNUNET_ATS_NETWORK_TYPE:
269 return "GNUNET_ATS_NETWORK_TYPE";
270 case GNUNET_ATS_QUALITY_NET_DELAY:
271 return "GNUNET_ATS_QUALITY_NET_DELAY";
272 case GNUNET_ATS_QUALITY_NET_DISTANCE:
273 return "GNUNET_ATS_QUALITY_NET_DISTANCE";
281 * Translate glpk status error codes to text
282 * @param retcode return code
283 * @return string with result
286 mlp_status_to_string (int retcode)
290 return "solution is undefined";
292 return "solution is feasible";
294 return "solution is infeasible";
296 return "no feasible solution exists";
298 return "solution is optimal";
300 return "solution is unbounded";
303 return "unknown error";
308 * Translate glpk solver error codes to text
309 * @param retcode return code
310 * @return string with result
313 mlp_solve_to_string (int retcode)
319 return "invalid basis";
321 return "singular matrix";
323 return "ill-conditioned matrix";
325 return "invalid bounds";
327 return "solver failed";
329 return "objective lower limit reached";
331 return "objective upper limit reached";
333 return "iteration limit exceeded";
335 return "time limit exceeded";
337 return "no primal feasible solution";
339 return "no dual feasible solution";
341 return "root LP optimum not provided";
343 return "search terminated by application";
345 return "relative mip gap tolerance reached";
347 return "no dual feasible solution";
349 return "no convergence";
351 return "numerical instability";
353 return "invalid data";
355 return "result out of range";
358 return "unknown error";
363 * Extract an ATS performance info from an address
365 * @param address the address
366 * @param type the type to extract in HBO
367 * @return the value in HBO or GNUNET_ATS_VALUE_UNDEFINED in HBO if value does not exist
370 get_performance_info (struct ATS_Address *address, uint32_t type)
373 GNUNET_assert (NULL != address);
375 if ((NULL == address->atsi) || (0 == address->atsi_count))
376 return GNUNET_ATS_VALUE_UNDEFINED;
378 for (c1 = 0; c1 < address->atsi_count; c1++)
380 if (ntohl(address->atsi[c1].type) == type)
381 return ntohl(address->atsi[c1].value);
383 return GNUNET_ATS_VALUE_UNDEFINED;
389 const struct GNUNET_CONTAINER_MultiPeerMap *map;
394 mlp_create_problem_count_addresses_it (void *cls,
395 const struct GNUNET_PeerIdentity *key,
398 struct CountContext *cctx = cls;
400 /* Check if we have to add this peer due to a pending request */
401 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (cctx->map, key))
408 mlp_create_problem_count_addresses (const struct GNUNET_CONTAINER_MultiPeerMap *requested_peers,
409 const struct GNUNET_CONTAINER_MultiPeerMap *addresses)
411 struct CountContext cctx;
413 cctx.map = requested_peers;
415 GNUNET_CONTAINER_multipeermap_iterate (addresses,
416 &mlp_create_problem_count_addresses_it, &cctx);
422 mlp_create_problem_count_peers_it (void *cls,
423 const struct GNUNET_PeerIdentity *key,
426 struct CountContext *cctx = cls;
428 /* Check if we have to addresses for the requested peer */
429 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (cctx->map, key))
436 mlp_create_problem_count_peers (const struct GNUNET_CONTAINER_MultiPeerMap *requested_peers,
437 const struct GNUNET_CONTAINER_MultiPeerMap *addresses)
439 struct CountContext cctx;
441 cctx.map = addresses;
443 GNUNET_CONTAINER_multipeermap_iterate (requested_peers,
444 &mlp_create_problem_count_peers_it, &cctx);
450 * Updates an existing value in the matrix
452 * Extract the row, updates the value and updates the row in the problem
454 * @param p the mlp problem
455 * @param row the row to create the value in
456 * @param col the column to create the value in
457 * @param val the value to set
458 * @param line calling line for debbuging
459 * @return GNUNET_YES value changed, GNUNET_NO value did not change, GNUNET_SYSERR
463 mlp_create_problem_update_value (struct MLP_Problem *p,
464 int row, int col, double val,
475 GNUNET_assert (NULL != p);
476 GNUNET_assert (NULL != p->prob);
478 /* Get number of columns and prepare data structure */
479 c_cols = glp_get_num_cols(p->prob);
481 return GNUNET_SYSERR;
483 val_array = GNUNET_malloc ((c_cols +1)* sizeof (double));
484 GNUNET_assert (NULL != val_array);
485 ind_array = GNUNET_malloc ((c_cols+1) * sizeof (int));
486 GNUNET_assert (NULL != ind_array);
487 /* Extract the row */
489 /* Update the value */
490 c_elems = glp_get_mat_row (p->prob, row, ind_array, val_array);
492 for (c1 = 1; c1 < (c_elems+1); c1++)
494 if (ind_array[c1] == col)
500 if (GNUNET_NO == found)
502 ind_array[c_elems+1] = col;
503 val_array[c_elems+1] = val;
504 LOG (GNUNET_ERROR_TYPE_DEBUG, "[P] Setting value in [%s : %s] to `%.2f'\n",
505 glp_get_row_name (p->prob, row), glp_get_col_name (p->prob, col),
507 glp_set_mat_row (p->prob, row, c_elems+1, ind_array, val_array);
508 GNUNET_free (ind_array);
509 GNUNET_free (val_array);
515 LOG (GNUNET_ERROR_TYPE_DEBUG, "[P] Updating value in [%s : %s] from `%.2f' to `%.2f'\n",
516 glp_get_row_name (p->prob, row), glp_get_col_name (p->prob, col),
518 if (val != val_array[c1])
523 /* Update the row in the matrix */
524 glp_set_mat_row (p->prob, row, c_elems, ind_array, val_array);
527 GNUNET_free (ind_array);
528 GNUNET_free (val_array);
533 * Creates a new value in the matrix
535 * Sets the row and column index in the problem array and increments the
538 * @param p the mlp problem
539 * @param row the row to create the value in
540 * @param col the column to create the value in
541 * @param val the value to set
542 * @param line calling line for debbuging
545 mlp_create_problem_set_value (struct MLP_Problem *p,
546 int row, int col, double val,
549 if ((p->ci) >= p->num_elements)
551 LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: line %u: Request for index %u bigger than array size of %u\n",
552 line, p->ci + 1, p->num_elements);
556 if ((0 == row) || (0 == col))
561 #if DEBUG_MLP_PROBLEM_CREATION
562 LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: line %u: Set value [%u,%u] in index %u == %.2f\n",
563 line, p->ia[p->ci], p->ja[p->ci], p->ci, p->ar[p->ci]);
569 mlp_create_problem_create_column (struct MLP_Problem *p, char *name,
570 unsigned int type, unsigned int bound, double lb, double ub,
573 int col = glp_add_cols (p->prob, 1);
574 glp_set_col_name (p->prob, col, name);
575 glp_set_col_bnds (p->prob, col, bound, lb, ub);
576 glp_set_col_kind (p->prob, col, type);
577 glp_set_obj_coef (p->prob, col, coef);
578 #if DEBUG_MLP_PROBLEM_CREATION
579 LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: Added column [%u] `%s': %.2f\n",
586 mlp_create_problem_create_constraint (struct MLP_Problem *p, char *name,
587 unsigned int bound, double lb, double ub)
590 int row = glp_add_rows (p->prob, 1);
592 glp_set_row_name (p->prob, row, name);
593 /* set row bounds: <= 0 */
594 glp_set_row_bnds (p->prob, row, bound, lb, ub);
598 GNUNET_asprintf(&op, "-inf <= x <= %.2f", ub);
601 GNUNET_asprintf(&op, "%.2f <= x <= %.2f", lb, ub);
604 GNUNET_asprintf(&op, "%.2f == x == %.2f", lb, ub);
607 GNUNET_asprintf(&op, "%.2f <= x <= inf", lb);
610 GNUNET_asprintf(&op, "ERROR");
613 #if DEBUG_MLP_PROBLEM_CREATION
614 LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: Added row [%u] `%s': %s\n",
623 * - address columns b and n
624 * - address dependent constraint rows c1, c3
625 * - peer dependent rows c2 and c9
626 * - Set address dependent entries in problem matrix as well
629 mlp_create_problem_add_address_information (void *cls,
630 const struct GNUNET_PeerIdentity *key,
633 struct GAS_MLP_Handle *mlp = cls;
634 struct MLP_Problem *p = &mlp->p;
635 struct ATS_Address *address = value;
636 struct ATS_Peer *peer;
637 struct MLP_information *mlpi;
643 /* Check if we have to add this peer due to a pending request */
644 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(mlp->requested_peers, key))
647 mlpi = address->solver_information;
650 fprintf (stderr, "%s %p\n",GNUNET_i2s (&address->peer), address);
656 peer = GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, key);
657 if (peer->processed == GNUNET_NO)
659 /* Add peer dependent constraints */
660 /* Add constraint c2 */
661 GNUNET_asprintf(&name, "c2_%s", GNUNET_i2s(&address->peer));
662 peer->r_c2 = mlp_create_problem_create_constraint (p, name, GLP_FX, 1.0, 1.0);
664 /* Add constraint c9 */
665 GNUNET_asprintf(&name, "c9_%s", GNUNET_i2s(&address->peer));
666 peer->r_c9 = mlp_create_problem_create_constraint (p, name, GLP_LO, 0.0, 0.0);
668 /* c 9) set coefficient */
669 mlp_create_problem_set_value (p, peer->r_c9, p->c_r, -peer->f, __LINE__);
670 peer->processed = GNUNET_YES;
673 /* Reset addresses' solver information */
680 /* Add bandwidth column */
681 GNUNET_asprintf (&name, "b_%s_%s_%p", GNUNET_i2s (&address->peer), address->plugin, address);
682 #if TEST_MAX_BW_ASSIGNMENT
683 mlpi->c_b = mlp_create_problem_create_column (p, name, GLP_CV, GLP_LO, 0.0, 0.0, 1.0);
685 mlpi->c_b = mlp_create_problem_create_column (p, name, GLP_CV, GLP_LO, 0.0, 0.0, 0.0);
690 /* Add usage column */
691 GNUNET_asprintf (&name, "n_%s_%s_%p", GNUNET_i2s (&address->peer), address->plugin, address);
692 mlpi->c_n = mlp_create_problem_create_column (p, name, GLP_IV, GLP_DB, 0.0, 1.0, 0.0);
695 /* Add address dependent constraints */
696 /* Add constraint c1) bandwidth capping
697 * b_t + (-M) * n_t <= 0
699 GNUNET_asprintf(&name, "c1_%s_%s_%p", GNUNET_i2s(&address->peer), address->plugin, address);
700 mlpi->r_c1 = mlp_create_problem_create_constraint (p, name, GLP_UP, 0.0, 0.0);
703 /* c1) set b = 1 coefficient */
704 mlp_create_problem_set_value (p, mlpi->r_c1, mlpi->c_b, 1, __LINE__);
705 /* c1) set n = -M coefficient */
706 mlp_create_problem_set_value (p, mlpi->r_c1, mlpi->c_n, -mlp->pv.BIG_M, __LINE__);
708 /* Add constraint c 3) minimum bandwidth
709 * b_t + (-n_t * b_min) >= 0
711 GNUNET_asprintf(&name, "c3_%s_%s_%p", GNUNET_i2s(&address->peer), address->plugin, address);
712 mlpi->r_c3 = mlp_create_problem_create_constraint (p, name, GLP_LO, 0.0, 0.0);
715 /* c3) set b = 1 coefficient */
716 mlp_create_problem_set_value (p, mlpi->r_c3, mlpi->c_b, 1, __LINE__);
717 /* c3) set n = -b_min coefficient */
718 mlp_create_problem_set_value (p, mlpi->r_c3, mlpi->c_n, - ((double )mlp->pv.b_min), __LINE__);
721 /* Set coefficient entries in invariant rows */
722 /* c 4) minimum connections */
723 mlp_create_problem_set_value (p, p->r_c4, mlpi->c_n, 1, __LINE__);
724 /* c 6) maximize diversity */
725 mlp_create_problem_set_value (p, p->r_c6, mlpi->c_n, 1, __LINE__);
726 /* c 2) 1 address peer peer */
727 mlp_create_problem_set_value (p, peer->r_c2, mlpi->c_n, 1, __LINE__);
728 /* c 9) relativity */
729 mlp_create_problem_set_value (p, peer->r_c9, mlpi->c_b, 1, __LINE__);
731 mlp_create_problem_set_value (p, p->r_c8, mlpi->c_b, 1, __LINE__);
733 /* c 10) obey network specific quotas
734 * (1)*b_1 + ... + (1)*b_m <= quota_n
736 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
738 addr_net = get_performance_info (address, GNUNET_ATS_NETWORK_TYPE);
739 if (GNUNET_ATS_VALUE_UNDEFINED == addr_net)
740 addr_net = GNUNET_ATS_NET_UNSPECIFIED;
742 if (mlp->pv.quota_index[c] == addr_net)
744 mlp_create_problem_set_value (p, p->r_quota[c], mlpi->c_b, 1, __LINE__);
749 /* c 7) Optimize quality */
750 /* For all quality metrics, set quality of this address */
751 props = mlp->get_properties (mlp->get_properties_cls, address);
752 for (c = 0; c < mlp->pv.m_q; c++)
753 mlp_create_problem_set_value (p, p->r_q[c], mlpi->c_b, props[c], __LINE__);
759 * Create the invariant columns c4, c6, c10, c8, c7
762 mlp_create_problem_add_invariant_rows (struct GAS_MLP_Handle *mlp, struct MLP_Problem *p)
767 /* Row for c4) minimum connection */
768 /* Number of minimum connections is min(|Peers|, n_min) */
769 p->r_c4 = mlp_create_problem_create_constraint (p, "c4", GLP_LO, (mlp->pv.n_min > p->num_peers) ? p->num_peers : mlp->pv.n_min, 0.0);
771 /* Add row for c6) */
772 p->r_c6 = mlp_create_problem_create_constraint (p, "c6", GLP_FX, 0.0, 0.0);
774 mlp_create_problem_set_value (p, p->r_c6, p->c_d, -1, __LINE__);
776 /* Add rows for c 10) */
777 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
780 GNUNET_asprintf(&text, "c10_quota_ats_%s",
781 GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]));
782 p->r_quota[c] = mlp_create_problem_create_constraint (p, text, GLP_DB, 0.0, mlp->pv.quota_out[c]);
786 /* Adding rows for c 8) */
787 p->r_c8 = mlp_create_problem_create_constraint (p, "c8", GLP_FX, 0.0, 0.0);
789 mlp_create_problem_set_value (p, p->r_c8, p->c_u, -1, __LINE__);
791 /* c 7) For all quality metrics */
792 for (c = 0; c < mlp->pv.m_q; c++)
794 GNUNET_asprintf(&name, "c7_q%i_%s", c, mlp_ats_to_string(mlp->pv.q[c]));
795 p->r_q[c] = mlp_create_problem_create_constraint (p, name, GLP_FX, 0.0, 0.0);
797 mlp_create_problem_set_value (p, p->r_q[c], p->c_q[c], -1, __LINE__);
803 * Create the invariant columns d, u, r, q0 ... qm
806 mlp_create_problem_add_invariant_columns (struct GAS_MLP_Handle *mlp, struct MLP_Problem *p)
811 #if TEST_MAX_BW_ASSIGNMENT
816 //mlp->pv.co_R = 0.0;
818 /* Diversity d column */
819 p->c_d = mlp_create_problem_create_column (p, "d", GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_D);
821 /* Utilization u column */
822 p->c_u = mlp_create_problem_create_column (p, "u", GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_U);
824 /* Relativity r column */
825 p->c_r = mlp_create_problem_create_column (p, "r", GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_R);
827 /* Quality metric columns */
828 for (c = 0; c < mlp->pv.m_q; c++)
830 GNUNET_asprintf (&name, "q_%u", mlp->pv.q[c]);
831 #if TEST_MAX_BW_ASSIGNMENT
832 p->c_q[c] = mlp_create_problem_create_column (p, name, GLP_CV, GLP_LO, 0.0, 0.0, 0.0);
834 p->c_q[c] = mlp_create_problem_create_column (p, name, GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_Q[c]);
842 * Create the MLP problem
844 * @param mlp the MLP handle
845 * @return GNUNET_OK or GNUNET_SYSERR
848 mlp_create_problem (struct GAS_MLP_Handle *mlp)
850 struct MLP_Problem *p = &mlp->p;
853 GNUNET_assert (p->prob == NULL);
854 GNUNET_assert (p->ia == NULL);
855 GNUNET_assert (p->ja == NULL);
856 GNUNET_assert (p->ar == NULL);
857 /* Reset MLP problem struct */
859 /* create the glpk problem */
860 p->prob = glp_create_prob ();
861 GNUNET_assert (NULL != p->prob);
862 p->num_peers = mlp_create_problem_count_peers (mlp->requested_peers, mlp->addresses);
863 p->num_addresses = mlp_create_problem_count_addresses (mlp->requested_peers, mlp->addresses);
865 /* Create problem matrix: 10 * #addresses + #q * #addresses + #q, + #peer + 2 + 1 */
866 p->num_elements = (10 * p->num_addresses + mlp->pv.m_q * p->num_addresses +
867 mlp->pv.m_q + p->num_peers + 2 + 1);
868 LOG (GNUNET_ERROR_TYPE_DEBUG,
869 "Rebuilding problem for %u peer(s) and %u addresse(s) and %u quality metrics == %u elements\n",
875 /* Set a problem name */
876 glp_set_prob_name (p->prob, "GNUnet ATS bandwidth distribution");
877 /* Set optimization direction to maximize */
878 glp_set_obj_dir (p->prob, GLP_MAX);
880 /* Create problem matrix */
881 /* last +1 caused by glpk index starting with one: [1..elements]*/
884 p->ia = GNUNET_malloc (p->num_elements * sizeof (int));
886 p->ja = GNUNET_malloc (p->num_elements * sizeof (int));
888 p->ar = GNUNET_malloc (p->num_elements * sizeof (double));
890 if ((NULL == p->ia) || (NULL == p->ja) || (NULL == p->ar))
892 LOG (GNUNET_ERROR_TYPE_ERROR, _("Problem size too large, cannot allocate memory!\n"));
893 return GNUNET_SYSERR;
896 /* Adding invariant columns */
897 mlp_create_problem_add_invariant_columns (mlp, p);
899 /* Adding address independent constraint rows */
900 mlp_create_problem_add_invariant_rows (mlp, p);
902 /* Adding address dependent columns constraint rows */
903 GNUNET_CONTAINER_multipeermap_iterate (mlp->addresses,
904 &mlp_create_problem_add_address_information,
907 /* Load the matrix */
908 LOG (GNUNET_ERROR_TYPE_DEBUG, "Loading matrix\n");
909 glp_load_matrix(p->prob, (p->ci)-1, p->ia, p->ja, p->ar);
915 * Solves the LP problem
917 * @param mlp the MLP Handle
918 * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure
921 mlp_solve_lp_problem (struct GAS_MLP_Handle *mlp)
925 res = glp_simplex(mlp->p.prob, &mlp->control_param_lp);
927 LOG (GNUNET_ERROR_TYPE_DEBUG, "Solving LP problem: 0x%02X %s\n", res, mlp_solve_to_string(res));
929 LOG (GNUNET_ERROR_TYPE_WARNING, "Solving LP problem failed: 0x%02X %s\n", res, mlp_solve_to_string(res));
931 /* Analyze problem status */
932 res = glp_get_status (mlp->p.prob);
934 /* solution is optimal */
936 /* solution is feasible */
938 LOG (GNUNET_ERROR_TYPE_DEBUG, "Solving LP problem: 0x%02X %s\n",
939 res, mlp_status_to_string(res));
941 /* Problem was ill-defined, no way to handle that */
943 LOG (GNUNET_ERROR_TYPE_WARNING, "Solving LP problem failed, no solution: 0x%02X %s\n",
944 res, mlp_status_to_string(res));
945 return GNUNET_SYSERR;
951 * Solves the MLP problem
953 * @param mlp the MLP Handle
954 * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure
957 mlp_solve_mlp_problem (struct GAS_MLP_Handle *mlp)
960 res = glp_intopt(mlp->p.prob, &mlp->control_param_mlp);
962 LOG (GNUNET_ERROR_TYPE_DEBUG, "Solving MLP problem: 0x%02X %s\n", res, mlp_solve_to_string(res));
964 LOG (GNUNET_ERROR_TYPE_WARNING, "Solving MLP problem failed: 0x%02X %s\n", res, mlp_solve_to_string(res));
965 /* Analyze problem status */
966 res = glp_mip_status(mlp->p.prob);
968 /* solution is optimal */
970 /* solution is feasible */
972 LOG (GNUNET_ERROR_TYPE_DEBUG, "Solving MLP problem: 0x%02X %s\n", res, mlp_status_to_string(res));
974 /* Problem was ill-defined, no way to handle that */
976 LOG (GNUNET_ERROR_TYPE_WARNING,"Solving MLP problem failed, 0x%02X %s\n\n", res, mlp_status_to_string(res));
977 return GNUNET_SYSERR;
982 * Propagates the results when MLP problem was solved
984 * @param cls the MLP handle
985 * @param key the peer identity
986 * @param value the address
987 * @return #GNUNET_OK to continue
990 mlp_propagate_results (void *cls,
991 const struct GNUNET_PeerIdentity *key,
994 struct GAS_MLP_Handle *mlp = cls;
995 struct ATS_Address *address;
996 struct MLP_information *mlpi;
997 double mlp_bw_in = MLP_NaN;
998 double mlp_bw_out = MLP_NaN;
999 double mlp_use = MLP_NaN;
1001 /* Check if we have to add this peer due to a pending request */
1002 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (mlp->requested_peers,
1008 GNUNET_assert (address->solver_information != NULL);
1009 mlpi = address->solver_information;
1011 mlp_bw_in = glp_mip_col_val(mlp->p.prob, mlpi->c_b);/* FIXME */
1012 if (mlp_bw_in > (double) UINT32_MAX)
1014 LOG (GNUNET_ERROR_TYPE_DEBUG, "Overflow in assigned bandwidth, reducing ...\n" );
1015 mlp_bw_in = (double) UINT32_MAX;
1017 mlp_bw_out = glp_mip_col_val(mlp->p.prob, mlpi->c_b);
1018 if (mlp_bw_out > (double) UINT32_MAX)
1020 LOG (GNUNET_ERROR_TYPE_DEBUG, "Overflow in assigned bandwidth, reducing ...\n" );
1021 mlp_bw_out = (double) UINT32_MAX;
1023 mlp_use = glp_mip_col_val(mlp->p.prob, mlpi->c_n);
1027 * LOG (GNUNET_ERROR_TYPE_INFO, "MLP result address: `%s' `%s' length %u session %u, mlp use %f\n",
1028 * GNUNET_i2s(&address->peer), address->plugin,
1029 * address->addr_len, address->session_id);
1032 if (GLP_YES == mlp_use)
1034 /* This address was selected by the solver to be used */
1035 mlpi->n = GNUNET_YES;
1036 if (GNUNET_NO == address->active)
1038 /* Address was not used before, enabling address */
1039 LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : enabling address\n",
1040 (1 == mlp_use) ? "[x]": "[ ]", mlp_bw_out);
1041 address->active = GNUNET_YES;
1042 address->assigned_bw_in.value__ = htonl (mlp_bw_in);
1043 mlpi->b_in.value__ = htonl(mlp_bw_in);
1044 address->assigned_bw_out.value__ = htonl (mlp_bw_out);
1045 mlpi->b_out.value__ = htonl(mlp_bw_out);
1046 if ((NULL == mlp->exclude_peer) || (0 != memcmp (&address->peer, mlp->exclude_peer, sizeof (address->peer))))
1047 mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address);
1050 else if (GNUNET_YES == address->active)
1052 /* Address was used before, check for bandwidth change */
1053 if ((mlp_bw_out != ntohl(address->assigned_bw_out.value__)) ||
1054 (mlp_bw_in != ntohl(address->assigned_bw_in.value__)))
1056 LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : bandwidth changed\n",
1057 (1 == mlp_use) ? "[x]": "[ ]", mlp_bw_out);
1058 address->assigned_bw_in.value__ = htonl (mlp_bw_in);
1059 mlpi->b_in.value__ = htonl(mlp_bw_in);
1060 address->assigned_bw_out.value__ = htonl (mlp_bw_out);
1061 mlpi->b_out.value__ = htonl(mlp_bw_out);
1062 if ((NULL == mlp->exclude_peer) || (0 != memcmp (&address->peer, mlp->exclude_peer, sizeof (address->peer))))
1063 mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address);
1070 else if (GLP_NO == mlp_use)
1072 /* This address was selected by the solver to be not used */
1073 mlpi->n = GNUNET_NO;
1074 if (GNUNET_NO == address->active)
1076 /* Address was not used before, nothing to do */
1077 LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : no change\n",
1078 (1 == mlp_use) ? "[x]": "[ ]", mlp_bw_out);
1081 else if (GNUNET_YES == address->active)
1083 /* Address was used before, disabling address */
1084 LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : disabling address\n",
1085 (1 == mlp_use) ? "[x]": "[ ]", mlp_bw_out);
1086 address->active = GNUNET_NO;
1087 /* Set bandwidth to 0 */
1088 address->assigned_bw_in = BANDWIDTH_ZERO;
1089 mlpi->b_in.value__ = htonl(mlp_bw_in);
1090 address->assigned_bw_out = BANDWIDTH_ZERO;
1091 mlpi->b_out.value__ = htonl(mlp_bw_out);
1092 //mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address);
1104 static void notify (struct GAS_MLP_Handle *mlp,
1105 enum GAS_Solver_Operation op,
1106 enum GAS_Solver_Status stat,
1107 enum GAS_Solver_Additional_Information add)
1109 if (NULL != mlp->env->info_cb)
1110 mlp->env->info_cb (mlp->env->info_cb_cls, op, stat, add);
1113 * Solves the MLP problem
1115 * @param solver the MLP Handle
1116 * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure
1119 GAS_mlp_solve_problem (void *solver)
1121 struct GAS_MLP_Handle *mlp = solver;
1126 struct GNUNET_TIME_Absolute start_total;
1127 struct GNUNET_TIME_Absolute start_cur_op;
1128 struct GNUNET_TIME_Relative dur_total;
1129 struct GNUNET_TIME_Relative dur_setup;
1130 struct GNUNET_TIME_Relative dur_lp;
1131 struct GNUNET_TIME_Relative dur_mlp;
1133 GNUNET_assert(NULL != solver);
1135 if (GNUNET_YES == mlp->stat_bulk_lock)
1137 mlp->stat_bulk_requests++;
1140 notify(mlp, GAS_OP_SOLVE_START, GAS_STAT_SUCCESS,
1141 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED);
1142 start_total = GNUNET_TIME_absolute_get();
1144 if (0 == GNUNET_CONTAINER_multipeermap_size(mlp->requested_peers))
1146 notify(mlp, GAS_OP_SOLVE_STOP, GAS_STAT_SUCCESS, GAS_INFO_NONE);
1147 return GNUNET_OK; /* No pending requests */
1149 if (0 == GNUNET_CONTAINER_multipeermap_size(mlp->addresses))
1151 notify(mlp, GAS_OP_SOLVE_STOP, GAS_STAT_SUCCESS, GAS_INFO_NONE);
1152 return GNUNET_OK; /* No addresses available */
1155 if ((GNUNET_NO == mlp->stat_mlp_prob_changed)
1156 && (GNUNET_NO == mlp->stat_mlp_prob_updated))
1158 LOG(GNUNET_ERROR_TYPE_DEBUG, "No changes to problem\n");
1159 notify(mlp, GAS_OP_SOLVE_STOP, GAS_STAT_SUCCESS, GAS_INFO_NONE);
1162 if (GNUNET_YES == mlp->stat_mlp_prob_changed)
1164 LOG(GNUNET_ERROR_TYPE_DEBUG, "Problem size changed, rebuilding\n");
1165 notify(mlp, GAS_OP_SOLVE_SETUP_START, GAS_STAT_SUCCESS, GAS_INFO_FULL);
1166 mlp_delete_problem(mlp);
1167 if (GNUNET_SYSERR == mlp_create_problem(mlp))
1169 notify(mlp, GAS_OP_SOLVE_SETUP_STOP, GAS_STAT_FAIL, GAS_INFO_FULL);
1170 return GNUNET_SYSERR;
1172 notify(mlp, GAS_OP_SOLVE_SETUP_STOP, GAS_STAT_SUCCESS, GAS_INFO_FULL);
1173 mlp->control_param_lp.presolve = GLP_YES;
1174 mlp->control_param_mlp.presolve = GNUNET_NO; /* No presolver, we have LP solution */
1178 LOG(GNUNET_ERROR_TYPE_DEBUG, "Problem was updated, resolving\n");
1181 dur_setup = GNUNET_TIME_absolute_get_duration (start_total);
1184 notify(mlp, GAS_OP_SOLVE_MLP_LP_START, GAS_STAT_SUCCESS,
1185 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED);
1186 LOG(GNUNET_ERROR_TYPE_DEBUG,
1187 "Running LP solver %s\n",
1188 (GLP_YES == mlp->control_param_lp.presolve)? "with presolver": "without presolver");
1189 start_cur_op = GNUNET_TIME_absolute_get();
1192 mlp->control_param_lp.presolve = GLP_YES;
1193 res_lp = mlp_solve_lp_problem(mlp);
1195 dur_lp = GNUNET_TIME_absolute_get_duration (start_cur_op);
1196 notify(mlp, GAS_OP_SOLVE_MLP_LP_STOP,
1197 (GNUNET_OK == res_lp) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL,
1198 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED);
1201 /* Run MLP solver */
1202 if (GNUNET_OK == res_lp)
1204 LOG(GNUNET_ERROR_TYPE_DEBUG, "Running MLP solver \n");
1205 notify(mlp, GAS_OP_SOLVE_MLP_MLP_START, GAS_STAT_SUCCESS,
1206 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED);
1207 start_cur_op = GNUNET_TIME_absolute_get();
1210 //mlp->control_param_mlp.presolve = GNUNET_YES;
1211 res_mip = mlp_solve_mlp_problem(mlp);
1213 dur_mlp = GNUNET_TIME_absolute_get_duration (start_cur_op);
1214 dur_total = GNUNET_TIME_absolute_get_duration (start_total);
1216 notify(mlp, GAS_OP_SOLVE_MLP_MLP_STOP,
1217 (GNUNET_OK == res_mip) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL,
1218 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED);
1222 /* Do not execute mip solver since lp solution is invalid */
1223 dur_mlp = GNUNET_TIME_UNIT_ZERO;
1224 dur_total = GNUNET_TIME_absolute_get_duration (start_total);
1225 notify(mlp, GAS_OP_SOLVE_MLP_MLP_STOP, GAS_STAT_FAIL,
1226 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED);
1227 res_mip = GNUNET_SYSERR;
1231 /* Notify about end */
1232 notify(mlp, GAS_OP_SOLVE_STOP,
1233 ((GNUNET_OK == res_mip) && (GNUNET_OK == res_mip)) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL,
1234 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED);
1236 LOG (GNUNET_ERROR_TYPE_DEBUG,
1237 "Execution time for %s solve: (total/setup/lp/mlp) : %llu %llu %llu %llu\n",
1238 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? "full" : "updated",
1239 (unsigned long long) dur_total.rel_value_us,
1240 (unsigned long long) dur_setup.rel_value_us,
1241 (unsigned long long) dur_lp.rel_value_us,
1242 (unsigned long long) dur_mlp.rel_value_us);
1245 mlp->ps.lp_res = res_lp;
1246 mlp->ps.mip_res = res_mip;
1247 mlp->ps.lp_presolv = mlp->control_param_lp.presolve;
1248 mlp->ps.mip_presolv = mlp->control_param_mlp.presolve;
1249 mlp->ps.p_cols = glp_get_num_cols(mlp->p.prob);
1250 mlp->ps.p_rows = glp_get_num_rows(mlp->p.prob);
1251 mlp->ps.p_elements = mlp->p.num_elements;
1253 /* Propagate result*/
1254 notify(mlp, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START,
1255 (GNUNET_OK == res_lp) && (GNUNET_OK == res_mip) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL,
1257 if ((GNUNET_OK == res_lp) && (GNUNET_OK == res_mip))
1259 GNUNET_CONTAINER_multipeermap_iterate(mlp->addresses,
1260 &mlp_propagate_results, mlp);
1262 notify(mlp, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP,
1263 (GNUNET_OK == res_lp) && (GNUNET_OK == res_mip) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL,
1266 struct GNUNET_TIME_Absolute time = GNUNET_TIME_absolute_get();
1267 if ( (GNUNET_YES == mlp->opt_dump_solution_all) ||
1268 (mlp->opt_dump_solution_on_fail && ((GNUNET_OK != res_lp) || (GNUNET_OK != res_mip))) )
1270 /* Write problem to disk */
1271 GNUNET_asprintf(&filename, "problem_p_%u_a%u_%llu.lp", mlp->p.num_peers,
1272 mlp->p.num_addresses, time.abs_value_us);
1273 LOG(GNUNET_ERROR_TYPE_ERROR, "Dumped problem to file: `%s' \n", filename);
1274 glp_write_lp (mlp->p.prob, NULL, filename);
1275 GNUNET_free(filename);
1277 if ( (mlp->opt_dump_solution_all) ||
1278 (mlp->opt_dump_solution_on_fail && ((GNUNET_OK != res_lp) || (GNUNET_OK != res_mip))) )
1280 /* Write solution to disk */
1281 GNUNET_asprintf(&filename, "problem_p_%u_a%u_%llu.sol", mlp->p.num_peers,
1282 mlp->p.num_addresses, time.abs_value_us);
1283 glp_print_mip(mlp->p.prob, filename);
1284 LOG(GNUNET_ERROR_TYPE_ERROR, "Dumped solution to file: `%s' \n", filename);
1285 GNUNET_free(filename);
1288 /* Reset change and update marker */
1289 mlp->control_param_lp.presolve = GLP_NO;
1290 mlp->stat_mlp_prob_updated = GNUNET_NO;
1291 mlp->stat_mlp_prob_changed = GNUNET_NO;
1293 if ((GNUNET_OK == res_lp) && (GNUNET_OK == res_mip))
1296 return GNUNET_SYSERR;
1300 * Add a single address to the solve
1302 * @param solver the solver Handle
1303 * @param address the address to add
1304 * @param network network type of this address
1307 GAS_mlp_address_add (void *solver,
1308 struct ATS_Address *address,
1311 struct GAS_MLP_Handle *mlp = solver;
1314 GNUNET_assert (NULL != solver);
1315 GNUNET_assert (NULL != address);
1317 if (GNUNET_ATS_NetworkTypeCount <= network)
1323 if (NULL == address->solver_information)
1325 address->solver_information = GNUNET_new (struct MLP_information);
1328 LOG (GNUNET_ERROR_TYPE_ERROR,
1329 _("Adding address for peer `%s' multiple times\n"),
1330 GNUNET_i2s(&address->peer));
1332 /* Is this peer included in the problem? */
1333 if (NULL == (p = GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers,
1336 LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding address for peer `%s' without address request \n", GNUNET_i2s(&address->peer));
1340 LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding address for peer `%s' with address request \n", GNUNET_i2s(&address->peer));
1341 /* Problem size changed: new address for peer with pending request */
1342 mlp->stat_mlp_prob_changed = GNUNET_YES;
1343 if (GNUNET_YES == mlp->opt_mlp_auto_solve)
1344 GAS_mlp_solve_problem (solver);
1349 * Transport properties for this address have changed
1351 * @param solver solver handle
1352 * @param address the address
1353 * @param type the ATSI type in HBO
1354 * @param abs_value the absolute value of the property
1355 * @param rel_value the normalized value
1358 GAS_mlp_address_property_changed (void *solver,
1359 struct ATS_Address *address,
1364 struct MLP_information *mlpi = address->solver_information;
1365 struct GAS_MLP_Handle *mlp = solver;
1370 GNUNET_assert (NULL != solver);
1371 GNUNET_assert (NULL != address);
1375 LOG (GNUNET_ERROR_TYPE_ERROR,
1376 _("Updating address property `%s' for peer `%s' %p not added before\n"),
1377 GNUNET_ATS_print_property_type (type),
1378 GNUNET_i2s(&address->peer),
1384 if (NULL == (p = GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers,
1387 /* Peer is not requested, so no need to update problem */
1390 LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating property `%s' address for peer `%s'\n",
1391 GNUNET_ATS_print_property_type (type),
1392 GNUNET_i2s(&address->peer));
1394 /* Find row index */
1396 for (c1 = 0; c1 < mlp->pv.m_q; c1++)
1398 if (type == mlp->pv.q[c1])
1404 if (-1 == type_index)
1407 return; /* quality index not found */
1410 /* Update c7) [r_q[index]][c_b] = f_q * q_averaged[type_index] */
1411 if (GNUNET_YES == mlp_create_problem_update_value (&mlp->p,
1412 mlp->p.r_q[type_index], mlpi->c_b, rel_value, __LINE__))
1414 mlp->stat_mlp_prob_updated = GNUNET_YES;
1415 if (GNUNET_YES == mlp->opt_mlp_auto_solve)
1416 GAS_mlp_solve_problem (solver);
1422 * Transport session for this address has changed
1424 * NOTE: values in addresses are already updated
1426 * @param solver solver handle
1427 * @param address the address
1428 * @param cur_session the current session
1429 * @param new_session the new session
1432 GAS_mlp_address_session_changed (void *solver,
1433 struct ATS_Address *address,
1434 uint32_t cur_session,
1435 uint32_t new_session)
1437 /* Nothing to do here */
1443 * Transport session for this address has changed
1445 * NOTE: values in addresses are already updated
1447 * @param solver solver handle
1448 * @param address the address
1449 * @param in_use usage state
1452 GAS_mlp_address_inuse_changed (void *solver,
1453 struct ATS_Address *address,
1456 /* Nothing to do here */
1462 * Network scope for this address has changed
1464 * NOTE: values in addresses are already updated
1466 * @param solver solver handle
1467 * @param address the address
1468 * @param current_network the current network
1469 * @param new_network the new network
1472 GAS_mlp_address_change_network (void *solver,
1473 struct ATS_Address *address,
1474 uint32_t current_network,
1475 uint32_t new_network)
1477 struct MLP_information *mlpi = address->solver_information;
1478 struct GAS_MLP_Handle *mlp = solver;
1480 int nets_avail[] = GNUNET_ATS_NetworkType;
1483 GNUNET_assert (NULL != solver);
1484 GNUNET_assert (NULL != address);
1486 if (GNUNET_ATS_NetworkTypeCount <= new_network)
1498 if (mlpi->c_b == MLP_UNDEFINED)
1499 return; /* This address is not yet in the matrix*/
1501 if (NULL == (p = GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers,
1504 /* Peer is not requested, so no need to update problem */
1509 if (current_network == new_network)
1515 for (c1 = 0; c1 < GNUNET_ATS_NetworkTypeCount ; c1 ++)
1517 if (nets_avail[c1] == new_network)
1521 if (GNUNET_ATS_NetworkTypeCount == c1)
1523 /* Invalid network */
1528 LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating network for peer `%s' from `%s' to `%s'\n",
1529 GNUNET_i2s (&address->peer),
1530 GNUNET_ATS_print_network_type(current_network),
1531 GNUNET_ATS_print_network_type(new_network));
1533 for (c1 = 0; c1 < GNUNET_ATS_NetworkTypeCount; c1++)
1535 if (mlp->pv.quota_index[c1] == current_network)
1537 /* Remove from old network */
1538 mlp_create_problem_update_value (&mlp->p,
1540 mlpi->c_b, 0.0, __LINE__);
1545 for (c1 = 0; c1 < GNUNET_ATS_NetworkTypeCount; c1++)
1547 if (mlp->pv.quota_index[c1] == new_network)
1549 /* Remove from old network */
1550 if (GNUNET_SYSERR == mlp_create_problem_update_value (&mlp->p,
1552 mlpi->c_b, 1.0, __LINE__))
1554 /* This quota did not exist in the problem, recreate */
1561 mlp->stat_mlp_prob_changed = GNUNET_YES;
1566 * Deletes a single address in the MLP problem
1568 * The MLP problem has to be recreated and the problem has to be resolved
1570 * @param solver the MLP Handle
1571 * @param address the address to delete
1572 * @param session_only delete only session not whole address
1575 GAS_mlp_address_delete (void *solver,
1576 struct ATS_Address *address,
1580 struct GAS_MLP_Handle *mlp = solver;
1581 struct MLP_information *mlpi;
1584 GNUNET_assert (NULL != solver);
1585 GNUNET_assert (NULL != address);
1587 mlpi = address->solver_information;
1588 if ((GNUNET_NO == session_only) && (NULL != mlpi))
1590 /* Remove full address */
1592 address->solver_information = NULL;
1594 was_active = address->active;
1595 address->active = GNUNET_NO;
1596 address->assigned_bw_in = BANDWIDTH_ZERO;
1597 address->assigned_bw_out = BANDWIDTH_ZERO;
1599 /* Is this peer included in the problem? */
1600 if (NULL == (p = GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers,
1603 LOG (GNUNET_ERROR_TYPE_INFO, "Deleting %s for peer `%s' without address request \n",
1604 (session_only == GNUNET_YES) ? "session" : "address",
1605 GNUNET_i2s(&address->peer));
1608 LOG (GNUNET_ERROR_TYPE_INFO, "Deleting %s for peer `%s' with address request \n",
1609 (session_only == GNUNET_YES) ? "session" : "address",
1610 GNUNET_i2s(&address->peer));
1612 /* Problem size changed: new address for peer with pending request */
1613 mlp->stat_mlp_prob_changed = GNUNET_YES;
1614 if (GNUNET_YES == mlp->opt_mlp_auto_solve)
1616 GAS_mlp_solve_problem (solver);
1618 if (GNUNET_YES == was_active)
1620 if (NULL == GAS_mlp_get_preferred_address (solver, &address->peer))
1622 /* No alternative address, disconnecting peer */
1623 mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address);
1632 * Find the active address in the set of addresses of a peer
1633 * @param cls destination
1634 * @param key peer id
1635 * @param value address
1639 mlp_get_preferred_address_it (void *cls,
1640 const struct GNUNET_PeerIdentity *key,
1643 static int counter = 0;
1644 struct ATS_Address **aa = cls;
1645 struct ATS_Address *addr = value;
1646 struct MLP_information *mlpi = addr->solver_information;
1653 * GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1654 * "MLP [%u] Peer `%s' %s length %u session %u active %s mlp active %s\n",
1655 * counter, GNUNET_i2s (&addr->peer), addr->plugin, addr->addr_len, addr->session_id,
1656 * (GNUNET_YES == addr->active) ? "active" : "inactive",
1657 * (GNUNET_YES == mlpi->n) ? "active" : "inactive");
1660 if (GNUNET_YES == mlpi->n)
1664 (*aa)->assigned_bw_in = mlpi->b_in;
1665 (*aa)->assigned_bw_out = mlpi->b_out;
1674 get_peer_pref_value (struct GAS_MLP_Handle *mlp, const struct GNUNET_PeerIdentity *peer)
1677 const double *preferences = NULL;
1679 preferences = mlp->get_preferences (mlp->get_preferences_cls, peer);
1682 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
1684 if (c != GNUNET_ATS_PREFERENCE_END)
1686 //fprintf (stderr, "VALUE[%u] %s %.3f \n", c, GNUNET_i2s (&cur->addr->peer), t[c]);
1687 res += preferences[c];
1690 res /= (GNUNET_ATS_PreferenceCount -1);
1696 * Get the preferred address for a specific peer
1698 * @param solver the MLP Handle
1699 * @param peer the peer
1700 * @return suggested address
1702 const struct ATS_Address *
1703 GAS_mlp_get_preferred_address (void *solver,
1704 const struct GNUNET_PeerIdentity *peer)
1706 struct GAS_MLP_Handle *mlp = solver;
1708 struct ATS_Address *res;
1710 GNUNET_assert (NULL != solver);
1711 GNUNET_assert (NULL != peer);
1713 LOG (GNUNET_ERROR_TYPE_DEBUG, "Getting preferred address for `%s'\n",
1716 /* Is this peer included in the problem? */
1717 if (NULL == (p = GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers,
1720 LOG (GNUNET_ERROR_TYPE_INFO, "Adding peer `%s' to list of requested_peers with requests\n",
1723 p = GNUNET_new (struct ATS_Peer);
1725 p->f = get_peer_pref_value (mlp, peer);
1726 GNUNET_CONTAINER_multipeermap_put (mlp->requested_peers,
1728 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
1730 /* Added new peer, we have to rebuild problem before solving */
1731 mlp->stat_mlp_prob_changed = GNUNET_YES;
1733 if ((GNUNET_YES == mlp->opt_mlp_auto_solve)&&
1734 (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains(mlp->addresses,
1737 mlp->exclude_peer = peer;
1738 GAS_mlp_solve_problem (mlp);
1739 mlp->exclude_peer = NULL;
1742 /* Get prefered address */
1744 GNUNET_CONTAINER_multipeermap_get_multiple (mlp->addresses, peer,
1745 mlp_get_preferred_address_it, &res);
1751 * Start a bulk operation
1753 * @param solver the solver
1756 GAS_mlp_bulk_start (void *solver)
1758 LOG (GNUNET_ERROR_TYPE_DEBUG, "Locking solver for bulk operation ...\n");
1759 struct GAS_MLP_Handle *s = (struct GAS_MLP_Handle *) solver;
1761 GNUNET_assert (NULL != solver);
1763 s->stat_bulk_lock ++;
1767 GAS_mlp_bulk_stop (void *solver)
1769 LOG (GNUNET_ERROR_TYPE_DEBUG, "Unlocking solver from bulk operation ...\n");
1771 struct GAS_MLP_Handle *s = (struct GAS_MLP_Handle *) solver;
1772 GNUNET_assert (NULL != solver);
1774 if (s->stat_bulk_lock < 1)
1779 s->stat_bulk_lock --;
1781 if (0 < s->stat_bulk_requests)
1783 GAS_mlp_solve_problem (solver);
1784 s->stat_bulk_requests= 0;
1791 * Stop notifying about address and bandwidth changes for this peer
1793 * @param solver the MLP handle
1794 * @param peer the peer
1797 GAS_mlp_stop_get_preferred_address (void *solver,
1798 const struct GNUNET_PeerIdentity *peer)
1800 struct GAS_MLP_Handle *mlp = solver;
1801 struct ATS_Peer *p = NULL;
1803 GNUNET_assert (NULL != solver);
1804 GNUNET_assert (NULL != peer);
1805 if (NULL != (p = GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, peer)))
1807 GNUNET_CONTAINER_multipeermap_remove (mlp->requested_peers, peer, p);
1810 mlp->stat_mlp_prob_changed = GNUNET_YES;
1811 if (GNUNET_YES == mlp->opt_mlp_auto_solve)
1813 GAS_mlp_solve_problem (solver);
1820 * Changes the preferences for a peer in the MLP problem
1822 * @param solver the MLP Handle
1823 * @param peer the peer
1824 * @param kind the kind to change the preference
1825 * @param pref_rel the relative score
1828 GAS_mlp_address_change_preference (void *solver,
1829 const struct GNUNET_PeerIdentity *peer,
1830 enum GNUNET_ATS_PreferenceKind kind,
1833 struct GAS_MLP_Handle *mlp = solver;
1834 struct ATS_Peer *p = NULL;
1836 LOG (GNUNET_ERROR_TYPE_DEBUG, "Changing preference for address for peer `%s' to %.2f\n",
1837 GNUNET_i2s(peer), pref_rel);
1839 GNUNET_STATISTICS_update (mlp->stats,"# LP address preference changes", 1, GNUNET_NO);
1840 /* Update the constraints with changed preferences */
1842 /* Update quality constraint c7 */
1844 /* Update relativity constraint c9 */
1845 if (NULL == (p = GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, peer)))
1847 LOG (GNUNET_ERROR_TYPE_ERROR, "Updating preference for unknown peer `%s'\n", GNUNET_i2s(peer));
1850 p->f = get_peer_pref_value (mlp, peer);
1852 LOG (GNUNET_ERROR_TYPE_ERROR, "PEER PREF: %s %.2f\n",
1853 GNUNET_i2s(peer), p->f);*/
1854 mlp_create_problem_update_value (&mlp->p, p->r_c9, mlp->p.c_r, -p->f, __LINE__);
1856 /* Problem size changed: new address for peer with pending request */
1857 mlp->stat_mlp_prob_updated = GNUNET_YES;
1858 if (GNUNET_YES == mlp->opt_mlp_auto_solve)
1859 GAS_mlp_solve_problem (solver);
1865 * Get application feedback for a peer
1867 * @param solver the solver handle
1868 * @param application the application
1869 * @param peer the peer to change the preference for
1870 * @param scope the time interval for this feedback: [now - scope .. now]
1871 * @param kind the kind to change the preference
1872 * @param score the score
1875 GAS_mlp_address_preference_feedback (void *solver,
1877 const struct GNUNET_PeerIdentity *peer,
1878 const struct GNUNET_TIME_Relative scope,
1879 enum GNUNET_ATS_PreferenceKind kind,
1882 struct GAS_PROPORTIONAL_Handle *s = solver;
1883 GNUNET_assert (NULL != solver);
1884 GNUNET_assert (NULL != peer);
1886 GNUNET_assert (NULL != s);
1891 mlp_free_peers (void *cls,
1892 const struct GNUNET_PeerIdentity *key, void *value)
1894 struct GNUNET_CONTAINER_MultiPeerMap *map = cls;
1895 struct ATS_Peer *p = value;
1897 GNUNET_CONTAINER_multipeermap_remove (map, key, value);
1905 * Shutdown the MLP problem solving component
1907 * @param cls the solver handle
1911 libgnunet_plugin_ats_mlp_done (void *cls)
1913 struct GAS_MLP_Handle *mlp = cls;
1914 GNUNET_assert (mlp != NULL);
1916 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down mlp solver\n");
1917 mlp_delete_problem (mlp);
1919 GNUNET_CONTAINER_multipeermap_iterate (mlp->requested_peers,
1921 mlp->requested_peers);
1922 GNUNET_CONTAINER_multipeermap_destroy (mlp->requested_peers);
1923 mlp->requested_peers = NULL;
1925 /* Clean up GLPK environment */
1929 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutdown down of mlp solver complete\n");
1935 libgnunet_plugin_ats_mlp_init (void *cls)
1937 struct GNUNET_ATS_PluginEnvironment *env = cls;
1938 struct GAS_MLP_Handle * mlp = GNUNET_new (struct GAS_MLP_Handle);
1943 unsigned long long tmp;
1950 struct GNUNET_TIME_Relative max_duration;
1951 long long unsigned int max_iterations;
1953 GNUNET_assert (NULL != env->cfg);
1954 GNUNET_assert (NULL != env->addresses);
1955 GNUNET_assert (NULL != env->bandwidth_changed_cb);
1956 GNUNET_assert (NULL != env->get_preferences);
1957 GNUNET_assert (NULL != env->get_property);
1959 /* Init GLPK environment */
1960 int res = glp_init_env();
1963 LOG (GNUNET_ERROR_TYPE_DEBUG, "GLPK: `%s'\n",
1964 "initialization successful");
1967 LOG (GNUNET_ERROR_TYPE_DEBUG, "GLPK: `%s'\n",
1968 "environment is already initialized");
1971 LOG (GNUNET_ERROR_TYPE_ERROR, "Could not init GLPK: `%s'\n",
1972 "initialization failed (insufficient memory)");
1977 LOG (GNUNET_ERROR_TYPE_ERROR, "Could not init GLPK: `%s'\n",
1978 "initialization failed (unsupported programming model)");
1986 mlp->opt_dump_problem_all = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
1987 "ats", "MLP_DUMP_PROBLEM_ALL");
1988 if (GNUNET_SYSERR == mlp->opt_dump_problem_all)
1989 mlp->opt_dump_problem_all = GNUNET_NO;
1991 mlp->opt_dump_solution_all = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
1992 "ats", "MLP_DUMP_SOLUTION_ALL");
1993 if (GNUNET_SYSERR == mlp->opt_dump_solution_all)
1994 mlp->opt_dump_solution_all = GNUNET_NO;
1996 mlp->opt_dump_problem_on_fail = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
1997 "ats", "MLP_DUMP_PROBLEM_ON_FAIL");
1998 if (GNUNET_SYSERR == mlp->opt_dump_problem_on_fail)
1999 mlp->opt_dump_problem_on_fail = GNUNET_NO;
2001 mlp->opt_dump_solution_on_fail = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
2002 "ats", "MLP_DUMP_SOLUTION_ON_FAIL");
2003 if (GNUNET_SYSERR == mlp->opt_dump_solution_on_fail)
2004 mlp->opt_dump_solution_on_fail = GNUNET_NO;
2006 mlp->opt_glpk_verbose = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
2007 "ats", "MLP_GLPK_VERBOSE");
2008 if (GNUNET_SYSERR == mlp->opt_glpk_verbose)
2009 mlp->opt_glpk_verbose = GNUNET_NO;
2011 mlp->pv.BIG_M = (double) BIG_M_VALUE;
2013 /* Get timeout for iterations */
2014 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time(env->cfg, "ats",
2015 "MLP_MAX_DURATION", &max_duration))
2017 max_duration = MLP_MAX_EXEC_DURATION;
2020 /* Get maximum number of iterations */
2021 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_size(env->cfg, "ats",
2022 "MLP_MAX_ITERATIONS", &max_iterations))
2024 max_iterations = MLP_MAX_ITERATIONS;
2027 /* Get diversity coefficient from configuration */
2028 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg,
2029 "ats", "MLP_COEFFICIENT_D", &tmp))
2030 D = (double) tmp / 100;
2034 /* Get proportionality coefficient from configuration */
2035 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg,
2036 "ats", "MLP_COEFFICIENT_R", &tmp))
2037 R = (double) tmp / 100;
2041 /* Get utilization coefficient from configuration */
2042 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg,
2043 "ats", "MLP_COEFFICIENT_U", &tmp))
2044 U = (double) tmp / 100;
2048 /* Get quality metric coefficients from configuration */
2049 int i_delay = MLP_NaN;
2050 int i_distance = MLP_NaN;
2051 int q[GNUNET_ATS_QualityPropertiesCount] = GNUNET_ATS_QualityProperties;
2052 for (c = 0; c < GNUNET_ATS_QualityPropertiesCount; c++)
2054 /* initialize quality coefficients with default value 1.0 */
2055 mlp->pv.co_Q[c] = DEFAULT_QUALITY;
2057 mlp->pv.q[c] = q[c];
2058 if (q[c] == GNUNET_ATS_QUALITY_NET_DELAY)
2060 if (q[c] == GNUNET_ATS_QUALITY_NET_DISTANCE)
2064 if ( (i_delay != MLP_NaN) &&
2065 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats",
2066 "MLP_COEFFICIENT_QUALITY_DELAY", &tmp)) )
2067 mlp->pv.co_Q[i_delay] = (double) tmp / 100;
2069 mlp->pv.co_Q[i_delay] = DEFAULT_QUALITY;
2071 if ( (i_distance != MLP_NaN) &&
2072 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats",
2073 "MLP_COEFFICIENT_QUALITY_DISTANCE", &tmp)) )
2074 mlp->pv.co_Q[i_distance] = (double) tmp / 100;
2076 mlp->pv.co_Q[i_distance] = DEFAULT_QUALITY;
2078 /* Get minimum bandwidth per used address from configuration */
2079 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats",
2080 "MLP_MIN_BANDWIDTH",
2085 b_min = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
2088 /* Get minimum number of connections from configuration */
2089 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats",
2090 "MLP_MIN_CONNECTIONS",
2094 n_min = DEFAULT_MIN_CONNECTIONS;
2096 /* Init network quotas */
2097 int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
2098 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
2101 for (c2 = 0; c2 < env->network_count; c2++)
2103 if (quotas[c] == env->networks[c2])
2105 mlp->pv.quota_index[c] = env->networks[c2];
2106 mlp->pv.quota_out[c] = env->out_quota[c2];
2107 mlp->pv.quota_in[c] = env->in_quota[c2];
2109 LOG (GNUNET_ERROR_TYPE_DEBUG,
2110 "Quota for network `%s' (in/out) %llu/%llu\n",
2111 GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]),
2112 mlp->pv.quota_out[c],
2113 mlp->pv.quota_in[c]);
2118 /* Check if defined quota could make problem unsolvable */
2119 if ((n_min * b_min) > mlp->pv.quota_out[c])
2121 LOG (GNUNET_ERROR_TYPE_INFO,
2122 _("Adjusting inconsistent outbound quota configuration for network `%s', is %llu must be at least %llu\n"),
2123 GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]),
2124 mlp->pv.quota_out[c],
2126 mlp->pv.quota_out[c] = (n_min * b_min);
2128 if ((n_min * b_min) > mlp->pv.quota_in[c])
2130 LOG (GNUNET_ERROR_TYPE_INFO,
2131 _("Adjusting inconsistent inbound quota configuration for network `%s', is %llu must be at least %llu\n"),
2132 GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]),
2133 mlp->pv.quota_in[c],
2135 mlp->pv.quota_in[c] = (n_min * b_min);
2138 /* Check if bandwidth is too big to make problem solvable */
2139 if (mlp->pv.BIG_M < mlp->pv.quota_out[c])
2141 LOG (GNUNET_ERROR_TYPE_INFO,
2142 _("Adjusting outbound quota configuration for network `%s'from %llu to %.0f\n"),
2143 GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]),
2144 mlp->pv.quota_out[c],
2146 mlp->pv.quota_out[c] = mlp->pv.BIG_M ;
2148 if (mlp->pv.BIG_M < mlp->pv.quota_in[c])
2150 LOG (GNUNET_ERROR_TYPE_INFO, _("Adjusting inbound quota configuration for network `%s' from %llu to %.0f\n"),
2151 GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]),
2152 mlp->pv.quota_in[c],
2154 mlp->pv.quota_in[c] = mlp->pv.BIG_M ;
2157 if (GNUNET_NO == found)
2159 mlp->pv.quota_in[c] = ntohl(GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
2160 mlp->pv.quota_out[c] = ntohl(GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
2161 LOG (GNUNET_ERROR_TYPE_INFO, _("Using default quota configuration for network `%s' (in/out) %llu/%llu\n"),
2162 GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]),
2163 mlp->pv.quota_in[c],
2164 mlp->pv.quota_out[c]);
2168 env->sf.s_add = &GAS_mlp_address_add;
2169 env->sf.s_address_update_property = &GAS_mlp_address_property_changed;
2170 env->sf.s_address_update_session = &GAS_mlp_address_session_changed;
2171 env->sf.s_address_update_inuse = &GAS_mlp_address_inuse_changed;
2172 env->sf.s_address_update_network = &GAS_mlp_address_change_network;
2173 env->sf.s_get = &GAS_mlp_get_preferred_address;
2174 env->sf.s_get_stop = &GAS_mlp_stop_get_preferred_address;
2175 env->sf.s_pref = &GAS_mlp_address_change_preference;
2176 env->sf.s_feedback = &GAS_mlp_address_preference_feedback;
2177 env->sf.s_del = &GAS_mlp_address_delete;
2178 env->sf.s_bulk_start = &GAS_mlp_bulk_start;
2179 env->sf.s_bulk_stop = &GAS_mlp_bulk_stop;
2182 /* Assign options to handle */
2183 mlp->stats = (struct GNUNET_STATISTICS_Handle *) env->stats;
2184 mlp->addresses = env->addresses;
2185 mlp->bw_changed_cb = env->bandwidth_changed_cb;
2186 mlp->bw_changed_cb_cls = env->bw_changed_cb_cls;
2187 mlp->get_preferences = env->get_preferences;
2188 mlp->get_preferences_cls = env->get_preference_cls;
2189 mlp->get_properties = env->get_property;
2190 mlp->get_properties_cls = env->get_property_cls;
2191 /* Setting MLP Input variables */
2196 mlp->pv.b_min = b_min;
2197 mlp->pv.n_min = n_min;
2198 mlp->pv.m_q = GNUNET_ATS_QualityPropertiesCount;
2199 mlp->stat_mlp_prob_changed = GNUNET_NO;
2200 mlp->stat_mlp_prob_updated = GNUNET_NO;
2201 mlp->opt_mlp_auto_solve = GNUNET_YES;
2202 mlp->requested_peers = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
2203 mlp->stat_bulk_requests = 0;
2204 mlp->stat_bulk_lock = 0;
2207 /* Redirect GLPK output to GNUnet logging */
2208 glp_term_hook (&mlp_term_hook, (void *) mlp);
2210 /* Init LP solving parameters */
2211 glp_init_smcp(&mlp->control_param_lp);
2212 mlp->control_param_lp.msg_lev = GLP_MSG_OFF;
2213 if (GNUNET_YES == mlp->opt_glpk_verbose)
2214 mlp->control_param_lp.msg_lev = GLP_MSG_ALL;
2216 mlp->control_param_lp.it_lim = max_iterations;
2217 mlp->control_param_lp.tm_lim = max_duration.rel_value_us / 1000LL;
2219 /* Init MLP solving parameters */
2220 glp_init_iocp(&mlp->control_param_mlp);
2221 mlp->control_param_mlp.msg_lev = GLP_MSG_OFF;
2222 if (GNUNET_YES == mlp->opt_glpk_verbose)
2223 mlp->control_param_mlp.msg_lev = GLP_MSG_ALL;
2224 mlp->control_param_mlp.tm_lim = max_duration.rel_value_us / 1000LL;
2226 LOG (GNUNET_ERROR_TYPE_DEBUG, "solver ready\n");
2231 /* end of plugin_ats_mlp.c */