HLPL / VerTeX Modelling Language Documentation

← lessons

Integer variables

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.

Predict before running

For int 0 <= n, 3*n <= 11, max n, what does n become?

Starter code

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

Hint

Run it. The answer should be a whole number.

What counts as correct

Mastery variant

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.