@@ -37,11 +37,10 @@ function addbridge!(b::LazyBridgeOptimizer, BT::Type{<:AbstractBridge})
37
37
i = 0
38
38
for BT in b. bridgetypes
39
39
i += 1
40
- @show i
41
- for (F, S) in supportedconstraints (BT)
42
- if all (MOI. supportsconstraint, addedconstraints (BT, F, S))
40
+ for (F, S) in supportedconstrainttypes (BT)
41
+ if all (C -> MOI. supportsconstraint (b, C... ), addedconstrainttypes (BT, F, S))
43
42
# Number of bridges needed using BT
44
- dist = sum (C -> _dist (b, C... ), addedconstraints (BT, F, S))
43
+ dist = sum (C -> _dist (b, C... ), addedconstrainttypes (BT, F, S))
45
44
# Is it better that what can currently be done ?
46
45
if dist < _dist (b, F, S)
47
46
b. dist[(F, S)] = dist
@@ -54,51 +53,9 @@ function addbridge!(b::LazyBridgeOptimizer, BT::Type{<:AbstractBridge})
54
53
end
55
54
end
56
55
57
- function MOI. get (b:: LazyBridgeOptimizer , attr:: InstanceConstraintAttribute , ci:: CI{F, S} ) where {F, S}
58
- if MOI. supportsconstraint (b. model, F, S)
59
- MOI. get (b. model, attr, ci)
60
- else
61
- MOI. get (b. bridged, attr, ci)
62
- end
63
- end
64
- function MOI. get (b:: LazyBridgeOptimizer , attr:: SolverConstraintAttribute , ci:: CI{F, S} ) where {F, S}
65
- if MOI. supportsconstraint (b. model, F, S)
66
- MOI. get (b. model, attr, ci)
67
- else
68
- MOI. get (b. model, attr, bridge (b, ci))
69
- end
70
- end
71
-
72
56
# It only bridges when the constraint is not supporting, hence the name "Lazy"
73
- isbridged (b:: LazyBridgeOptimizer , F:: Type{<:MOI.AbstractFunction} , S:: Type{<:MOI.AbstractSet} ) = MOI. supportsconstraint (b. model, F, S)
74
- bridgetype (b:: LazyBridgeOptimizer{BT} , :: Type{<:MOI.AbstractFunction} , :: Type{<:MOI.AbstractSet} ) where BT = b. best[(typeof (f), typeof (s))]
75
-
76
- # Constraints
77
- function MOI. supportsconstraint (b:: LazyBridgeOptimizer , F:: Type{<:MOI.AbstractFunction} , S:: Type{<:MOI.AbstractSet} )
78
- || (F, S) in keys (b. dist)
79
- end
80
- function MOI. canaddconstraint (b:: LazyBridgeOptimizer , F:: Type{<:MOI.AbstractFunction} , S:: Type{<:MOI.AbstractSet} )
81
- MOI. canaddconstraint (b. model, F, S) || ((F, S) in b. best && all (C -> MOI. canaddconstraint (b, C... ), addedconstraints (b. best[(F, S)], F, S)))
82
- end
83
- function MOI. addconstraint! (b:: LazyBridgeOptimizer{T} , f:: MOI.AbstractFunction , s:: MOI.AbstractSet ) where T
84
- if MOI. supportsconstraint (b. model, typeof (f), typeof (s))
85
- MOI. addconstraint! (b. model, f, s)
86
- else
87
- ci = MOI. addconstraint! (b. bridged, f, s)
88
- @assert ! haskey (b. bridges, ci)
89
- b. bridges[ci] = (b. model, f, s)
90
- ci
91
- end
92
- end
93
-
94
- for f in (:canmodifyconstraint , :modifyconstraint! )
95
- @eval begin
96
- function MOI. $f (b:: LazyBridgeOptimizer , ci:: CI{F, S} , change) where {F, S}
97
- if MOI. supportsconstraint (b. model, F, S)
98
- MOI.$ f (b. model, ci, change)
99
- else
100
- $ f (b, ci, change)
101
- end
102
- end
103
- end
57
+ function isbridged (b:: LazyBridgeOptimizer , F:: Type{<:MOI.AbstractFunction} , S:: Type{<:MOI.AbstractSet} )
58
+ ! MOI. supportsconstraint (b. model, F, S)
104
59
end
60
+ supportsbridgingconstraint (b:: LazyBridgeOptimizer , F:: Type{<:MOI.AbstractFunction} , S:: Type{<:MOI.AbstractSet} ) = (F, S) in keys (b. best)
61
+ bridgetype (b:: LazyBridgeOptimizer{BT} , F:: Type{<:MOI.AbstractFunction} , S:: Type{<:MOI.AbstractSet} ) where BT = b. best[(F, S)]
0 commit comments