-
Notifications
You must be signed in to change notification settings - Fork 86
/
Bridges.jl
70 lines (60 loc) · 2.08 KB
/
Bridges.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
module Bridges
using MathOptInterface
const MOI = MathOptInterface
const MOIU = MOI.Utilities
const CI = MOI.ConstraintIndex
include("bridge.jl")
include("bridge_optimizer.jl")
# Variable bridges
include("Variable/Variable.jl")
# Constraint bridges
include("Constraint/Constraint.jl")
# Objective bridges
include("Objective/Objective.jl")
include("lazy_bridge_optimizer.jl")
include("debug.jl")
"""
full_bridge_optimizer(model::MOI.ModelLike, ::Type{T}) where T
Returns a `LazyBridgeOptimizer` bridging `model` for every bridge defined in
this package and for the coefficient type `T`.
"""
function full_bridge_optimizer(model::MOI.ModelLike, T::Type)
bridged_model = LazyBridgeOptimizer(model)
Variable.add_all_bridges(bridged_model, T)
Constraint.add_all_bridges(bridged_model, T)
Objective.add_all_bridges(bridged_model, T)
return bridged_model
end
print_num_bridges(io::IO, ::Variable.EmptyMap) = nothing
print_num_bridges(io::IO, ::Constraint.EmptyMap) = nothing
print_num_bridges(io::IO, ::Objective.EmptyMap) = nothing
function print_num_bridges(io::IO, B::Variable.Map)
s(n) = n == 1 ? "" : "s"
indent = " "^get(io, :indent, 0)
n = length(B)
print(io, "\n$(indent)with $(n) variable bridge$(s(n))")
end
function print_num_bridges(io::IO, B::Constraint.Map)
s(n) = n == 1 ? "" : "s"
indent = " "^get(io, :indent, 0)
n = length(B)
print(io, "\n$(indent)with $(n) constraint bridge$(s(n))")
end
function print_num_bridges(io::IO, B::Objective.Map)
s(n) = n == 1 ? "" : "s"
indent = " "^get(io, :indent, 0)
n = length(B)
print(io, "\n$(indent)with $(n) objective bridge$(s(n))")
end
function Base.show(io::IO, B::AbstractBridgeOptimizer)
MOIU.print_with_acronym(io, summary(B))
print_num_bridges(io, Variable.bridges(B))
print_num_bridges(io, Constraint.bridges(B))
print_num_bridges(io, Objective.bridges(B))
if :model in propertynames(B)
indent = " "^get(io, :indent, 0)
print(io, "\n$(indent)with inner model ")
show(IOContext(io, :indent => get(io, :indent, 0)+2), B.model)
end
end
end # module