CYCLUS
Loading...
Searching...
No Matches
symbolic_functions.h
Go to the documentation of this file.
1#ifndef CYCLUS_SRC_TOOLKIT_SYMBOLIC_FUNCTIONS_H_
2#define CYCLUS_SRC_TOOLKIT_SYMBOLIC_FUNCTIONS_H_
3
4#include <list>
5#include <string>
6
7#include <boost/shared_ptr.hpp>
8
9namespace cyclus {
10namespace toolkit {
11
12// Forward declarations
13class LinearFunction;
16
17/// Abstract base class for symbolic functions
19 public:
20 typedef boost::shared_ptr<SymFunction> Ptr;
21
22 /// Virtual destructor for an abstract base class
23 virtual ~SymFunction() {}
24
25 /// Base class must define how to calculate demand (dbl argument)
26 virtual double value(double x) = 0;
27
28 /// Every function must print itself
29 virtual std::string Print() = 0;
30};
31
32/// Linear functions
33/// f(x) = slope_ * x + intercept_
35 public:
36 /// Constructor for a linear function
37 /// @param s the slope
38 /// @param i the intercept, with the default being 0
39 LinearFunction(double s, double i = 0.0) : slope_(s), intercept_(i) {}
40
41 /// Evaluation for an double argument
42 virtual double value(double x);
43
44 /// Print a string of the function
45 virtual std::string Print();
46
47 private:
48 /// The slope
49 double slope_ = 0;
50
51 /// The intercept
52 double intercept_ = 0;
53};
54
55/// Exponential functions
56/// f(x) = constant_ * exp ( exponent_ * x ) + intercept_
58 public:
59 /// Constructor for an exponential function
60 /// @param c the leading constant
61 /// @param e the exponent multiplier
62 /// @param i the intercept, with the default being 0
63 ExponentialFunction(double c, double e, double i = 0.0)
64 : constant_(c), exponent_(e), intercept_(i) {}
65
66 /// Evaluation for a double argument
67 virtual double value(double x);
68
69 /// Print a string of the function
70 virtual std::string Print();
71
72 private:
73 /// The constant factor
74 double constant_;
75
76 /// The exponent multiplier
77 double exponent_;
78
79 /// The intercept
80 double intercept_;
81};
82
83/// Piecewise function
84/// f(x) for all x in [lhs,rhs]
85/// 0 otherwise
87 struct PiecewiseFunctionInfo {
88 PiecewiseFunctionInfo(SymFunction::Ptr function_, double xoff_ = 0,
89 double yoff_ = 0)
90 : function(function_), xoffset(xoff_), yoffset(yoff_) {}
91
92 SymFunction::Ptr function;
93 double xoffset, yoffset;
94 };
95
96 public:
97 /// Evaluation for an double argument
98 virtual double value(double x);
99
100 /// Print a string of the function
101 virtual std::string Print();
102
103 private:
104 std::list<PiecewiseFunctionInfo> functions_;
105
107};
108
109} // namespace toolkit
110} // namespace cyclus
111
112#endif // CYCLUS_SRC_TOOLKIT_SYMBOLIC_FUNCTIONS_H_
Exponential functions f(x) = constant_ * exp ( exponent_ * x ) + intercept_.
ExponentialFunction(double c, double e, double i=0.0)
Constructor for an exponential function.
virtual std::string Print()
Print a string of the function.
virtual double value(double x)
Evaluation for a double argument.
Linear functions f(x) = slope_ * x + intercept_.
virtual double value(double x)
Evaluation for an double argument.
LinearFunction(double s, double i=0.0)
Constructor for a linear function.
virtual std::string Print()
Print a string of the function.
Piecewise function f(x) for all x in [lhs,rhs] 0 otherwise.
virtual double value(double x)
Evaluation for an double argument.
virtual std::string Print()
Print a string of the function.
Abstract base class for symbolic functions.
boost::shared_ptr< SymFunction > Ptr
virtual ~SymFunction()
Virtual destructor for an abstract base class.
virtual std::string Print()=0
Every function must print itself.
virtual double value(double x)=0
Base class must define how to calculate demand (dbl argument)
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition agent.cc:14