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/Bridges/Constraint/soc_to_nonconvex_quad.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function bridge_constraint(
push!(q_terms, MOI.ScalarQuadraticTerm(T(2), var, var))
end

fq = MOI.ScalarQuadraticFunction(a_terms, q_terms, zero(T))
fq = MOI.ScalarQuadraticFunction(q_terms, a_terms, zero(T))
quad = MOI.add_constraint(model, fq, MOI.LessThan(zero(T)))
# ScalarAffineFunction's are added instead of SingleVariable's
# because models can only have one SingleVariable per variable.
Expand Down Expand Up @@ -107,7 +107,7 @@ function bridge_constraint(
push!(q_terms, MOI.ScalarQuadraticTerm(T(2), var, var))
end

fq = MOI.ScalarQuadraticFunction(a_terms, q_terms, zero(T))
fq = MOI.ScalarQuadraticFunction(q_terms, a_terms, zero(T))
quad = MOI.add_constraint(model, fq, MOI.LessThan(zero(T)))
# ScalarAffineFunction's are added instead of SingleVariable's
# because models can only have one SingleVariable per variable.
Expand Down
4 changes: 2 additions & 2 deletions src/DeprecatedTest/UnitTests/basic_constraint_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const dummy_scalar_affine =
# 1.0 * x + 1.0 * x^2 + 0.0
const dummy_scalar_quadratic =
(x::Vector{MOI.VariableIndex}) -> MOI.ScalarQuadraticFunction(
MOI.ScalarAffineTerm.(1.0, x),
MOI.ScalarQuadraticTerm.(1.0, x, x),
MOI.ScalarAffineTerm.(1.0, x),
0.0,
)
# x₁ + + 0.0
Expand All @@ -26,11 +26,11 @@ const dummy_vector_affine =
# + x₂ + + x₂^2 + 0.0
const dummy_vector_quadratic =
(x::Vector{MOI.VariableIndex}) -> MOI.VectorQuadraticFunction(
MOI.VectorAffineTerm.(1:length(x), MOI.ScalarAffineTerm.(1.0, x)), # affine component
MOI.VectorQuadraticTerm.(
1:length(x),
MOI.ScalarQuadraticTerm.(1.0, x, x),
), # affine component
MOI.VectorAffineTerm.(1:length(x), MOI.ScalarAffineTerm.(1.0, x)), # affine component
zeros(Float64, length(x)), # constant term
)

Expand Down
4 changes: 2 additions & 2 deletions src/DeprecatedTest/UnitTests/constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,12 @@ function solve_qcp_edge_cases(model::MOI.ModelLike, config::Config)
MOI.add_constraint(
model,
MOI.ScalarQuadraticFunction(
MOI.ScalarAffineTerm.([1.0], [x[2]]), # affine terms
MOI.ScalarQuadraticTerm.(
[2.0, 2.0],
[x[1], x[1]],
[x[1], x[1]],
), # quad
MOI.ScalarAffineTerm.([1.0], [x[2]]), # affine terms
0.0, # constant
),
MOI.LessThan(1.0),
Expand Down Expand Up @@ -341,12 +341,12 @@ function solve_qcp_edge_cases(model::MOI.ModelLike, config::Config)
MOI.add_constraint(
model,
MOI.ScalarQuadraticFunction(
MOI.ScalarAffineTerm{Float64}[], # affine terms
MOI.ScalarQuadraticTerm.(
[2.0, 0.25, 0.25, 0.5, 2.0],
[x[1], x[1], x[2], x[1], x[2]],
[x[1], x[2], x[1], x[2], x[2]],
), # quad
MOI.ScalarAffineTerm{Float64}[], # affine terms
0.0, # constant
),
MOI.LessThan(1.0),
Expand Down
10 changes: 5 additions & 5 deletions src/DeprecatedTest/UnitTests/objectives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ function solve_qp_edge_cases(model::MOI.ModelLike, config::Config)
model,
obj_attr,
MOI.ScalarQuadraticFunction(
MOI.ScalarAffineTerm{Float64}[], # affine terms
MOI.ScalarQuadraticTerm.([2.0, 2.0], x, x), # quad
MOI.ScalarAffineTerm{Float64}[], # affine terms
0.0, # constant
),
)
Expand All @@ -250,8 +250,8 @@ function solve_qp_edge_cases(model::MOI.ModelLike, config::Config)
model,
obj_attr,
MOI.ScalarQuadraticFunction(
MOI.ScalarAffineTerm.([1.0, 1.0], [x[1], x[1]]), # affine terms
MOI.ScalarQuadraticTerm.([2.0, 2.0], x, x), # quad
MOI.ScalarAffineTerm.([1.0, 1.0], [x[1], x[1]]), # affine terms
0.0, # constant
),
)
Expand All @@ -268,12 +268,12 @@ function solve_qp_edge_cases(model::MOI.ModelLike, config::Config)
model,
obj_attr,
MOI.ScalarQuadraticFunction(
MOI.ScalarAffineTerm{Float64}[], # affine terms
MOI.ScalarQuadraticTerm.(
[2.0, 2.0],
[x[1], x[1]],
[x[1], x[1]],
), # quad
MOI.ScalarAffineTerm{Float64}[], # affine terms
0.0, # constant
),
)
Expand All @@ -290,12 +290,12 @@ function solve_qp_edge_cases(model::MOI.ModelLike, config::Config)
model,
obj_attr,
MOI.ScalarQuadraticFunction(
MOI.ScalarAffineTerm{Float64}[], # affine terms
MOI.ScalarQuadraticTerm.(
[2.0, 0.25, 0.25, 0.5, 2.0],
[x[1], x[1], x[2], x[1], x[2]],
[x[1], x[2], x[1], x[2], x[2]],
), # quad
MOI.ScalarAffineTerm{Float64}[], # affine terms
0.0, # constant
),
)
Expand Down Expand Up @@ -338,12 +338,12 @@ function solve_qp_zero_offdiag(model::MOI.ModelLike, config::Config)
model,
obj_attr,
MOI.ScalarQuadraticFunction(
MOI.ScalarAffineTerm{Float64}[], # affine terms
MOI.ScalarQuadraticTerm.(
[2.0, 0.0, 2.0],
[x[1], x[1], x[2]],
[x[1], x[2], x[2]],
), # quad
MOI.ScalarAffineTerm{Float64}[], # affine terms
0.0, # constant
),
)
Expand Down
24 changes: 12 additions & 12 deletions src/DeprecatedTest/contquadratic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ function qp1test(model::MOI.ModelLike, config::Config)
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
@test MOI.get(model, MOI.ObjectiveSense()) == MOI.MIN_SENSE
obj = MOI.ScalarQuadraticFunction(
MOI.ScalarAffineTerm{Float64}[],
MOI.ScalarQuadraticTerm.(
[2.0, 1.0, 2.0, 1.0, 2.0],
v[[1, 1, 2, 2, 3]],
v[[1, 2, 2, 3, 3]],
),
MOI.ScalarAffineTerm{Float64}[],
0.0,
)
MOI.set(
Expand Down Expand Up @@ -153,12 +153,12 @@ function qp2test(model::MOI.ModelLike, config::Config)
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
@test MOI.get(model, MOI.ObjectiveSense()) == MOI.MIN_SENSE
obj = MOI.ScalarQuadraticFunction(
MOI.ScalarAffineTerm.(0.0, v),
MOI.ScalarQuadraticTerm.(
[2.0, 0.5, 0.5, 2.0, 1.0, 1.0, 1.0],
[v[1], v[1], v[1], v[2], v[2], v[3], v[3]],
[v[1], v[2], v[2], v[2], v[3], v[3], v[3]],
),
MOI.ScalarAffineTerm.(0.0, v),
0.0,
)
MOI.set(
Expand Down Expand Up @@ -197,12 +197,12 @@ function qp2test(model::MOI.ModelLike, config::Config)
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
@test MOI.get(model, MOI.ObjectiveSense()) == MOI.MAX_SENSE
obj2 = MOI.ScalarQuadraticFunction(
MOI.ScalarAffineTerm.(0.0, v),
MOI.ScalarQuadraticTerm.(
[-4.0, -1.0, -1.0, -4.0, -2.0, -2.0, -2.0],
[v[1], v[1], v[1], v[2], v[2], v[3], v[3]],
[v[1], v[2], v[2], v[2], v[3], v[3], v[3]],
),
MOI.ScalarAffineTerm.(0.0, v),
0.0,
)
MOI.set(
Expand Down Expand Up @@ -272,8 +272,8 @@ function qp3test(model::MOI.ModelLike, config::Config)
@test vc2.value == y.value
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
obj = MOI.ScalarQuadraticFunction(
MOI.ScalarAffineTerm.([1.0, 1.0], [x, y]),
MOI.ScalarQuadraticTerm.([4.0, 2.0, 1.0], [x, y, x], [x, y, y]),
MOI.ScalarAffineTerm.([1.0, 1.0], [x, y]),
1.0,
)
MOI.set(
Expand Down Expand Up @@ -404,8 +404,8 @@ function qcp1test(model::MOI.ModelLike, config::Config)
) == 1
end
c2f = MOI.ScalarQuadraticFunction(
[MOI.ScalarAffineTerm(1.0, y)],
[MOI.ScalarQuadraticTerm(2.0, x, x)],
[MOI.ScalarAffineTerm(1.0, y)],
0.0,
)
c2 = MOI.add_constraint(model, c2f, MOI.LessThan(2.0))
Expand Down Expand Up @@ -491,8 +491,8 @@ function qcp2test(model::MOI.ModelLike, config::Config)
x = MOI.add_variable(model)
@test MOI.get(model, MOI.NumberOfVariables()) == 1
cf = MOI.ScalarQuadraticFunction(
[MOI.ScalarAffineTerm(0.0, x)],
[MOI.ScalarQuadraticTerm(2.0, x, x)],
[MOI.ScalarAffineTerm(0.0, x)],
0.0,
)
c = MOI.add_constraint(model, cf, MOI.LessThan(2.0))
Expand Down Expand Up @@ -557,8 +557,8 @@ function qcp3test(model::MOI.ModelLike, config::Config)
x = MOI.add_variable(model)
@test MOI.get(model, MOI.NumberOfVariables()) == 1
cf = MOI.ScalarQuadraticFunction(
MOI.ScalarAffineTerm{Float64}[],
[MOI.ScalarQuadraticTerm(2.0, x, x)],
MOI.ScalarAffineTerm{Float64}[],
0.0,
)
c = MOI.add_constraint(model, cf, MOI.LessThan(2.0))
Expand Down Expand Up @@ -631,8 +631,8 @@ function _qcp4test(model::MOI.ModelLike, config::Config, less_than::Bool)
vc = MOI.add_constraint(model, MOI.SingleVariable(y), MOI.EqualTo(1.0))
@test vc.value == y.value
cf = MOI.ScalarQuadraticFunction(
[MOI.ScalarAffineTerm(0.0, x)],
MOI.ScalarQuadraticTerm.([2.0, 1.0, 2.0], [x, x, y], [x, y, y]),
[MOI.ScalarAffineTerm(0.0, x)],
0.0,
)
if !less_than
Expand Down Expand Up @@ -736,8 +736,8 @@ function ncqcp1test(model::MOI.ModelLike, config::Config)
vc2 = MOI.add_constraint(model, MOI.SingleVariable(y), MOI.GreaterThan(1.0))
@test vc2.value == y.value
cf = MOI.ScalarQuadraticFunction(
[MOI.ScalarAffineTerm(0.0, x)],
[MOI.ScalarQuadraticTerm(1.0, x, y)],
[MOI.ScalarAffineTerm(0.0, x)],
0.0,
)
c = MOI.add_constraint(model, cf, MOI.LessThan(4.0))
Expand Down Expand Up @@ -805,14 +805,14 @@ function ncqcp2test(model::MOI.ModelLike, config::Config)
vc2 = MOI.add_constraint(model, MOI.SingleVariable(y), MOI.GreaterThan(0.0))
@test vc2.value == y.value
cf = MOI.ScalarQuadraticFunction(
[MOI.ScalarAffineTerm(0.0, x)],
[MOI.ScalarQuadraticTerm(1.0, x, y)],
[MOI.ScalarAffineTerm(0.0, x)],
0.0,
)
c = MOI.add_constraint(model, cf, MOI.EqualTo(4.0))
cf2 = MOI.ScalarQuadraticFunction(
[MOI.ScalarAffineTerm(0.0, x)],
[MOI.ScalarQuadraticTerm(2.0, x, x)],
[MOI.ScalarAffineTerm(0.0, x)],
0.0,
)
c2 = MOI.add_constraint(model, cf2, MOI.EqualTo(4.0))
Expand Down Expand Up @@ -903,8 +903,8 @@ function socp1test(model::MOI.ModelLike, config::Config)
) == 1
end
c2f = MOI.ScalarQuadraticFunction(
MOI.ScalarAffineTerm{Float64}[],
MOI.ScalarQuadraticTerm.([2.0, 2.0, -2.0], [x, y, t], [x, y, t]),
MOI.ScalarAffineTerm{Float64}[],
0.0,
)
c2 = MOI.add_constraint(model, c2f, MOI.LessThan(0.0))
Expand Down
2 changes: 1 addition & 1 deletion src/DeprecatedTest/nlp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,8 @@ function test_qp_complementarity_constraint(
model,
MOI.ObjectiveFunction{MOI.ScalarQuadraticFunction{Float64}}(),
MOI.ScalarQuadraticFunction(
MOI.ScalarAffineTerm.([-10.0, 4.0], x[[1, 2]]),
MOI.ScalarQuadraticTerm.([2.0, 8.0], x[1:2], x[1:2]),
MOI.ScalarAffineTerm.([-10.0, 4.0], x[[1, 2]]),
26.0,
),
)
Expand Down
4 changes: 2 additions & 2 deletions src/FileFormats/MOF/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ function function_to_moi(
name_map::Dict{String,MOI.VariableIndex},
)
return MOI.ScalarQuadraticFunction{Float64}(
parse_scalar_affine_term.(object["affine_terms"], Ref(name_map)),
parse_scalar_quadratic_term.(object["quadratic_terms"], Ref(name_map)),
parse_scalar_affine_term.(object["affine_terms"], Ref(name_map)),
object["constant"]::Float64,
)
end
Expand Down Expand Up @@ -269,8 +269,8 @@ function function_to_moi(
name_map::Dict{String,MOI.VariableIndex},
)
return MOI.VectorQuadraticFunction{Float64}(
parse_vector_affine_term.(object["affine_terms"], Ref(name_map)),
parse_vector_quadratic_term.(object["quadratic_terms"], Ref(name_map)),
parse_vector_affine_term.(object["affine_terms"], Ref(name_map)),
Float64.(object["constants"]),
)
end
Expand Down
4 changes: 2 additions & 2 deletions src/Test/test_basic_constraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ function _function(
x::Vector{MOI.VariableIndex},
) where {T}
return MOI.ScalarQuadraticFunction(
MOI.ScalarAffineTerm.(one(T), x),
MOI.ScalarQuadraticTerm.(one(T), x, x),
MOI.ScalarAffineTerm.(one(T), x),
zero(T),
)
end
Expand All @@ -51,11 +51,11 @@ function _function(
x::Vector{MOI.VariableIndex},
) where {T}
return MOI.VectorQuadraticFunction(
MOI.VectorAffineTerm.(1:length(x), MOI.ScalarAffineTerm.(one(T), x)),
MOI.VectorQuadraticTerm.(
1:length(x),
MOI.ScalarQuadraticTerm.(one(T), x, x),
),
MOI.VectorAffineTerm.(1:length(x), MOI.ScalarAffineTerm.(one(T), x)),
zeros(T, length(x)),
)
end
Expand Down
4 changes: 2 additions & 2 deletions src/Test/test_constraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,8 @@ function test_constraint_qcp_duplicate_diagonal(
MOI.add_constraint(
model,
MOI.ScalarQuadraticFunction(
MOI.ScalarAffineTerm.([1.0], [x[2]]), # affine terms
MOI.ScalarQuadraticTerm.([2.0, 2.0], [x[1], x[1]], [x[1], x[1]]), # quad
MOI.ScalarAffineTerm.([1.0], [x[2]]), # affine terms
0.0, # constant
),
MOI.LessThan(1.0),
Expand Down Expand Up @@ -490,12 +490,12 @@ function test_constraint_qcp_duplicate_off_diagonal(
MOI.add_constraint(
model,
MOI.ScalarQuadraticFunction(
MOI.ScalarAffineTerm{Float64}[], # affine terms
MOI.ScalarQuadraticTerm.(
[2.0, 0.25, 0.25, 0.5, 2.0],
[x[1], x[1], x[2], x[1], x[2]],
[x[1], x[2], x[1], x[2], x[2]],
), # quad
MOI.ScalarAffineTerm{Float64}[], # affine terms
0.0, # constant
),
MOI.LessThan(1.0),
Expand Down
2 changes: 1 addition & 1 deletion src/Test/test_nonlinear.jl
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,8 @@ function test_nonlinear_qp_complementarity_constraint(
model,
MOI.ObjectiveFunction{MOI.ScalarQuadraticFunction{Float64}}(),
MOI.ScalarQuadraticFunction(
MOI.ScalarAffineTerm.([-10.0, 4.0], x[[1, 2]]),
MOI.ScalarQuadraticTerm.([2.0, 8.0], x[1:2], x[1:2]),
MOI.ScalarAffineTerm.([-10.0, 4.0], x[[1, 2]]),
26.0,
),
)
Expand Down
Loading