diff --git a/src/COPSBenchmark.jl b/src/COPSBenchmark.jl index 479341e..a679bc0 100644 --- a/src/COPSBenchmark.jl +++ b/src/COPSBenchmark.jl @@ -5,6 +5,7 @@ using JuMP include("bearing.jl") +include("chain.jl") include("camshape.jl") include("catmix.jl") include("channel.jl") @@ -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") diff --git a/src/chain.jl b/src/chain.jl new file mode 100644 index 0000000..069ecb1 --- /dev/null +++ b/src/chain.jl @@ -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 diff --git a/src/polygon.jl b/src/polygon.jl new file mode 100644 index 0000000..37df44c --- /dev/null +++ b/src/polygon.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index b41a12a..e86567b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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), @@ -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),