|
4 | 4 | # Use of this source code is governed by an MIT-style license that can be found
|
5 | 5 | # in the LICENSE.md file or at https://opensource.org/licenses/MIT.
|
6 | 6 |
|
| 7 | +# Functions convertible to a ScalarAffineFunction |
| 8 | +const ScalarAffineLike{T} = |
| 9 | + Union{T,MOI.VariableIndex,MOI.ScalarAffineFunction{T}} |
| 10 | +# Functions convertible to a ScalarQuadraticFunction |
| 11 | +const ScalarQuadraticLike{T} = |
| 12 | + Union{ScalarAffineLike{T},MOI.ScalarQuadraticFunction{T}} |
| 13 | + |
| 14 | +# `ScalarLike` for which `T` is defined to avoid defining, e.g., |
| 15 | +# `+(::VariableIndex, ::Any)` which should rather be |
| 16 | +# `+(::VariableIndex, ::Number)`. |
| 17 | +const TypedScalarLike{T} = |
| 18 | + Union{MOI.ScalarAffineFunction{T},MOI.ScalarQuadraticFunction{T}} |
| 19 | +# Used for overloading Base operator functions so `T` is not in the union to |
| 20 | +# avoid overloading e.g. `+(::Float64, ::Float64)` |
| 21 | +const ScalarLike{T} = Union{MOI.VariableIndex,TypedScalarLike{T}} |
| 22 | + |
| 23 | +# Functions convertible to a VectorAffineFunction |
| 24 | +const VectorAffineLike{T} = |
| 25 | + Union{Vector{T},MOI.VectorOfVariables,MOI.VectorAffineFunction{T}} |
| 26 | +# Functions convertible to a VectorQuadraticFunction |
| 27 | +const VectorQuadraticLike{T} = |
| 28 | + Union{VectorAffineLike{T},MOI.VectorQuadraticFunction{T}} |
| 29 | + |
| 30 | +# `VectorLike` for which `T` is defined to avoid defining, e.g., |
| 31 | +# `+(::VectorOfVariables, ::Any)` which should rather be |
| 32 | +# `+(::VectorOfVariables, ::Number)`. |
| 33 | +const TypedVectorLike{T} = |
| 34 | + Union{MOI.VectorAffineFunction{T},MOI.VectorQuadraticFunction{T}} |
| 35 | +# Used for overloading Base operator functions so `T` is not in the union to |
| 36 | +# avoid overloading e.g. `+(::Float64, ::Float64)` |
| 37 | +const VectorLike{T} = Union{MOI.VectorOfVariables,TypedVectorLike{T}} |
| 38 | + |
| 39 | +const TypedLike{T} = Union{TypedScalarLike{T},TypedVectorLike{T}} |
| 40 | + |
7 | 41 | variable_function_type(::Type{<:MOI.AbstractScalarSet}) = MOI.VariableIndex
|
8 | 42 | variable_function_type(::Type{<:MOI.AbstractVectorSet}) = MOI.VectorOfVariables
|
9 | 43 |
|
| 44 | +""" |
| 45 | + value_type(::Type{T}, ::Type{F}) where {T,F<:AbstractFunction} |
| 46 | +
|
| 47 | +Returns the output type that results if a function of type `F` is evaluated |
| 48 | +using variables with numeric type `T`. |
| 49 | +
|
| 50 | +In other words, this is the return type for |
| 51 | +`MOI.Utilities.eval_variables(variable_values::Function, f::F)` |
| 52 | +for a function `variable_values(::MOI.VariableIndex)::T`. |
| 53 | +""" |
| 54 | +function value_type end |
| 55 | + |
| 56 | +value_type(::Type{T}, ::Type{MOI.VariableIndex}) where {T} = T |
| 57 | + |
| 58 | +value_type(::Type{T}, ::Type{MOI.VectorOfVariables}) where {T} = Vector{T} |
| 59 | + |
| 60 | +function value_type(::Type{T}, ::Type{<:TypedScalarLike{C}}) where {C,T} |
| 61 | + return MA.promote_operation(*, C, T) |
| 62 | +end |
| 63 | + |
| 64 | +function value_type(::Type{T}, ::Type{<:TypedVectorLike{C}}) where {C,T} |
| 65 | + return Vector{MA.promote_operation(*, C, T)} |
| 66 | +end |
| 67 | + |
10 | 68 | """
|
11 | 69 | eval_variables(varval::Function, f::AbstractFunction)
|
12 | 70 |
|
@@ -1494,40 +1552,6 @@ function map_terms!(
|
1494 | 1552 | return map!(op, func.quadratic_terms, func.quadratic_terms)
|
1495 | 1553 | end
|
1496 | 1554 |
|
1497 |
| -# Functions convertible to a ScalarAffineFunction |
1498 |
| -const ScalarAffineLike{T} = |
1499 |
| - Union{T,MOI.VariableIndex,MOI.ScalarAffineFunction{T}} |
1500 |
| -# Functions convertible to a ScalarQuadraticFunction |
1501 |
| -const ScalarQuadraticLike{T} = |
1502 |
| - Union{ScalarAffineLike{T},MOI.ScalarQuadraticFunction{T}} |
1503 |
| - |
1504 |
| -# `ScalarLike` for which `T` is defined to avoid defining, e.g., |
1505 |
| -# `+(::VariableIndex, ::Any)` which should rather be |
1506 |
| -# `+(::VariableIndex, ::Number)`. |
1507 |
| -const TypedScalarLike{T} = |
1508 |
| - Union{MOI.ScalarAffineFunction{T},MOI.ScalarQuadraticFunction{T}} |
1509 |
| -# Used for overloading Base operator functions so `T` is not in the union to |
1510 |
| -# avoid overloading e.g. `+(::Float64, ::Float64)` |
1511 |
| -const ScalarLike{T} = Union{MOI.VariableIndex,TypedScalarLike{T}} |
1512 |
| - |
1513 |
| -# Functions convertible to a VectorAffineFunction |
1514 |
| -const VectorAffineLike{T} = |
1515 |
| - Union{Vector{T},MOI.VectorOfVariables,MOI.VectorAffineFunction{T}} |
1516 |
| -# Functions convertible to a VectorQuadraticFunction |
1517 |
| -const VectorQuadraticLike{T} = |
1518 |
| - Union{VectorAffineLike{T},MOI.VectorQuadraticFunction{T}} |
1519 |
| - |
1520 |
| -# `VectorLike` for which `T` is defined to avoid defining, e.g., |
1521 |
| -# `+(::VectorOfVariables, ::Any)` which should rather be |
1522 |
| -# `+(::VectorOfVariables, ::Number)`. |
1523 |
| -const TypedVectorLike{T} = |
1524 |
| - Union{MOI.VectorAffineFunction{T},MOI.VectorQuadraticFunction{T}} |
1525 |
| -# Used for overloading Base operator functions so `T` is not in the union to |
1526 |
| -# avoid overloading e.g. `+(::Float64, ::Float64)` |
1527 |
| -const VectorLike{T} = Union{MOI.VectorOfVariables,TypedVectorLike{T}} |
1528 |
| - |
1529 |
| -const TypedLike{T} = Union{TypedScalarLike{T},TypedVectorLike{T}} |
1530 |
| - |
1531 | 1555 | ###################################### +/- #####################################
|
1532 | 1556 | ## promote_operation
|
1533 | 1557 |
|
|
0 commit comments