|
2 | 2 | const VF = Union{ |
3 | 3 | MOI.VectorAffineFunction, |
4 | 4 | MOI.VectorQuadraticFunction, |
| 5 | + MOI.VectorNonlinearFunction, |
5 | 6 | } |
6 | 7 |
|
7 | 8 | function has_complementarity(model::MOI.ModelLike) |
@@ -29,28 +30,13 @@ function _is_single_variable(func::MOI.ScalarQuadraticFunction) |
29 | 30 | false |
30 | 31 | end |
31 | 32 | end |
| 33 | +function _is_single_variable(func::MOI.ScalarNonlinearFunction) |
| 34 | + return func.head == :+ && length(func.args) == 1 && isa(func.args[1], MOI.VariableIndex) |
| 35 | +end |
32 | 36 | _get_variable(func::MOI.ScalarAffineFunction) = func.terms[1].variable |
33 | 37 | _get_variable(func::MOI.ScalarQuadraticFunction) = func.affine_terms[1].variable |
| 38 | +_get_variable(func::MOI.ScalarNonlinearFunction) = func.args[1] |
34 | 39 |
|
35 | | -# Reformulate |
36 | | -function _vertical_formulation!(model, terms::Vector{MOI.ScalarAffineTerm{T}}, c::T) where T |
37 | | - x = MOI.add_variable(model) |
38 | | - push!(terms, MOI.ScalarAffineTerm{T}(-one(T), x)) |
39 | | - func = MOI.ScalarAffineFunction{T}(terms, zero(T)) |
40 | | - MOI.add_constraint(model, func, MOI.EqualTo{T}(-c)) |
41 | | - return x |
42 | | -end |
43 | | - |
44 | | -function _add_slack!(model, func::MOI.ScalarAffineFunction{T}) where T |
45 | | - x = MOI.add_variable(model) |
46 | | - push!(func.terms, MOI.ScalarAffineTerm{T}(-one(T), x)) |
47 | | - return x |
48 | | -end |
49 | | -function _add_slack!(model, func::MOI.ScalarQuadraticFunction{T}) where T |
50 | | - x = MOI.add_variable(model) |
51 | | - push!(func.affine_terms, MOI.ScalarAffineTerm{T}(-one(T), x)) |
52 | | - return x |
53 | | -end |
54 | 40 |
|
55 | 41 | # TODO: add support for ScalarNonlinearTerm |
56 | 42 | function _parse_complementarity_constraint(fun::MOI.AbstractVectorFunction, n_comp) |
@@ -129,8 +115,9 @@ function reformulate_to_vertical!(model::MOI.ModelLike) |
129 | 115 | push!(ind_cc2, x2) |
130 | 116 | else |
131 | 117 | # Else, reformulate LHS using vertical form |
132 | | - x1 = _add_slack!(model, lhs) |
133 | | - MOI.add_constraint(model, lhs, MOI.EqualTo{Float64}(0)) |
| 118 | + x1 = MOI.add_variable(model) |
| 119 | + new_lhs = MOIU.operate!(-, Float64, lhs, x1) |
| 120 | + MOI.add_constraint(model, new_lhs, MOI.EqualTo{Float64}(0)) |
134 | 121 | push!(ind_cc1, x1) |
135 | 122 | push!(ind_cc2, x2) |
136 | 123 | end |
|
0 commit comments