3.2.14.2. hyperflow/LinExp.hpp¶
This header implements variable specifiers, linear expressions, and linear constraints. See Variable Specifiers, Linear Expressions, and Constraints for a higher-level description of these entities.
Linear expressions and constraints can be implicitly created from variable specifiers and operators, meaning one rarely need to instantiate them explicitly. However creating the zero-expression might sometimes be useful (e.g., in a sum expression) and can be done simply with the expression hyperflow::LinExp().
A variable specifier is a representation of either a single variable or a sum of variables. The addition, multiplication and division operators are overloaded for variable specifiers and linear expressions such that expressions can be written in the natural manner.
The operators <=
, ==
and >=
are overloaded on linear expressions to make the creation of
linear constraints easier. However, one argument to the operator must be a linear expression while
the other argument must be a number.
3.2.14.2.1. Variable Specifier Classes¶
The main variables in a flow model are associated with either vertices or hyperedges in the underlying derivation graph. A variable specifier represents either a set of variables or a single variable, Each specifier has an associated ID that must be registered by a flow model module at the time when the specifier is added to the model. See also Hyperflow Model for an overview of the specifiers.
3.2.14.2.2. Class hyperflow::VarSumVertex
¶
-
class hyperflow::VarSumVertex¶
Represents the sum of all variables indicated by the given id. Can be indexed to retrieve a specifier for a single variable in the set.
3.2.14.2.2.1. Synopsis¶
-
explicit VarSumVertex(std::string id)
-
friend std::ostream &operator<<(std::ostream &s, const VarSumVertex &v)
-
friend bool operator==(const VarSumVertex &a, const VarSumVertex &b)
-
VarVertex operator[](dg::DG::Vertex v) const
-
VarVertexGraph operator[](std::shared_ptr<graph::Graph> g) const
-
std::string id
3.2.14.2.2.2. Details¶
-
explicit VarSumVertex(std::string id)¶
Construct a variable specifier for a sum of variables associated with vertices in the underlying derivation graph.
-
friend std::ostream &operator<<(std::ostream &s, const VarSumVertex &v)¶
-
friend bool operator==(const VarSumVertex &a, const VarSumVertex &b)¶
-
VarVertex operator[](dg::DG::Vertex v) const¶
Select the variable associated with the given derivation graph vertex. When the resulting specifier is given to a flow model the vertex must be from the underlying derivation graph.
- Returns:
a variable specifier for a single variable in the set represented by this object.
- Throws:
LogicError if !v.
Select the variable associated with the derivation graph vertex which represents the given graph. When the resulting specifier is given to a flow model such a vertex must then exist in the underlying derivation graph.
- Returns:
a variable specifier for a single variable in the set represented by this object.
-
std::string id¶
The ID for this specifier.
3.2.14.2.3. Class hyperflow::VarVertex
¶
-
class hyperflow::VarVertex¶
Represents a variable associated with a single vertex in a derivation graph.
3.2.14.2.3.1. Synopsis¶
3.2.14.2.3.2. Details¶
-
explicit VarVertex(std::string id, dg::DG::Vertex v)¶
- Throws:
LogicError if !v.
-
std::string id¶
3.2.14.2.4. Class hyperflow::VarVertexGraph
¶
-
class hyperflow::VarVertexGraph¶
Represents a variable associated with a single vertex in a derivation graph. This is done implicitly by a graph, and when this specifier is later given to a flow model a vertex with the graph associated must exist in the underlying derivation graph.
3.2.14.2.4.1. Synopsis¶
-
explicit VarVertexGraph(std::string id, std::shared_ptr<graph::Graph> g)
-
friend std::ostream &operator<<(std::ostream &s, const VarVertexGraph &v)
-
friend bool operator==(const VarVertexGraph &a, const VarVertexGraph &b)
-
std::string id
-
std::shared_ptr<graph::Graph> g
3.2.14.2.4.2. Details¶
-
friend std::ostream &operator<<(std::ostream &s, const VarVertexGraph &v)¶
-
friend bool operator==(const VarVertexGraph &a, const VarVertexGraph &b)¶
-
std::string id¶
3.2.14.2.5. Class hyperflow::VarSumEdge
¶
-
class hyperflow::VarSumEdge¶
Represents the sum of all variables indicated by the given id. Can be indexed to retrieve a specifier for a single variable in the set.
3.2.14.2.5.1. Synopsis¶
-
explicit VarSumEdge(std::string id)
-
friend std::ostream &operator<<(std::ostream &s, const VarSumEdge &v)
-
friend bool operator==(const VarSumEdge &a, const VarSumEdge &b)
-
VarEdge operator[](dg::DG::HyperEdge e) const
-
std::string id
3.2.14.2.5.2. Details¶
-
explicit VarSumEdge(std::string id)¶
Construct a variable specifier for a sum of variables associated with hyperedges in the underlying derivation graph.
-
friend std::ostream &operator<<(std::ostream &s, const VarSumEdge &v)¶
-
friend bool operator==(const VarSumEdge &a, const VarSumEdge &b)¶
-
VarEdge operator[](dg::DG::HyperEdge e) const¶
Select the variable associated with the given derivation graph hyperedge. When the resulting specifier is given to a flow model its underlying derivation graph must be the same as the derivation graph the given hyperedge belongs to.
- Returns:
a variable specifier for a single variable in the set represented by this object.
- Throws:
LogicError
if !e.
-
std::string id¶
3.2.14.2.6. Class hyperflow::VarEdge
¶
-
class hyperflow::VarEdge¶
Represents a variable associated with a single hyperedge in a derivation graph. When this specifier is later given to a flow model its underlying derivation graph must be the same as the derivation graph the hyperedge in this object belongs to.
3.2.14.2.6.1. Synopsis¶
3.2.14.2.6.2. Details¶
-
explicit VarEdge(std::string id, dg::DG::HyperEdge e)¶
- Throws:
LogicError
if !e.
-
std::string id¶
3.2.14.2.7. Class hyperflow::VarSumCustom
¶
-
class hyperflow::VarSumCustom¶
Represents the sum of all variables indicated by the given id. Can be indexed to retrieve a specifier for a single variable in the set.
3.2.14.2.7.1. Synopsis¶
-
explicit VarSumCustom(std::string id)
-
friend std::ostream &operator<<(std::ostream &s, const VarSumCustom &v)
-
friend bool operator==(const VarSumCustom &a, const VarSumCustom &b)
-
VarCustom operator[](std::string name) const
-
std::string id
3.2.14.2.7.2. Details¶
-
explicit VarSumCustom(std::string id)¶
-
friend std::ostream &operator<<(std::ostream &s, const VarSumCustom &v)¶
-
friend bool operator==(const VarSumCustom &a, const VarSumCustom &b)¶
-
VarCustom operator[](std::string name) const¶
Select the variable associated with the given name. When the resulting specifier is given to a flow model that variable must have been created in the specification in some way.
- Returns:
a variable specifier for a single variable in the set represented by this object.
-
std::string id¶
3.2.14.2.8. Class hyperflow::VarCustom
¶
-
class hyperflow::VarCustom¶
Represents a custom variable.
3.2.14.2.8.1. Synopsis¶
3.2.14.2.8.2. Details¶
-
explicit VarCustom(std::string id, std::string name)¶
-
std::string id¶
-
std::string name¶
3.2.14.2.9. Class hyperflow::Var
¶
-
class hyperflow::Var¶
Represents any of the variable specifier types, and can be implicitly converted to from any of them.
3.2.14.2.9.1. Synopsis¶
-
using VarImpl = std::variant<VarSumVertex, VarVertex, VarVertexGraph, VarSumEdge, VarEdge, VarSumCustom, VarCustom>
-
template<typename T>
Var(T v) -
template<typename Visitor>
decltype(auto) applyVisitor(Visitor &&visitor) -
template<typename Visitor>
decltype(auto) applyVisitor(Visitor &&visitor) const -
template<typename T>
const T *get() const -
friend std::ostream &operator<<(std::ostream &s, const Var &v)
-
friend bool operator==(const Var &a, const Var &b)
-
private VarImpl v
3.2.14.2.9.2. Details¶
-
using VarImpl = std::variant<VarSumVertex, VarVertex, VarVertexGraph, VarSumEdge, VarEdge, VarSumCustom, VarCustom>¶
3.2.14.2.10. Class hyperflow::LinExp
¶
-
class hyperflow::LinExp¶
Represents a linear expression over variable specifiers.
3.2.14.2.10.1. Synopsis¶
-
using IntElement = std::pair<int, Var>
-
using FloatElement = std::pair<double, Var>
-
LinExp() = default
-
LinExp(Var v)
-
template<typename T>
LinExp(T v) -
friend std::ostream &operator<<(std::ostream &s, const LinExp &exp)
-
const std::vector<IntElement> &getIntElements() const
-
const std::vector<FloatElement> &getFloatElements() const
-
LinExp &operator+=(const LinExp &e)
-
LinExp &operator-=(const LinExp &e)
-
LinExp &operator*=(int c)
-
LinExp &operator*=(double c)
3.2.14.2.10.2. Details¶
-
LinExp() = default¶
-
const std::vector<IntElement> &getIntElements() const¶
- Returns:
all elements of the linear expression that have integer coefficients.
-
const std::vector<FloatElement> &getFloatElements() const¶
- Returns:
all elements of the linear expression that have floating point coefficients.
3.2.14.2.11. Class hyperflow::LinConstraint
¶
3.2.14.2.11.1. Synopsis¶
3.2.14.2.11.2. Details¶
-
enum class Relation¶
-
friend std::ostream &operator<<(std::ostream &s, const LinConstraint &c)¶
-
double bound¶
-
LinConstraint operator<=(const LinExp &e, double c)¶
-
LinConstraint operator==(const LinExp &e, double c)¶
-
LinConstraint operator>=(const LinExp &e, double c)¶
-
LinConstraint operator<=(double c, const LinExp &e)¶
-
LinConstraint operator==(double c, const LinExp &e)¶
-
LinConstraint operator>=(double c, const LinExp &e)¶
3.2.14.2.11.3. Pre-defined Variable Specifiers¶
Each of the variable specifiers are defined in a separate namespace,
so you can use using namespace mod::hyperflow::vars;
in the scopes where you need them,
without having to fully qualify their names each time.
3.2.14.2.11.3.1. Base Model¶
-
const hyperflow::VarSumVertex hyperflow::vars::inFlow¶
-
const hyperflow::VarSumVertex hyperflow::vars::outFlow¶
-
const hyperflow::VarSumVertex hyperflow::vars::isInUsed¶
-
const hyperflow::VarSumVertex hyperflow::vars::isOutUsed¶
-
const hyperflow::VarSumVertex hyperflow::vars::isInLessOut¶
-
const hyperflow::VarSumVertex hyperflow::vars::isInGreaterOut¶
-
const hyperflow::VarSumVertex hyperflow::vars::isInOutZero¶
-
const hyperflow::VarSumVertex hyperflow::vars::vertexFlow¶
-
const hyperflow::VarSumVertex hyperflow::vars::isVertexUsed¶
-
const hyperflow::VarSumVertex hyperflow::vars::transitInternalFlow¶
-
const hyperflow::VarSumEdge hyperflow::vars::edgeFlow¶
-
const hyperflow::VarSumEdge hyperflow::vars::isEdgeUsed¶
-
const hyperflow::VarSumEdge hyperflow::vars::isBothReverseUsed¶
3.2.14.2.11.3.2. OverallCatalysis¶
-
const hyperflow::VarSumVertex hyperflow::vars::isOverallCata¶
3.2.14.2.11.3.3. OverallAutocatalysis¶
-
const hyperflow::VarSumVertex hyperflow::vars::isOverallAutocata¶
3.2.14.2.11.3.4. Thermodynamics¶
-
const hyperflow::VarSumVertex hyperflow::vars::energy¶
-
const hyperflow::VarSumVertex hyperflow::vars::logConcentration¶
-
const hyperflow::VarSumEdge hyperflow::vars::deltaEnergy¶