Skip to content

Entities

Constr

The constraint class.

Constraints are created by adding linear equations to a model using the addConstr method.

idx: int property readonly

The unique id of the constraint in the model.

Graph

The graph class.

Graphs are created by adding them to a model using the the addGraph method.

idx property readonly

The unique id of the graph in the model.

m property readonly

The number of edges.

n property readonly

The number of vertices.

sink property readonly

The sink vertex of the graph.

source property readonly

The source vertex of the graph.

vars property readonly

The edge variables associated to the graph

LinEqua

Class to represent linear equations.

Equations are primarily used as temporary objects when adding linear expressions to models. It should not be necessary to use them by themselves.

The equation consists of an LinExpr and a ConstrSense such that

expr = 2 * x + 3 * y + 6
equa = LinEqua(expr, 'L') # 2 * x + 3 * y <= 6
equa = expr <= 0 # 2 * x + 3 * y <= 6

The LinEqua derives from LinExpr and can be manipulated in the same fashion.

__init__(self, expr, sense='E', rhs=0) special

Initialize linear equation

Parameters:

Name Type Description Default
expr Union[flowty.entities.LinExpr, LinEqua]

An expression or copy from another equation

required
sense str

The constraints sense as either Equal, LessOrEqual, or GreaterOrEqual.

'E'

LinExpr

Class to represent linear expressions.

Expressions are operator overloaded so it is possible to do

expr = 2 * x - y + 4
expr += 3 * z
expr *= 2
expr += otherExpr

coefs: List[float] property readonly

A list of the coefficients.

constant: float property readonly

The constant term.

vars: List[Var] property readonly

A list of the variables.

__init__(self, coefs=[], vars=[], constant=0.0) special

Initialize linear expression

Parameters:

Name Type Description Default
coefs List[float]

List of coefficients.

[]
vars List[Var]

List of variables.

[]
constant float

A constant term

0.0

Exceptions:

Type Description
ValueError

If coefs and vars do not have the same length.

addConstant(self, constant)

Adds a constant to the linear expression.

Parameters:

Name Type Description Default
constant float

The constant to add.

required

addExpr(self, expr)

Adds another expression to the linear expression.

Parameters:

Name Type Description Default
expr LinExpr

The expression to add.

required

addTerm(self, coef, var)

Adds a term to the linear expression.

Parameters:

Name Type Description Default
coef float

The coefficients.

required
var Var

The variable.

required

Var

The variable class.

Variables are created by adding variables to a model using the either the addVar method to create a single variable or the addGraph method to add a graph with corresponding edge variables stored in the Graph.vars property.

For an edge variable this class offers the possibility to query for source and target vertices or the edge in the graph.

edge: Tuple[int, int] property readonly

The edge of a edge variable.

Exceptions:

Type Description
ValueError

If the variable is not associated with a graph.

idx: int property readonly

The unique id of the variable in the model.

lb: float property writable

The lower bound.

name: str property readonly

The variable name.

source: int property readonly

The source vertex of a edge variable.

Exceptions:

Type Description
ValueError

If the variable is not associated with a graph.

target: int property readonly

The target vertex of a edge variable.

Exceptions:

Type Description
ValueError

If the variable is not associated with a graph.

type: str property readonly

The type given with VarType.

ub: float property writable

The upper bound.

x: float property readonly

The value in the current solution