Skip to content

Commit e385b52

Browse files
authored
Get rewrite up and running (#59)
* Do not track manifest * Bump dependencies and use HiGHS as test solver * Correct type in dictionary * Add field for segment structure and constructors to match old interface * Specialize piecewiselinear for typical 1D and 2D usage * Include segment structure in triangle selection * Update tests to reflect changes, use HiGHS and run all bivariate * Fix triangulation * Avoid explicit use of MOI
1 parent ffdc911 commit e385b52

17 files changed

+293
-323
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
.DS_Store
2+
Manifest.toml
3+
.vscode/settings.json

Manifest.toml

Lines changed: 0 additions & 184 deletions
This file was deleted.

Project.toml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@ version = "0.3.0"
66
[deps]
77
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
88
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
9-
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
109
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1110

1211
[compat]
13-
Cbc = "≥ 0.6.0"
14-
JuMP = "~0.21"
15-
MathOptInterface = "~0.9"
12+
HiGHS = "1"
13+
JuMP = "1"
1614
julia = "1"
1715

1816
[extras]
19-
Cbc = "9961bab8-2fa3-5c5a-9d89-47fab24efd76"
20-
Gurobi = "2e9cd046-0924-5485-92f1-d5272153d98b"
17+
HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b"
2118
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2219

2320
[targets]
24-
test = ["Test", "Cbc", "Gurobi"]
21+
test = ["Test", "HiGHS"]

src/PiecewiseLinearOpt.jl

Lines changed: 68 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ __precompile__()
33
module PiecewiseLinearOpt
44

55
import JuMP
6-
import MathOptInterface
7-
const MOI = MathOptInterface
86
using LinearAlgebra
97
using Random
108

@@ -26,38 +24,45 @@ end
2624

2725
const VarOrAff = Union{JuMP.VariableRef,JuMP.AffExpr}
2826

29-
include(joinpath("methods", "util.jl"))
27+
include("methods/util.jl")
3028

3129
export Incremental, LogarithmicEmbedding, LogarithmicIndependentBranching, NativeSOS2, ZigZagBinary, ZigZagInteger
32-
include(joinpath("methods", "univariate", "incremental.jl"))
33-
include(joinpath("methods", "univariate", "logarithmic_embedding.jl"))
34-
include(joinpath("methods", "univariate", "logarithmic_independent_branching.jl"))
35-
include(joinpath("methods", "univariate", "native_sos2.jl"))
36-
include(joinpath("methods", "univariate", "zig_zag_binary.jl"))
37-
include(joinpath("methods", "univariate", "zig_zag_integer.jl"))
30+
include("methods/univariate/incremental.jl")
31+
32+
include("methods/univariate/logarithmic_embedding.jl")
33+
include("methods/univariate/logarithmic_independent_branching.jl")
34+
include("methods/univariate/native_sos2.jl")
35+
include("methods/univariate/zig_zag_binary.jl")
36+
include("methods/univariate/zig_zag_integer.jl")
3837
# ConvexCombination has an SOS2 formulation, so defer this until after the
3938
# multivariate formulations are defined
40-
include(joinpath("methods", "univariate", "sos2_formulation_base.jl"))
39+
include("methods/univariate/sos2_formulation_base.jl")
4140

4241
# Consider the colloqial "log" to refer to the embedding formulation
4342
const Logarithmic = LogarithmicEmbedding
4443
export Logarithmic
4544

46-
export K1, NineStencil, OptimalIndendentBranching, OptimalTriangleSelection, SixStencil, UnionJack
47-
include(joinpath("methods", "bivariate", "k1.jl"))
48-
include(joinpath("methods", "bivariate", "nine_stencil.jl"))
49-
include(joinpath("methods", "bivariate", "optimal_independent_branching.jl"))
50-
include(joinpath("methods", "bivariate", "optimal_triangle_selection.jl"))
51-
include(joinpath("methods", "bivariate", "six_stencil.jl"))
52-
include(joinpath("methods", "bivariate", "union_jack.jl"))
53-
include(joinpath("methods", "bivariate", "common.jl"))
54-
55-
export ConvexCombination, DisaggregatedLogarithmic, MultipleChoice, OptimalIndependentBranching, OptimalTriangleSelection
56-
include(joinpath("methods", "multivariate", "convex_combination.jl"))
57-
include(joinpath("methods", "multivariate", "disaggregated_logarithmic.jl"))
58-
include(joinpath("methods", "multivariate", "multiple_choice.jl"))
59-
60-
function formulate_pwl!(model::JuMP.Model, input_vals::Vector{NTuple{D,VarOrAff}}, output_vals::Vector{NTuple{F,VarOrAff}}, pwl::PWLFunction, method::Method, direction::DIRECTION) where {D,F}
45+
export K1, NineStencil, OptimalIndependentBranching, OptimalTriangleSelection, SixStencil, UnionJack
46+
include("methods/bivariate/k1.jl")
47+
include("methods/bivariate/nine_stencil.jl")
48+
include("methods/bivariate/optimal_independent_branching.jl")
49+
include("methods/bivariate/optimal_triangle_selection.jl")
50+
include("methods/bivariate/six_stencil.jl")
51+
include("methods/bivariate/union_jack.jl")
52+
include("methods/bivariate/common.jl")
53+
54+
export ConvexCombination, DisaggregatedLogarithmic, MultipleChoice
55+
include("methods/multivariate/convex_combination.jl")
56+
include("methods/multivariate/disaggregated_logarithmic.jl")
57+
include("methods/multivariate/multiple_choice.jl")
58+
59+
function formulate_pwl!(
60+
model::JuMP.Model,
61+
input_vals::Vector{NTuple{D,VarOrAff}},
62+
output_vals::Vector{NTuple{F,VarOrAff}},
63+
pwl::PWLFunction,
64+
method::Method,
65+
direction::DIRECTION) where {D,F}
6166
error("No support for a R^$D -> R^$F piecewise linear function using the $method method.")
6267
end
6368

@@ -93,4 +98,42 @@ function piecewiselinear(model::JuMP.Model,
9398
return output_vars
9499
end
95100

101+
function piecewiselinear(
102+
model::JuMP.Model,
103+
input_var::VarOrAff,
104+
pwl::PWLFunction{1,1,SegmentPointRep{1,1}};
105+
method::Method = _default_method(Val(1)),
106+
direction::DIRECTION = Graph,
107+
output_var::Union{Nothing, VarOrAff} = nothing
108+
)
109+
return piecewiselinear(
110+
model,
111+
(input_var,),
112+
pwl;
113+
method = method,
114+
direction = direction,
115+
output_vars = isnothing(output_var) ? nothing : (output_var,)
116+
)[1]
117+
end
118+
119+
function piecewiselinear(
120+
model::JuMP.Model,
121+
input_var_x::VarOrAff,
122+
input_var_y::VarOrAff,
123+
pwl::PWLFunction{2,1,SegmentPointRep{2,1}};
124+
method::Method = _default_method(Val(2)),
125+
direction::DIRECTION = Graph,
126+
output_var::Union{Nothing, VarOrAff} = nothing
127+
)
128+
return piecewiselinear(
129+
model,
130+
(input_var_x, input_var_y),
131+
pwl;
132+
method = method,
133+
direction = direction,
134+
output_vars = isnothing(output_var) ? nothing : (output_var,)
135+
)[1]
136+
end
137+
138+
96139
end # module

src/methods/bivariate/common.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const BivariateSOS2Method = Union{K1, OptimalTriangleSelection, NineStencil, SixStencil, UnionJack}
22

3-
function formulate_pwl!(model::JuMP.Model, input_vars::NTuple{2, VarOrAff}, output_vars::NTuple{F, VarOrAff}, pwl::BivariatePWLFunction{F}, method::BivariateSOS2Method, direction::DIRECTION) where {F}
3+
function formulate_pwl!(model::JuMP.Model, input_vars::NTuple{2, VarOrAff}, output_vars::NTuple{F, VarOrAff}, pwl::PWLFunctionPointRep{2, F}, method::BivariateSOS2Method, direction::DIRECTION) where {F}
44
initPWL!(model)
55
counter = model.ext[:PWL].counter
66
counter += 1
@@ -58,5 +58,9 @@ function formulate_pwl!(model::JuMP.Model, input_vars::NTuple{2, VarOrAff}, outp
5858
end
5959
end
6060

61-
formulate_triangle_selection!(model, λ, triangle_direction, method)
61+
formulate_triangle_selection!(model, λ, triangle_direction, method, pwl.structure)
62+
end
63+
64+
function formulate_triangle_selection!(model::JuMP.Model, λ::Matrix{JuMP.VariableRef}, triangle_direction::Matrix{Bool}, method::BivariateSOS2Method, structure::GridTriangulation)
65+
error("The triangulation structure $structure is not suppported for method $method")
6266
end

src/methods/bivariate/k1.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ K1() = K1(Logarithmic())
55

66
axis_method(method::K1) = method.axis_method
77

8-
function formulate_triangle_selection!(model::JuMP.Model, λ::Matrix{JuMP.VariableRef}, triangle_direction::Matrix{Bool}, method::K1)
8+
function formulate_triangle_selection!(model::JuMP.Model, λ::Matrix{JuMP.VariableRef}, triangle_direction::Matrix{Bool}, method::K1, structure::K1Triangulation)
99
n_1, n_2 = size(λ)
1010
@assert size(triangle_direction) == (n_1 - 1, n_2 - 1)
1111
counter = model.ext[:PWL].counter

src/methods/bivariate/nine_stencil.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ NineStencil() = NineStencil(Logarithmic())
66
axis_method(method::NineStencil) = method.axis_method
77

88
# TODO: Unit tests for biclique cover
9-
function formulate_triangle_selection!(model::JuMP.Model, λ::Matrix{JuMP.VariableRef}, triangle_direction::Matrix{Bool}, method::NineStencil)
9+
function formulate_triangle_selection!(model::JuMP.Model, λ::Matrix{JuMP.VariableRef}, triangle_direction::Matrix{Bool}, method::NineStencil, _::GridTriangulation)
1010
n_1, n_2 = size(λ)
1111
@assert size(triangle_direction) == (n_1 - 1, n_2 - 1)
1212
counter = model.ext[:PWL].counter

0 commit comments

Comments
 (0)