Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / src / kernel / resource / profile / StochasticDatedValue.cpp
1 /* Copyright (c) 2004-2022. 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 {
12 namespace kernel {
13 namespace profile {
14
15 double StochasticDatedValue::draw(Distribution law, std::vector<double> params)
16 {
17   switch (law) {
18     case Distribution::DET:
19       return params[0];
20     case Distribution::EXP:
21       return simgrid::xbt::random::exponential(params[0]);
22     case Distribution::UNIF:
23       return simgrid::xbt::random::uniform_real(params[0], params[1]);
24     case Distribution::NORM:
25       return simgrid::xbt::random::normal(params[0], params[1]);
26     default:
27       xbt_die("Unimplemented distribution");
28   }
29 }
30
31 double StochasticDatedValue::get_value() const
32 {
33   return draw(value_law, value_params);
34 }
35
36 double StochasticDatedValue::get_date() const
37 {
38   return draw(date_law, date_params);
39 }
40
41 DatedValue StochasticDatedValue::get_datedvalue() const
42 {
43   DatedValue event;
44   event.date_  = get_date();
45   event.value_ = get_value();
46   return event;
47 }
48
49 bool StochasticDatedValue::operator==(StochasticDatedValue const& e2) const
50 {
51   return (e2.date_law == date_law) && (e2.value_law == value_law) && (e2.value_params == value_params) &&
52          (e2.date_params == date_params);
53 }
54
55 } // namespace profile
56 } // namespace kernel
57 } // namespace simgrid