Skip to content

Commit

Permalink
fix float assumption in bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
stelmo committed Dec 27, 2023
1 parent 8df256b commit f3a772d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions docs/src/3-mixed-integer-optimization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ IntegerFromTo(1, 6)

# ...and include this bound in constraints and variables:

dice_system =
C.variables(keys = [:first_dice, :second_dice], bounds = [IntegerFromTo(1, 6)])
dice_system = C.variables(keys = [:first_dice, :second_dice], bounds = IntegerFromTo(1, 6))

# Now the main thing that is left is to be able to translate this bound to JuMP
# for solving. We can slightly generalize our constraint-translation system
Expand Down Expand Up @@ -103,7 +102,7 @@ dices_thrown = C.constraint_values(
# Let's find the size of the smallest right-angled triangle with integer side
# sizes (aka a Pythagorean triple).

vars = C.variables(keys = [:a, :b, :c], bounds = (IntegerFromTo(1, 100),))
vars = C.variables(keys = [:a, :b, :c], bounds = IntegerFromTo(1, 100))

# For simpliclty, we make a shortcut for "values" in all variables:
v = C.tree_map(vars, C.value, C.Value)
Expand Down
2 changes: 1 addition & 1 deletion src/constraint_tree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ maximum))`, which has the correct length.
function variables(; keys::AbstractVector{Symbol}, bounds = nothing)
bs =
isnothing(bounds) ? Base.Iterators.cycle(tuple(nothing)) :
length(bounds) == 1 ? Base.Iterators.cycle(bounds) :
typeof(bounds) <: Bound ? Base.Iterators.cycle(tuple(bounds)) :
length(bounds) == length(keys) ? bounds :
error("lengths of bounds and keys differ for allocated variables")
ConstraintTree(
Expand Down

0 comments on commit f3a772d

Please sign in to comment.