API reference#

Models#

class jumpy.Model(backend: str = 'juliac')#

A JuMPy optimization model.

Example:

m = jp.Model() x = m.variables(100, lower=0)

i = m.iterator(range(99)) m.constraint_group(x[i] + x[i + 1] <= 10)

m.objective = jp.minimize(x[0] + x[1]) m.optimize()

close() None#

Release the backend model. The model must not be used afterwards.

constraint(con: Constraint) None#

Add a single constraint (MOI.add_constraint).

constraint_group(con: Constraint) None#

Add a constraint group: one constraint per combination of the values of the iterators appearing in the template.

Example:

i = m.iterator(range(99)) m.constraint_group(x[i] + x[i + 1] <= 10)

iterator(values) Node#

An index set for constraint groups (a GenOpt iterator).

Used in expressions, it is a symbolic placeholder that GenOpt expands over its values when the group constraint is added.

optimize() None#

MOI.optimize!, then retrieve the solution.

parameter(values, name: str | None = None) Parameter#

A vector of constant data, symbolically indexable in templates.

value(var: Variable) float#

Get the solved value of a variable.

variable(*, lower: float | None = None, upper: float | None = None, name: str | None = None, binary: bool = False, integer: bool = False) Variable#

Add a single decision variable.

variables(count: int, *, lower: float | None = None, upper: float | None = None, name: str | None = None, binary: bool = False, integer: bool = False) VariableVector#

Add a block of decision variables (MOI.add_variables + bounds).

jumpy.minimize(func: Node) Objective#
jumpy.maximize(func: Node) Objective#

Expressions#

class jumpy.Variable(ops, index: int, name: str | None = None)#

A single decision variable; keeps its column for solution lookup.

class jumpy.VariableVector(ops, start: int, count: int, name: str | None = None)#

A block of decision variables returned by Model.variables().

Concrete indexing (x[0]) returns a Variable; symbolic indexing (x[i] with an expression) builds a getindex template node over the contiguous block.

class jumpy.Parameter(ops, values, name: str | None = None)#

A vector of constant data returned by Model.parameter().

Concrete indexing (costs[0]) returns a float; symbolic indexing (costs[i]) builds a getindex template node over the data vector.

class jumpy.Node(ops, moi, *, linear: bool = True)#

A handle to an MOI expression owned by the model’s backend.

class jumpy.Constraint(func: Node, sense: str)#

A normalized constraint: func sense 0.

class jumpy.Objective(sense: str, func: Node)#

An optimization objective (minimize or maximize).

Nonlinear functions#

jumpy.sin(x)#
jumpy.cos(x)#
jumpy.exp(x)#
jumpy.log(x)#
jumpy.sqrt(x)#
jumpy.jp_abs(x)#