Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2023.
[simgrid.git] / src / kernel / resource / profile / StochasticDatedValue.cpp
1 /* Copyright (c) 2004-2023. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "src/kernel/resource/profile/StochasticDatedValue.hpp"
7 #include "xbt.h"
8 #include "xbt/random.hpp"
9 #include <math.h>
10
11 namespace simgrid::kernel::profile {
12
13 double StochasticDatedValue::draw(Distribution law, std::vector<double> params)
14 {
15   switch (law) {
16     case Distribution::DET:
17       return params[0];
18     case Distribution::EXP:
19       return simgrid::xbt::random::exponential(params[0]);
20     case Distribution::UNIF:
21       return simgrid::xbt::random::uniform_real(params[0], params[1]);
22     case Distribution::NORM:
23       return simgrid::xbt::random::normal(params[0], params[1]);
24     default:
25       xbt_die("Unimplemented distribution");
26   }
27 }
28
29 double StochasticDatedValue::get_value() const
30 {
31   return draw(value_law, value_params);
32 }
33
34 double StochasticDatedValue::get_date() const
35 {
36   return draw(date_law, date_params);
37 }
38
39 DatedValue StochasticDatedValue::get_datedvalue() const
40 {
41   DatedValue event;
42   event.date_  = get_date();
43   event.value_ = get_value();
44   return event;
45 }
46
47 bool StochasticDatedValue::operator==(StochasticDatedValue const& e2) const
48 {
49   return (e2.date_law == date_law) && (e2.value_law == value_law) && (e2.value_params == value_params) &&
50          (e2.date_params == date_params);
51 }
52
53 } // namespace simgrid::kernel::profile