Skip to main content

Worked models

nimopt.models contains ten models. Each is a module with three functions.

NameReturns
definition()a Definition: the formulation with no data bound
data(scale=1)the inputs, at a given size
reference(data)the optimal objective, computed by direct arithmetic

The three functions have different callers. This documentation calls explain(), a benchmark calls build(data(100)), and a test compares a solve against reference(data(1)). A reference is arithmetic over the inputs and calls nothing from nimopt. A formulation error is therefore not checked against a copy of itself.

ModelExercises
dispatchthe baseline formulation
transporta sparse network over a subset of a product
storagetemporal coupling and a cyclic lag
nodalgrouping through a lookup parameter
commitmentbinary columns
fleetmany small declarations rather than one large one
profileda bound that varies by hour
sectormixed density: dense in one axis, sparse in another
expansiona two-stage stochastic program: capacity before the scenario, dispatch after
recoursea binary first stage taken before the scenario is known
from nimopt.models import dispatch

inputs = dispatch.data()
solution = dispatch.definition().build(inputs).solve()
print(solution.status, solution.objective, dispatch.reference(inputs))
Output
optimal 1920.0 1920.0