3.2.13.3. flow/LinExp.hpp

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 flow::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.13.3.1. Variable Specifiers

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.13.3.2. Class flow::VarSumVertex

class flow::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.13.3.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.13.3.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.

VarVertexGraph operator[](std::shared_ptr<graph::Graph> g) const

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.13.3.3. Class flow::VarVertex

class flow::VarVertex

Represents a variable associated with a single vertex in a derivation graph.

3.2.13.3.3.1. Synopsis

explicit VarVertex(std::string id, dg::DG::Vertex v)
friend std::ostream &operator<<(std::ostream &s, const VarVertex &v)
friend bool operator==(const VarVertex &a, const VarVertex &b)
std::string id
dg::DG::Vertex v

3.2.13.3.3.2. Details

explicit VarVertex(std::string id, dg::DG::Vertex v)
Throws

LogicError if !v.

friend std::ostream &operator<<(std::ostream &s, const VarVertex &v)
friend bool operator==(const VarVertex &a, const VarVertex &b)
std::string id
dg::DG::Vertex v

3.2.13.3.4. Class flow::VarVertexGraph

class flow::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.13.3.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.13.3.4.2. Details

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.13.3.5. Class flow::VarSumEdge

class flow::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.13.3.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.13.3.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.13.3.6. Class flow::VarEdge

class flow::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.13.3.6.1. Synopsis

explicit VarEdge(std::string id, dg::DG::HyperEdge e)
friend std::ostream &operator<<(std::ostream &s, const VarEdge &v)
friend bool operator==(const VarEdge &a, const VarEdge &b)
std::string id
dg::DG::HyperEdge edge

3.2.13.3.6.2. Details

explicit VarEdge(std::string id, dg::DG::HyperEdge e)
Throws

LogicError if !e.

friend std::ostream &operator<<(std::ostream &s, const VarEdge &v)
friend bool operator==(const VarEdge &a, const VarEdge &b)
std::string id
dg::DG::HyperEdge edge

3.2.13.3.7. Class flow::VarSumCustom

class flow::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.13.3.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.13.3.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.13.3.8. Class flow::VarCustom

class flow::VarCustom

Represents a custom variable.

3.2.13.3.8.1. Synopsis

explicit VarCustom(std::string id, std::string name)
friend std::ostream &operator<<(std::ostream &s, const VarCustom &v)
friend bool operator==(const VarCustom &a, const VarCustom &b)
std::string id
std::string name

3.2.13.3.8.2. Details

explicit VarCustom(std::string id, std::string name)
friend std::ostream &operator<<(std::ostream &s, const VarCustom &v)
friend bool operator==(const VarCustom &a, const VarCustom &b)
std::string id
std::string name

3.2.13.3.9. Class flow::Var

class flow::Var

Represents any of the variable specifier types, and can be implicitly converted to from any of them.

3.2.13.3.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.13.3.9.2. Details

using VarImpl = std::variant<VarSumVertex, VarVertex, VarVertexGraph, VarSumEdge, VarEdge, VarSumCustom, VarCustom>
template<typename T>
Var(T v)

Requires T being a variable specifier type.

template<typename Visitor>
decltype(auto) applyVisitor(Visitor &&visitor)
template<typename Visitor>
decltype(auto) applyVisitor(Visitor &&visitor) const
Returns

boost::apply_visitor(visitor, v)

template<typename T>
const T *get() const
Returns

get<T>(&v)

friend std::ostream &operator<<(std::ostream &s, const Var &v)
friend bool operator==(const Var &a, const Var &b)
private VarImpl v

3.2.13.3.10. Class flow::LinExp

class flow::LinExp

Represents a linear expression over variable specifiers.

3.2.13.3.10.1. Synopsis

using IntElement = std::pair<long int, Var>
using FloatElement = std::pair<double, Var>
LinExp() = default
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

3.2.13.3.10.2. Details

using IntElement = std::pair<long int, Var>
using FloatElement = std::pair<double, Var>
LinExp() = default
template<typename T>
LinExp(T v)

Requires T convertible to Var.

friend std::ostream &operator<<(std::ostream &s, const LinExp &exp)
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.13.3.11. Class flow::LinConstraint

class flow::LinConstraint

Represents a linear constraint on the form exp relation bound,

3.2.13.3.11.1. Synopsis

enum class Relation
explicit LinConstraint(LinExp exp, Relation relation, double bound)
friend std::ostream &operator<<(std::ostream &s, const LinConstraint &c)
LinExp exp
Relation relation
double bound

3.2.13.3.11.2. Details

enum class Relation
explicit LinConstraint(LinExp exp, Relation relation, double bound)
friend std::ostream &operator<<(std::ostream &s, const LinConstraint &c)
LinExp exp
Relation relation
double bound