Latest attempt at jump. Does not work yet.
This commit is contained in:
@@ -1,10 +1,38 @@
|
||||
using NLsolve
|
||||
using JuMP, Ipopt
|
||||
|
||||
export nlp_solve
|
||||
|
||||
function treat_inputs(x::AbstractVector)
|
||||
n::Int = length(x)/3
|
||||
reshape(x,(3,n))'
|
||||
function treat_inputs(x::Vector{T}) where T <: Real
|
||||
thrust = T[]
|
||||
α = T[]
|
||||
β = T[]
|
||||
n::Int = length(x)
|
||||
for i in 1:n
|
||||
if i % 3 == 1
|
||||
push!(thrust,x[i])
|
||||
elseif i % 3 == 2
|
||||
push!(α,x[i])
|
||||
else
|
||||
push!(β,x[i])
|
||||
end
|
||||
end
|
||||
hcat(thrust, α, β)
|
||||
end
|
||||
|
||||
function treat_inputs(x::NTuple{90,T}) where T <: Real
|
||||
thrust = T[]
|
||||
α = T[]
|
||||
β = T[]
|
||||
for i in 1:90
|
||||
if i % 3 == 1
|
||||
push!(thrust,x[i])
|
||||
elseif i % 3 == 2
|
||||
push!(α,x[i])
|
||||
else
|
||||
push!(β,x[i])
|
||||
end
|
||||
end
|
||||
hcat(thrust, α, β)
|
||||
end
|
||||
|
||||
function nlp_solve(start::Vector{Float64},
|
||||
@@ -13,15 +41,87 @@ function nlp_solve(start::Vector{Float64},
|
||||
μ::Float64,
|
||||
t0::Float64,
|
||||
tf::Float64,
|
||||
x0::AbstractVector;
|
||||
Txi::Vector{Float64},
|
||||
Tyi::Vector{Float64},
|
||||
Tzi::Vector{Float64},
|
||||
tol=1e-6)
|
||||
|
||||
n::Int = length(x0)/3
|
||||
function f!(F,x)
|
||||
F[1:6] .= prop(treat_inputs(x), start, craft, μ, tf-t0)[1][end,:] - final
|
||||
F[7:3n] .= 0.
|
||||
n::Int = length(Txi)
|
||||
if length(Tyi) != n
|
||||
throw("Bad number of Tys")
|
||||
elseif length(Tzi) != n
|
||||
throw("Bad number of Tzs")
|
||||
end
|
||||
|
||||
return nlsolve(f!, x0, ftol=tol, autodiff=:forward, iterations=1_000)
|
||||
model = Model(Ipopt.Optimizer)
|
||||
set_optimizer_attribute(model, "max_cpu_time", 30.)
|
||||
|
||||
@variables(model, begin
|
||||
Tx[i=1:n], (start=Txi[i])
|
||||
Ty[i=1:n], (start=Tyi[i])
|
||||
Tz[i=1:n], (start=Tzi[i])
|
||||
x[1:n]
|
||||
y[1:n]
|
||||
z[1:n]
|
||||
dx[1:n]
|
||||
dy[1:n]
|
||||
dz[1:n]
|
||||
mass[1:n]
|
||||
end)
|
||||
|
||||
@constraints(model,begin
|
||||
x[1] == start[1]
|
||||
y[1] == start[2]
|
||||
z[1] == start[3]
|
||||
dx[1] == start[4]
|
||||
dy[1] == start[5]
|
||||
dz[1] == start[6]
|
||||
mass[1] == craft.mass
|
||||
x[n] == final[1]
|
||||
y[n] == final[2]
|
||||
z[n] == final[3]
|
||||
dx[n] == final[4]
|
||||
dy[n] == final[5]
|
||||
dz[n] == final[6]
|
||||
end)
|
||||
|
||||
register(model, :prop_one_simple, 11, prop_one_simple; autodiff = true)
|
||||
@NLexpression(model, )
|
||||
|
||||
# @NLexpression()
|
||||
|
||||
for i in 2:n
|
||||
@NLconstraint(model, x[i] == sqrt(x[i-1]^2))
|
||||
# @NLconstraint(model, x[i] == prop_one_simple(Tx[i-1], Ty[i-1], Tz[i-1],
|
||||
# x[i-1], y[i-1], z[i-1],
|
||||
# dx[i-1], dy[i-1], dz[i-1],
|
||||
# (tf-t0)/n, μ)[1])
|
||||
# @NLconstraint(model, y[i] == prop_one_simple(Tx[i-1], Ty[i-1], Tz[i-1],
|
||||
# x[i-1], y[i-1], z[i-1],
|
||||
# dx[i-1], dy[i-1], dz[i-1],
|
||||
# (tf-t0)/n, μ)[2])
|
||||
# @NLconstraint(model, z[i] == prop_one_simple(Tx[i-1], Ty[i-1], Tz[i-1],
|
||||
# x[i-1], y[i-1], z[i-1],
|
||||
# dx[i-1], dy[i-1], dz[i-1],
|
||||
# (tf-t0)/n, μ)[3])
|
||||
# @NLconstraint(model, dx[i] == prop_one_simple(Tx[i-1], Ty[i-1], Tz[i-1],
|
||||
# x[i-1], y[i-1], z[i-1],
|
||||
# dx[i-1], dy[i-1], dz[i-1],
|
||||
# (tf-t0)/n, μ)[4])
|
||||
# @NLconstraint(model, dy[i] == prop_one_simple(Tx[i-1], Ty[i-1], Tz[i-1],
|
||||
# x[i-1], y[i-1], z[i-1],
|
||||
# dx[i-1], dy[i-1], dz[i-1],
|
||||
# (tf-t0)/n, μ)[5])
|
||||
# @NLconstraint(model, dz[i] == prop_one_simple(Tx[i-1], Ty[i-1], Tz[i-1],
|
||||
# x[i-1], y[i-1], z[i-1],
|
||||
# dx[i-1], dy[i-1], dz[i-1],
|
||||
# (tf-t0)/n, μ)[6])
|
||||
@NLconstraint(model, mass[i] == mass[i-1] - craft.mass_flow_rate*√(Tx[i-1]^2 +
|
||||
Ty[i-1]^2 +
|
||||
Tz[i-1]^2)*(tf-t0)/n)
|
||||
end
|
||||
|
||||
optimize!(model)
|
||||
return model
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user