15#ifndef MINOTAURCNODE_H
16#define MINOTAURCNODE_H
27 bool operator()(
const CNode *n1,
const CNode *n2)
const;
31 bool operator()(
const CNode *n1,
const CNode *n2)
const;
33 typedef std::set<CNode *, CompareCNodes> CNodeSet;
34 typedef std::set<CNode *, CompareCNodesR> CNodeRSet;
61 CNode(OpCode op,
CNode **children,
size_t num_child);
108 std::map<const CNode *, CNode *> *nmap)
const;
120 void eval(
const double *x,
int *error);
134 double evalSingle(
double x,
int *error)
const;
150 bool getB()
const {
return b_; };
182 int getTempI()
const {
return ti_; };
205 void grad(
int *error);
239 void hess(
int *error);
249 void hess2(CNodeRSet *nset,
int *error);
376 void write(std::ostream &out)
const;
388 void writeSubNl(std::stringstream &s,
int *err)
const;
432 void propBounds_(
double lb,
double ub,
bool *is_inf);
434 typedef std::vector<CNode *> CNodeVector;
Declare the OpCodes used in Minotaur.
Declare important 'types' used in Minotaur.
CNode denotes a node in the computational graph. It stores the op-code, children, parents and other a...
Definition: CNode.h:48
void setType(FunctionType t)
Set the value of function type of the graph rooted at this node.
Definition: CNode.cpp:1670
FunctionType findFType()
Find the type of the function (constant, linear, polynomial, etc.) based on the function type of chil...
Definition: CNode.cpp:534
double val_
Pointer the variable in case it is OpVar.
Definition: CNode.h:419
double gi_
Definition: CNode.h:398
void setB(bool b)
Set the boolean flag.
Definition: CNode.h:256
size_t id_
Value of the hessian.
Definition: CNode.h:401
void write(std::ostream &out) const
Print the function expression at current node only.
Definition: CNode.cpp:1888
size_t numPar_
Number of children.
Definition: CNode.h:406
void setV(VariablePtr v)
Set the Variable at this node (for OpVar nodes)
Definition: CNode.h:361
double g_
Function type of the graph rooted at this node.
Definition: CNode.h:396
CNode ** getListL() const
Definition: CNode.h:171
int ti_
Right child.
Definition: CNode.h:411
void setGi(double gi)
Set the value of the derivative (forward mode gradient)
Definition: CNode.h:289
void setOp(OpCode op)
Set the OpCode.
Definition: CNode.h:325
double getH() const
Definition: CNode.h:156
void hess(int *error)
Reverse mode hessian evaluation. Hessian values are pushed to children nodes.
Definition: CNode.cpp:1082
void propHessSpa()
Find whether child-nodes must participate in evaluation of the current column of the hessian-matrix....
Definition: CNode.cpp:1546
void propBounds(bool *is_inf, int *error)
Deduce and push new bounds to child-nodes based on bounds of this node.
Definition: CNode.cpp:1246
size_t getIndex() const
Definition: CNode.h:162
double h_
Definition: CNode.h:400
size_t numChild() const
Definition: CNode.h:208
void propBounds_(double lb, double ub, bool *is_inf)
Change the current bounds of the function value at this node to new bounds only if the new bounds are...
Definition: CNode.cpp:1489
const Variable * v_
Definition: CNode.h:418
void setIndex(size_t i)
Set the value of the node index.
Definition: CNode.h:310
OpCode getOp() const
Definition: CNode.h:177
void setL(CNode *n)
Set the pointer to the left-most child.
Definition: CNode.h:318
OpCode op_
Number of parents.
Definition: CNode.h:407
void writeSubExp(std::ostream &out) const
Print the function expression at current node and the sub-tree.
Definition: CNode.cpp:2063
CNode * r_
Pointer to the last parent (parents end)
Definition: CNode.h:410
size_t numChild_
lower bound that a node can achieve
Definition: CNode.h:405
void setTempI(int i)
Set the value of the temporary integer ti_.
Definition: CNode.h:339
bool getB() const
Definition: CNode.h:150
void setR(CNode *n)
Set the pointer to the right-most child.
Definition: CNode.h:332
void setG(double g)
Set the value of the derivative (reverse mode gradient)
Definition: CNode.h:282
void propHessSpa2(CNodeRSet *nset)
A variant of propHessSpa()
Definition: CNode.cpp:1514
CNode * getR() const
Definition: CNode.h:181
void setH(double h)
Set the value of the hessian.
Definition: CNode.h:296
void setBounds(double lb, double ub)
Set lower and upper bounds on the node.
Definition: CNode.h:264
FunctionType fType_
Constant double value in OpNum and OpInt nodes.
Definition: CNode.h:395
double d_
array of size numChild_ + 1. The last pointer is a null
Definition: CNode.h:394
void setId(size_t i)
Set the value of the node ID.
Definition: CNode.h:303
CNode()
Default constructor.
Definition: CNode.cpp:32
void eval(const double *x, int *error)
Evaluate the function at this node.
Definition: CNode.cpp:402
size_t index_
Unique ID of a dependent node. 0 for independent nodes.
Definition: CNode.h:402
void fwdGrad()
Calculate the derivative of the function at this node based on values and gradients of children nodes...
Definition: CNode.cpp:809
const Variable * getV() const
Definition: CNode.h:194
CQIter2 * parE_
Pointer to the first parent (parents begin)
Definition: CNode.h:409
double getLb() const
Definition: CNode.h:168
double getG() const
Definition: CNode.h:153
double evalSingle(double x, int *error) const
Evaluate the value of just this node based on the single value given as an input parameter....
Definition: CNode.cpp:308
void grad(int *error)
Push gradient values to children for reverse mode gradient evaluation.
Definition: CNode.cpp:939
void setVal(double v)
Set the value of function at this node.
Definition: CNode.cpp:1676
CNode * clone() const
Clone the node. Does not copy pointers to parents, children, etc.
Definition: CNode.cpp:200
double ub_
Definition: CNode.h:413
CNode ** getListR() const
Definition: CNode.h:174
~CNode()
Destroy.
Definition: CNode.cpp:153
CNode * getL() const
Definition: CNode.h:165
size_t getId() const
Definition: CNode.h:159
CQIter2 * parB_
Operation code.
Definition: CNode.h:408
void changeChild(CNode *out, CNode *in)
Replace one of the children of a given node by another node.
Definition: CNode.cpp:225
CNode * uPar_
upper bound that a node can achieve
Definition: CNode.h:416
void copyParChild(CNode *out, std::map< const CNode *, CNode * > *nmap) const
Make copies of links pointing to parents and children to another node. Used in cloning the CGraph.
Definition: CNode.cpp:256
CNode * getUPar() const
Definition: CNode.h:191
size_t numPar() const
Definition: CNode.h:211
void hess2(CNodeRSet *nset, int *error)
Reverse mode hessian evaluation with sparsity detection. Hessian values are pushed to children nodes.
Definition: CNode.cpp:1239
double lb_
Left child.
Definition: CNode.h:404
void setDouble(double d)
Set the constant double value (OpNum and OpInt).
Definition: CNode.h:275
void writeSubNl(std::stringstream &s, int *err) const
Write the function expression in ASL's text format (reverse polish notation) for the current node and...
Definition: CNode.cpp:1902
void addPar(CNode *node)
Add a parent to a given node (a parent depends on the child in function evaluation).
Definition: CNode.cpp:171
FunctionType getType() const
Definition: CNode.h:185
CNode ** child_
Boolean flag used in finding hessian sparsity.
Definition: CNode.h:393
double getUb() const
Definition: CNode.h:188
double getVal() const
Definition: CNode.h:197
CNode * l_
Unique index of the node.
Definition: CNode.h:403
void updateBnd(int *error)
Find bounds deduced from the bounds of children nodes and update lb_ and ub_.
Definition: CNode.cpp:1684
Definition: Variable.h:31
Definition: ActiveNodeStore.h:20
FunctionType
Different types of functions in Minotaur.
Definition: Types.h:65