Skip to content

Commit b87d690

Browse files
committed
Update and fix format
1 parent c3b5602 commit b87d690

File tree

3 files changed

+18
-20
lines changed

3 files changed

+18
-20
lines changed

ext/PolyhedraExt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ function MultiObjectiveAlgorithms._halfspaces(IPS::Vector{Vector{Float64}})
99
return [(-H_i.a, -H_i.β) for H_i in H]
1010
end
1111

12-
end
12+
end

src/algorithms/Sandwiching.jl

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
function _halfspaces(IPS::Vector{Vector{Float64}})
2-
error("MOA.Sandwiching requires Polyhedra.jl to be loaded")
1+
function _halfspaces(IPS)
2+
return error("MOA.Sandwiching requires Polyhedra.jl to be loaded")
33
end
44

55
mutable struct Sandwiching <: AbstractAlgorithm
@@ -80,7 +80,7 @@ function optimize_multiobjective!(algorithm::Sandwiching, model::Optimizer)
8080
@info "yI: $(yI)"
8181
@info "yUB: $(yUB)"
8282
IPS = [yUB, keys(anchors)...]
83-
OPS = Tuple{Vector{Float64}, Float64}[]
83+
OPS = Tuple{Vector{Float64},Float64}[]
8484
for i in 1:n
8585
e_i = Float64.(1:n .== i)
8686
push!(OPS, (e_i, yI[i])) # e_i' * y >= yI_i
@@ -90,17 +90,13 @@ function optimize_multiobjective!(algorithm::Sandwiching, model::Optimizer)
9090
@info "OPS: $(OPS)"
9191
u = MOI.add_variables(model.inner, n)
9292
u_constraints = [ # u_i >= 0 for all i = 1:n
93-
MOI.add_constraint(
94-
model.inner,
95-
u_i,
96-
MOI.GreaterThan{Float64}(0),
97-
)
93+
MOI.add_constraint(model.inner, u_i, MOI.GreaterThan{Float64}(0))
9894
for u_i in u
9995
]
10096
f_constraints = [ # f_i + u_i <= yUB_i for all i = 1:n
10197
MOI.Utilities.normalize_and_add_constraint(
10298
model.inner,
103-
scalars[i] + u[i],
99+
scalars[i] + u[i],
104100
MOI.LessThan(yUB[i]),
105101
) for i in 1:n
106102
]
@@ -116,7 +112,7 @@ function optimize_multiobjective!(algorithm::Sandwiching, model::Optimizer)
116112
@info "Selected halfspace: w: $(w), b: $(b)"
117113
@info "δ: $(δ)"
118114
if δ - tol > ε # added some convergence tolerance
119-
# would not terminate when precision is set to 0
115+
# would not terminate when precision is set to 0
120116
new_f = sum(w[i] * (scalars[i] + u[i]) for i in 1:n) # w' * (f(x) + u)
121117
MOI.set(model.inner, MOI.ObjectiveFunction{typeof(new_f)}(), new_f)
122118
MOI.optimize!(model.inner)
@@ -142,4 +138,4 @@ function optimize_multiobjective!(algorithm::Sandwiching, model::Optimizer)
142138
MOI.delete.(model.inner, u_constraints)
143139
MOI.delete.(model.inner, u)
144140
return MOI.OPTIMAL, [SolutionPoint(X, Y) for (Y, X) in solutions]
145-
end
141+
end

test/algorithms/Sandwiching.jl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ function run_tests()
1818
return
1919
end
2020

21-
2221
# From International Doctoral School Algorithmic Decision Theory: MCDA and MOO
2322
# Lecture 2: Multiobjective Linear Programming
2423
# Matthias Ehrgott
@@ -55,20 +54,23 @@ function test_molp()
5554
end
5655
f = MOI.VectorAffineFunction(
5756
[
58-
MOI.VectorAffineTerm(i, MOI.ScalarAffineTerm(C[i, j], x[j]))
59-
for i in 1:p for j in 1:n
57+
MOI.VectorAffineTerm(i, MOI.ScalarAffineTerm(C[i, j], x[j])) for
58+
i in 1:p for j in 1:n
6059
],
6160
zeros(p),
6261
)
6362
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
6463
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
6564
MOI.optimize!(model)
6665
N = MOI.get(model, MOI.ResultCount())
67-
solutions = reverse([MOI.get(model, MOI.VariablePrimal(i), x) => MOI.get(model, MOI.ObjectiveValue(i)) for i in 1:N])
66+
solutions = reverse([
67+
MOI.get(model, MOI.VariablePrimal(i), x) =>
68+
MOI.get(model, MOI.ObjectiveValue(i)) for i in 1:N
69+
])
6870
results = reverse([
69-
[0., 0.] => [0., 0.],
70-
[0., 3.] => [3., -6.],
71-
[3., 3.] => [12., -9.],
71+
[0.0, 0.0] => [0.0, 0.0],
72+
[0.0, 3.0] => [3.0, -6.0],
73+
[3.0, 3.0] => [12.0, -9.0],
7274
])
7375
@test length(solutions) == length(results)
7476
for (sol, res) in zip(solutions, results)
@@ -81,4 +83,4 @@ end
8183

8284
end
8385

84-
TestSandwiching.run_tests()
86+
TestSandwiching.run_tests()

0 commit comments

Comments
 (0)