Hello everyone,
I am implementing an optimization problem for a satellite that has to move from a radius 1 orbit to a radius 2 orbit. The objective of my optimization is to minimize the required deltaV. I am trying to define this objective function but I get an error saying that the way I define the deltaV is not supported by Jump. How can I define it in another way so that it accepts the function? I attach the code and the error obtained in case you can help me to solve it.
Thanks in advance
The error is:
ERROR: The objective function deltaV
is not supported by JuMP.
The implemented code:
using JuMP
import Ipopt
import Plots
using Plots
# Constants and initial conditions
μ = 3.986e5 #[km^3/s^2]
x0 = 1 #[m]
y0 = 0 #[m]
xf = 2 #[m]
yf = 0 #[m]
m = 100 #[kg]
n = 500 #Number of iterations
const integration_rule = "Trapezoidal integration"
# Create the Model
Hohmann = Model(Ipopt.Optimizer)
set_attribute(Hohmann,"print_level", 4) #Da mas informacion sobre la optimizacion
set_attribute(Hohmann, "max_iter", 20000) #Define el numero maximo de iteraciones del solucionador
set_attribute(Hohmann, "print_timing_statistics", "yes") #Nos proporciona informacion sobre el tiempo que toma cada fase del proceso de optimizacion
# Create variables
@variables(Hohmann, begin
x[1:n]
y[1:n]
u[1:n]
v[1:n]
end)
# Set initial conditions
fix(x[1], x0, force=true)
fix(x[n], xf, force=true)
fix(y[1], y0, force=true)
fix(y[n], xf, force=true)
#Aditional equations
@NLexpression(Hohmann, Δt, 0.2/n) #Time step
@NLexpressions(Hohmann, begin
T[j=1:n], sqrt(u[j]^2 + v[j]^2)
R[j=1:n], sqrt(x[j]^2 + y[j]^2)
tf[j=1:n], Δt*n
end)
# Dynamic equations
@NLexpressions(Hohmann, begin
δδx[j=1:n], -μ/R[j]*x[j] + u[j]/m
δδy[j=1:n], -μ/R[j]*y[j] + v[j]/m
end)
# Collocation method (trapezoidal integration function)
function CollocationMethods(x, y, Δt)
if integration_rule == "Rectangular integration"
for j in 2:n
@NLconstraint(Hohmann, x[j] == x[j-1] + Δt*y[j-1])
end
elseif integration_rule == "Trapezoidal integration"
for j in 2:n
@NLconstraint(Hohmann, x[j] == x[j-1] + 0.5*Δt*(y[j]+y[j-1]))
end
else
@error "Unexpected integration rule '$(integration_rule)'"
end
end
# Objective function
function deltaV(T,tf)
term = 0
for i in 2:n-1
term = term + 2*(T[i]/m)
end
h = tf/n
deltaV = h/2*(T[0]/m + T[n]/m + term)
end
register(Hohmann, :deltaV, 2, deltaV; autodiff = true)
# Use collocation method
CollocationMethods(x, δδx, Δt)
CollocationMethods(y, δδy, Δt)
@objective(Hohmann, Min, deltaV)
optimize!(Hohmann)
println( "The minimun deltaV is: ", objective_value(Hohmann))