creativity  v1.3.0
Agent-based model of creativity and piracy
Equation.hpp
1 #pragma once
2 #include <list>
3 #include <memory>
4 #include <functional>
5 #include <utility>
6 #include <ostream>
7 #include <string>
8 #include <type_traits>
9 #include <vector>
10 #include "creativity/data/Variable.hpp"
11 
12 namespace creativity { namespace data {
13 
33 class Equation {
34  public:
36  Equation() = delete;
37 
39  Equation(Equation &&move) = default;
40 
42  Equation(const Equation &copy) = default;
43 
45  Equation(const std::shared_ptr<const Variable> &y);
46 
47  // Forward declaration
48  class Proxy;
49 
54  Proxy operator % (const std::shared_ptr<const Variable> &var);
55 
57  Proxy operator % (double c);
58 
62  Equation operator + (const std::shared_ptr<const Variable> &var) const &;
63 
67  Equation operator + (const std::shared_ptr<const Variable> &var) &&;
68 
70  Equation operator + (double c) const &;
71 
73  Equation operator + (double c) &&;
74 
76  std::shared_ptr<const Variable> depVar() const;
77 
79  unsigned int numVars() const;
80 
84  bool hasConstant() const;
85 
89  std::vector<std::string> names() const;
90 
95  std::list<std::shared_ptr<const Variable>>::const_iterator begin() const;
96 
99  std::list<std::shared_ptr<const Variable>>::const_iterator end() const;
100 
104  friend std::ostream& operator<<(std::ostream &os, const Equation &eq);
105 
106  protected:
108  std::shared_ptr<const Variable> dep_var_;
109 
111  std::list<std::shared_ptr<const Variable>> indep_vars_{{ConstantVariable::create()}};
112 
114  void addVar(const std::shared_ptr<const Variable> &var);
115 };
116 
118 class Equation::Proxy final {
119  public:
121  Proxy& operator + (const std::shared_ptr<const Variable> &var);
122  private:
123  Equation &eq_;
124  Proxy(Equation &eq);
125  friend class Equation;
126 };
127 
128 }}
std::list< std::shared_ptr< const Variable > >::const_iterator end() const
Const access to the past-the-end iterator of independent variables.
Primary namespace for all Creativity library code.
Definition: config.hpp:4
std::shared_ptr< const Variable > dep_var_
The dependent variable.
Definition: Equation.hpp:108
Class to store a equation.
Definition: Equation.hpp:33
std::shared_ptr< const Variable > depVar() const
Accesses the dependent variable.
void addVar(const std::shared_ptr< const Variable > &var)
Internal method to add a variable to the model.
friend std::ostream & operator<<(std::ostream &os, const Equation &eq)
Overloaded so that an Equation can be sent to an output stream, resulting in output such as y ~ const...
Equation()=delete
Not default constructible.
std::list< std::shared_ptr< const Variable > > indep_vars_
The independent variables; the first is always a ConstantVariable.
Definition: Equation.hpp:111
Proxy operator%(const std::shared_ptr< const Variable > &var)
Adds a variable (lvalue version).
std::list< std::shared_ptr< const Variable > >::const_iterator begin() const
Const access to the beginning iterator of independent variables.
Proxy object returned by << that allows more variables to be appended with +.
Definition: Equation.hpp:118
unsigned int numVars() const
Returns the number of independent variables.
bool hasConstant() const
Returns true if the model includes a constant, false if it does not.
Equation operator+(const std::shared_ptr< const Variable > &var) const &
The addition operator duplicates the called-upon Equation an adds a new term to the duplicate...
static std::shared_ptr< ConstantVariable > create(Args... args)
Forwards arguments to the protected constructor and returns a shared_ptr to the created object...
Definition: Variable.hpp:93
std::vector< std::string > names() const
Returns the names of the variables in the same order they will be returned by begin()/end().