Skip to content

[Bug] Convergence when initial time is not set to zero #573

@remydutto

Description

@remydutto

Describe the bug
I am working with an optimal control problem in which the model is fitted on data, and where the initial time is therefore not zero.
I tried to solve this problem using the direct method starting from this initial time and the solver seems not to converge (more than 20 minutes, stopped before the end). However, when I set this initial time to zero, there was no problem (less than 15s, 48 iterations) . Since my problem is autonomous, it's not a major issue, but I don't really understand why there is such difference.

To Reproduce
Give if possible the code to reproduce the error:

using OptimalControl
using NLPModelsIpopt

# Short term Parameters
Cxi = 0.77; Xi = 0.3; Csi = 0.001 ; Si = 0.13; 
Gq1 = 0.01; Gq2 = 0.001;  
w01 = 6.827; w02 = 0.08;
γ = 0.02; Jv = 10; A0 = 1.; Qout = Jv*A0
R0 = 1.26e12; ϵ = 0.4;
σ1 = 10. ; σ2 = 10.; μ = 1e-3; 
α1 = 1.1e12; α2 = 1.2e11;

# Parameters for OCP
m0 = 2.8; S0 = 0.2
x0 = [0., 0., m0, S0]
vf =  42.75833335588798

# Intermediate functions
fp₁(m) = Qout*(Cxi*Xi+Csi*Si) - Gq1*m  # can be all fitted
fp₂(S) = Qout**Si) - Gq2*S
fr₁(m) = -(w01+Gq1)*m # Same 
fr₂(S) = -(w02+Gq2)*S
A(m,S) = A0/(1 + m/σ1 + S/σ2)
e(m,S) = (A0*Jv^2*μ*(R0 + α1*m/A(m,S) + α2*S/*A(m,S))))/1e12

# Production and recuperation vector fields
Fp(x) = [e(x[3],x[4]);  Jv; fp₁(x[3]); fp₂(x[4])] 
Fr(x) = [e(x[3],x[4]); -1.5*Jv; fr₁(x[3]); fr₂(x[4])]

# Vector fields for OCP
F0(x) = (Fp(x) + Fr(x))/2
F1(x) = (Fp(x) - Fr(x))/2;


# Initial time 
t0 = 19.7493287*24 # Does not works 
t0 = 0. # Works 
ocp = @def begin
    tf  R, variable 
    t  [t0, tf], time
    x = (e, v, m, S)  R⁴, state
    u  R, control
    -1  u(t)  1
    x(t0) == x0
    v(tf) == vf
    (t) == F0(x(t)) + u(t)*F1(x(t))
    e(tf)  min
end
direct_sol = OptimalControl.solve(ocp; display = true, max_iter=500);

Additional context
For t0 = 1, it takes 176 iterations.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions