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/gnunet-service-ats-solver_mlp.h
23 * @brief ats MLP problem solver
24 * @author Matthias Wachs
25 * @author Christian Grothoff
28 #include "gnunet_statistics_service.h"
29 #include "gnunet-service-ats_addresses.h"
34 #ifndef GNUNET_SERVICE_ATS_ADDRESSES_MLP_H
35 #define GNUNET_SERVICE_ATS_ADDRESSES_MLP_H
37 #define BIG_M_VALUE (UINT32_MAX) /10
38 #define BIG_M_STRING "unlimited"
40 #define MLP_AVERAGING_QUEUE_LENGTH 3
42 #define MLP_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10)
43 #define MLP_MAX_ITERATIONS 4096
48 #define DEFAULT_QUALITY 1.0
49 #define DEFAULT_MIN_CONNECTIONS 4
50 #define DEFAULT_PEER_PREFERENCE 1.0
53 #define MLP_UNDEFINED 0
60 struct GNUNET_TIME_Relative build_dur;
61 struct GNUNET_TIME_Relative lp_dur;
62 struct GNUNET_TIME_Relative mip_dur;
80 struct GNUNET_PeerIdentity id;
82 /* Was this peer already added to the current problem? */
85 /* constraint 2: 1 address per peer*/
88 /* constraint 9: relativity */
91 /* Legacy preference value */
95 /* Array of quality preferences */
96 double f_q[GNUNET_ATS_QualityPropertiesCount];
106 * GLPK (MLP) problem object
114 /* Number of addresses in problem */
115 unsigned int num_addresses;
116 /* Number of peers in problem */
117 unsigned int num_peers;
118 /* Number of elements in problem matrix */
119 unsigned int num_elements;
121 /* Row index constraint 2: */
123 /* Row index constraint 4: minimum connections */
125 /* Row index constraint 6: maximize diversity */
127 /* Row index constraint 8: utilization*/
129 /* Row index constraint 9: relativity*/
131 /* Row indices quality metrics */
132 int r_q[GNUNET_ATS_QualityPropertiesCount];
133 /* Row indices ATS network quotas */
134 int r_quota[GNUNET_ATS_NetworkTypeCount];
136 /* Column index Diversity (D) column */
138 /* Column index Utilization (U) column */
140 /* Column index Proportionality (R) column */
142 /* Column index quality metrics */
143 int c_q[GNUNET_ATS_QualityPropertiesCount];
148 /* Row index array */
150 /* Column index array */
152 /* Column index value */
159 /* Big M value for bandwidth capping */
162 /* ATS Quality metrics
164 * Array with GNUNET_ATS_QualityPropertiesCount elements
165 * contains mapping to GNUNET_ATS_Property*/
166 int q[GNUNET_ATS_QualityPropertiesCount];
168 /* Number of quality metrics */
171 /* Number of quality metrics */
174 /* Quality metric coefficients*/
175 double co_Q[GNUNET_ATS_QualityPropertiesCount];
177 /* Ressource costs coefficients*/
178 double co_RC[GNUNET_ATS_QualityPropertiesCount];
180 /* Diversity coefficient */
183 /* Utility coefficient */
186 /* Relativity coefficient */
189 /* Minimum bandwidth assigned to an address */
192 /* Minimum number of addresses with bandwidth assigned */
196 /* Array mapping array index to ATS network */
197 int quota_index [GNUNET_ATS_NetworkTypeCount];
198 /* Outbound quotas */
199 unsigned long long quota_out[GNUNET_ATS_NetworkTypeCount];
202 unsigned long long quota_in[GNUNET_ATS_NetworkTypeCount];
204 /* ATS ressource costs
205 * array with GNUNET_ATS_QualityPropertiesCount elements
206 * contains mapping to GNUNET_ATS_Property
208 int rc[GNUNET_ATS_QualityPropertiesCount];
216 struct GAS_MLP_Handle
221 struct GNUNET_STATISTICS_Handle *stats;
224 * Address hashmap for lookups
226 struct GNUNET_CONTAINER_MultiHashMap *addresses;
229 * Addresses' bandwidth changed callback
231 GAS_bandwidth_changed_cb bw_changed_cb;
234 * Addresses' bandwidth changed callback closure
236 void *bw_changed_cb_cls;
238 GAS_get_preferences get_preferences;
240 void *get_preferences_cls;
242 struct MLP_Problem p;
244 struct MLP_Variables pv;
246 struct MLP_Solution ps;
255 * Number of changes while solver was locked
260 * GLPK LP control parameter
263 glp_smcp control_param_lp;
265 void *control_param_lp;
269 * GLPK LP control parameter
272 glp_iocp control_param_mlp;
274 void *control_param_mlp;
278 * Peers with pending address requests
280 struct GNUNET_CONTAINER_MultiHashMap *peers;
283 * Was the problem updated since last solution
285 int mlp_prob_updated;
288 * Has the problem size changed since last solution
290 int mlp_prob_changed;
293 * Solve the problem automatically when updates occur?
294 * Default: GNUNET_YES
295 * Can be disabled for test and measurements
300 * Write MILP problem to a MPS file
305 * Write MILP problem to a MPS file
313 * Address specific MLP information
315 struct MLP_information
318 /* Bandwidth assigned */
319 struct GNUNET_BANDWIDTH_Value32NBO b_out;
320 struct GNUNET_BANDWIDTH_Value32NBO b_in;
322 /* Address selected */
325 /* bandwidth column index */
328 /* address usage column */
333 /* constraint 1: bandwidth capping */
336 /* constraint 3: minimum bandwidth */
339 /* Quality information row indices */
340 unsigned int r_q[GNUNET_ATS_QualityPropertiesCount];
342 /* Quality information */
343 double q[GNUNET_ATS_QualityPropertiesCount][MLP_AVERAGING_QUEUE_LENGTH];
345 /* Quality information averaged */
346 double q_averaged[GNUNET_ATS_QualityPropertiesCount];
348 /* Averaging index */
349 int q_avg_i[GNUNET_ATS_QualityPropertiesCount];
353 * Solves the MLP problem
355 * @param solver the MLP Handle
356 * @param addresses the address hashmap
357 * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure
360 GAS_mlp_solve_problem (void *solver, struct GNUNET_CONTAINER_MultiHashMap * addresses);
364 * Init the MLP problem solving component
366 * @param cfg the GNUNET_CONFIGURATION_Handle handle
367 * @param stats the GNUNET_STATISTICS handle
368 * @param network array of GNUNET_ATS_NetworkType with length dest_length
369 * @param out_dest array of outbound quotas
370 * @param in_dest array of outbound quota
371 * @param dest_length array length for quota arrays
372 * @param bw_changed_cb callback for changed bandwidth amounts
373 * @param bw_changed_cb_cls cls for callback
374 * @param get_preference callback to get relative preferences for a peer
375 * @param get_preference_cls cls for callback to get relative preferences
376 * @return struct GAS_MLP_Handle on success, NULL on fail
379 GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
380 const struct GNUNET_STATISTICS_Handle *stats,
382 unsigned long long *out_dest,
383 unsigned long long *in_dest,
385 GAS_bandwidth_changed_cb bw_changed_cb,
386 void *bw_changed_cb_cls,
387 GAS_get_preferences get_preference,
388 void *get_preference_cls);
392 * Add a single address within a network to the solver
394 * @param solver the solver Handle
395 * @param addresses the address hashmap containing all addresses
396 * @param address the address to add
397 * @param network network type of this address
400 GAS_mlp_address_add (void *solver,
401 struct GNUNET_CONTAINER_MultiHashMap *addresses,
402 struct ATS_Address *address,
406 * Updates a single address in the MLP problem
408 * If the address did not exist before in the problem:
409 * The MLP problem has to be recreated and the problem has to be resolved
411 * ATS performance information in address are already updated, delta + previous
412 * values are included in atsi_prev (value GNUNET_ATS_VALUE_UNDEFINED if not existing before)
414 * Otherwise the addresses' values can be updated and the existing base can
417 * @param solver the solver Handle
418 * @param addresses the address hashmap containing all addresses
419 * @param address the update address
420 * @param prev_session the new session (if changed otherwise current)
421 * @param prev_in_use the new address in use state (if changed otherwise current)
422 * @param prev_atsi ATS information updated + previous values, GNUNET_ATS_VALUE_UNDEFINED if not existing before
423 * @param prev_atsi_count number of atsi values updated
426 GAS_mlp_address_update (void *solver,
427 struct GNUNET_CONTAINER_MultiHashMap *addresses,
428 struct ATS_Address *address,
429 uint32_t prev_session,
431 const struct GNUNET_ATS_Information *prev_atsi,
432 uint32_t prev_atsi_count);
436 * Deletes a single address in the MLP problem
438 * The MLP problem has to be recreated and the problem has to be resolved
440 * @param solver the MLP Handle
441 * @param addresses the address hashmap
442 * the address has to be already removed from the hashmap
443 * @param address the address to delete
444 * @param session_only delete only session not whole address
447 GAS_mlp_address_delete (void *solver,
448 struct GNUNET_CONTAINER_MultiHashMap *addresses,
449 struct ATS_Address *address,
454 * Changes the preferences for a peer in the MLP problem
456 * @param solver the MLP Handle
457 * @param addresses the address hashmap
458 * @param peer the peer
459 * @param kind the kind to change the preference
460 * @param pref_rel the relative score
463 GAS_mlp_address_change_preference (void *solver,
464 struct GNUNET_CONTAINER_MultiHashMap *addresses,
465 const struct GNUNET_PeerIdentity *peer,
466 enum GNUNET_ATS_PreferenceKind kind,
471 * Start a bulk operation
473 * @param solver the solver
476 GAS_mlp_bulk_start (void *solver);
480 * Bulk operation done
483 GAS_mlp_bulk_stop (void *solver);
487 * Get the preferred address for a specific peer
489 * @param solver the MLP Handle
490 * @param addresses address hashmap
491 * @param peer the peer
492 * @return suggested address
494 const struct ATS_Address *
495 GAS_mlp_get_preferred_address (void *solver,
496 struct GNUNET_CONTAINER_MultiHashMap * addresses,
497 const struct GNUNET_PeerIdentity *peer);
501 * Stop notifying about address and bandwidth changes for this peer
503 * @param solver the MLP handle
504 * @param addresses address hashmap
505 * @param peer the peer
509 GAS_mlp_stop_get_preferred_address (void *solver,
510 struct GNUNET_CONTAINER_MultiHashMap *addresses,
511 const struct GNUNET_PeerIdentity *peer);
515 * Shutdown the MLP problem solving component
517 * @param solver the solver handle
520 GAS_mlp_done (void *solver);
523 /* end of gnunet-service-ats_addresses_mlp.h */