X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/61427a88a76a2c2ef25d0d5b8132995c6f550e5c..95fcf20e6ef0f0cb449faddd00b5500bede028af:/teshsuite/surf/lmm_usage/lmm_usage.cpp diff --git a/teshsuite/surf/lmm_usage/lmm_usage.cpp b/teshsuite/surf/lmm_usage/lmm_usage.cpp index 01a2dfadb4..71c2fd4c58 100644 --- a/teshsuite/surf/lmm_usage/lmm_usage.cpp +++ b/teshsuite/surf/lmm_usage/lmm_usage.cpp @@ -1,17 +1,19 @@ /* A few tests for the maxmin library */ -/* Copyright (c) 2007-2015. The SimGrid Team. +/* Copyright (c) 2007-2017. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include "xbt/sysdep.h" -#include "surf/maxmin.h" +#include "simgrid/msg.h" +#include "src/surf/surf_interface.hpp" +#include "surf/maxmin.hpp" #include "xbt/log.h" #include "xbt/module.h" -#include -#include "src/surf/surf_interface.hpp" +#include "xbt/sysdep.h" +#include +#include XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example"); @@ -22,11 +24,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example"); /* ==l1== L2 ==L3== */ /* ------ */ -typedef enum { - MAXMIN, - LAGRANGE_RENO, - LAGRANGE_VEGAS -} method_t; +enum method_t { MAXMIN, LAGRANGE_RENO, LAGRANGE_VEGAS }; static double dichotomy(double func(double), double min, double max, double min_error) { @@ -148,10 +146,10 @@ static void test1(method_t method) lagrange_solve(Sys); double max_deviation = 0.0; - max_deviation = MAX(max_deviation, fabs(lmm_variable_getvalue(R_1) - x)); - max_deviation = MAX(max_deviation, fabs(lmm_variable_getvalue(R_3) - x)); - max_deviation = MAX(max_deviation, fabs(lmm_variable_getvalue(R_2) - (b - a + x))); - max_deviation = MAX(max_deviation, fabs(lmm_variable_getvalue(R_1_2_3) - (a - x))); + max_deviation = std::max(max_deviation, fabs(lmm_variable_getvalue(R_1) - x)); + max_deviation = std::max(max_deviation, fabs(lmm_variable_getvalue(R_3) - x)); + max_deviation = std::max(max_deviation, fabs(lmm_variable_getvalue(R_2) - (b - a + x))); + max_deviation = std::max(max_deviation, fabs(lmm_variable_getvalue(R_1_2_3) - (a - x))); if (max_deviation > 0.00001) { // Legacy value used in lagrange.c XBT_WARN("Max Deviation from optimal solution : %g", max_deviation); @@ -218,12 +216,12 @@ static void test3(method_t method) int flows = 11; int links = 10; - double **A = xbt_new0(double *, links + 5); + double** A = new double*[links + 5]; /* array to add the constraints of fictitious variables */ double B[15] = { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 1, 1, 1, 1, 1 }; for (int i = 0; i < links + 5; i++) { - A[i] = xbt_new0(double, flows + 5); + A[i] = new double[flows + 5]; for (int j = 0; j < flows + 5; j++) { A[i][j] = 0.0; @@ -258,12 +256,12 @@ static void test3(method_t method) lmm_system_t Sys = lmm_system_new(1); /* Creates the constraints */ - lmm_constraint_t *tmp_cnst = xbt_new0(lmm_constraint_t, 15); + lmm_constraint_t* tmp_cnst = new lmm_constraint_t[15]; for (int i = 0; i < 15; i++) tmp_cnst[i] = lmm_constraint_new(Sys, nullptr, B[i]); /* Creates the variables */ - lmm_variable_t *tmp_var = xbt_new0(lmm_variable_t, 16); + lmm_variable_t* tmp_var = new lmm_variable_t[16]; for (int j = 0; j < 16; j++) { tmp_var[j] = lmm_variable_new(Sys, nullptr, 1.0, -1.0, 15); lmm_update_variable_weight(Sys, tmp_var[j], 1.0); @@ -290,16 +288,17 @@ static void test3(method_t method) for (int j = 0; j < 16; j++) lmm_variable_free(Sys, tmp_var[j]); - xbt_free(tmp_var); - xbt_free(tmp_cnst); + delete[] tmp_var; + delete[] tmp_cnst; lmm_system_free(Sys); for (int i = 0; i < links + 5; i++) - xbt_free(A[i]); - xbt_free(A); + delete[] A[i]; + delete[] A; } -int main() +int main(int argc, char** argv) { + MSG_init(&argc, argv); XBT_INFO("***** Test 1 (Max-Min)"); test1(MAXMIN); XBT_INFO("***** Test 1 (Lagrange - Vegas)");