The modeling DSL: model do ... end with variable/constraint/objective.
import Optex.DSL
m =
model sense: :min do
variable x, lb: 0.0
variable y[i], i <- [1, 2, 3], lb: 0.0
variable z, type: :bin
constraint 2 * x + sum(y[i], i <- [1, 2, 3]) <= 10
constraint x - y[1] >= 0
constraint sum(y[i], i <- [1, 2, 3], i > 1) == 4
objective x + 2 * y[1] + z
endIndexed families use one generator clause per index. A single index keys the
family map by the bare index (y[i]); multiple indices use an explicit tuple
key (w[{i, j}], declared as variable w[{i, j}], i <- 1..2, j <- 1..2),
because Elixir's parser rejects w[i, j] outright.
Constraints accept the same trailing generator/filter clauses to declare a whole family at once, one constraint per binding:
constraint sum(ship[{p, mk}], mk <- markets) <= supply[p], p <- plants
constraint y[i] <= y[i + 1], i <- [1, 2]Two conventions worth knowing:
- In
if: {b, 0}(indicator active when the binary is off), a 2-tuple whose second element is the literal 0 or 1 is always read as the negation form. To reference an indexed binary inif:, use the access form (if: open[s]), never a raw name tuple. - Defined variables (
variable t = abs(e)/pwl(e, points)/max(args...)/min(args...)) with non-bare arguments introduce machinery: a free auxiliary variable named{t, :arg}pinned by an equality row named{t, :def}(position-indexed{t, {:arg, i}}/{t, {:def, i}}for the multi-argument min/max forms). These are real model variables and appear in solution values (their value is the argument expression's value, often useful when debugging). min/max accept numbers among their arguments (folded into one constant operand) and are a Gurobi-only capability.
Summary
Functions
Build an Optex.Model declaratively. See the module docs for the full
surface. Options: sense: (:min default, :max). The block may contain
only variable, constraint, and objective statements and returns the
finished model.
Functions
Build an Optex.Model declaratively. See the module docs for the full
surface. Options: sense: (:min default, :max). The block may contain
only variable, constraint, and objective statements and returns the
finished model.