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);
58 if (presolve == GNUNET_YES) opt_mlp.presolve = GLP_ON;
62 glp_init_smcp(&opt_lp);
64 opt_lp.presolve = GLP_OFF;
65 opt_lp.msg_lev = GLP_MSG_OFF;
66 result = glp_simplex(prob, &opt_lp);
68 opt_mlp.msg_lev = GLP_MSG_OFF;
70 result = glp_intopt (prob, &opt_mlp);
71 solution = glp_mip_status (prob);
72 GNUNET_assert ((solution == 5) && (result==0));
75 void solve_lp(int presolve)
80 glp_init_smcp(&opt_lp);
82 opt_lp.msg_lev = GLP_MSG_OFF;
83 if (presolve==GNUNET_YES) opt_lp.presolve = GLP_ON;
85 result = glp_simplex(prob, &opt_lp);
86 solution = glp_get_status (prob);
87 GNUNET_assert ((solution == 5) && (result==0));
91 void bench_simplex_optimization(char * file, int executions)
95 prob = glp_create_prob();
96 glp_read_lp(prob, NULL, file);
100 for (c=0; c<executions;c++)
102 start = GNUNET_TIME_absolute_get();
104 end = GNUNET_TIME_absolute_get();
106 exec_time[c] = GNUNET_TIME_absolute_get_difference(start, end).rel_value;
108 sim_with_opt_avg += exec_time[c];
109 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Simplex /w optimization iterations %i: %llu \n", c, exec_time[c]);
112 glp_delete_prob(prob);
116 void bench_simplex_no_optimization(char * file, int executions)
120 prob = glp_create_prob();
121 glp_read_lp(prob, NULL, file);
123 for (c=0; c<executions;c++)
125 start = GNUNET_TIME_absolute_get();
126 solve_lp(GNUNET_YES);
127 end = GNUNET_TIME_absolute_get();
129 exec_time[c] = GNUNET_TIME_absolute_get_difference(start, end).rel_value;
131 sim_no_opt_avg += exec_time[c];
132 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Simplex iterations %i: %llu \n", c, exec_time[c]);
135 glp_delete_prob(prob);
138 void bench_mlp_no_optimization(char * file, int executions)
142 prob = glp_create_prob();
143 glp_read_lp(prob, NULL, file);
145 for (c=0; c<executions;c++)
147 start = GNUNET_TIME_absolute_get();
148 solve_lp(GNUNET_YES);
149 solve_mlp (GNUNET_NO);
150 end = GNUNET_TIME_absolute_get();
152 exec_time[c] = GNUNET_TIME_absolute_get_difference(start, end).rel_value;
154 mlp_no_opt_avg += exec_time[c];
155 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MLP iterations no optimization%i: %llu \n", c, exec_time[c]);
158 glp_delete_prob(prob);
162 void bench_mlp_with_optimization(char * file, int executions)
165 prob = glp_create_prob();
166 glp_read_lp(prob, NULL, file);
168 solve_lp(GNUNET_YES);
170 for (c=0; c<executions;c++)
172 start = GNUNET_TIME_absolute_get();
174 solve_mlp (GNUNET_NO);
175 end = GNUNET_TIME_absolute_get();
177 exec_time[c] = GNUNET_TIME_absolute_get_difference(start, end).rel_value;
179 mlp_with_opt_avg += exec_time[c];
180 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MLP /w optimization iterations %i: %llu \n", c, exec_time[c]);
183 glp_delete_prob(prob);
186 /* Modify quality constraint */
187 void modify_qm(int start, int length, int count)
189 //int * ind = GNUNET_malloc (length * sizeof (int));
190 //double *val = GNUNET_malloc (length * sizeof (double));
196 while (c<=(start+count))
198 res = glp_get_mat_row(prob, c, ind, val);
200 printf("%i %i \n", c, res);
201 for (c2=0; c2<res; c2++)
203 printf("%i = %f \n", ind[c2], val[c2]);
208 //glp_set_mat_row(prob, start, length, ind, val);
211 void modify_cr (int start, int length, int count)
213 //int * ind = GNUNET_malloc (length * sizeof (int));
214 //double *val = GNUNET_malloc (length * sizeof (double));
219 while (c<=(start+count))
221 res = glp_get_mat_row(prob, c, ind, val);
223 printf("row index: %i non-zero elements: %i \n", c, res);
224 for (c2=1; c2<=res; c2++)
226 printf("%i = %f ", ind[c2], val[c2]);
231 //glp_set_mat_row(prob, start, length, ind, val);
234 void test_mlp(char * file)
237 prob = glp_create_prob();
238 glp_read_lp(prob, NULL, file);
240 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%i iterations simplex, presolve: YES, keep problem: YES!\n", executions, exec_time[c]);
243 mlp_w_ps_w_keep_avg = 0;
244 for (c=0; c<executions;c++)
246 start = GNUNET_TIME_absolute_get();
247 solve_mlp(GNUNET_NO);
248 //modify_qm (906,10,2);
249 modify_cr (901,10,3);
250 end = GNUNET_TIME_absolute_get();
252 exec_time[c] = GNUNET_TIME_absolute_get_difference(start, end).rel_value;
253 mlp_wo_ps_w_keep_avg += exec_time[c];
259 int main (int argc, char *argv[])
261 GNUNET_log_setup ("test-transport-ats",
270 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GLPK not installed, exiting testcase\n");
276 char * file = "ats_mlp_p500_m2000.problem";
278 bench_simplex_no_optimization (file, executions);
279 bench_simplex_optimization (file, executions);
280 bench_mlp_no_optimization (file, executions);
281 bench_mlp_with_optimization (file, executions);
283 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Simplex no optimization average: %llu\n", sim_no_opt_avg / EXECS);
284 GAUGER ("TRANSPORT","GLPK simplex 500 peers 2000 addresses no optimization", sim_no_opt_avg / EXECS, "ms");
285 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Simplex optimization average: %llu\n", sim_with_opt_avg / EXECS);
286 GAUGER ("TRANSPORT","GLPK simplex 500 peers 2000 addresses with optimization", sim_with_opt_avg / EXECS, "ms");
287 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MLP no optimization average: %llu\n", mlp_no_opt_avg / EXECS);
288 GAUGER ("TRANSPORT","GLPK MLP 500 peers 2000 addresses no optimization", mlp_no_opt_avg / EXECS, "ms");
289 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MLP optimization average: %llu\n", mlp_with_opt_avg / EXECS);
290 GAUGER ("TRANSPORT","GLPK MLP 500 peers 2000 addresses with optimization", mlp_with_opt_avg / EXECS, "ms");
295 /* end of test_transport_ats_perf.c*/