-
Notifications
You must be signed in to change notification settings - Fork 86
/
bellman_ford.jl
57 lines (51 loc) · 2.36 KB
/
bellman_ford.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
# Copyright (c) 2017: Miles Lubin and contributors
# Copyright (c) 2017: Google Inc.
#
# Use of this source code is governed by an MIT-style license that can be found
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.
using BenchmarkTools
import MathOptInterface as MOI
import MathOptInterface.Utilities as MOIU
# Model similar to SDPA format, it gives a good example because it does not
# support a lot hence need a lot of bridges
MOIU.@model(SDPAModel,
(), (MOI.EqualTo,), (MOI.Nonnegatives, MOI.PositiveSemidefiniteConeTriangle), (),
(), (MOI.ScalarAffineFunction,), (MOI.VectorOfVariables,), ())
MOI.supports_constraint(::SDPAModel{T}, ::Type{MOI.VariableIndex}, ::Type{MOI.GreaterThan{T}}) where {T} = false
MOI.supports_constraint(::SDPAModel{T}, ::Type{MOI.VariableIndex}, ::Type{MOI.LessThan{T}}) where {T} = false
MOI.supports_constraint(::SDPAModel{T}, ::Type{MOI.VariableIndex}, ::Type{MOI.EqualTo{T}}) where {T} = false
MOI.supports_constraint(::SDPAModel{T}, ::Type{MOI.VariableIndex}, ::Type{MOI.Interval{T}}) where {T} = false
MOI.supports_constraint(::SDPAModel, ::Type{MOI.VectorOfVariables}, ::Type{MOI.Reals}) = false
MOI.supports(::SDPAModel{T}, ::MOI.ObjectiveFunction{MOI.ScalarQuadraticFunction{T}}) where {T} = false
MOI.supports(::SDPAModel, ::MOI.ObjectiveFunction{MOI.VariableIndex}) = false
function interval_constraint()
model = SDPAModel{Float64}()
bridged = MOI.Bridges.full_bridge_optimizer(model, Float64)
F = MOI.ScalarAffineFunction{Float64}
S = MOI.Interval{Float64}
MOI.Bridges.bridge_index(bridged, F, S)
display(@benchmark begin
MOI.Bridges._reset_bridge_graph($bridged)
MOI.Bridges.node($bridged, $F, $S)
end)
display(@benchmark begin
MOI.Bridges._reset_bridge_graph($bridged)
MOI.Bridges.bridge_index($bridged, $F, $S)
end)
end
interval_constraint()
function quadratic_objective()
model = SDPAModel{Float64}()
bridged = MOI.Bridges.full_bridge_optimizer(model, Float64)
F = MOI.ScalarQuadraticFunction{Float64}
MOI.Bridges.bridge_index(bridged, F)
display(@benchmark begin
MOI.Bridges._reset_bridge_graph($bridged)
MOI.Bridges.node($bridged, $F)
end)
display(@benchmark begin
MOI.Bridges._reset_bridge_graph($bridged)
MOI.Bridges.bridge_index($bridged, $F)
end)
end
display(quadratic_objective())