One decision, one number.
Chapter: I — Foundations · lesson id first-variable · practice lesson
An optimization model decides values for variables. The simplest possible model has one variable x, no extra constraints, and an objective. Without bounds a maximisation can run away to infinity — so we bound x between 0 and 10 and ask the solver to maximise it.
var 0 <= x <= 10 declares the variable with its bounds attached inline — the cleanest way to say "x lives between 0 and 10". You'll see this inline-bound form throughout the rest of the course: var 0 <= x, var x <= 5, and var 0 <= x <= 1 are all valid. Variable bounds use only the <= operator — the lower bound goes on the left, the upper on the right.
Before you Run. Where will the solver place x?
model tiny
var 0 <= x <= 10
max x
end
import elytica
def main():
elytica.init_model("tiny")
elytica.run_model("tiny")
print("x =", elytica.get_variable_value("tiny", "x"))
return 0
Just run it. The solver pushes x to its upper bound.
no-error — Model solvesnumeric-match — Solver pushes x to its upper bound (10)code-contains — Reads variable values from the solver (no hardcoding)Same idea, different numbers. Bound the variable and minimise this time.
model tiny_v
var -4 <= w <= 7
min w
end
import elytica
def main():
elytica.init_model("tiny_v")
elytica.run_model("tiny_v")
print("w =", elytica.get_variable_value("tiny_v", "w"))
return 0
Read this through MCP: read with path: "lessons/first-variable", or resource hlpl://lessons/first-variable.