- improved error logging
[oweals/gnunet.git] / src / ats / gnunet-service-ats_addresses_mlp.h
1 /*
2      This file is part of GNUnet.
3      (C) 2011 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 ats/gnunet-service-ats_addresses_mlp.h
23  * @brief ats mlp problem solver
24  * @author Matthias Wachs
25  * @author Christian Grothoff
26  */
27 #include "platform.h"
28 #include "gnunet_statistics_service.h"
29 #include "gnunet-service-ats_addresses.h"
30 #if HAVE_LIBGLPK
31 #include "glpk.h"
32 #endif
33
34 #ifndef GNUNET_SERVICE_ATS_ADDRESSES_MLP_H
35 #define GNUNET_SERVICE_ATS_ADDRESSES_MLP_H
36
37 #define VERBOSE GNUNET_EXTRA_LOGGING
38 #define DEBUG_MLP GNUNET_EXTRA_LOGGING
39
40 #define MLP_MAX_EXEC_DURATION   GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3)
41 #define MLP_MAX_ITERATIONS      INT_MAX
42
43 /**
44  * MLP Handle
45  */
46 struct GAS_MLP_Handle
47 {
48   /**
49    * Statistics handle
50    */
51   struct GNUNET_STATISTICS_Handle *stats;
52
53   /**
54    * GLPK (MLP) problem object
55    */
56 #if HAVE_LIBGLPK
57   glp_prob *prob;
58 #else
59   void *prob;
60 #endif
61
62   /**
63    * GLPK LP control parameter
64    */
65   glp_smcp control_param_lp;
66
67   /**
68    * GLPK LP control parameter
69    */
70   glp_iocp control_param_mlp;
71
72   /**
73    * Maximum execution time per problem solving
74    */
75   struct GNUNET_TIME_Relative max_exec_duration;
76
77   /**
78    * Maximum number of LP iterations per problem solving
79    */
80   unsigned int max_iterations;
81
82   /* state information */
83
84   /**
85    * Do we need to use the LP presolver?
86    *
87    * If the problem addresses were added or removed and the last basis was we
88    * need to use the presolver.
89    * presolver_required == GNUNET_YES
90    *
91    * If values were modified, we can reuse a valid basis
92    * presolver_required == GNUNET_NO
93    */
94   int presolver_required;
95
96   /* statistics */
97
98   /**
99    * Time of last execution
100    */
101   struct GNUNET_TIME_Absolute last_execution;
102
103
104   /**
105    * How often was the LP problem solved
106    */
107   unsigned int lp_solved;
108
109   /**
110    * total duration of all lp solver executions
111    */
112   uint64_t lp_total_duration;
113
114   /**
115    * How often was the MLP problem solved
116    */
117   unsigned int mlp_solved;
118
119   /**
120    * total duration of all mlp solver executions
121    */
122   uint64_t mlp_total_duration;
123
124   /* Information about the problem */
125
126
127   /* column index Diversity (D) column */
128   int c_d;
129   double co_D;
130
131   /* column index Utilization (U) column */
132   int c_u;
133   double co_U;
134
135   /* column index Proportionality (R) column */
136   int c_r;
137   double co_R;
138
139   /* ATS Quality metrics
140    * array with GNUNET_ATS_QualityPropertiesCount elements
141    * contains mapping to GNUNET_ATS_Property*/
142   int q[GNUNET_ATS_QualityPropertiesCount];
143
144   /* column index quality metrics  */
145   int c_q[GNUNET_ATS_QualityPropertiesCount];
146
147   /* quality metric coefficients*/
148   double co_Q[GNUNET_ATS_QualityPropertiesCount];
149
150   /* number of quality metrics */
151   int m;
152
153   /* minimum bandwidth assigned to an address */
154   unsigned int b_min;
155
156   /* minimum number of addresses with bandwidth assigned */
157   unsigned int n_min;
158 };
159
160
161 /**
162  * Address specific MLP information
163  */
164 struct MLP_information
165 {
166   /* bandwidth column index */
167   signed int c_b;
168
169   /* address usage column */
170   signed int c_n;
171 };
172
173
174 /**
175  * Init the MLP problem solving component
176  *
177  * @param cfg configuration handle
178  * @param stats the GNUNET_STATISTICS handle
179  * @param max_duration maximum numbers of iterations for the LP/MLP Solver
180  * @param max_iterations maximum time limit for the LP/MLP Solver
181  * @return struct GAS_MLP_Handle * on success, NULL on fail
182  */
183 struct GAS_MLP_Handle *
184 GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
185               const struct GNUNET_STATISTICS_Handle *stats,
186               struct GNUNET_TIME_Relative max_duration,
187               unsigned int max_iterations);
188
189
190 /**
191  * Updates a single address in the MLP problem
192  *
193  * If the address did not exist before in the problem:
194  * The MLP problem has to be recreated and the problem has to be resolved
195  *
196  * Otherwise the addresses' values can be updated and the existing base can
197  * be reused
198  *
199  * @param mlp the MLP Handle
200  * @param addresses the address hashmap
201  * @param address the address to update
202  */
203 void
204 GAS_mlp_address_update (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address);
205
206
207 /**
208  * Deletes a single address in the MLP problem
209  *
210  * The MLP problem has to be recreated and the problem has to be resolved
211  *
212  * @param mlp the MLP Handle
213  * @param addresses the address hashmap
214  * @param address the address to delete
215  */
216 void
217 GAS_mlp_address_delete (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address);
218
219
220 /**
221  * Deletes a single address in the MLP problem
222  *
223  * @param mlp the MLP Handle
224  * @param addresses the address hashmap
225  * @param address the address to change the preference
226  */
227 void
228 GAS_mlp_address_change_preference (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address);
229
230
231 /**
232  * Shutdown the MLP problem solving component
233  */
234 void
235 GAS_mlp_done ();
236
237 #endif
238 /* end of gnunet-service-ats_addresses_mlp.h */