psamm.lpsolver.glpk – GLPK LP solver

Linear programming solver using GLPK.

class psamm.lpsolver.glpk.Constraint(prob, name)

Represents a constraint in a Problem.

exception psamm.lpsolver.glpk.GLPKError

Error from calling GLPK library.

class psamm.lpsolver.glpk.MIPResult(prob, ret_val=0)

Specialization of Result for MIP problems.

class psamm.lpsolver.glpk.Problem(**kwargs)

Represents an LP-problem of a Solver.


Add constraints to the problem.

Each constraint is represented by a Relation, and the expression in that relation can be a set expression.

define(*names, **kwargs)

Define a variable in the problem.

Variables must be defined before they can be accessed by var() or set(). This function takes keyword arguments lower and upper to define the bounds of the variable (default: -inf to inf). The keyword argument types can be used to select the type of the variable (Continuous (default), Binary or Integer). Setting any variables different than Continuous will turn the problem into an MILP problem. Raises ValueError if a name is already defined.


Feasibility tolerance.


The underlying GLPK (SWIG) object.


Check whether variable is defined in the model.


Integrality tolerance.


Optimality tolerance.


Set objective of problem.


Set objective of problem.


Set type of problem (maximize or minimize).


Solve problem and return result.

The user must manually check the status of the result to determine whether an optimal solution was found. A SolverError may still be raised if the underlying solver raises an exception.

class psamm.lpsolver.glpk.Result(prob, ret_val=0)

Represents the solution to a Problem.

This object will be returned from the solve() method on Problem or by accessing the result property on Problem after solving a problem. This class should not be instantiated manually.

Result will evaluate to a boolean according to the success of the solution, so checking the truth value of the result will immediately indicate whether solving was successful.


Return value of expression.


Return string indicating the error encountered on failure.


Return boolean indicating whether a solution was found.


Whether solution is unbounded

class psamm.lpsolver.glpk.Solver

Represents an LP-solver using GLPK.


Create a new LP-problem using the solver.