3 /* A crash few tests for the maxmin library */
5 /* Copyright (c) 2004 Arnaud Legrand. All rights reserved. */
7 /* This program is free software; you can redistribute it and/or modify it
8 * under the terms of the license (GNU LGPL) which comes with this package. */
17 #include "surf/maxmin.h"
18 #include "xbt/xbt_os_time.h"
19 #include "xbt/sysdep.h" /* time manipulation for benchmarking */
23 double float_random(double max);
24 double float_random(double max)
26 return ((max * rand()) / (RAND_MAX + 1.0));
29 int int_random(int max);
30 int int_random(int max)
32 return (int) (((max * 1.0) * rand()) / (RAND_MAX + 1.0));
35 void test(int nb_cnst, int nb_var, int nb_elem);
36 void test(int nb_cnst, int nb_var, int nb_elem)
38 lmm_system_t Sys = NULL;
39 lmm_constraint_t *cnst = xbt_new0(lmm_constraint_t,nb_cnst);
40 lmm_variable_t *var = xbt_new0(lmm_variable_t,nb_var);
41 int *used = xbt_new0(int,nb_cnst);
44 Sys = lmm_system_new();
46 for (i = 0; i < nb_cnst; i++) {
47 cnst[i] = lmm_constraint_new(Sys, NULL, float_random(10.0));
50 for (i = 0; i < nb_var; i++) {
51 var[i] = lmm_variable_new(Sys, NULL, 1.0, -1.0, nb_elem);
52 for (j = 0; j < nb_cnst; j++)
54 for (j = 0; j < nb_elem; j++) {
55 k = int_random(nb_cnst);
60 lmm_expand(Sys, cnst[k], var[i], float_random(1.0));
65 printf("Starting to solve\n");
66 date = xbt_os_time() * 1000000;
68 date = xbt_os_time() * 1000000 - date;
81 int main(int argc, char **argv)
86 date = xbt_os_time() * 1000000;
87 test(nb_cnst, nb_var, nb_elem);
88 printf("One shot execution time for a total of %d constraints, "
89 "%d variables with %d active constraint each : %g microsecondes \n",
90 nb_cnst, nb_var, nb_elem, date);