2 This file is part of GNUnet.
3 (C) 2009 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/test_transport_ats_perf.c
22 * @brief testcase for ats functionality
25 #include "gnunet_time_lib.h"
29 #define VERBOSE GNUNET_NO
35 static int executions = EXECS;
36 static uint64_t exec_time[EXECS];
38 static uint64_t sim_no_opt_avg;
39 static uint64_t sim_with_opt_avg;
40 static uint64_t mlp_no_opt_avg;
41 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;
51 void solve_mlp(int presolve)
56 glp_init_iocp(&opt_mlp);
57 opt_mlp.msg_lev = GLP_MSG_OFF;
59 result = glp_intopt (prob, &opt_mlp);
60 solution = glp_mip_status (prob);
61 GNUNET_assert ((solution == 5) && (result==0));
64 void solve_lp(int presolve)
69 glp_init_smcp(&opt_lp);
71 opt_lp.msg_lev = GLP_MSG_OFF;
72 if (presolve==GNUNET_YES) opt_lp.presolve = GLP_ON;
74 result = glp_simplex(prob, &opt_lp);
75 solution = glp_get_status (prob);
76 GNUNET_assert ((solution == 5) && (result==0));
80 void bench_simplex_optimization(char * file, int executions)
84 prob = glp_create_prob();
85 glp_read_lp(prob, NULL, file);
89 for (c=0; c<executions;c++)
91 start = GNUNET_TIME_absolute_get();
93 end = GNUNET_TIME_absolute_get();
95 exec_time[c] = GNUNET_TIME_absolute_get_difference(start, end).rel_value;
97 sim_with_opt_avg += exec_time[c];
98 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Simplex /w optimization iterations %i: %llu \n", c, exec_time[c]);
101 glp_delete_prob(prob);
105 void bench_simplex_no_optimization(char * file, int executions)
109 prob = glp_create_prob();
110 glp_read_lp(prob, NULL, file);
112 for (c=0; c<executions;c++)
114 start = GNUNET_TIME_absolute_get();
115 solve_lp(GNUNET_YES);
116 end = GNUNET_TIME_absolute_get();
118 exec_time[c] = GNUNET_TIME_absolute_get_difference(start, end).rel_value;
120 sim_no_opt_avg += exec_time[c];
121 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Simplex iterations %i: %llu \n", c, exec_time[c]);
124 glp_delete_prob(prob);
127 void bench_mlp_no_optimization(char * file, int executions)
131 prob = glp_create_prob();
132 glp_read_lp(prob, NULL, file);
134 for (c=0; c<executions;c++)
136 start = GNUNET_TIME_absolute_get();
137 solve_lp(GNUNET_YES);
138 solve_mlp (GNUNET_NO);
139 end = GNUNET_TIME_absolute_get();
141 exec_time[c] = GNUNET_TIME_absolute_get_difference(start, end).rel_value;
143 mlp_no_opt_avg += exec_time[c];
144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MLP iterations no optimization %i: %llu \n", c, exec_time[c]);
147 glp_delete_prob(prob);
151 void bench_mlp_with_optimization(char * file, int executions)
154 prob = glp_create_prob();
155 glp_read_lp(prob, NULL, file);
157 solve_lp(GNUNET_YES);
159 for (c=0; c<executions;c++)
161 start = GNUNET_TIME_absolute_get();
163 solve_mlp (GNUNET_NO);
164 end = GNUNET_TIME_absolute_get();
166 exec_time[c] = GNUNET_TIME_absolute_get_difference(start, end).rel_value;
168 mlp_with_opt_avg += exec_time[c];
169 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MLP /w optimization iterations %i: %llu \n", c, exec_time[c]);
172 glp_delete_prob(prob);
175 /* Modify quality constraint */
176 void modify_qm(int start, int length, int count)
178 //int * ind = GNUNET_malloc (length * sizeof (int));
179 //double *val = GNUNET_malloc (length * sizeof (double));
185 while (c<=(start+count))
187 res = glp_get_mat_row(prob, c, ind, val);
189 printf("%i %i \n", c, res);
190 for (c2=0; c2<res; c2++)
192 printf("%i = %f \n", ind[c2], val[c2]);
197 //glp_set_mat_row(prob, start, length, ind, val);
200 void modify_cr (int start, int length, int count)
202 //int * ind = GNUNET_malloc (length * sizeof (int));
203 //double *val = GNUNET_malloc (length * sizeof (double));
208 while (c<=(start+count))
210 res = glp_get_mat_row(prob, c, ind, val);
212 printf("row index: %i non-zero elements: %i \n", c, res);
213 for (c2=1; c2<=res; c2++)
215 printf("%i = %f ", ind[c2], val[c2]);
220 //glp_set_mat_row(prob, start, length, ind, val);
223 void test_mlp(char * file)
226 prob = glp_create_prob();
227 glp_read_lp(prob, NULL, file);
229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%i iterations simplex, presolve: YES, keep problem: YES!\n", executions, exec_time[c]);
232 mlp_w_ps_w_keep_avg = 0;
233 for (c=0; c<executions;c++)
235 start = GNUNET_TIME_absolute_get();
236 solve_mlp(GNUNET_NO);
237 //modify_qm (906,10,2);
238 modify_cr (901,10,3);
239 end = GNUNET_TIME_absolute_get();
241 exec_time[c] = GNUNET_TIME_absolute_get_difference(start, end).rel_value;
242 mlp_wo_ps_w_keep_avg += exec_time[c];
248 int main (int argc, char *argv[])
250 GNUNET_log_setup ("test-transport-ats",
259 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GLPK not installed, exiting testcase\n");
265 char * file = "ats_mlp_p100_m400.problem";
266 bench_simplex_no_optimization (file, executions);
267 bench_simplex_optimization (file, executions);
268 bench_mlp_no_optimization (file, executions);
269 bench_mlp_with_optimization (file, executions);
271 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Simplex no optimization average: %llu\n", sim_no_opt_avg / EXECS);
272 GAUGER ("TRANSPORT","GLPK simplex 500 peers 2000 addresses no optimization", sim_no_opt_avg / EXECS, "ms");
273 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Simplex optimization average: %llu\n", sim_with_opt_avg / EXECS);
274 GAUGER ("TRANSPORT","GLPK simplex 500 peers 2000 addresses with optimization", sim_with_opt_avg / EXECS, "ms");
275 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MLP no optimization average: %llu\n", mlp_no_opt_avg / EXECS);
276 GAUGER ("TRANSPORT","GLPK MLP 500 peers 2000 addresses no optimization", mlp_no_opt_avg / EXECS, "ms");
277 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MLP optimization average: %llu\n", mlp_with_opt_avg / EXECS);
278 GAUGER ("TRANSPORT","GLPK MLP 500 peers 2000 addresses with optimization", mlp_with_opt_avg / EXECS, "ms");
283 /* end of test_transport_ats_perf.c*/