Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add problems chain and polygon #5

Merged
merged 4 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/COPSBenchmark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ using JuMP


include("bearing.jl")
include("chain.jl")
include("camshape.jl")
include("catmix.jl")
include("channel.jl")
Expand All @@ -14,6 +15,7 @@ include("glider.jl")
include("marine.jl")
include("methanol.jl")
include("pinene.jl")
include("polygon.jl")
include("robot.jl")
include("rocket.jl")
include("steering.jl")
Expand Down
59 changes: 59 additions & 0 deletions src/chain.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Hanging Chain

# Find the chain (of uniform density) of length L suspended between two points with minimal
# potential energy.

# This is problem 4 in the COPS (Version 3) collection of
# E. Dolan and J. More'
# see "Benchmarking Optimization Software with COPS"
# Argonne National Labs Technical Report ANL/MCS-246 (2004)

# This file has been adapted from https://github.com/JuliaSmoothOptimizers/OptimizationProblems.jl

function chain_model(n::Int)
nh = max(2, div(n - 4, 4))

L = 4
a = 1
b = 3
tmin = b > a ? 1 / 4 : 3 / 4
tf = 1.0
h = tf / nh

nlp = Model()

@variable(nlp, u[k = 1:(nh + 1)], start = 4 * abs(b - a) * (k / nh - tmin))
@variable(nlp, x1[k = 1:(nh + 1)], start = 4 * abs(b - a) * k / nh * (1 / 2 * k / nh - tmin) + a)
@variable(
nlp,
x2[k = 1:(nh + 1)],
start =
(4 * abs(b - a) * k / nh * (1 / 2 * k / nh - tmin) + a) * (4 * abs(b - a) * (k / nh - tmin))
)
@variable(nlp, x3[k = 1:(nh + 1)], start = 4 * abs(b - a) * (k / nh - tmin))

@objective(nlp, Min, x2[nh + 1])

for j = 1:nh
@constraint(nlp, x1[j + 1] - x1[j] - 1 / 2 * h * (u[j] + u[j + 1]) == 0)
end
@constraint(nlp, x1[1] == a)
@constraint(nlp, x1[nh + 1] == b)
@constraint(nlp, x2[1] == 0)
@constraint(nlp, x3[1] == 0)
@constraint(nlp, x3[nh + 1] == L)

@constraint(
nlp,
[j = 1:nh],
x2[j + 1] - x2[j] - 1 / 2 * h * (x1[j] * sqrt(1 + u[j]^2) + x1[j + 1] * sqrt(1 + u[j + 1]^2)) ==
0
)
@constraint(
nlp,
[j = 1:nh],
x3[j + 1] - x3[j] - 1 / 2 * h * (sqrt(1 + u[j]^2) + sqrt(1 + u[j + 1]^2)) == 0
)

return nlp
end
31 changes: 31 additions & 0 deletions src/polygon.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Find the polygon of maximal area, among polygons with nv sides and
# diameter d <= 1

# This is problem 1 in the COPS (Version 3) collection of
# E. Dolan and J. More'
# see "Benchmarking Optimization Software with COPS"
# Argonne National Labs Technical Report ANL/MCS-246 (2004)

# This file has been adapted from https://github.com/JuliaSmoothOptimizers/OptimizationProblems.jl

function polygon_model(n::Int)
nlp = Model()
N = div(n, 2)
@variable(nlp, 0 <= r[1:N] <= 1, start = 1)
@variable(nlp, 0 <= θ[i = 1:N] <= π, start = i * π / (N - 1) - π / (N - 1))

# impose an order to the angles
@constraint(nlp, θ[N] == π)
@constraint(nlp, r[N] == 0)
for i = 1:(N - 1)
@constraint(nlp, θ[i + 1] - θ[i] >= 0.0)
end
for i = 1:(N - 1)
for j = (i + 1):N
@constraint(nlp, r[i]^2 + r[j]^2 - 2 * r[i] * r[j] * cos(θ[i] - θ[j]) - 1 <= 0)
end
end

@objective(nlp, Min, -0.5 * sum(r[i] * r[i + 1] * sin(θ[i + 1] - θ[i]) for i = 1:(N - 1)))
return nlp
end
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ using COPSBenchmark

COPS_INSTANCES = [
(COPSBenchmark.bearing_model, (50, 50), -1.5482e-1),
(COPSBenchmark.chain_model, (800,), 5.06891),
(COPSBenchmark.camshape_model, (1000,), 4.2791), # TODO: result is slightly different
(COPSBenchmark.catmix_model, (100,), -4.80556e-2),
(COPSBenchmark.channel_model, (200,), 1.0),
Expand All @@ -15,6 +16,7 @@ COPS_INSTANCES = [
(COPSBenchmark.marine_model, (100,), 1.97462e7),
(COPSBenchmark.methanol_model, (100,), 9.02229e-3),
(COPSBenchmark.pinene_model, (100,), 1.98721e1),
(COPSBenchmark.polygon_model, (100,), -0.674981), # N.B: objective depends on the optimizer used.
(COPSBenchmark.robot_model, (200,), 9.14138),
(COPSBenchmark.rocket_model, (400,), 1.01283),
(COPSBenchmark.steering_model, (200,), 5.54577e-1),
Expand Down
Loading