Minsky: 3.17.0
MathDAG::VariableDAG Class Reference

#include <equations.h>

Inheritance diagram for MathDAG::VariableDAG:
Inheritance graph
Collaboration diagram for MathDAG::VariableDAG:
Collaboration graph

Public Member Functions

 VariableDAG ()
 reference to operation if this is an integral variable More...
 
 VariableDAG (const string &valueId, const string &name, Type type)
 
int BODMASlevel () const override
 algebraic heirarchy level, used for working out whether brackets are necessary. More...
 
int order (unsigned maxOrder) const override
 returns evaluation order in sequence of variable defintions More...
 
bool tensorEval (std::set< const Node *> &) const override
 returns true if the evaluation of this involves tensor processing More...
 
ostream & latex (ostream &) const override
 writes LaTeX representation of this DAG to the stream More...
 
ostream & matlab (ostream &) const override
 writes a matlab representation of this DAG to the stream More...
 
VariableValuePtr addEvalOps (EvalOpVector &, const VariableValuePtr &v={}) override
 adds EvalOps to an EvalOpVector representing this node. More...
 
void render (ecolab::cairo::Surface &surf) const override
 renders a visual representation of this node to surf graphic extends right from the current pen position (which needs to be defined), and pen is moved to the right edge of the graphic. The determine bounding box, render into a recording surface, and use width()/height() More...
 
NodePtr derivative (SystemOfEquations &) const override
 support for the derivative operator. More...
 
bool addTensorOp (EvalOpVector &ev)
 adds a TensorEvalOp, returns true if successful More...
 
virtual bool tensorEval (std::set< const Node * > &visited) const=0
 returns true if the evaluation of this involves tensor processing More...
 
bool tensorEval ()
 returns true if the evaluation of this involves tensor processing More...
 
virtual ostream & latex (ostream &) const=0
 writes LaTeX representation of this DAG to the stream More...
 
LaTeXManip latex () const
 used within io streaming More...
 
virtual ostream & matlab (ostream &) const=0
 writes a matlab representation of this DAG to the stream More...
 
MatlabManip matlab () const
 
virtual VariableValuePtr addEvalOps (EvalOpVector &, const VariableValuePtr &result={})=0
 adds EvalOps to an EvalOpVector representing this node. More...
 
- Public Member Functions inherited from MathDAG::Node
virtual ~Node ()
 
std::string latexStr () const
 
std::string matlabStr () const
 
bool tensorEval ()
 returns true if the evaluation of this involves tensor processing More...
 
LaTeXManip latex () const
 used within io streaming More...
 
MatlabManip matlab () const
 

Public Attributes

string valueId
 
Type type =undefined
 
string name
 
string init ="0"
 
WeakNodePtr rhs
 
IntOpintOp =0
 
- Public Attributes inherited from MathDAG::Node
int cachedOrder =-1
 
VariableValuePtr result
 reference to where this node's value is stored More...
 

Additional Inherited Members

- Public Types inherited from minsky::VariableType
enum  Type {
  undefined, constant, parameter, flow,
  integral, stock, tempFlow, numVarTypes
}
 
- Static Public Member Functions inherited from minsky::VariableType
static std::string typeName (int t)
 

Detailed Description

Definition at line 171 of file equations.h.

Constructor & Destructor Documentation

◆ VariableDAG() [1/2]

MathDAG::VariableDAG::VariableDAG ( )
inline

reference to operation if this is an integral variable

Definition at line 181 of file equations.h.

181 {}

◆ VariableDAG() [2/2]

MathDAG::VariableDAG::VariableDAG ( const string &  valueId,
const string &  name,
Type  type 
)
inline

Definition at line 182 of file equations.h.

Member Function Documentation

◆ addEvalOps() [1/2]

virtual VariableValuePtr MathDAG::Node::addEvalOps

adds EvalOps to an EvalOpVector representing this node.

Returns
a variable where the result is stored. If a flowVariable has been provided in result, that may be used directly, otherwise a copy operation is added to ensure it receives the result.

◆ addEvalOps() [2/2]

VariableValuePtr MathDAG::VariableDAG::addEvalOps ( EvalOpVector ,
const VariableValuePtr result = {} 
)
overridevirtual

adds EvalOps to an EvalOpVector representing this node.

Returns
a variable where the result is stored. If a flowVariable has been provided in result, that may be used directly, otherwise a copy operation is added to ensure it receives the result.

Implements MathDAG::Node.

Reimplemented in MathDAG::IntegralInputVariableDAG.

Definition at line 120 of file equations.cc.

References MathDAG::anonymous_namespace{equations.cc}::addTensorOp(), minsky::doOneEvent(), minsky::isValueId(), minsky::minsky(), minsky::VariableType::tempFlow, minsky::VariableType::undefined, minsky::valueId(), and minsky::Minsky::variableValues.

121  {
122  if (result->idx()<0)
123  {
124  assert(isValueId(valueId));
125  auto ri=minsky::minsky().variableValues.find(valueId);
126  if (ri==minsky::minsky().variableValues.end())
128  result=ri->second;
129  if (rhs)
130  {
131  if ((!tensorEval() && !rhs->tensorEval()) || !addTensorOp(ev))
132  { // everything scalar, revert to scalar processing
133  if (result->idx()<0) result->allocValue();
134  rhs->addEvalOps(ev, result);
135  }
136  }
137  else
138  if (result->idx()<0) result->allocValue();
139  }
140  if (r->type()!=VariableType::undefined && r->isFlowVar() && (r!=result || result->isFlowVar()))
141  ev.emplace_back(EvalOpPtr(new TensorEval(r,result)));
142  assert(result->idx()>=0);
143  doOneEvent(true);
144  return result;
145  }
virtual VariableValuePtr addEvalOps(EvalOpVector &, const VariableValuePtr &result={})=0
adds EvalOps to an EvalOpVector representing this node.
bool tensorEval()
returns true if the evaluation of this involves tensor processing
Definition: equations.h:116
bool addTensorOp(EvalOpVector &ev)
adds a TensorEvalOp, returns true if successful
Definition: equations.cc:111
void doOneEvent(bool idleTasksOnly)
checks if any GUI events are waiting, and proces an event if so
Definition: addon.cc:550
A helper to evaluate a variable value.
VariableValues variableValues
Definition: minsky.h:188
VariableValuePtr result
reference to where this node&#39;s value is stored
Definition: equations.h:128
a shared_ptr that default constructs a default target, and is always valid
bool isValueId(const string &name)
check that name is a valid valueId (useful for assertions)
Definition: valueId.cc:33
virtual bool tensorEval(std::set< const Node *> &visited) const =0
returns true if the evaluation of this involves tensor processing
Minsky & minsky()
global minsky object
Definition: addon.cc:545
WeakNodePtr rhs
Definition: equations.h:178
Here is the call graph for this function:

◆ addTensorOp()

bool MathDAG::VariableDAG::addTensorOp ( EvalOpVector ev)

adds a TensorEvalOp, returns true if successful

Definition at line 111 of file equations.cc.

References MathDAG::anonymous_namespace{equations.cc}::addTensorOp().

112  {
113  if (rhs)
114  if (auto nodeOp=dynamic_cast<OperationDAGBase*>(rhs.payload))
115  return MathDAG::addTensorOp(result,*nodeOp,ev);
116  return false;
117  }
bool addTensorOp(const shared_ptr< VariableValue > &result, OperationDAGBase &nodeOp, EvalOpVector &ev)
Definition: equations.cc:88
VariableValuePtr result
reference to where this node&#39;s value is stored
Definition: equations.h:128
WeakNodePtr rhs
Definition: equations.h:178
Here is the call graph for this function:

◆ BODMASlevel()

int MathDAG::VariableDAG::BODMASlevel ( ) const
inlineoverridevirtual

algebraic heirarchy level, used for working out whether brackets are necessary.

Implements MathDAG::Node.

Definition at line 184 of file equations.h.

184 {return 0;}

◆ derivative()

NodePtr MathDAG::VariableDAG::derivative ( SystemOfEquations ) const
overridevirtual

support for the derivative operator.

Implements MathDAG::Node.

Definition at line 34 of file derivative.cc.

◆ latex() [1/3]

virtual ostream& MathDAG::Node::latex

writes LaTeX representation of this DAG to the stream

◆ latex() [2/3]

LaTeXManip MathDAG::Node::latex
inline

used within io streaming

Definition at line 119 of file equations.h.

119 {return LaTeXManip(*this);}

◆ latex() [3/3]

ostream & MathDAG::VariableDAG::latex ( ostream &  ) const
overridevirtual

writes LaTeX representation of this DAG to the stream

Implements MathDAG::Node.

Definition at line 98 of file node_latex.cc.

References MathDAG::mathrm().

99  {
100  if (type==constant)
101  return o<<init;
102  return o<<mathrm(name);
103  }
string mathrm(const string &nm)
wraps in if nm has more than one letter - and also takes into account LaTeX subscript/superscripts ...
Definition: node_latex.cc:41
Here is the call graph for this function:

◆ matlab() [1/3]

MatlabManip MathDAG::Node::matlab
inline

Definition at line 120 of file equations.h.

120 {return MatlabManip(*this);}

◆ matlab() [2/3]

virtual ostream& MathDAG::Node::matlab

writes a matlab representation of this DAG to the stream

◆ matlab() [3/3]

ostream & MathDAG::VariableDAG::matlab ( ostream &  ) const
overridevirtual

writes a matlab representation of this DAG to the stream

Implements MathDAG::Node.

Definition at line 72 of file node_matlab.cc.

References MathDAG::anonymous_namespace{node_matlab.cc}::validMatlabIdentifier().

73  {
74  if (type==constant)
75  return o<<init;
76  return o<<validMatlabIdentifier(name);
77  }
Here is the call graph for this function:

◆ order()

int MathDAG::VariableDAG::order ( unsigned  maxOrder) const
inlineoverridevirtual

returns evaluation order in sequence of variable defintions

Parameters
maxOrderis used to limit the recursion depth

Implements MathDAG::Node.

Definition at line 185 of file equations.h.

References MathDAG::Node::order().

Referenced by MathDAG::anonymous_namespace{equations.cc}::VariableDefOrder::operator()().

185  {
186  if (rhs) {
187  if (cachedOrder>=0) return cachedOrder;
188  if (maxOrder==0) throw error("maximum order recursion reached");
189  return cachedOrder=rhs->order(maxOrder-1)+1;
190  }
191  else
192  return 0;
193  }
virtual int order(unsigned maxOrder) const =0
returns evaluation order in sequence of variable defintions
WeakNodePtr rhs
Definition: equations.h:178
Here is the call graph for this function:
Here is the caller graph for this function:

◆ render()

void MathDAG::VariableDAG::render ( ecolab::cairo::Surface &  surf) const
overridevirtual

renders a visual representation of this node to surf graphic extends right from the current pen position (which needs to be defined), and pen is moved to the right edge of the graphic. The determine bounding box, render into a recording surface, and use width()/height()

Implements MathDAG::Node.

Definition at line 219 of file equationDisplayRender.cc.

References minsky::latexToPango(), MathDAG::mathrm(), and MathDAG::anonymous_namespace{equationDisplayRender.cc}::print().

220  {
221  print(surf.cairo(), latexToPango(mathrm(name)), Anchor::nw);
222  }
std::string latexToPango(const char *s)
Definition: latexMarkup.h:30
double print(cairo_t *cairo, const string &text, Anchor anchor)
string mathrm(const string &nm)
wraps in if nm has more than one letter - and also takes into account LaTeX subscript/superscripts ...
Definition: node_latex.cc:41
Here is the call graph for this function:

◆ tensorEval() [1/3]

bool MathDAG::VariableDAG::tensorEval ( std::set< const Node *> &  visited) const
overridevirtual

returns true if the evaluation of this involves tensor processing

Parameters
visitedset to break graph cycles

Implements MathDAG::Node.

Definition at line 106 of file equations.cc.

References minsky::cminsky(), minsky::valueId(), and minsky::Minsky::variableValues.

107  {
108  return cminsky().variableValues[valueId]->rank()>0;
109  }
VariableValues variableValues
Definition: minsky.h:188
const Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:538
Here is the call graph for this function:

◆ tensorEval() [2/3]

bool MathDAG::Node::tensorEval
inline

returns true if the evaluation of this involves tensor processing

Definition at line 116 of file equations.h.

116 {std::set<const Node*> visited; return tensorEval(visited);}
bool tensorEval()
returns true if the evaluation of this involves tensor processing
Definition: equations.h:116

◆ tensorEval() [3/3]

virtual bool MathDAG::Node::tensorEval

returns true if the evaluation of this involves tensor processing

Parameters
visitedset to break graph cycles

Member Data Documentation

◆ init

string MathDAG::VariableDAG::init ="0"

◆ intOp

IntOp* MathDAG::VariableDAG::intOp =0

Definition at line 179 of file equations.h.

Referenced by MathDAG::SystemOfEquations::SystemOfEquations().

◆ name

◆ rhs

◆ type

Type MathDAG::VariableDAG::type =undefined

Definition at line 175 of file equations.h.

Referenced by MathDAG::SystemOfEquations::derivative().

◆ valueId

string MathDAG::VariableDAG::valueId

Definition at line 174 of file equations.h.

Referenced by MathDAG::SystemOfEquations::derivative().


The documentation for this class was generated from the following files: