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 robot_arm_dynamics #175

Merged
merged 7 commits into from
Jun 1, 2022
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
76 changes: 76 additions & 0 deletions src/ADNLPProblems/robotarm.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
export robotarm

# Minimize the time taken for a robot arm to travel between two points.

# This is problem 8 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)

# classification OOR2-AN-V-V

function robotarm(;n::Int = default_nvar,L = 4.5, type::Val{T} = Val(Float64), kwargs...) where {T}

N = max(2, div(n, 9))
n = N + 1
L=T(L)

# x : vector of variables, of the form : [ρ(t=t1); ρ(t=t2); ... ρ(t=tf), θ(t=t1), ..., then ρ_dot, ..., then ρ_acc, .. ϕ_acc, tf]
# There are N+1 values of each 9 variables
# x = [ρ, θ, ϕ, ρ_dot, θ_dot, ϕ_dot, ρ_acc, θ_acc, ϕ_acc, tf]

# objective function
function f(x)
x[end]
end

# constraints function
function c(x)

# dynamic bounds on ρ_acc, θ_acc, ϕ_acc
c_ρ_acc = L*x[6n+1:7n]
c_θ_acc = x[7n+1:8n] .* ((L .- x[1:n]).^3 .+ x[1:n].^3)/3 .* sin.(x[2n+1:3n]).^2
c_ϕ_acc = x[8n+1:9n] .* ((L .- x[1:n]).^3 .+ x[1:n].^3)/3

# Euler's constraints
c_euler1 = x[2:n] - x[1:n-1] - x[3n+1:4n-1]*x[end]/n
c_euler2 = x[n+2:2n] - x[n+1:2n-1] - x[4n+1:5n-1]*x[end]/n
c_euler3 = x[2n+2:3n] - x[2n+1:3n-1] - x[5n+1:6n-1]*x[end]/n
c_euler4 = x[3n+2:4n] - x[3n+1:4n-1] - x[6n+1:7n-1]*x[end]/n
c_euler5 = x[4n+2:5n] - x[4n+1:5n-1] - x[7n+1:8n-1]*x[end]/n
c_euler6 = x[5n+2:6n] - x[5n+1:6n-1] - x[8n+1:9n-1]*x[end]/n
c_euler = [c_euler1; c_euler2; c_euler3; c_euler4; c_euler5; c_euler6]

return [c_ρ_acc; c_θ_acc; c_ϕ_acc; c_euler]
end

lcon = T[-ones(n);
-ones(n);
-ones(n);
zeros(6N)]

ucon = T[ones(n);
ones(n);
ones(n);
zeros(6N)]

# Building a feasible x0
tf0=T(1)
θ0 = T[2π/3*(t/n)^2 for t in 1:n]
θ0[1]=T(0)
x0 = [L*ones(T, n); θ0; π*ones(T, n)/4; zeros(T, 6n); tf0]


# defining the bounds on the variables
lvar = T[zeros(n); -π*ones(n); zeros(n) ; -Inf*ones(6n); 0]
uvar = T[L*ones(n); π*ones(n); 2π*ones(n) ; Inf*ones(6n); Inf]
lvar[1] = uvar[1] = lvar[n] = uvar[n] = T(L)
lvar[n+1] = uvar[n+1] = T(0)
lvar[2n] = uvar[2n] = T(2*π/3)
lvar[2n+1] = uvar[2n+1] = lvar[3n] = uvar[3n] = T(π/4)
lvar[3n+1] = uvar[3n+1] = lvar[4n] = uvar[4n] = lvar[4n+1] = uvar[4n+1] = lvar[5n] = uvar[5n] = lvar[5n+1] = uvar[5n+1] = lvar[6n] = uvar[6n] = lvar[6n+1] = uvar[6n+1] = lvar[7n] = uvar[7n] = lvar[7n+1] = uvar[7n+1] = lvar[8n] = uvar[8n] = lvar[8n+1] = uvar[8n+1] = lvar[9n] = uvar[9n] = T(0)



return ADNLPModels.ADNLPModel(f, x0, lvar, uvar, c, lcon, ucon, name="robotarm"; kwargs...)
end
25 changes: 25 additions & 0 deletions src/Meta/robotarm.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
robotarm_meta = Dict(
:nvar => 109,
:variable_nvar => true,
:ncon => 102,
:variable_ncon => true,
:minimize => true,
:name => "robotarm",
:has_equalities_only => false,
:has_inequalities_only => false,
:has_bounds => true,
:has_fixed_variables => true,
:objtype => :other,
:contype => :general,
:best_known_lower_bound => -Inf,
:best_known_upper_bound => Inf,
:is_feasible => missing,
:defined_everywhere => missing,
:origin => :unknown,
)
get_robotarm_nvar(; n::Integer = default_nvar, kwargs...) = 9 * (max(2, div(n, 9)) + 1) + 1
get_robotarm_ncon(; n::Integer = default_nvar, kwargs...) = 3 * (max(2, div(n, 9)) + 1) + 6 * max(2, div(n, 9))
get_robotarm_nlin(; n::Integer = default_nvar, kwargs...) = 0
get_robotarm_nnln(; n::Integer = default_nvar, kwargs...) = 3 * (max(2, div(n, 9)) + 1) + 6 * max(2, div(n, 9))
get_robotarm_nequ(; n::Integer = default_nvar, kwargs...) = 6 * max(2, div(n, 9))
get_robotarm_nineq(; n::Integer = default_nvar, kwargs...) = 3 * (max(2, div(n, 9)) + 1)
71 changes: 71 additions & 0 deletions src/PureJuMP/robotarm.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Minimize the time taken for a robot arm to travel between two points.

# This is problem 8 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)

# classification OOR2-AN-V-V

# x : vector of variables, of the form : [ρ(t=t1); ρ(t=t2); ... ρ(t=tf), θ(t=t1), ..., then ρ_dot, ..., then ρ_acc, .. ϕ_acc, tf]
# There are N+1 values of each 9 variables
# x = [ρ, θ, ϕ, ρ_dot, θ_dot, ϕ_dot, ρ_acc, θ_acc, ϕ_acc, tf]

export robotarm

function robotarm(;n::Int = default_nvar,L = 4.5, kwargs...)

N = max(2, div(n, 9))
n = N + 1

nlp = Model()

# defining the bounds on the variables
lvar = [zeros(n); -π*ones(n); zeros(n) ; -Inf*ones(6n); 0]
uvar = [L*ones(n); π*ones(n); 2π*ones(n) ; Inf*ones(6n); Inf]
lvar[1] = uvar[1] = lvar[n] = uvar[n] = L
lvar[n+1] = uvar[n+1] = 0
lvar[2n] = uvar[2n] = 2*π/3
lvar[2n+1] = uvar[2n+1] = lvar[3n] = uvar[3n] = π/4
lvar[3n+1] = uvar[3n+1] = lvar[4n] = uvar[4n] = lvar[4n+1] = uvar[4n+1] = lvar[5n] = uvar[5n] = lvar[5n+1] = uvar[5n+1] = lvar[6n] = uvar[6n] = lvar[6n+1] = uvar[6n+1] = lvar[7n] = uvar[7n] = lvar[7n+1] = uvar[7n+1] = lvar[8n] = uvar[8n] = lvar[8n+1] = uvar[8n+1] = lvar[9n] = uvar[9n] = 0

# Building a feasible x0
tf0=1
θ0 = [2π/3*(t/n)^2 for t in 1:n]
θ0[1]=0
x0 = [L*ones(n); θ0; π*ones(n)/4; zeros(6n); tf0]

@variable(nlp, lvar[i] <= x[i = 1:length(x0)] <= uvar[i], start = x0[i])

@objective(nlp, Min, x[end])

for j=1:n
@NLconstraint(nlp, -1 <= L*x[6n + j] <= 1)
end
for j=1:n
@NLconstraint(nlp, -1 <= x[7n+j] * ((L - x[j])^3 + x[j]^3)/3 * sin(x[2n+j])^2 <= 1)
end
for j=1:n
@NLconstraint(nlp, -1 <= x[8n+j] * ((L - x[j])^3 + x[j]^3)/3 <= 1)
end
for j=1:(n-1)
@NLconstraint(nlp, x[j+1] - x[j] - x[3n+j]*x[end]/n == 0)
end
for j=1:(n-1)
@NLconstraint(nlp, x[n+1+j] - x[n+j] - x[4n+j]*x[end]/n == 0)
end
for j=1:(n-1)
@NLconstraint(nlp, x[2n+1+j] - x[2n+j] - x[5n+j]*x[end]/n == 0)
end
for j=1:(n-1)
@NLconstraint(nlp, x[3n+1+j] - x[3n+j] - x[6n+j]*x[end]/n == 0)
end
for j=1:(n-1)
@NLconstraint(nlp, x[4n+1+j] - x[4n+j] - x[7n+j]*x[end]/n == 0)
end
for j=1:(n-1)
@NLconstraint(nlp, x[5n+1+j] - x[5n+j] - x[8n+j]*x[end]/n == 0)
end

return nlp
end