CYCLUS
symbolic_functions.cc
Go to the documentation of this file.
1 #include "symbolic_functions.h"
2 
3 #include <limits>
4 #include <math.h>
5 #include <sstream>
6 #include <string>
7 
8 namespace cyclus {
9 namespace toolkit {
10 
11 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
12 double LinearFunction::value(double x) {
13  return slope_ * x + intercept_;
14 }
15 
16 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
17 std::string LinearFunction::Print() {
18  std::stringstream ss("");
19  ss << "y = " << slope_ << " * x + " << intercept_;
20  return ss.str();
21 }
22 
23 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
24 double ExponentialFunction::value(double x) {
25  return constant_ * exp(exponent_ * x) + intercept_;
26 }
27 
28 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
30  std::stringstream ss("");
31  ss << "y = " << constant_
32  << " * exp(" << exponent_ << " * x) + " << intercept_;
33  return ss.str();
34 }
35 
36 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
37 double PiecewiseFunction::value(double x) {
38  double ret;
39  if (functions_.empty() || (x < functions_.front().xoffset)) {
40  ret = 0.0;
41  } else {
42  std::list<PiecewiseFunctionInfo>::iterator f = functions_.begin();
43  while (f != functions_.end() && (x >= f->xoffset)) {
44  ++f; // exceeds search by 1
45  }
46  --f; // go back to the correct one
47  ret = f->function->value(x - f->xoffset) + f->yoffset;
48  }
49  return ret;
50 }
51 
52 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
53 std::string PiecewiseFunction::Print() {
54  std::stringstream ss("");
55  ss << "Piecewise Function comprised of: ";
56  std::list<PiecewiseFunctionInfo>::iterator f;
57  for (f = functions_.begin(); f != functions_.end(); f++) {
58  ss << " * " << f->function->Print()
59  << " starting at coordinate (" << f->xoffset << ","
60  << f->yoffset << ")";
61  }
62  return ss.str();
63 }
64 
65 } // namespace toolkit
66 } // namespace cyclus
virtual std::string Print()
Print a string of the function.
virtual double value(double x)
Evaluation for a double argument.
virtual std::string Print()
Print a string of the function.
virtual double value(double x)
Evaluation for an double argument.
virtual std::string Print()
Print a string of the function.
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or.org/Osi/browser/trunk.
Definition: agent.cc:14
virtual double value(double x)
Evaluation for an double argument.