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_addresses_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 DEBUG_MLP GNUNET_EXTRA_LOGGING
39 #define BIG_M_VALUE (UINT32_MAX) /10
40 #define BIG_M_STRING "unlimited"
42 #define MLP_AVERAGING_QUEUE_LENGTH 3
44 #define MLP_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3)
45 #define MLP_MAX_ITERATIONS INT_MAX
49 struct ATS_Peer *next;
50 struct ATS_Peer *prev;
52 struct GNUNET_PeerIdentity id;
54 /* Array of quality preferences */
55 double f_q[GNUNET_ATS_QualityPropertiesCount];
56 /* Legacy preference value */
59 /* constraint 2: 1 address per peer*/
62 /* constraint 9: relativity */
65 struct ATS_Address *head;
66 struct ATS_Address *tail;
69 struct ATS_PreferedAddress
71 uint32_t bandwidth_out;
72 uint32_t bandwidth_in;
73 struct ATS_Address *address;
84 struct GNUNET_STATISTICS_Handle *stats;
87 * GLPK (MLP) problem object
98 * GLPK LP control parameter
100 glp_smcp control_param_lp;
103 * GLPK LP control parameter
105 glp_iocp control_param_mlp;
108 * Solves the task in an regular interval
110 GNUNET_SCHEDULER_TaskIdentifier mlp_task;
113 * Interval between scheduled problem solving
115 struct GNUNET_TIME_Relative exec_interval;
118 * Maximum execution time per problem solving
120 struct GNUNET_TIME_Relative max_exec_duration;
123 * Maximum number of LP iterations per problem solving
125 unsigned int max_iterations;
128 * Solve the problem automatically when updates occur?
129 * Default: GNUNET_YES
130 * Can be disabled for test and measurements
134 /* state information */
137 * Do we need to use the LP presolver?
139 * If the problem addresses were added or removed and the last basis was we
140 * need to use the presolver.
141 * presolver_required == GNUNET_YES
143 * If values were modified, we can reuse a valid basis
144 * presolver_required == GNUNET_NO
146 int presolver_required;
151 * Time of last execution
153 struct GNUNET_TIME_Absolute last_execution;
157 * How often was the LP problem solved
159 unsigned int lp_solved;
162 * total duration of all lp solver executions
164 uint64_t lp_total_duration;
167 * How often was the MLP problem solved
169 unsigned int mlp_solved;
172 * total duration of all mlp solver executions
174 uint64_t mlp_total_duration;
176 unsigned int addr_in_problem;
178 /* Information about the problem */
180 struct ATS_Peer *peer_head;
181 struct ATS_Peer *peer_tail;
183 /* Number of peers */
186 /* current problem matrix */
187 /* row index array */
189 /* column index array */
191 /* column index array */
193 /* current size of the constraint matrix |indices| */
194 unsigned int cm_size;
197 /* Row index constraint 2: */
199 /* Row index constraint 4: minimum connections */
201 /* Row index constraint 6: maximize diversity */
203 /* Row index constraint 8: utilization*/
205 /* Row index constraint 9: relativity*/
208 /* column index Diversity (D) column */
212 /* column index Utilization (U) column */
216 /* column index Proportionality (R) column */
220 /* ATS Quality metrics
222 * array with GNUNET_ATS_QualityPropertiesCount elements
223 * contains mapping to GNUNET_ATS_Property*/
224 int q[GNUNET_ATS_QualityPropertiesCount];
226 /* column index quality metrics */
227 int c_q[GNUNET_ATS_QualityPropertiesCount];
229 /* column index quality metrics */
230 int r_q[GNUNET_ATS_QualityPropertiesCount];
232 /* quality metric coefficients*/
233 double co_Q[GNUNET_ATS_QualityPropertiesCount];
235 /* number of quality metrics */
238 /* ATS network quotas */
239 int c_quota[GNUNET_ATS_NetworkTypeCount];
240 int r_quota[GNUNET_ATS_NetworkTypeCount];
241 int quota_index [GNUNET_ATS_NetworkTypeCount];
242 unsigned long long quota_out[GNUNET_ATS_NetworkTypeCount];
243 unsigned long long quota_in[GNUNET_ATS_NetworkTypeCount];
245 /* ATS ressource costs
247 * array with GNUNET_ATS_QualityPropertiesCount elements
248 * contains mapping to GNUNET_ATS_Property*/
249 int rc[GNUNET_ATS_QualityPropertiesCount];
251 /* column index ressource costs */
252 int c_rc[GNUNET_ATS_QualityPropertiesCount];
254 /* ressource costs coefficients*/
255 double co_RC[GNUNET_ATS_QualityPropertiesCount];
257 /* number of quality metrics */
260 /* minimum bandwidth assigned to an address */
263 /* minimum number of addresses with bandwidth assigned */
269 * Address specific MLP information
271 struct MLP_information
277 /* bandwidth column index */
280 /* address usage column */
285 /* constraint 1: bandwidth capping */
288 /* constraint 3: minimum bandwidth */
291 /* Quality information row indices */
292 unsigned int r_q[GNUNET_ATS_QualityPropertiesCount];
294 /* Quality information */
295 double q[GNUNET_ATS_QualityPropertiesCount][MLP_AVERAGING_QUEUE_LENGTH];
297 /* Quality information averaged */
298 double q_averaged[GNUNET_ATS_QualityPropertiesCount];
300 /* Averaging index */
301 int q_avg_i[GNUNET_ATS_QualityPropertiesCount];
306 * Init the MLP problem solving component
308 * @param cfg configuration handle
309 * @param stats the GNUNET_STATISTICS handle
310 * @param max_duration maximum numbers of iterations for the LP/MLP Solver
311 * @param max_iterations maximum time limit for the LP/MLP Solver
312 * @return struct GAS_MLP_Handle * on success, NULL on fail
314 struct GAS_MLP_Handle *
315 GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
316 const struct GNUNET_STATISTICS_Handle *stats,
317 struct GNUNET_TIME_Relative max_duration,
318 unsigned int max_iterations);
321 * Solves the MLP problem on demand
323 * @param mlp the MLP Handle
324 * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure
327 GAS_mlp_solve_problem (struct GAS_MLP_Handle *mlp);
331 * Updates a single address in the MLP problem
333 * If the address did not exist before in the problem:
334 * The MLP problem has to be recreated and the problem has to be resolved
336 * Otherwise the addresses' values can be updated and the existing base can
339 * @param mlp the MLP Handle
340 * @param addresses the address hashmap
341 * the address has to be already added from the hashmap
342 * @param address the address to update
345 GAS_mlp_address_update (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address);
349 * Deletes a single address in the MLP problem
351 * The MLP problem has to be recreated and the problem has to be resolved
353 * @param mlp the MLP Handle
354 * @param addresses the address hashmap
355 * the address has to be already removed from the hashmap
356 * @param address the address to delete
359 GAS_mlp_address_delete (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address);
363 * Changes the preferences for a peer in the MLP problem
365 * @param mlp the MLP Handle
366 * @param peer the peer
367 * @param kind the kind to change the preference
368 * @param score the score
371 GAS_mlp_address_change_preference (struct GAS_MLP_Handle *mlp,
372 const struct GNUNET_PeerIdentity *peer,
373 enum GNUNET_ATS_PreferenceKind kind,
378 * Get the preferred address for a specific peer
380 * @param mlp the MLP Handle
381 * @param addresses address hashmap
382 * @param peer the peer
383 * @return suggested address
385 struct ATS_PreferedAddress *
386 GAS_mlp_get_preferred_address (struct GAS_MLP_Handle *mlp,
387 struct GNUNET_CONTAINER_MultiHashMap * addresses,
388 const struct GNUNET_PeerIdentity *peer);
391 * Shutdown the MLP problem solving component
397 /* end of gnunet-service-ats_addresses_mlp.h */