-
Notifications
You must be signed in to change notification settings - Fork 6
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
Bug tf variable #189
Comments
With an indirect method I get: julia> H(x, p, u, tf) = tf*p*u-u^2/2
H (generic function with 2 methods)
julia> u(x, p, tf) = tf*p
u (generic function with 1 method)
julia> H(x, p, tf) = H(x, p, u(x, p, tf), tf)
H (generic function with 2 methods)
julia> F = Flow(ocp, u);
julia> function S(s, p0, tf)
xf, pf = F(0, 0, p0, tf, tf)
s .= [xf-1; H(xf, pf, tf)-1]
end
S (generic function with 2 methods)
julia> nle = (s, ξ, λ) -> S(s, ξ[1], ξ[2])
#19 (generic function with 1 method)
julia> prob = NonlinearProblem(nle, ξ)
NonlinearProblem with uType Vector{Int64}. In-place: true
u0: 2-element Vector{Int64}:
1
1
julia> indirect_sol = NonlinearSolve.solve(prob)
retcode: Success
u: 2-element Vector{Float64}:
1.6817928305074286
0.8408964152537142
julia> p0_sol = indirect_sol.u[1]
1.6817928305074286
julia> tf_sol = indirect_sol.u[2]
0.8408964152537142 |
It was a problem to make some tests to: control-toolbox/CTFlows.jl#15. |
well mr @ocots, I would first put the problem in canonical form (as such, it is not), having |
Hi Olivier, JB This is actually a nice test problem with a Bolza objective. There are none currently in the test suite so bugs may have slipped through. Also, until very recently the Mayer objective was in autonomous form only so there may be something here. I'll check this ! |
With PMP I got the same as with indirect shooting. |
@ocots can you plot the indirect solution ? Also I noticed we have the free tf explicitely in the dynamics, this is new as well. |
Thanks ! For the indirect solution the objective seems to be 1.67 if we take tf=0.84 and u=1.41. Could we have a local solution ? Can you try a solve with the direct data as initial guess ? Ps. @jbcaillau the non-autonomous Mayer is not yet in CTBase main right ? |
If I am not wrong, the solution is |
using OptimalControl
using NLPModelsIpopt
using OrdinaryDiffEq
@def ocp begin
tf ∈ R, variable
t ∈ [0, tf], time
x ∈ R, state
u ∈ R, control
ẋ(t) == tf * u(t)
x(0) == 0
x(tf) == 1
tf + 0.5∫(u(t)^2) → min
end
sol = solve(ocp)
x = sol.state
u = sol.control
tf = sol.variable
p0 = sol.costate(0)
@def ocp2 begin
s ∈ [0, 1], time
y = (x, tf) ∈ R², state
u ∈ R, control
dx = tf(s)^2 * u(s)
dtf = 0 * u(s) # 0
ẏ(s) == [dx, dtf]
x(0) == 0
x(1) == 1
tf(1) + 0.5∫(tf(s) * u(s)^2) → min
end
init2 = (state=s -> [x(tf * s), tf], control=s -> u(tf * s))
sol2 = solve(ocp2; init=init2)
tf2 = sol2.state(0)[2]
p02 = sol2.costate(0)[1]
ur(y, q) = y[2] * q[1]
f = Flow(ocp2, ur)
function S(tf, p0)
yf, qf = f(0, [0, tf], [p0, 0], 1)
s = [yf[1] - 1, qf[2] + 1]
return s
end
S(tf2, p02) |
|
@jbcaillau Alors, tu trouves quoi ? Après, moi je ne veux pas transformer le problème car j'avais besoin d'un exemple pour ça : control-toolbox/CTFlows.jl#38 |
Essaie tu verras 🫢 |
I tried to check the dynamics and final state for both our solutions, and both seem correct oO |
Essayez de mettre 200 pas. |
Ok vous m'avez perdu :D (avec 200 steps je retrouve la meme solution qu'a 100, par contre il faut ajouter une borne inf sur tf, comme a chaque fois qu'on est a tf libre en fait, sinon on risque toujours d'aller dans les tf negatifs) |
En effet, en utilisant proprement le PMP on retrouve bien le bon résultat :-) La fonction de tir : function S(s, p0, tf)
xf, pf = F(0, 0, p0, tf, tf)
s .= [xf-1; H(xf, pf, tf)+tf^2*pf^2-1]
end et on obtient : p0 = 0.7377879464668851
tf = 1.1066819197003364 A la main, la solution est : |
@PierreMartinon Ici tu as 3 exemples avec |
@PierreMartinon please take a look |
Pssst, celui avec t0,tf libres a l'air d'admettre une autre (meilleure) solution avec t0=0.14 :D |
J'avoue que je ne l'ai pas résolu même si j'ai écrit |
It seems that this is not correct:
The text was updated successfully, but these errors were encountered: