3.2.14.3. hyperflow/Model.hpp

3.2.14.3.1. Class hyperflow::Model

class hyperflow::Model

A Model object represents a hyperflow model on a given derivation graph. A model consists of a set of modules with the base module modelling the edge flow and input/output flow. Each module is accessed using proxy objects accessible as public members in the main model object.

3.2.14.3.1.1. Synopsis

int getId() const
std::shared_ptr<dg::DG> getDG() const
bool isSpecificationLocked() const
void listSpecification() const
void addSource(dg::DG::Vertex v)
void addSource(std::shared_ptr<graph::Graph> g)
std::vector<dg::DG::Vertex> getSources() const
void addSink(dg::DG::Vertex v)
void addSink(std::shared_ptr<graph::Graph> g)
std::vector<dg::DG::Vertex> getSinks() const
void exclude(dg::DG::Vertex v)
void exclude(std::shared_ptr<graph::Graph> g)
std::vector<dg::DG::Vertex> getExcluded() const
void separateIOInternalTransit(dg::DG::Vertex v)
void separateIOInternalTransit(std::shared_ptr<graph::Graph> g)
std::vector<dg::DG::Vertex> getSeparatedIOInternalTransit() const
void setAllowHyperLoops(bool value)
bool getAllowHyperLoops() const
void setAllowReversal(bool value)
bool getAllowReversal() const
void setAllowIOReversal(bool value)
bool getAllowIOReversal() const
void setRelaxed(bool value)
bool getRelaxed() const
void setObjectiveFunction(LinExp func)
void addBoolVariable(const std::string &name)
void addIntVariable(const std::string &name)
void addFloatVariable(const std::string &name)
std::vector<VarCustom> getCustomBoolVariables() const
std::vector<VarCustom> getCustomIntVariables() const
std::vector<VarCustom> getCustomFloatVariables() const
void addConstraint(const LinConstraint &constraint)
OverallAutocatalysis overallAutocatalysis
OverallCatalysis overallCatalysis
Thermodynamics thermodynamics
void addEnumerationVar(Var var)
std::vector<Var> getEnumerationVars() const
void addTransitEnumeration(dg::DG::Vertex v)
void addTransitEnumeration(std::shared_ptr<graph::Graph> g)
std::vector<dg::DG::Vertex> getTransitEnumeration() const
void setAbsGap(int absGap)
std::optional<int> getAbsGap()
SolutionRange findSolutions(int maxNumSolutions)
SolutionRange findSolutions(int maxNumSolutions, int verbosity)
SolutionRange findSolutions(int maxNumSolutions, int verbosity, int ilpVerbosity)
std::string dump() const
std::string dump(const std::string &filename) const
SolutionRange getSolutions() const
std::string printExpandedVertex(dg::DG::Vertex v) const
std::string printExpandedVertex(std::shared_ptr<graph::Graph> g) const
std::string printExpanded() const
std::string printEnumerationTree() const
static std::shared_ptr<Model> make(std::shared_ptr<dg::DG> dg_)
static std::shared_ptr<Model> make(std::shared_ptr<dg::DG> dg_, const std::string &ilpSolver)
static std::shared_ptr<Model> copy(std::shared_ptr<Model> other)
static std::shared_ptr<Model> load(std::shared_ptr<dg::DG> dg_, const std::string &file)
static std::shared_ptr<Model> load(std::shared_ptr<dg::DG> dg_, const std::string &file, const std::string &ilpSolver, int verbosity)
static std::shared_ptr<Model> loadString(std::shared_ptr<dg::DG> dg_, const std::string &data)
static std::shared_ptr<Model> loadString(std::shared_ptr<dg::DG> dg_, const std::string &data, const std::string &ilpSolver, int verbosity)
class hyperflow::Model::OverallAutocatalysis
class hyperflow::Model::OverallCatalysis
class hyperflow::Model::Thermodynamics

3.2.14.3.1.2. Details

int getId() const
Returns:

the unique instance ID for the object.

std::shared_ptr<dg::DG> getDG() const
Returns:

the underlying derivation graph.

bool isSpecificationLocked() const
Returns:

whether the specification is locked for modifications.

void listSpecification() const

List the specification textually to standard output.

void addSource(dg::DG::Vertex v)

Add the vertex as a possible source.

Throws:

LogicError if isSpecificationLocked().

Throws:

LogicError if !v.

Throws:

LogicError if v.getDG() != getDG().

void addSource(std::shared_ptr<graph::Graph> g)

Equivalent to calling addSource(getDG()->findVertex(g)).

std::vector<dg::DG::Vertex> getSources() const

Retrieve the list of source vertices for the model.

void addSink(dg::DG::Vertex v)

Add the vertex as a possible sink.

Throws:

LogicError if isSpecificationLocked().

Throws:

LogicError if !v.

Throws:

LogicError if v.getDG() != getDG().

void addSink(std::shared_ptr<graph::Graph> g)

Equivalent to calling addSink(getDG()->findVertex(g)).

std::vector<dg::DG::Vertex> getSinks() const

Retrieve the list of sink vertices for the model.

void exclude(dg::DG::Vertex v)

Exclude the vertex and all its incident edges from the model. This will not only add a constraint to disallow flow through this vertex, but will make some algorithms in various modules pretend the vertex and incident edges were never part of the model in the first place.

Throws:

LogicError if isSpecificationLocked().

Throws:

LogicError if !v.

Throws:

LogicError if v.getDG() != getDG().

void exclude(std::shared_ptr<graph::Graph> g)

Equivalent to calling exclude(getDG()->findVertex(g)).

std::vector<dg::DG::Vertex> getExcluded() const

Retrieve the list of excluded vertices for the model.

void separateIOInternalTransit(dg::DG::Vertex v)

Ensure that the expanded vertex of v has transit edges such that flow going from the input edge or to the output edge can be distinguished from flow going from the network and back to the network.

The vertex expansion is lazy, and thus calling this function is necessary in order to, e.g., access the corresponding transitInternal variable.

Throws:

LogicError if isSpecificationLocked().

Throws:

LogicError if !v.

Throws:

LogicError if v.getDG() != getDG().

void separateIOInternalTransit(std::shared_ptr<graph::Graph> g)

Equivalent to calling separateIOInternalTransit(getDG()->findVertex(g)).

std::vector<dg::DG::Vertex> getSeparatedIOInternalTransit() const
Returns:

a list of vertices where separateIOInternalTransit() has been called. Note, this does not mean that other vertices do not have separated transit edges. For example, calling setAllowIOReversal(true) implies separation as well.

void setAllowHyperLoops(bool value)
bool getAllowHyperLoops() const

Control or query whether flow is allowed through loop hyperedges. I.e., hyperedges with identical source and target multisets.

Throws:

(only set) LogicError if isSpecificationLocked().

Note:

This setting may be changed when certain modules are enabled.

void setAllowReversal(bool value)
bool getAllowReversal() const

Control or query whether flow may go through one edge and then directly afterwards the inverse edge.

Throws:

(only set) LogicError if isSpecificationLocked().

Note:

This setting may be modified when certain modules are enabled.

void setAllowIOReversal(bool value)
bool getAllowIOReversal() const

Control or query whether flow may go through an input edge and directly afterwards through the corresponding output edge.

This implies that transit edges gets separated in all vertices, as if separateIOInternalTransit() was called on all of them.

Throws:

(only set) LogicError if isSpecificationLocked().

Note:

This setting may be modified when certain modules are enabled.

void setRelaxed(bool value)
bool getRelaxed() const

Controls whether the core flow variables are integer or continuous. The default is False, meaning integer. Using the relaxed model significantly changes the meaning of solutions, and all features that rely on flows being integer will be disabled.

Throws:

(only set) LogicError if isSpecificationLocked().

void setObjectiveFunction(LinExp func)

Set the objective function used when finding solutions.

Throws:

LogicError if isSpecificationLocked().

void addBoolVariable(const std::string &name)
void addIntVariable(const std::string &name)
void addFloatVariable(const std::string &name)

Create a new custom boolean, integer, or floating point variable with the given name.

Returns:

a handle to the variable.

Throws:

LogicError if isSpecificationLocked().

Throws:

LogicError if :cpp:var`name` is already in use.

std::vector<VarCustom> getCustomBoolVariables() const
std::vector<VarCustom> getCustomIntVariables() const
std::vector<VarCustom> getCustomFloatVariables() const
Returns:

a list of handles to the variables added with addBoolVariable()/addIntVariable()/addFloatVariable().

void addConstraint(const LinConstraint &constraint)

Add the given linear constraint to the model.

Throws:

LogicError if isSpecificationLocked().

OverallAutocatalysis overallAutocatalysis

The access object for the overall autocatalysis module of the flow model.

OverallCatalysis overallCatalysis

The access object for the overall catalysis module of the flow model.

Thermodynamics thermodynamics

The access object for the thermodynamics module of the flow model.

void addEnumerationVar(Var var)

Add the variables specified by the given variable specifier for solution enumeration.

The default variables are vars::edgeFlow, vars::inFlow, and vars::outFlow. These are removed the first time this function is called.

Throws:

LogicError if isSpecificationLocked().

std::vector<Var> getEnumerationVars() const

Retrieve the list of variable specifiers used for solution enumeration.

void addTransitEnumeration(dg::DG::Vertex v)

Add the transit edges of the vertex for solution enumeration.

Throws:

LogicError if isSpecificationLocked(). :throws: LogicError if !v. :throws: LogicError if v.getDG() != getDG().

void addTransitEnumeration(std::shared_ptr<graph::Graph> g)

Equivalent to calling addTransitEnumeration(getDG()->findVertex(g)).

std::vector<dg::DG::Vertex> getTransitEnumeration() const

Retrieve the list of vertices where the transit edges are used for solution enumeration.

void setAbsGap(int absGap)

Set the absolute gap in objective value between the optimal solution and the worst solution. As default there is no constraint on this gap. Pass a negative number to reset to this unconstrained state.

Throws:

LogicError if isSpecificationLocked().

std::optional<int> getAbsGap()
Returns:

the absolution gap in objective value.

SolutionRange findSolutions(int maxNumSolutions)
SolutionRange findSolutions(int maxNumSolutions, int verbosity)
SolutionRange findSolutions(int maxNumSolutions, int verbosity, int ilpVerbosity)

Find the next up to maxNumSolutions best solutions.

This may be called multiple times to find additional solutions in an incremental fashion. After the first call the specification will be locked, i.e., isSpecificationLocked() will return true.

Calling with maxNumSolutions set to 0 will still lock the specification, but will create the internal model.

Parameters:
  • verbosity

    controls the amount of information printed during solution enumeration, defaults to 1:

    • 0: print no information, and cap ilpVerbosity to 0, no matter the given value.

    • 1: print status updates periodically.

    • 2: print debug information.

  • ilpVerbosity

    controls the amount of information printed by the underlying ILP solver, defaults to 1:

    • 0: print no information.

    • 1: print default information for the first solution only.

    • 2: print default information when finding a solution.

Returns:

a range of the newly found solutions.

Throws:

LogicError if maxNumSolutions is less than 0.

Throws:

LogicError the first time it is called, if an enabled module can not create its model. See the documentation for each module.

std::string dump() const
std::string dump(const std::string &filename) const

Dump all model settings and all solutions found to a file. This file can be loaded in again.

Parameters:

filename – the name of the file to save the dump to. If non is given an auto-generated name in the out/ folder is used. If an empty string is given, it is treated as if non is given.

Returns:

the filename with the dumped model.

SolutionRange getSolutions() const
Returns:

a range of the solutions found so far.

Throws:

LogicError if isSpecificationLocked().

std::string printExpandedVertex(dg::DG::Vertex v) const

Print the expanded flow network for the given vertex.

Returns:

the name of the PDF-file which will be created in post-processing.

Throws:

LogicError if !isSpecificationLocked().

Throws:

LogicError if !v.

Throws:

LogicError if v.getDG() != getDG().

std::string printExpandedVertex(std::shared_ptr<graph::Graph> g) const

Equivalent to calling printExpandedVertex(getDG()->findVertex(g)).

std::string printExpanded() const

Print the complete expanded derivation graph.

Returns:

the name of the PDF-file which will be created in post-processing.

Throws:

LogicError if !isSpecificationLocked().

std::string printEnumerationTree() const

Print the search tree generated by the solution enumeration.

Returns:

the name of the generated file.

Throws:

LogicError if !isSpecificationLocked().

static std::shared_ptr<Model> make(std::shared_ptr<dg::DG> dg_)
static std::shared_ptr<Model> make(std::shared_ptr<dg::DG> dg_, const std::string &ilpSolver)
Parameters:

ilpSolver – defaults to default. See getAvailableILPSolvers().

Returns:

a new flow model over the given derivation graph.

Throws:

LogicError if !dg.

Throws:

LogicError if !dg->isLocked().

Throws:

LogicError if dg->numVertices() == 0.

static std::shared_ptr<Model> copy(std::shared_ptr<Model> other)
Parameters:

other – a model to copy the specification from.

Returns:

a new flow model starting with a copy of the specification from other. The returned model is not locked.

Throws:

LogicError if !other.

static std::shared_ptr<Model> load(std::shared_ptr<dg::DG> dg_, const std::string &file)
static std::shared_ptr<Model> load(std::shared_ptr<dg::DG> dg_, const std::string &file, const std::string &ilpSolver, int verbosity)
Parameters:
Returns:

a flow model (possibly with solutions) corresponding to the model stored in the given file. The given derivation graph must match the derivation graph originally used to create the dump.

Throws:

LogicError if !dg.

Throws:

InputError on bad data or if the given derivation graph does not match the data.

static std::shared_ptr<Model> loadString(std::shared_ptr<dg::DG> dg_, const std::string &data)
static std::shared_ptr<Model> loadString(std::shared_ptr<dg::DG> dg_, const std::string &data, const std::string &ilpSolver, int verbosity)
Parameters:
Returns:

a flow model (possibly with solutions) corresponding to the model stored in the given string. The given derivation graph must match the derivation graph originally used to create the dump.

Throws:

LogicError if !dg.

Throws:

InputError on bad data or if the given derivation graph does not match the data.

3.2.14.3.2. Class hyperflow::Model::OverallAutocatalysis

class hyperflow::Model::OverallAutocatalysis

This class provides access to the module for overall autocatalysis of a flow model.

void enable()

Enable the module. This will automatically call setAllowReversal(false) and setAllowIOReversal(false).

Throws:

LogicError if isSpecificationLocked().

Throws:

during model creation, LogicError if in relaxed mode.

bool isEnabled()
Returns:

whether the module is enabled.

void setForceExistence(bool value)
bool getForceExistence() const

Control or query whether a solution must be overall autocatalytic.

Throws:

LogicError if the module is not enabled.

Throws:

(only set) LogicError if isSpecificationLocked().

void setStrictTransit(bool value)
bool getStrictTransit() const

Control or query whether transit flow in overall autocatalytic vertices is restricted or not.

Throws:

LogicError if the module is not enabled.

Throws:

(only set) LogicError if isSpecificationLocked().

void setBFSExclusive(bool value)
bool getBFSExclusive() const

Control or query whether vertices must be exclusively overall autocatalytic, as determined by breadth-first marking.

Throws:

LogicError if the module is not enabled.

Throws:

(only set) LogicError if isSpecificationLocked().

3.2.14.3.3. Class hyperflow::Model::OverallCatalysis

class hyperflow::Model::OverallCatalysis

This class provides access to the module for overall catalysis of a flow model.

void enable()
Enable the module. This will automatically call setAllowReversal(false)

and setAllowIOReversal(false).

Throws:

LogicError if isSpecificationLocked().

Throws:

during model creation, LogicError if in relaxed mode.

bool isEnabled()
Returns:

whether the module is enabled.

void setForceExistence(bool value)
bool getForceExistence() const

Control or query whether a solution must be overall catalytic.

Throws:

LogicError if the module is not enabled.

Throws:

(only set) LogicError if isSpecificationLocked().

void setStrictTransit(bool value)
bool getStrictTransit() const

Control or query whether transit flow in overall catalytic vertices is restricted or not.

Throws:

LogicError if the module is not enabled.

Throws:

(only set) LogicError if isSpecificationLocked().

3.2.14.3.4. Class hyperflow::Model::Thermodynamics

class hyperflow::Model::Thermodynamics

This class provides access to the module for thermodynamics module of a flow model.

void enable()

Enable the module.

Throws:

LogicError if isSpecificationLocked().

Throws:

during model creation, LogicError if in relaxed mode.

Throws:

during model creation, LogicError if a non-excluded vertex has no energy bounds.

bool isEnabled()
Returns:

whether the module is enabled.

void setTemperature(double value)
double getTemperature() const

Control or query the temperature, in Kelvin, used in the constraints.

Throws:

LogicError if the module is not enabled.

Throws:

(only set) LogicError if value is not a finite non-negative number.

Throws:

(only set) LogicError if isSpecificationLocked().

void setEnergyBounds(dg::DG::Vertex v, double min, double max)

Set the bounds for the energy estimate, in kcal/mol, of the given vertex. The module assumes that stable compounds have energy values less than 0, i.e., a high-energy compound has a more negative energy than a low-energy compound, and the max must thus be less than the min.

Throws:

LogicError if isSpecificationLocked().

Throws:

LogicError if !v.

Throws:

LogicError if v.getDG() != getDG().

Throws:

LogicError if min is not a finite non-positive number.

Throws:

LogicError if max is not a finite non-positive number less than or equal to min.

void setEnergyBounds(std::shared_ptr<graph::Graph> g, double min, double max)

Equivalent to calling setEnergyBounds(getDG()->findVertex(g), min, max).

std::pair<double, double> getEnergyBounds(dg::DG::Vertex v) const
Returns:

the minimum and maximum bound on the energy estimate for this vertex.

Throws:

LogicError if no bound has been set for this vertex.

std::pair<double, double> getEnergyBounds(std::shared_ptr<graph::Graph> g) const

Equivalent to calling getEnergyBounds(getDG()->findVertex(g)).