Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/Test/test_nonlinear.jl
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@

function MOI.constraint_expr(::FeasibilitySenseEvaluator, i::Int)
@assert i == 1
return :(x[$(MOI.VariableIndex(1))]^2 == 1)
return :(x[$(MOI.VariableIndex(1))]^2.0 == 1.0)

Check warning on line 326 in src/Test/test_nonlinear.jl

View check run for this annotation

Codecov / codecov/patch

src/Test/test_nonlinear.jl#L326

Added line #L326 was not covered by tests
end

MOI.eval_objective(d::FeasibilitySenseEvaluator, x) = 0.0
Expand Down Expand Up @@ -1072,7 +1072,7 @@
function test_nonlinear_Feasibility_internal(::MOI.ModelLike, ::Config)
d = FeasibilitySenseEvaluator(true)
@test MOI.objective_expr(d) == :()
@test MOI.constraint_expr(d, 1) == :(x[$(MOI.VariableIndex(1))]^2 == 1.0)
@test MOI.constraint_expr(d, 1) == :(x[$(MOI.VariableIndex(1))]^2.0 == 1.0)

Check warning on line 1075 in src/Test/test_nonlinear.jl

View check run for this annotation

Codecov / codecov/patch

src/Test/test_nonlinear.jl#L1075

Added line #L1075 was not covered by tests
@test_throws AssertionError MOI.constraint_expr(d, 2)
MOI.initialize(d, [:Grad, :Jac, :ExprGraph, :Hess])
@test :Hess in MOI.features_available(d)
Expand Down
10 changes: 6 additions & 4 deletions test/FileFormats/MOF/MOF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ function HS071(x::Vector{MOI.VariableIndex})
ExprEvaluator(
:(x[$x1] * x[$x4] * (x[$x1] + x[$x2] + x[$x3]) + x[$x3]),
[
:(x[$x1] * x[$x2] * x[$x3] * x[$x4] >= 25),
:(x[$x1]^2 + x[$x2]^2 + x[$x3]^2 + x[$x4]^2 == 40),
:(x[$x1] * x[$x2] * x[$x3] * x[$x4] >= 25.0),
:(x[$x1]^2.0 + x[$x2]^2.0 + x[$x3]^2.0 + x[$x4]^2.0 == 40.0),
],
),
true,
Expand All @@ -117,7 +117,9 @@ function test_HS071()
target = read(joinpath(@__DIR__, "nlp.mof.json"), String)
target = replace(target, r"\s" => "")
target = replace(target, "MathOptFormatModel" => "MathOptFormat Model")
@test read(TEST_MOF_FILE, String) == target
# Normalize .0 floats and integer representations in JSON
normalize(x) = replace(x, ".0" => "")
@test normalize(read(TEST_MOF_FILE, String)) == normalize(target)
_validate(TEST_MOF_FILE)
return
end
Expand Down Expand Up @@ -308,7 +310,7 @@ function test_nonlinear_readingwriting()
block = MOI.get(model2, MOI.NLPBlock())
MOI.initialize(block.evaluator, [:ExprGraph])
@test MOI.constraint_expr(block.evaluator, 1) ==
:(2 * x[$x] + sin(x[$x])^2 - x[$y] == 1.0)
:(2.0 * x[$x] + sin(x[$x])^2.0 - x[$y] == 1.0)
_validate(TEST_MOF_FILE)
return
end
Expand Down
5 changes: 3 additions & 2 deletions test/FileFormats/NL/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ function test_parse_expr()
# (* x1 (* 2 (* x4 x2)))
seekstart(io)
x = MOI.VariableIndex.(1:4)
@test NL._parse_expr(io, model) == :(*($(x[1]), *(2, *($(x[4]), $(x[2])))))
@test NL._parse_expr(io, model) ==
:(*($(x[1]), *(2.0, *($(x[4]), $(x[2])))))
@test eof(io)
return
end
Expand All @@ -76,7 +77,7 @@ function test_parse_expr_nary()
seekstart(io)
x = MOI.VariableIndex.(1:4)
@test NL._parse_expr(io, model) ==
:(+($(x[1])^2, $(x[3])^2, $(x[4])^2, $(x[2])^2))
:(+($(x[1])^2.0, $(x[3])^2.0, $(x[4])^2.0, $(x[2])^2.0))
@test eof(io)
return
end
Expand Down
28 changes: 14 additions & 14 deletions test/Nonlinear/Nonlinear.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function test_parse_sin_squared()
Nonlinear.set_objective(model, :(sin($x)^2))
evaluator = Nonlinear.Evaluator(model)
MOI.initialize(evaluator, [:ExprGraph])
@test MOI.objective_expr(evaluator) == :(sin(x[$x])^2)
@test MOI.objective_expr(evaluator) == :(sin(x[$x])^2.0)
return
end

Expand All @@ -72,7 +72,7 @@ function test_parse_ifelse()
Nonlinear.set_objective(model, :(ifelse($x, 1, 2)))
evaluator = Nonlinear.Evaluator(model)
MOI.initialize(evaluator, [:ExprGraph])
@test MOI.objective_expr(evaluator) == :(ifelse(x[$x], 1, 2))
@test MOI.objective_expr(evaluator) == :(ifelse(x[$x], 1.0, 2.0))
return
end

Expand All @@ -83,7 +83,7 @@ function test_parse_ifelse_inequality_less()
evaluator = Nonlinear.Evaluator(model)
MOI.initialize(evaluator, [:ExprGraph])
@test MOI.objective_expr(evaluator) ==
:(ifelse(x[$x] < 1, x[$x] - 1, x[$x] + 1))
:(ifelse(x[$x] < 1.0, x[$x] - 1.0, x[$x] + 1.0))
return
end

Expand All @@ -94,7 +94,7 @@ function test_parse_ifelse_inequality_greater()
evaluator = Nonlinear.Evaluator(model)
MOI.initialize(evaluator, [:ExprGraph])
@test MOI.objective_expr(evaluator) ==
:(ifelse(x[$x] > 1, x[$x] - 1, x[$x] + 1))
:(ifelse(x[$x] > 1.0, x[$x] - 1.0, x[$x] + 1.0))
return
end

Expand All @@ -105,7 +105,7 @@ function test_parse_ifelse_comparison()
evaluator = Nonlinear.Evaluator(model)
MOI.initialize(evaluator, [:ExprGraph])
@test MOI.objective_expr(evaluator) ==
:(ifelse(0 <= x[$x] <= 1, x[$x] - 1, x[$x] + 1))
:(ifelse(0.0 <= x[$x] <= 1.0, x[$x] - 1.0, x[$x] + 1.0))
return
end

Expand Down Expand Up @@ -251,7 +251,7 @@ function test_set_objective()
@test model.objective == Nonlinear.parse_expression(model, input)
evaluator = Nonlinear.Evaluator(model)
MOI.initialize(evaluator, [:ExprGraph])
@test MOI.objective_expr(evaluator) == :(x[$x]^2 + 1)
@test MOI.objective_expr(evaluator) == :(x[$x]^2.0 + 1.0)
return
end

Expand All @@ -263,7 +263,7 @@ function test_set_objective_subexpression()
Nonlinear.set_objective(model, :($expr^2))
evaluator = Nonlinear.Evaluator(model)
MOI.initialize(evaluator, [:ExprGraph])
@test MOI.objective_expr(evaluator) == :((x[$x]^2 + 1)^2)
@test MOI.objective_expr(evaluator) == :((x[$x]^2.0 + 1.0)^2.0)
return
end

Expand All @@ -276,7 +276,7 @@ function test_set_objective_nested_subexpression()
Nonlinear.set_objective(model, :($expr_2^2))
evaluator = Nonlinear.Evaluator(model)
MOI.initialize(evaluator, [:ExprGraph])
@test MOI.objective_expr(evaluator) == :(((x[$x]^2 + 1)^2)^2)
@test MOI.objective_expr(evaluator) == :(((x[$x]^2.0 + 1.0)^2.0)^2.0)
return
end

Expand All @@ -287,7 +287,7 @@ function test_set_objective_parameter()
Nonlinear.set_objective(model, :($x^2 + $p))
evaluator = Nonlinear.Evaluator(model)
MOI.initialize(evaluator, [:ExprGraph])
@test MOI.objective_expr(evaluator) == :(x[$x]^2 + 1.2)
@test MOI.objective_expr(evaluator) == :(x[$x]^2.0 + 1.2)
return
end

Expand All @@ -300,7 +300,7 @@ function test_add_constraint_less_than()
@test model[c].set == set
evaluator = Nonlinear.Evaluator(model)
MOI.initialize(evaluator, [:ExprGraph])
@test MOI.constraint_expr(evaluator, 1) == :(x[$x]^2 + 1 <= 1.0)
@test MOI.constraint_expr(evaluator, 1) == :(x[$x]^2.0 + 1.0 <= 1.0)
return
end

Expand All @@ -311,7 +311,7 @@ function test_add_constraint_delete()
_ = Nonlinear.add_constraint(model, :(sqrt($x)), MOI.LessThan(1.0))
evaluator = Nonlinear.Evaluator(model)
MOI.initialize(evaluator, [:ExprGraph])
@test MOI.constraint_expr(evaluator, 1) == :(x[$x]^2 + 1 <= 1.0)
@test MOI.constraint_expr(evaluator, 1) == :(x[$x]^2.0 + 1.0 <= 1.0)
@test MOI.constraint_expr(evaluator, 2) == :(sqrt(x[$x]) <= 1.0)
Nonlinear.delete(model, c1)
evaluator = Nonlinear.Evaluator(model)
Expand All @@ -330,7 +330,7 @@ function test_add_constraint_greater_than()
@test model[c].set == set
evaluator = Nonlinear.Evaluator(model)
MOI.initialize(evaluator, [:ExprGraph])
@test MOI.constraint_expr(evaluator, 1) == :(x[$x]^2 + 1 >= 1.0)
@test MOI.constraint_expr(evaluator, 1) == :(x[$x]^2.0 + 1.0 >= 1.0)
return
end

Expand All @@ -342,7 +342,7 @@ function test_add_constraint_equal_to()
@test model[c].set == set
evaluator = Nonlinear.Evaluator(model)
MOI.initialize(evaluator, [:ExprGraph])
@test MOI.constraint_expr(evaluator, 1) == :(x[$x]^2 + 1 == 1.0)
@test MOI.constraint_expr(evaluator, 1) == :(x[$x]^2.0 + 1.0 == 1.0)
return
end

Expand All @@ -354,7 +354,7 @@ function test_add_constraint_interval()
@test model[c].set == set
evaluator = Nonlinear.Evaluator(model)
MOI.initialize(evaluator, [:ExprGraph])
@test MOI.constraint_expr(evaluator, 1) == :(-1.0 <= x[$x]^2 + 1 <= 1.0)
@test MOI.constraint_expr(evaluator, 1) == :(-1.0 <= x[$x]^2.0 + 1.0 <= 1.0)
return
end

Expand Down
Loading