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

Suppress Index in constraints #155

Closed
jbcaillau opened this issue Jun 14, 2024 · 14 comments
Closed

Suppress Index in constraints #155

jbcaillau opened this issue Jun 14, 2024 · 14 comments
Assignees

Comments

@jbcaillau
Copy link
Member

... but keep for (variable) times
IMG_3235

@PierreMartinon
Copy link
Member

Can you elaborate please :D ?

@ocots ocots mentioned this issue Jun 15, 2024
13 tasks
@PierreMartinon
Copy link
Member

PierreMartinon commented Jun 21, 2024

Hi @ocots @jbcaillau
What is the new syntax for a basic initial condition x(t0) = x0 ?
The version below is not accepted anymore.
I updated the time! call but got stuck on the constraint! (did not find a similar example in the doc)

ocp = Model(variable=true)
state!(ocp, 3)
control!(ocp, 1)
variable!(ocp, 1)
time!(ocp, t0=0, indf=1)
constraint!(ocp, :initial, [1,0,1], :initial_constraint)

@ocots
Copy link
Member

ocots commented Jun 21, 2024

constraint!(ocp, :initial; lb=[1,0,1], ub=[1,0,1], label=:initial_constraint)

Documentation

@PierreMartinon
Copy link
Member

PierreMartinon commented Jun 21, 2024

Ok, so basically everything after the constraint type is now a named argument.
Regarding the doc I would put at least one equality constraint example, currently they all have differnt bounds.

@PierreMartinon
Copy link
Member

PierreMartinon commented Jun 21, 2024

Another question @ocots :D
On the goddard problem, the following box constraint is fine

constraint!(ocp, :state, lb=[r0,v0,mf], ub=[r0+0.2,vmax,m0])

while the functional version fails (restoration error at first iteration)

constraint!(ocp1, :state, f=(x,v)->x, lb=[r0,v0,mf], ub=[r0+0.2,vmax,m0])

I tried splitting in 3 separate constraints, same problem. Did I miss something ?

To clarify: I don't need this specific formulation, I'm just trying to update my test cases with the different constraints types.

@jbcaillau
Copy link
Member Author

@PierreMartinon there is a difference (that should not suffice to alter solving, though) as

  • in the first case I suppose that the range is implemented as a box constraint in CTDirect.jl
  • while in the second case, a genuine (functional) constraint is added

Note that while the first syntax is allowed, it is more readable to write

constraint!(ocp, :state; rg=1:end, lb=[r0,v0,mf], ub=[r0+0.2,vmax,m0])

Currently fixing a few things in the constraint! function 🤞🏾

@PierreMartinon
Copy link
Member

Yup. As I said, not a blocking issue, I'm just trying to figure out the different possibilities.
I'll try to look more closely at the actual constraints in the defined ocp

@jbcaillau
Copy link
Member Author

Yup. As I said, not a blocking issue, I'm just trying to figure out the different possibilities. I'll try to look more closely at the actual constraints in the defined ocp

@PierreMartinon please drop a pointer towards the example not converging with

constraint!(ocp1, :state, f=(x,v)->x, lb=[r0,v0,mf], ub=[r0+0.2,vmax,m0])

@PierreMartinon
Copy link
Member

PierreMartinon commented Jun 24, 2024

Here you go. The one below (scroll) converges

# general definitions
Cd = 310
Tmax = 3.5
β = 500
b = 2
r0 = 1
v0 = 0
vmax = 0.1
m0 = 1
mf = 0.6
x0 = [ r0, v0, m0 ]
function F0(x)
    r, v, m = x
    D = Cd * v^2 * exp(-β*(r - 1))
    return [ v, -D/m - 1/r^2, 0 ]
end
function F1(x)
    r, v, m = x
    return [ 0, Tmax/m, -b*Tmax ]
end

# box constraints
ocp = Model(variable=true)
state!(ocp, 3)
control!(ocp, 1)
variable!(ocp, 1)
time!(ocp, t0=0, indf=1)
constraint!(ocp, :initial, lb=x0, ub=x0)
constraint!(ocp, :final, rg=3, lb=mf, ub=Inf)
constraint!(ocp, :state, lb=[r0,v0,mf], ub=[r0+0.2,vmax,m0])
constraint!(ocp, :control, lb=0, ub=1)
constraint!(ocp, :variable, lb=0.01, ub=Inf)
objective!(ocp, :mayer, (x0, xf, v) -> xf[1], :max)
dynamics!(ocp, (x, u, v) -> F0(x) + u*F1(x) )

sol = solve(ocp, grid_size=100, print_level=0, tol=1e-8)

but using the functional constraint fails

constraint!(ocp1, :state, f=(x,v)->x, lb=[r0,v0,mf], ub=[r0+0.2,vmax,m0])

@PierreMartinon
Copy link
Member

PierreMartinon commented Jun 25, 2024

@jbcaillau, with Joseph we may have found the answer: ipopt will internally project the initial guess inside the variable bounds if needed. Here for instance the default init (0.1) will be projected for both r and m.

When using a functional (nonlinear) constraint, there is no such initial guess adjustment, and for this problem in particular, having r<1 (earth radius) is known to be problematic.

I'll recheck with a more sensible initial guess and see if the functional constraint converges.

@jbcaillau
Copy link
Member Author

@PierreMartinon @joseph-gergaud nice! indeed, not having a box prevents Ipopt from making this educated guess.

@PierreMartinon
Copy link
Member

Confirmed, we get the convergence back when initializing the state with r>1. No more remarks for me here, you can close when you want.

@ocots
Copy link
Member

ocots commented Jun 28, 2024

@jbcaillau Please review what is done:

  •  suppress index in constraints
  • add in the doc for the constraints at least one equality constraint example, cf. here

@jbcaillau
Copy link
Member Author

@ocots closed

@jbcaillau Please review what is done:

  •  suppress index in constraints
  • add in the doc for the constraints at least one equality constraint example, cf. here

closed in favour of control-toolbox/OptimalControl.jl#155

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants