Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Initial guess constraint violation #155

Open
ffgiardina opened this issue May 15, 2020 · 5 comments
Open

Initial guess constraint violation #155

ffgiardina opened this issue May 15, 2020 · 5 comments

Comments

@ffgiardina
Copy link
Contributor

Hi,
I'm setting an initial guess for the optimization with problem.initialize, and even though the constraints should be satisfied, the "constraint violation" output is rather high (I provide values for state and control for every grid point with problem.initialize). Any suggestions on how to check if the issue comes from the system dynamics constraints? Thanks!

@jkoendev
Copy link
Member

jkoendev commented May 17, 2020

Hi, there is no direct way at the moment to evaluate the constraints function for the different type of constraints. You could try to evaluate the (CasaADi ) constraints function on the initial guess and see if you can figure out which constraints are violated. For this you can set a breakpoint in +ocl/+casadi/CasadiSolver.m around line 346 before this line which calls the solver:

sol = self.nlpData.solver.call(args);

Then create a CasaADi function and evaluate it with the initial guess

g = casadi.Function('g', {self.nlpData.casadiNLP.x}, {self.nlpData.casadiNLP.g})
constraints = full(g(v0));

figure; hold on; grid minor;
lb = self.nlpData.constraints_LB;
ub = self.nlpData.constraints_UB;
lb(isinf(lb)) = min(constraints );
ub(isinf(ub)) = max(constraints);
stairs(lb, 'g')
stairs(ub, 'r')

stairs(constraints, 'k--', 'LineWidth',1)

ill post an example in a minute

@jkoendev
Copy link
Member

jkoendev commented May 17, 2020

For the Racecar example it looks like this:

constraints_racecar

For each control interval, there are in this order

  • 4 grid constraints (yellow)
  • 21 dynamics constraints for d=3 and n_x=7 (green)
  • 7 parameters (blue)
  • 1 constraint for the time (red)
  • 7 continuity constraints, because number of states n_x=7 (purple)

Red and green lines are upper and lower bounds for the constraints. The constraints are in the form g<=0 or g==0, so the upper bound is always 0 and the lower bound either 0 or minus infinity.

@ffgiardina
Copy link
Contributor Author

This is very helpful -- thanks very much!
I noticed that the user-provided control values are not assigned in getInitialGuessWithUserData.m. After changing that the obtained solution is as expected -- although I still can't figure out why the constraint violation is rather large at the initial step. What is the collocation method used in openOCL (e.g. trapezoidal or Hermite-Simpson?)

@jkoendev
Copy link
Member

ah yes the controls were missing when using .initialize(), if you fixed you could do a pull request, or i will fix it in the coming days..
The collocation method is based on Lagrange polynomials at Radau points.

@ffgiardina
Copy link
Contributor Author

Great, thanks for the info! I just did a pull request as well.

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

No branches or pull requests

2 participants