-/* Copyright (c) 2019-2021. The SimGrid Team. All rights reserved. */
+/* Copyright (c) 2019-2023. 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 "src/include/catch.hpp"
+#include "src/3rd-party/catch.hpp"
#include "src/kernel/lmm/maxmin.hpp"
-#include "src/surf/surf_interface.hpp"
+#include "src/simgrid/math_utils.h"
#include "xbt/log.h"
namespace lmm = simgrid::kernel::lmm;
TEST_CASE("kernel::lmm Single constraint shared systems", "[kernel-lmm-shared-single-sys]")
{
- lmm::System Sys(false);
+ lmm::MaxMin Sys(false);
SECTION("Variable penalty")
{
Sys.expand(sys_cnst, rho_2, 1);
Sys.solve();
- REQUIRE(double_equals(rho_1->get_value(), 2, sg_maxmin_precision));
- REQUIRE(double_equals(rho_2->get_value(), 1, sg_maxmin_precision));
+ REQUIRE(double_equals(rho_1->get_value(), 2, sg_precision_workamount));
+ REQUIRE(double_equals(rho_2->get_value(), 1, sg_precision_workamount));
}
SECTION("Consumption weight")
Sys.expand(sys_cnst, rho_2, 2);
Sys.solve();
- REQUIRE(double_equals(rho_1->get_value(), 1, sg_maxmin_precision));
- REQUIRE(double_equals(rho_2->get_value(), 1, sg_maxmin_precision));
+ REQUIRE(double_equals(rho_1->get_value(), 1, sg_precision_workamount));
+ REQUIRE(double_equals(rho_2->get_value(), 1, sg_precision_workamount));
}
SECTION("Consumption weight + variable penalty")
Sys.solve();
double rho_1_share = 10;
- REQUIRE(double_equals(rho_1->get_value(), rho_1_share, sg_maxmin_precision));
- REQUIRE(double_equals(rho_2->get_value(), rho_1_share / 2, sg_maxmin_precision));
+ REQUIRE(double_equals(rho_1->get_value(), rho_1_share, sg_precision_workamount));
+ REQUIRE(double_equals(rho_2->get_value(), rho_1_share / 2, sg_precision_workamount));
}
SECTION("Multiple constraints systems")
Sys.solve();
double rho_1_share = 10; // Start by solving the first constraint (results is the same as previous tests)
- REQUIRE(double_equals(rho_1->get_value(), rho_1_share, sg_maxmin_precision));
- REQUIRE(double_equals(rho_2->get_value(), rho_1_share / 2, sg_maxmin_precision));
- REQUIRE(double_equals(rho_3->get_value(), 60 - 2 * rho_1_share, sg_maxmin_precision));
+ REQUIRE(double_equals(rho_1->get_value(), rho_1_share, sg_precision_workamount));
+ REQUIRE(double_equals(rho_2->get_value(), rho_1_share / 2, sg_precision_workamount));
+ REQUIRE(double_equals(rho_3->get_value(), 60 - 2 * rho_1_share, sg_precision_workamount));
}
Sys.variable_free_all();
TEST_CASE("kernel::lmm Single constraint unshared systems", "[kernel-lmm-unshared-single-sys]")
{
- lmm::System Sys(false);
+ lmm::MaxMin Sys(false);
SECTION("Variable penalty")
{
Sys.expand(sys_cnst, rho_2, 1);
Sys.solve();
- REQUIRE(double_equals(rho_1->get_value(), 10, sg_maxmin_precision));
- REQUIRE(double_equals(rho_2->get_value(), 10 / 2, sg_maxmin_precision));
+ REQUIRE(double_equals(rho_1->get_value(), 10, sg_precision_workamount));
+ REQUIRE(double_equals(rho_2->get_value(), 10 / 2, sg_precision_workamount));
}
SECTION("Consumption weight")
Sys.expand(sys_cnst, rho_2, 2);
Sys.solve();
- REQUIRE(double_equals(rho_1->get_value(), 5, sg_maxmin_precision));
- REQUIRE(double_equals(rho_2->get_value(), 5, sg_maxmin_precision));
+ REQUIRE(double_equals(rho_1->get_value(), 5, sg_precision_workamount));
+ REQUIRE(double_equals(rho_2->get_value(), 5, sg_precision_workamount));
}
SECTION("Consumption weight + variable penalty")
Sys.expand(sys_cnst, sys_var_2, 2);
Sys.solve();
- REQUIRE(double_equals(sys_var_1->get_value(), 10, sg_maxmin_precision));
- REQUIRE(double_equals(sys_var_2->get_value(), 5, sg_maxmin_precision));
+ REQUIRE(double_equals(sys_var_1->get_value(), 10, sg_precision_workamount));
+ REQUIRE(double_equals(sys_var_2->get_value(), 5, sg_precision_workamount));
}
SECTION("Multiple constraints systems")
Sys.solve();
double rho_1_share = 10; // Start by solving the first constraint (results is the same as previous tests)
- REQUIRE(double_equals(rho_1->get_value(), rho_1_share, sg_maxmin_precision));
- REQUIRE(double_equals(rho_2->get_value(), rho_1_share / 2, sg_maxmin_precision));
- REQUIRE(double_equals(rho_3->get_value(), 60, sg_maxmin_precision));
+ REQUIRE(double_equals(rho_1->get_value(), rho_1_share, sg_precision_workamount));
+ REQUIRE(double_equals(rho_2->get_value(), rho_1_share / 2, sg_precision_workamount));
+ REQUIRE(double_equals(rho_3->get_value(), 60, sg_precision_workamount));
}
Sys.variable_free_all();
// decrease 10 % for each extra flow sharing this resource
return bound - (flows - 1) * .10 * bound;
};
- lmm::System Sys(false);
+ lmm::MaxMin Sys(false);
lmm::Constraint* sys_cnst = Sys.constraint_new(nullptr, 10);
sys_cnst->set_sharing_policy(lmm::Constraint::SharingPolicy::NONLINEAR, cb);
Sys.expand(sys_cnst, rho_1, 1);
Sys.solve();
- REQUIRE(double_equals(rho_1->get_value(), 10, sg_maxmin_precision));
+ REQUIRE(double_equals(rho_1->get_value(), 10, sg_precision_workamount));
}
SECTION("2 activities, but ignore crosstraffic 100% C")
Sys.expand(sys_cnst, rho_2, 0.05);
Sys.solve();
- REQUIRE(double_equals(rho_1->get_value(), 10 / 1.05, sg_maxmin_precision));
- REQUIRE(double_equals(rho_1->get_value(), rho_2->get_value(), sg_maxmin_precision));
+ REQUIRE(double_equals(rho_1->get_value(), 10 / 1.05, sg_precision_workamount));
+ REQUIRE(double_equals(rho_1->get_value(), rho_2->get_value(), sg_precision_workamount));
}
SECTION("2 activities, 1 inactive 100% C")
Sys.expand(sys_cnst, rho_2, 1);
Sys.solve();
- REQUIRE(double_equals(rho_1->get_value(), 10, sg_maxmin_precision));
- REQUIRE(double_equals(rho_2->get_value(), 0, sg_maxmin_precision));
+ REQUIRE(double_equals(rho_1->get_value(), 10, sg_precision_workamount));
+ REQUIRE(double_equals(rho_2->get_value(), 0, sg_precision_workamount));
}
SECTION("2 activity, 90% C")
Sys.expand(sys_cnst, rho_2, 1);
Sys.solve();
- REQUIRE(double_equals(rho_1->get_value(), 4.5, sg_maxmin_precision));
- REQUIRE(double_equals(rho_1->get_value(), 4.5, sg_maxmin_precision));
+ REQUIRE(double_equals(rho_1->get_value(), 4.5, sg_precision_workamount));
+ REQUIRE(double_equals(rho_1->get_value(), 4.5, sg_precision_workamount));
}
SECTION("3 activity, 80% C")
Sys.expand(sys_cnst, rho_3, 1);
Sys.solve();
- REQUIRE(double_equals(rho_1->get_value(), 4, sg_maxmin_precision));
- REQUIRE(double_equals(rho_2->get_value(), 2, sg_maxmin_precision));
- REQUIRE(double_equals(rho_3->get_value(), 2, sg_maxmin_precision));
+ REQUIRE(double_equals(rho_1->get_value(), 4, sg_precision_workamount));
+ REQUIRE(double_equals(rho_2->get_value(), 2, sg_precision_workamount));
+ REQUIRE(double_equals(rho_3->get_value(), 2, sg_precision_workamount));
+ }
+
+ Sys.variable_free_all();
+}
+
+TEST_CASE("kernel::lmm shared systems with crosstraffic", "[kernel-lmm-shared-crosstraffic]")
+{
+ lmm::MaxMin Sys(false);
+
+ SECTION("3 flows, 3 resource: crosstraffic")
+ {
+ /*
+ * 3 flows sharing 2 constraints, single
+ *
+ * In details:
+ * o System: a1 * \rho1 + a2 * \rho2 + epsilon * \rho3 < C1
+ * epsilon * \rho1 + epsilon * \rho2 + a3 * \rho3 < C2
+ * o consumption_weight: a1=1, a2=1, a3=1, epsilon=0.05
+ * o C1 = C2 = 1
+ *
+ * Expectations
+ * o rho1 = rho2 = rho3 = 1/2
+ */
+ lmm::Constraint* sys_cnst = Sys.constraint_new(nullptr, 1);
+ lmm::Constraint* sys_cnst2 = Sys.constraint_new(nullptr, 1);
+ lmm::Variable* rho_1 = Sys.variable_new(nullptr, 1, -1, 2);
+ lmm::Variable* rho_2 = Sys.variable_new(nullptr, 1, -1, 2);
+ lmm::Variable* rho_3 = Sys.variable_new(nullptr, 1, -1, 2);
+
+ double epsilon = 0.05;
+ Sys.expand(sys_cnst, rho_1, 1.0);
+ Sys.expand(sys_cnst2, rho_1, epsilon);
+ Sys.expand(sys_cnst, rho_2, 1.0);
+ Sys.expand(sys_cnst2, rho_2, epsilon);
+ Sys.expand(sys_cnst2, rho_3, 1.0);
+ Sys.expand(sys_cnst, rho_3, epsilon);
+ Sys.solve();
+
+ REQUIRE(double_equals(rho_1->get_value(), 1.0 / (2.0 + epsilon), sg_precision_workamount));
+ REQUIRE(double_equals(rho_2->get_value(), 1.0 / (2.0 + epsilon), sg_precision_workamount));
+ REQUIRE(double_equals(rho_3->get_value(), 1.0 / (2.0 + epsilon), sg_precision_workamount));
}
Sys.variable_free_all();