CYCLUS
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
9 namespace cyclus {
10 namespace toolkit {
11
12 // Forward declarations
13 class LinearFunction;
14 class ExponentialFunction;
15 class PiecewiseFunction;
16
17 /// Abstract base class for symbolic functions
18 class SymFunction {
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_
34 class LinearFunction : public SymFunction {
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_;
50
51  /// The intercept
52  double intercept_;
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),
65  exponent_(e),
66  intercept_(i) {}
67
68  /// Evaluation for a double argument
69  virtual double value(double x);
70
71  /// Print a string of the function
72  virtual std::string Print();
73
74  private:
75  /// The constant factor
76  double constant_;
77
78  /// The exponent multiplier
79  double exponent_;
80
81  /// The intercept
82  double intercept_;
83 };
84
85 /// Piecewise function
86 /// f(x) for all x in [lhs,rhs]
87 /// 0 otherwise
89  struct PiecewiseFunctionInfo {
90  PiecewiseFunctionInfo(SymFunction::Ptr function_, double xoff_ = 0,
91  double yoff_ = 0)
92  : function(function_),
93  xoffset(xoff_),
94  yoffset(yoff_) {}
95
96  SymFunction::Ptr function;
97  double xoffset, yoffset;
98  };
99
100  public:
101  /// Evaluation for an double argument
102  virtual double value(double x);
103
104  /// Print a string of the function
105  virtual std::string Print();
106
107  private:
108  std::list<PiecewiseFunctionInfo> functions_;
109
111 };
112
113 } // namespace toolkit
114 } // namespace cyclus
115
116 #endif // CYCLUS_SRC_TOOLKIT_SYMBOLIC_FUNCTIONS_H_
virtual double value(double x)=0
Base class must define how to calculate demand (dbl argument)
Linear functions f(x) = slope_ * x + intercept_.
ExponentialFunction(double c, double e, double i=0.0)
Constructor for an exponential function.
Piecewise function f(x) for all x in [lhs,rhs] 0 otherwise.
LinearFunction(double s, double i=0.0)
Constructor for a linear function.
Exponential functions f(x) = constant_ * exp ( exponent_ * x ) + intercept_.
virtual ~SymFunction()
Virtual destructor for an abstract base class.
A concrete factory for piecewise functions.
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or.org/Osi/browser/trunk.
Definition: agent.cc:14
Abstract base class for symbolic functions.
boost::shared_ptr< SymFunction > Ptr
virtual std::string Print()=0
Every function must print itself.