Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Prefer enum class over legacy enum.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 28 Oct 2020 16:32:40 +0000 (17:32 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 28 Oct 2020 16:51:51 +0000 (17:51 +0100)
src/kernel/resource/profile/Profile.cpp
src/kernel/resource/profile/Profile_test.cpp
src/kernel/resource/profile/StochasticDatedValue.cpp
src/kernel/resource/profile/StochasticDatedValue.hpp

index 587a063..a8ac733 100644 (file)
@@ -133,17 +133,17 @@ Profile* Profile::from_string(const std::string& name, const std::string& input,
       xbt_assert(splittedval.size() > 0, "Invalid profile line");
 
       if (splittedval[0] == "DET") {
-        stochevent.date_law = Dist_Det;
+        stochevent.date_law = Distribution::DET;
         i                   = 2;
       } else if (splittedval[0] == "NORM" || splittedval[0] == "NORMAL" || splittedval[0] == "GAUSS" ||
                  splittedval[0] == "GAUSSIAN") {
-        stochevent.date_law = Dist_Norm;
+        stochevent.date_law = Distribution::NORM;
         i                   = 3;
       } else if (splittedval[0] == "EXP" || splittedval[0] == "EXPONENTIAL") {
-        stochevent.date_law = Dist_Exp;
+        stochevent.date_law = Distribution::EXP;
         i                   = 2;
       } else if (splittedval[0] == "UNIF" || splittedval[0] == "UNIFORM") {
-        stochevent.date_law = Dist_Unif;
+        stochevent.date_law = Distribution::UNIF;
         i                   = 3;
       } else {
         xbt_assert(false, "Unknown law %s", splittedval[0].c_str());
@@ -158,17 +158,17 @@ Profile* Profile::from_string(const std::string& name, const std::string& input,
       }
 
       if (splittedval[i] == "DET") {
-        stochevent.value_law = Dist_Det;
+        stochevent.value_law = Distribution::DET;
         j                    = 1;
       } else if (splittedval[i] == "NORM" || splittedval[i] == "NORMAL" || splittedval[i] == "GAUSS" ||
                  splittedval[i] == "GAUSSIAN") {
-        stochevent.value_law = Dist_Norm;
+        stochevent.value_law = Distribution::NORM;
         j                    = 2;
       } else if (splittedval[i] == "EXP" || splittedval[i] == "EXPONENTIAL") {
-        stochevent.value_law = Dist_Exp;
+        stochevent.value_law = Distribution::EXP;
         j                    = 1;
       } else if (splittedval[i] == "UNIF" || splittedval[i] == "UNIFORM") {
-        stochevent.value_law = Dist_Unif;
+        stochevent.value_law = Distribution::UNIF;
         j                    = 2;
       } else {
         xbt_assert(false, "Unknown law %s", splittedval[i].c_str());
index 55f4c61..3dce615 100644 (file)
@@ -154,19 +154,21 @@ TEST_CASE("kernel::profile: Resource profiles, defining the external load", "ker
 
   SECTION("One stochastic event (parsing)")
   {
+    using simgrid::kernel::profile::Distribution;
     std::vector<simgrid::kernel::profile::StochasticDatedValue> got = trace2selist("STOCHASTIC\n"
                                                                                    "DET 0 UNIF 10 20");
 
     std::vector<simgrid::kernel::profile::StochasticDatedValue> want;
     want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(0, -1)); // The initial fake event
-    want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Det, {0},
-                                                                     simgrid::kernel::profile::Dist_Unif, {10, 20}));
+    want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(Distribution::DET, {0},
+                                                                     Distribution::UNIF, {10, 20}));
 
     REQUIRE(want == got);
   }
 
   SECTION("Several stochastic events (all possible parsing forms)")
   {
+    using simgrid::kernel::profile::Distribution;
     std::vector<simgrid::kernel::profile::StochasticDatedValue> got = trace2selist("STOCHASTIC\n"
                                                                                    "DET 0 DET 4\n"
                                                                                    "NORMAL 25 10 DET 3\n"
@@ -175,14 +177,14 @@ TEST_CASE("kernel::profile: Resource profiles, defining the external load", "ker
 
     std::vector<simgrid::kernel::profile::StochasticDatedValue> want;
     want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(0, -1));
-    want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Det, {0},
-                                                                     simgrid::kernel::profile::Dist_Det, {4}));
-    want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Norm, {25, 10},
-                                                                     simgrid::kernel::profile::Dist_Det, {3}));
-    want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Unif, {10, 20},
-                                                                     simgrid::kernel::profile::Dist_Norm, {25, 10}));
-    want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Det, {5},
-                                                                     simgrid::kernel::profile::Dist_Unif, {5, 25}));
+    want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(Distribution::DET, {0},
+                                                                     Distribution::DET, {4}));
+    want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(Distribution::NORM, {25, 10},
+                                                                     Distribution::DET, {3}));
+    want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(Distribution::UNIF, {10, 20},
+                                                                     Distribution::NORM, {25, 10}));
+    want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(Distribution::DET, {5},
+                                                                     Distribution::UNIF, {5, 25}));
 
     REQUIRE(want == got);
   }
index 3cf0407..0695de3 100644 (file)
@@ -15,13 +15,13 @@ namespace profile {
 double StochasticDatedValue::draw(Distribution law, std::vector<double> params)
 {
   switch (law) {
-    case Dist_Det:
+    case Distribution::DET:
       return params[0];
-    case Dist_Exp:
+    case Distribution::EXP:
       return simgrid::xbt::random::exponential(params[0]);
-    case Dist_Unif:
+    case Distribution::UNIF:
       return simgrid::xbt::random::uniform_real(params[0], params[1]);
-    case Dist_Norm:
+    case Distribution::NORM:
       return simgrid::xbt::random::normal(params[0], params[1]);
     default:
       xbt_assert(false, "Unimplemented distribution");
index 4533bb3..f432039 100644 (file)
@@ -14,22 +14,19 @@ namespace simgrid {
 namespace kernel {
 namespace profile {
 
-enum Distribution { Dist_Exp, Dist_Norm, Dist_Unif, Dist_Det };
+enum class Distribution { EXP, NORM, UNIF, DET };
 
 class XBT_PUBLIC StochasticDatedValue {
 public:
-  Distribution date_law;
+  Distribution date_law = Distribution::DET;
   std::vector<double> date_params;
-  Distribution value_law;
+  Distribution value_law = Distribution::DET;
   std::vector<double> value_params;
   DatedValue get_datedvalue();
   double get_date();
   double get_value();
   explicit StochasticDatedValue() = default;
-  explicit StochasticDatedValue(double d, double v)
-      : date_law(Dist_Det), date_params({d}), value_law(Dist_Det), value_params({v})
-  {
-  }
+  explicit StochasticDatedValue(double d, double v) : date_params({d}), value_params({v}) {}
   explicit StochasticDatedValue(Distribution dl, const std::vector<double>& dp, Distribution vl,
                                 const std::vector<double>& vp)
       : date_law(dl), date_params(dp), value_law(vl), value_params(vp)
@@ -38,7 +35,7 @@ public:
   bool operator==(StochasticDatedValue const& e2) const;
 
 private:
-  double draw(Distribution law, std::vector<double> params);
+  static double draw(Distribution law, std::vector<double> params);
 };
 
 } // namespace profile