Whole numbers only.
Chapter: IV — Discrete decisions · lesson id integer-variables · practice lesson
An int variable must take a whole-number value. Asking for 3.5 trucks is fine for the LP relaxation but nonsense in practice — int enforces reality.
How many widgets can we produce if each takes 3 hours and we have 11 hours? The LP would say 3.666… The integer programme says 3.
For int 0 <= n, 3*n <= 11, max n, what does n become?
model widgets
int 0 <= n
constr 3*n <= 11
max n
end
import elytica
def main():
elytica.init_model("widgets")
elytica.run_model("widgets")
print("n =", elytica.get_variable_value("widgets", "n"))
return 0
Run it. The answer should be a whole number.
no-error — Model solvesnumeric-match — Solver rounds down to a whole number (3)code-contains — Reads variable values from the solver (no hardcoding)5 hours per widget, 38-hour budget. How many whole widgets?
model widgets_v
int 0 <= m
constr 5*m <= 38
max m
end
import elytica
def main():
elytica.init_model("widgets_v")
elytica.run_model("widgets_v")
print("m =", elytica.get_variable_value("widgets_v", "m"))
return 0
Read this through MCP: read with path: "lessons/integer-variables", or resource hlpl://lessons/integer-variables.