2 This file is part of GNUnet.
3 (C) 2010, 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.
21 * @file testing/perf_transport_ats.c
22 * @brief testcase for ats functionality
25 #include "gnunet_time_lib.h"
31 #define VERBOSE GNUNET_NO
37 static int executions = EXECS;
38 static uint64_t exec_time[EXECS];
40 static uint64_t sim_no_opt_avg;
41 static uint64_t sim_with_opt_avg;
42 static uint64_t mlp_no_opt_avg;
43 static uint64_t mlp_with_opt_avg;
45 static glp_prob * prob;
47 static struct GNUNET_TIME_Absolute start;
48 static struct GNUNET_TIME_Absolute end;
52 solve_mlp(int presolve)
57 glp_init_iocp(&opt_mlp);
58 opt_mlp.msg_lev = GLP_MSG_OFF;
59 opt_mlp.presolve = GLP_OFF;
61 result = glp_intopt (prob, &opt_mlp);
62 solution = glp_mip_status (prob);
63 GNUNET_assert ((solution == 5) && (result==0));
67 solve_lp(int presolve)
72 glp_init_smcp(&opt_lp);
74 opt_lp.msg_lev = GLP_MSG_OFF;
75 if (presolve==GNUNET_YES) opt_lp.presolve = GLP_ON;
76 else opt_lp.presolve = GLP_OFF;
78 result = glp_simplex(prob, &opt_lp);
79 solution = glp_get_status (prob);
80 GNUNET_assert ((solution == 5) && (result==0));
84 /* Modify quality constraint */
86 modify_qm(int start, int length, int values_to_change)
88 //int * ind = GNUNET_malloc (length * sizeof (int));
89 //double *val = GNUNET_malloc (length * sizeof (double));
95 while (c<=(start+values_to_change))
97 res = glp_get_mat_row(prob, c, ind, val);
99 printf("%i %i \n", c, res);
100 for (c2=0; c2<res; c2++)
102 printf("%i = %f \n", ind[c2], val[c2]);
107 //glp_set_mat_row(prob, start, length, ind, val);
113 bench_simplex_optimization(char * file, int executions)
117 prob = glp_create_prob();
118 glp_read_lp(prob, NULL, file);
120 solve_lp(GNUNET_YES);
122 for (c=0; c<executions;c++)
124 start = GNUNET_TIME_absolute_get();
126 end = GNUNET_TIME_absolute_get();
128 exec_time[c] = GNUNET_TIME_absolute_get_difference(start, end).rel_value;
130 sim_with_opt_avg += exec_time[c];
131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
132 "Simplex /w optimization iterations %i: %llu \n",
136 glp_delete_prob(prob);
141 bench_simplex_no_optimization(char * file, int executions)
145 prob = glp_create_prob();
146 glp_read_lp(prob, NULL, file);
148 for (c=0; c<executions;c++)
150 start = GNUNET_TIME_absolute_get();
151 solve_lp(GNUNET_YES);
152 end = GNUNET_TIME_absolute_get();
154 exec_time[c] = GNUNET_TIME_absolute_get_difference(start, end).rel_value;
156 sim_no_opt_avg += exec_time[c];
157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
158 "Simplex iterations %i: %llu \n",
162 glp_delete_prob(prob);
167 bench_mlp_no_optimization(char * file, int executions)
171 prob = glp_create_prob();
172 glp_read_lp(prob, NULL, file);
174 for (c=0; c<executions;c++)
176 start = GNUNET_TIME_absolute_get();
177 solve_lp(GNUNET_YES);
178 solve_mlp (GNUNET_NO);
179 end = GNUNET_TIME_absolute_get();
181 exec_time[c] = GNUNET_TIME_absolute_get_difference(start, end).rel_value;
183 mlp_no_opt_avg += exec_time[c];
184 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MLP iterations no optimization %i: %llu \n", c, exec_time[c]);
187 glp_delete_prob(prob);
192 bench_mlp_with_optimization(char * file, int executions, int changes)
195 prob = glp_create_prob();
196 glp_read_lp(prob, NULL, file);
198 solve_lp(GNUNET_YES);
200 for (c=0; c<executions;c++)
202 start = GNUNET_TIME_absolute_get();
203 // modify_qm(906, 0, 0);
205 solve_mlp (GNUNET_NO);
206 end = GNUNET_TIME_absolute_get();
208 exec_time[c] = GNUNET_TIME_absolute_get_difference(start, end).rel_value;
210 mlp_with_opt_avg += exec_time[c];
211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MLP /w optimization iterations %i: %llu \n", c, exec_time[c]);
214 glp_delete_prob(prob);
219 modify_cr (int start, int length, int count)
221 //int * ind = GNUNET_malloc (length * sizeof (int));
222 //double *val = GNUNET_malloc (length * sizeof (double));
227 while (c<=(start+count))
229 res = glp_get_mat_row(prob, c, ind, val);
231 printf("row index: %i non-zero elements: %i \n", c, res);
232 for (c2=1; c2<=res; c2++)
234 printf("%i = %f ", ind[c2], val[c2]);
239 //glp_set_mat_row(prob, start, length, ind, val);
246 main (int argc, char *argv[])
249 GNUNET_log_setup ("perf-transport-ats",
258 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
259 "GLPK not installed, exiting testcase\n");
263 char * file = "ats_mlp_p100_m400.problem";
264 // char * file = "mlps/ats_mlp_p500_m2000.problem";
265 bench_simplex_no_optimization (file, executions);
266 bench_simplex_optimization (file, executions);
267 bench_mlp_no_optimization (file, executions);
268 bench_mlp_with_optimization (file, executions, 0);
270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
271 "Simplex no optimization average: %llu\n",
272 sim_no_opt_avg / EXECS);
275 "GLPK simplex no optimization",
276 (sim_no_opt_avg / EXECS) / 400,
278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
279 "Simplex, no optimization, average per peer: %llu\n",
280 (sim_with_opt_avg / EXECS) / 400);
282 "GLPK simplex with optimization",
283 (sim_with_opt_avg / EXECS) / 400,
285 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
286 "MLP no optimization average: %llu\n",
287 (mlp_no_opt_avg / EXECS) / 400);
289 "GLPK MLP no optimization",
290 (mlp_no_opt_avg / EXECS) / 400,
292 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MLP optimization average: %llu\n",
293 (mlp_with_opt_avg/ EXECS) / 400);
295 "GLPK MLP with optimization",
296 (mlp_with_opt_avg / EXECS) / 400, "ms/address");
302 /* end of per_transport_ats.c*/