X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/e709643ef0c5b61c6c878016c418bffa2b1b20cd..7d28d93b90eedd2a49da8b9b990296669e46d05c:/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 9ecc8e57ab..6175cd6d9b 100644 --- a/teshsuite/surf/lmm_usage/lmm_usage.cpp +++ b/teshsuite/surf/lmm_usage/lmm_usage.cpp @@ -12,6 +12,7 @@ #include "xbt/module.h" #include "xbt/sysdep.h" #include +#include #include XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example"); @@ -30,83 +31,79 @@ static void test1() double a = 1.0; double b = 10.0; - lmm::System* Sys = lmm::make_new_maxmin_system(false); - lmm::Constraint* L1 = Sys->constraint_new(nullptr, a); - lmm::Constraint* L2 = Sys->constraint_new(nullptr, b); - lmm::Constraint* L3 = Sys->constraint_new(nullptr, a); + lmm::System Sys(false); + lmm::Constraint* L1 = Sys.constraint_new(nullptr, a); + lmm::Constraint* L2 = Sys.constraint_new(nullptr, b); + lmm::Constraint* L3 = Sys.constraint_new(nullptr, a); - lmm::Variable* R_1_2_3 = Sys->variable_new(nullptr, 1.0, -1.0, 3); - lmm::Variable* R_1 = Sys->variable_new(nullptr, 1.0, -1.0, 1); - lmm::Variable* R_2 = Sys->variable_new(nullptr, 1.0, -1.0, 1); - lmm::Variable* R_3 = Sys->variable_new(nullptr, 1.0, -1.0, 1); + lmm::Variable* R_1_2_3 = Sys.variable_new(nullptr, 1.0, -1.0, 3); + lmm::Variable* R_1 = Sys.variable_new(nullptr, 1.0, -1.0, 1); + lmm::Variable* R_2 = Sys.variable_new(nullptr, 1.0, -1.0, 1); + lmm::Variable* R_3 = Sys.variable_new(nullptr, 1.0, -1.0, 1); - Sys->update_variable_penalty(R_1_2_3, 1.0); - Sys->update_variable_penalty(R_1, 1.0); - Sys->update_variable_penalty(R_2, 1.0); - Sys->update_variable_penalty(R_3, 1.0); + Sys.update_variable_penalty(R_1_2_3, 1.0); + Sys.update_variable_penalty(R_1, 1.0); + Sys.update_variable_penalty(R_2, 1.0); + Sys.update_variable_penalty(R_3, 1.0); - Sys->expand(L1, R_1_2_3, 1.0); - Sys->expand(L2, R_1_2_3, 1.0); - Sys->expand(L3, R_1_2_3, 1.0); + Sys.expand(L1, R_1_2_3, 1.0); + Sys.expand(L2, R_1_2_3, 1.0); + Sys.expand(L3, R_1_2_3, 1.0); - Sys->expand(L1, R_1, 1.0); - Sys->expand(L2, R_2, 1.0); - Sys->expand(L3, R_3, 1.0); + Sys.expand(L1, R_1, 1.0); + Sys.expand(L2, R_2, 1.0); + Sys.expand(L3, R_3, 1.0); - Sys->solve(); + Sys.solve(); PRINT_VAR(R_1_2_3); PRINT_VAR(R_1); PRINT_VAR(R_2); PRINT_VAR(R_3); - Sys->variable_free(R_1_2_3); - Sys->variable_free(R_1); - Sys->variable_free(R_2); - Sys->variable_free(R_3); - delete Sys; + Sys.variable_free(R_1_2_3); + Sys.variable_free(R_1); + Sys.variable_free(R_2); + Sys.variable_free(R_3); } static void test2() { - lmm::System* Sys = lmm::make_new_maxmin_system(false); + lmm::System Sys(false); - lmm::Constraint* CPU1 = Sys->constraint_new(nullptr, 200.0); - lmm::Constraint* CPU2 = Sys->constraint_new(nullptr, 100.0); + lmm::Constraint* CPU1 = Sys.constraint_new(nullptr, 200.0); + lmm::Constraint* CPU2 = Sys.constraint_new(nullptr, 100.0); - lmm::Variable* T1 = Sys->variable_new(nullptr, 1.0, -1.0, 1); - lmm::Variable* T2 = Sys->variable_new(nullptr, 1.0, -1.0, 1); + lmm::Variable* T1 = Sys.variable_new(nullptr, 1.0, -1.0, 1); + lmm::Variable* T2 = Sys.variable_new(nullptr, 1.0, -1.0, 1); - Sys->update_variable_penalty(T1, 1.0); - Sys->update_variable_penalty(T2, 1.0); + Sys.update_variable_penalty(T1, 1.0); + Sys.update_variable_penalty(T2, 1.0); - Sys->expand(CPU1, T1, 1.0); - Sys->expand(CPU2, T2, 1.0); + Sys.expand(CPU1, T1, 1.0); + Sys.expand(CPU2, T2, 1.0); - Sys->solve(); + Sys.solve(); PRINT_VAR(T1); PRINT_VAR(T2); - Sys->variable_free(T1); - Sys->variable_free(T2); - delete Sys; + Sys.variable_free(T1); + Sys.variable_free(T2); } static void test3() { - int flows = 11; - int links = 10; + constexpr int flows = 11; + constexpr int links = 10; - double** A = new double*[links + 5]; + std::array, links + 5> A; /* 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 }; + std::array B{{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] = new double[flows + 5]; for (int j = 0; j < flows + 5; j++) { A[i][j] = 0.0; - if (i >= links || j >= flows) { A[i][j] = 0.0; } @@ -130,39 +127,33 @@ static void test3() A[13][14] = 1.0; A[14][15] = 1.0; - lmm::System* Sys = lmm::make_new_maxmin_system(false); + lmm::System Sys(false); /* Creates the constraints */ - lmm::Constraint** tmp_cnst = new lmm::Constraint*[15]; + std::array tmp_cnst; for (int i = 0; i < 15; i++) - tmp_cnst[i] = Sys->constraint_new(nullptr, B[i]); + tmp_cnst[i] = Sys.constraint_new(nullptr, B[i]); /* Creates the variables */ - lmm::Variable** tmp_var = new lmm::Variable*[16]; + std::array tmp_var; for (int j = 0; j < 16; j++) { - tmp_var[j] = Sys->variable_new(nullptr, 1.0, -1.0, 15); - Sys->update_variable_penalty(tmp_var[j], 1.0); + tmp_var[j] = Sys.variable_new(nullptr, 1.0, -1.0, 15); + Sys.update_variable_penalty(tmp_var[j], 1.0); } /* Link constraints and variables */ for (int i = 0; i < 15; i++) for (int j = 0; j < 16; j++) if (A[i][j] != 0.0) - Sys->expand(tmp_cnst[i], tmp_var[j], 1.0); + Sys.expand(tmp_cnst[i], tmp_var[j], 1.0); - Sys->solve(); + Sys.solve(); for (int j = 0; j < 16; j++) PRINT_VAR(tmp_var[j]); for (int j = 0; j < 16; j++) - Sys->variable_free(tmp_var[j]); - delete[] tmp_var; - delete[] tmp_cnst; - delete Sys; - for (int i = 0; i < links + 5; i++) - delete[] A[i]; - delete[] A; + Sys.variable_free(tmp_var[j]); } int main(int argc, char** argv)