jump-dev / ComplexOptInterface.jl

Compare b34dd6a ... +0 ... fcbe09a

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.

Showing 2 of 3 files from the diff.
Other files ignored by Codecov
test/runtests.jl has changed.

@@ -0,0 +1,77 @@
Loading
1 +
function operate_coefficient(f, T::Type, term::MOI.ScalarAffineTerm)
2 +
    MOI.ScalarAffineTerm(f(term.coefficient), term.variable_index)
3 +
end
4 +
function operate_coefficient(f, T::Type, term::MOI.VectorAffineTerm)
5 +
    return MOI.VectorAffineTerm(term.output_index, operate_coefficient(f, T, term.scalar_term))
6 +
end
7 +
function operate_coefficients(f, T::Type, func::MOI.VectorAffineFunction)
8 +
    return MOI.VectorAffineFunction(
9 +
        [operate_coefficient(f, T, term) for term in func.terms],
10 +
        map(f, func.constants)
11 +
    )
12 +
end
13 +
14 +
similar_type(::Type{<:MOI.VectorAffineFunction}, T::Type) = MOI.VectorAffineFunction{T}
15 +
16 +
struct SplitZeroBridge{T, F<:MOI.Utilities.TypedLike{T}, G<:MOI.Utilities.TypedLike{Complex{T}}} <: MOI.Bridges.Constraint.AbstractBridge
17 +
    real::MOI.ConstraintIndex{F, MOI.Zeros}
18 +
    imag::MOI.ConstraintIndex{F, MOI.Zeros}
19 +
end
20 +
function MOI.Bridges.Constraint.bridge_constraint(
21 +
    ::Type{SplitZeroBridge{T, F, G}}, model::MOI.ModelLike,
22 +
    f::G,
23 +
    set::MOI.Zeros
24 +
) where {T, F, G}
25 +
    real_con = MOI.add_constraint(model, operate_coefficients(real, T, f), set)
26 +
    imag_con = MOI.add_constraint(model, operate_coefficients(imag, T, f), set)
27 +
    return SplitZeroBridge{T, F, G}(real_con, imag_con)
28 +
end
29 +
30 +
function MOI.supports_constraint(
31 +
    ::Type{SplitZeroBridge{T}}, ::Type{<:MOI.Utilities.TypedLike{Complex{T}}},
32 +
    ::Type{MOI.Zeros}) where T
33 +
    return true
34 +
end
35 +
MOIB.added_constrained_variable_types(::Type{<:SplitZeroBridge}) = Tuple{DataType}[]
36 +
function MOIB.added_constraint_types(::Type{SplitZeroBridge{T, F, G}}) where {T, F, G}
37 +
    return Tuple{DataType, DataType}[(F, MOI.Zeros)]
38 +
end
39 +
function MOI.Bridges.Constraint.concrete_bridge_type(
40 +
    ::Type{<:SplitZeroBridge{T}}, G::Type{<:MOI.Utilities.TypedLike},
41 +
    ::Type{MOI.Zeros}) where T
42 +
    return SplitZeroBridge{T, similar_type(G, T), G}
43 +
end
44 +
45 +
# Attributes, Bridge acting as a model
46 +
function MOI.get(::SplitZeroBridge{T, F},
47 +
                 ::MOI.NumberOfConstraints{F, MOI.Zeros}) where {T, F}
48 +
    return 2
49 +
end
50 +
function MOI.get(bridge::SplitZeroBridge{T, F},
51 +
                 ::MOI.ListOfConstraintIndices{F, MOI.Zeros}) where {T, F}
52 +
    return [bridge.real, bridge.imag]
53 +
end
54 +
55 +
# Indices
56 +
function MOI.delete(model::MOI.ModelLike, bridge::SplitZeroBridge)
57 +
    MOI.delete(model, bridge.imag)
58 +
    MOI.delete(model, bridge.real)
59 +
end
60 +
61 +
# Attributes, Bridge acting as a constraint
62 +
function MOI.supports(
63 +
    ::MOI.ModelLike,
64 +
    ::Union{MOI.ConstraintPrimalStart, MOI.ConstraintDualStart},
65 +
    ::Type{<:SplitZeroBridge})
66 +
67 +
    return true
68 +
end
69 +
function MOI.get(model::MOI.ModelLike, attr::Union{MOI.ConstraintPrimal, MOI.ConstraintPrimalStart, MOI.ConstraintDual, MOI.ConstraintDualStart},
70 +
                 bridge::SplitZeroBridge)
71 +
    return MOI.get(model, attr, bridge.real) + im * MOI.get(model, attr, bridge.imag)
72 +
end
73 +
function MOI.set(model::MOI.ModelLike, attr::Union{MOI.ConstraintPrimalStart, MOI.ConstraintDualStart},
74 +
                 bridge::SplitZeroBridge, value)
75 +
    MOI.set(model, attr, bridge.real, map(real, value))
76 +
    MOI.set(model, attr, bridge.imag, map(imag, value))
77 +
end

@@ -8,4 +8,6 @@
Loading
8 8
import ComplexOptInterface
9 9
const COI = ComplexOptInterface
10 10
11 +
include("split_zero.jl")
12 +
11 13
end

Learn more Showing 2 files with coverage changes found.

New file src/Bridges/Constraint/split_zero.jl
New
Loading file...
New file src/Bridges/Constraint/Constraint.jl
New
Loading file...
Files Coverage
src -7.68% 73.57%
Project Totals (6 files) 73.57%
Loading