Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] add modulo to tips_and_tricks.jl #3641

Merged
merged 2 commits into from
Dec 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/src/tutorials/linear/tips_and_tricks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,28 @@ model = Model();

# This reformulation does not work for ``t \le \max\{x, y\}``.

# ## Modulo

# To model ``y = x \text{ mod } n``, where ``n`` is a constant modulus, we use the
# relationship ``x = n \cdot z + y``, where ``z \in \mathbb{Z}_+`` is the number
# of times that ``n`` can be divided by ``x`` and ``y`` is the remainder.

n = 4
model = Model();
@variable(model, x >= 0, Int)
@variable(model, 0 <= y <= n - 1, Int)
@variable(model, z >= 0, Int)
@constraint(model, x == n * z + y)

# The modulo reformulation is often useful for subdividing a time increment into
# units of time like hours and days:

model = Model();
@variable(model, t >= 0, Int)
@variable(model, 0 <= hours <= 23, Int)
@variable(model, days >= 0, Int)
@constraint(model, t == 24 * days + hours)

# ## Boolean operators

# Binary variables can be used to construct logical operators. Here are some
Expand Down
Loading