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

The unique id of the constraint in the model.

name: str property

The constraint name.

Graph

The graph class.

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

idx: int property

The unique id of the graph in the model.

m: int property

The number of edges.

n: int property

The number of vertices.

sink: int property

The sink vertex of the graph.

source: int property

The source vertex of the graph.

vars: List[Var] property

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.

coefs: List[float] property

A list of the coefficients.

rhs: float property

The right-hand-side.

sense: float property

The right-hand-side.

vars: List[Var] property

A list of the variables.

__init__(expr, sense=ConstrSense.Equal, rhs=0)

Initialize linear equation

Parameters:

Name Type Description Default
expr Union[LinExpr, LinEqua]

An expression or copy from another equation

required
sense ConstrSense

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

ConstrSense.Equal

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

A list of the coefficients.

constant: float property

The constant term.

vars: List[Var] property

A list of the variables.

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

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

Raises:

Type Description
ValueError

If coefs and vars do not have the same length.

addConstant(constant)

Adds a constant to the linear expression.

Parameters:

Name Type Description Default
constant float

The constant to add.

required

addExpr(expr)

Adds another expression to the linear expression.

Parameters:

Name Type Description Default
expr LinExpr

The expression to add.

required

addTerm(coef, var)

Adds a term to the linear expression.

Parameters:

Name Type Description Default
coef float

The coefficients.

required
var Var

The variable.

required

Path

The path class.

Paths represents a list of edge variables for a graph in a solution. Obtain the paths of a solution using the path property.

graphIdx: int property

The id of the graph the path is associated to.

idx: int property

The unique id of the path in a solution.

obj: float property

The objective coefficient.

vars: List[Var] property

The edge variables associated to the path.

x: float property

The value in the current solution.

Solution

The solution class.

A solution holds a list of non-zero variables and a (if applicable) a list of paths. Obtain the solutions from the model using the solutions property.

idx: int property

The unique id of the solution.

objectiveValue: float property

The objective value of the solution.

paths: List[Path] property

The paths associated to the solution.

vars: List[Var] property

The variables in the solution. Including edge variables.

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

The edge of a edge variable.

Raises:

Type Description
ValueError

If the variable is not associated with a graph.

graphIdx: int property

The id of the graph the variable is associated to.

Raises:

Type Description
ValueError

If the variable is not associated with a graph.

idx: int property

The unique id of the variable in the model.

lb: float property

The lower bound.

name: str property

The variable name.

obj: float property

The objective coefficient.

source: int property

The source vertex of a edge variable.

Raises:

Type Description
ValueError

If the variable is not associated with a graph.

target: int property

The target vertex of a edge variable.

Raises:

Type Description
ValueError

If the variable is not associated with a graph.

type: str property

The type given with VarType.

ub: float property

The upper bound.

x: float property

The value in the best solution

xn(n)

The value in the n'th solution