Skip to content

Commit 94ccee7

Browse files
authored
Fix writing integer variables with float bounds (#68)
1 parent e77ce48 commit 94ccee7

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "MiniZinc"
22
uuid = "a7f392d2-6c35-496e-b8cc-0974fbfcbf91"
33
authors = ["odow <o.dowson@gmail.com>"]
4-
version = "0.3.8"
4+
version = "0.3.9"
55

66
[deps]
77
Chuffed_jll = "77125aae-c893-5498-99e3-e30470bfa328"

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ interact with `libminizinc`.
1111
This wrapper is maintained by the JuMP community and is not part of the MiniZinc
1212
project.
1313

14+
## Getting help
15+
16+
If you need help, please ask a question on the [JuMP community forum](https://jump.dev/forum).
17+
18+
If you have a reproducible example of a bug, please [open a GitHub issue](https://github.com/jump-dev/MiniZinc.jl/issues/new).
19+
1420
## License
1521

1622
`MiniZinc.jl` is licensed under the [MIT License](https://github.com/jump-dev/MiniZinc.jl/blob/master/LICENSE.md).

src/write.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ function _variable_info(model::Model{T}, x) where {T}
3535
lb, ub = set.lower, set.upper
3636
end
3737
if is_bool || is_int
38-
lb, ub = ceil(Int, lb), floor(Int, ub)
38+
if isfinite(lb) && !isinteger(lb)
39+
lb = ceil(Int, lb)
40+
end
41+
if isfinite(ub) && !isinteger(ub)
42+
ub = floor(Int, ub)
43+
end
3944
end
4045
return (name = name, lb = lb, ub = ub, is_int = is_int, is_bool = is_bool)
4146
end

test/runtests.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,39 @@ function test_run_failure()
15031503
return
15041504
end
15051505

1506+
function test_highs_free_binary()
1507+
model = MOI.Utilities.Model{Float64}()
1508+
x, _ = MOI.add_constrained_variable(model, MOI.ZeroOne())
1509+
solver = MiniZinc.Optimizer{Float64}("highs")
1510+
index_map, _ = MOI.optimize!(solver, model)
1511+
@test MOI.get(solver, MOI.TerminationStatus()) == MOI.OPTIMAL
1512+
return
1513+
end
1514+
1515+
function test_highs_int_frac_lb()
1516+
model = MOI.Utilities.Model{Float64}()
1517+
x, _ = MOI.add_constrained_variable(model, MOI.Integer())
1518+
MOI.add_constraint(model, x, MOI.GreaterThan(0.5))
1519+
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
1520+
MOI.set(model, MOI.ObjectiveFunction{typeof(x)}(), x)
1521+
solver = MiniZinc.Optimizer{Float64}("highs")
1522+
index_map, _ = MOI.optimize!(solver, model)
1523+
@test MOI.get(solver, MOI.VariablePrimal(), index_map[x]) 1.0
1524+
return
1525+
end
1526+
1527+
function test_highs_int_frac_ub()
1528+
model = MOI.Utilities.Model{Float64}()
1529+
x, _ = MOI.add_constrained_variable(model, MOI.Integer())
1530+
MOI.add_constraint(model, x, MOI.LessThan(2.5))
1531+
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
1532+
MOI.set(model, MOI.ObjectiveFunction{typeof(x)}(), x)
1533+
solver = MiniZinc.Optimizer{Float64}("highs")
1534+
index_map, _ = MOI.optimize!(solver, model)
1535+
@test MOI.get(solver, MOI.VariablePrimal(), index_map[x]) 2.0
1536+
return
1537+
end
1538+
15061539
end
15071540

15081541
TestMiniZinc.runtests()

0 commit comments

Comments
 (0)