Skip to content
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
29 changes: 29 additions & 0 deletions src/ADNLPProblems/polygon1.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export polygon1

function polygon1(args...; n::Int = default_nvar, type::Val{T} = Val(Float64), kwargs...) where {T}
N = div(n, 2)
function f(y)
r, θ = y[1:N], y[(N + 1):end]
return -T(0.5) * sum(r[i] * r[i + 1] * sin(θ[i + 1] - θ[i]) for i = 1:(N - 1)) -
T(0.5) * r[1] * r[N] * sin(θ[1] - θ[N])
end
function c(y)
r, θ = y[1:N], y[(N + 1):end]
return vcat(θ[1], [θ[i + 1] - θ[i] for i = 1:(N - 1)])
end
lvar = vcat(zeros(T, N), zeros(T, N))
uvar = vcat(ones(T, N), T(2π) * ones(T, N))
xi = zeros(T, 2 * N)
return ADNLPModels.ADNLPModel(
f,
xi,
lvar,
uvar,
c,
zeros(T, N),
vcat(zero(T), T(Inf) * ones(T, N - 1)),
name = "polygon1",
lin = collect(1:N);
kwargs...,
)
end
25 changes: 25 additions & 0 deletions src/Meta/polygon1.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
polygon1_meta = Dict(
:nvar => 2 * div(default_nvar, 2),
:variable_nvar => true,
:ncon => div(default_nvar, 2),
:variable_ncon => true,
:minimize => true,
:name => "polygon1",
:has_equalities_only => false,
:has_inequalities_only => false,
:has_bounds => true,
:has_fixed_variables => false,
:objtype => :other,
:contype => :linear,
:best_known_lower_bound => -Inf,
:best_known_upper_bound => Inf,
:is_feasible => false,
:defined_everywhere => missing,
:origin => :unknown,
)
get_polygon1_nvar(; n::Integer = default_nvar, kwargs...) = 2 * div(n, 2)
get_polygon1_ncon(; n::Integer = default_nvar, kwargs...) = div(n, 2)
get_polygon1_nlin(; n::Integer = default_nvar, kwargs...) = div(n, 2)
get_polygon1_nnln(; n::Integer = default_nvar, kwargs...) = 0
get_polygon1_nequ(; n::Integer = default_nvar, kwargs...) = 1
get_polygon1_nineq(; n::Integer = default_nvar, kwargs...) = div(n, 2) - 1
35 changes: 35 additions & 0 deletions src/PureJuMP/polygon1.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Find the polygon of maximal area, among polygons with nv sides and
# diameter d <= 1

# JuMP model follows Laurent Lessard CS/ECE/ISyE 524, University of Wisconsin–Madison,
# Introduction to Optimization class.
# https://laurentlessard.com/teaching/524-intro-to-optimization/

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

export polygon1

function polygon1(args...; n::Int = default_nvar, kwargs...)
nlp = Model()
N = div(n, 2)
@variable(nlp, 0 <= r[1:N] <= 1)
@variable(nlp, 0 <= θ[1:N] <= 2π)

# impose an order to the angles
@constraint(nlp, θ[1] == 0)
for i = 1:(N - 1)
@constraint(nlp, θ[i + 1] - θ[i] >= 0.0)
end

@NLobjective(
nlp,
Min,
-0.5 * sum(r[i] * r[i + 1] * sin(θ[i + 1] - θ[i]) for i = 1:(N - 1)) -
0.5 * r[1] * r[N] * sin(θ[1] - θ[N])
)
return nlp
end