casadi joel andersson moritz diehl
play

CasADi Joel Andersson Moritz Diehl Department of Electrical - PowerPoint PPT Presentation

Link oping, June 2011 CasADi Joel Andersson Moritz Diehl Department of Electrical Engineering (ESAT-SCD) & Optimization in Engineering Center (OPTEC) Katholieke Universiteit Leuven OPTEC (ESAT SCD) Katholieke Universiteit Leuven


  1. Link¨ oping, June 2011 CasADi Joel Andersson Moritz Diehl Department of Electrical Engineering (ESAT-SCD) & Optimization in Engineering Center (OPTEC) Katholieke Universiteit Leuven OPTEC (ESAT – SCD) – Katholieke Universiteit Leuven

  2. Outline Background 1 CasADi 2 3 Optimal control using CasADi

  3. Motivation Motivation – Large-scale Optimal Control Problems (OCP) � T min l ( t , x , u , p ) dt + E ( x ( T ) , p ) x , u , p 0 subj. to x = f ( t , x , u , p ) = 0 ˙ t ∈ [0 , T ] h ( t , x , u , p ) ≤ 0 t ∈ [0 , T ] (1) x (0) = x 0 x min ≤ x ≤ x max t ∈ [0 , T ] u min ≤ u ≤ u max t ∈ [0 , T ] p min ≤ p ≤ p max Here x ( · ) ∈ R Nx (differential) states, u ( · ) ∈ R Nu free control signals and p ∈ R Np free parameters. CasADi — Joel Andersson Moritz Diehl

  4. Motivation Solving optimal control problems Methods for solving OCP’s: Dynamic programming/HJB ”Smart exhaustive search” Indirect methods ”Solve necessary conditions for optimality” Direct methods ”Reformulate as a nonlinear programming problem (NLP)” CasADi — Joel Andersson Moritz Diehl

  5. Motivation Solving optimal control problems Methods for solving OCP’s: Dynamic programming/HJB ”Smart exhaustive search” Indirect methods ”Solve necessary conditions for optimality” Direct methods ”Reformulate as a nonlinear programming problem (NLP)” Direct methods Single shooting: parametrize only controls, eliminate state with ODE/DAE integrators Simultaneous methods: parametrize controls and state Direct collocation: Fine grid – interpolate between gridpoints Direct multiple shooting: Coarse grid – integrate between gridpoints Solve NLP with (structure exploiting) SQP or IP method CasADi — Joel Andersson Moritz Diehl

  6. Background Automatic differentiation, AD Efficient procedure to automatically calculate derivatives: ∂ F F ( x ) : R n → R m ( x ) : R n → R m × n ⇒ J ( x ) = (2) ∂ x CasADi — Joel Andersson Moritz Diehl

  7. Background Automatic differentiation, AD Efficient procedure to automatically calculate derivatives: ∂ F F ( x ) : R n → R m ( x ) : R n → R m × n ⇒ J ( x ) = (2) ∂ x How AD works Write F as a sequence of elementary operations: y i − n = x i , i ∈ { 1 , . . . , n } independent inputs (3) y i = f i ( y ji , y ki ) , j i < i , k i < i i ∈ { 1 , . . . , p } intermediate calculations (4) z j = y ij , j ∈ { 1 , . . . , m } function outputs (5) Consider the equality (with y = [ y 1 , . . . , y p ]): � y � = ˜ F ( x , y ) (6) z CasADi — Joel Andersson Moritz Diehl

  8. Background Now differentiate the extended equation � y � � y ˙ � � A L � � x ˙ � = ˜ F ( x , y ) ⇒ = (7) z z ˙ B M y ˙ CasADi — Joel Andersson Moritz Diehl

  9. Background Now differentiate the extended equation � y � � y ˙ � � A L � � x ˙ � = ˜ F ( x , y ) ⇒ = (7) z z ˙ B M y ˙ Eliminate ˙ y B + M ( I − L ) − 1 A � � z = ˙ ˙ x = J ˙ x (8) CasADi — Joel Andersson Moritz Diehl

  10. Background Now differentiate the extended equation � y � � y ˙ � � A L � � x ˙ � = ˜ F ( x , y ) ⇒ = (7) z z ˙ B M y ˙ Eliminate ˙ y B + M ( I − L ) − 1 A � � z = ˙ ˙ x = J ˙ x (8) Forward and adjoint mode AD Cheap to multiply J with a vector ( A , B , L , M sparse, I − L lower triangular): CasADi — Joel Andersson Moritz Diehl

  11. Background Now differentiate the extended equation � y � � y ˙ � � A L � � x ˙ � = ˜ F ( x , y ) ⇒ = (7) z z ˙ B M y ˙ Eliminate ˙ y B + M ( I − L ) − 1 A � � z = ˙ ˙ x = J ˙ x (8) Forward and adjoint mode AD Cheap to multiply J with a vector ( A , B , L , M sparse, I − L lower triangular): From the right ( forward mode ): J v = B v + M ( I − L ) − 1 A v From the left ( adjoint mode ): v T J = v T B + v T M ( I − L ) − 1 A CasADi — Joel Andersson Moritz Diehl

  12. Background Now differentiate the extended equation � y � � y ˙ � � A L � � x ˙ � = ˜ F ( x , y ) ⇒ = (7) z z ˙ B M y ˙ Eliminate ˙ y B + M ( I − L ) − 1 A � � z = ˙ ˙ x = J ˙ x (8) Forward and adjoint mode AD Cheap to multiply J with a vector ( A , B , L , M sparse, I − L lower triangular): From the right ( forward mode ): J v = B v + M ( I − L ) − 1 A v From the left ( adjoint mode ): v T J = v T B + v T M ( I − L ) − 1 A To calculate the full Jacobian, multiply by several forward and/or adjoint directions NP-hard optimization problem to find the least number of directions AD software tools: ADOL-C, CppAD, OpenAD, . . . CasADi — Joel Andersson Moritz Diehl

  13. Outline Background 1 CasADi 2 3 Optimal control using CasADi

  14. CasADi Existing tools for OCP Tools exist that accept OCP:s in a standard form and solves the problem... Shooting methods (e.g. MUSCOD-II, ACADO Toolkit) Direct collocation (e.g. DIRCOL) ... CasADi — Joel Andersson Moritz Diehl

  15. CasADi Existing tools for OCP Tools exist that accept OCP:s in a standard form and solves the problem... Shooting methods (e.g. MUSCOD-II, ACADO Toolkit) Direct collocation (e.g. DIRCOL) ... ... but advanced users often prefer to take the “NLP approach” (using e.g. AMPL) CasADi — Joel Andersson Moritz Diehl

  16. CasADi Existing tools for OCP Tools exist that accept OCP:s in a standard form and solves the problem... Shooting methods (e.g. MUSCOD-II, ACADO Toolkit) Direct collocation (e.g. DIRCOL) ... ... but advanced users often prefer to take the “NLP approach” (using e.g. AMPL) The user reformulates the OCP as an NLP Derivative information is generated automatically and passed to the NLP solver CasADi — Joel Andersson Moritz Diehl

  17. CasADi Existing tools for OCP Tools exist that accept OCP:s in a standard form and solves the problem... Shooting methods (e.g. MUSCOD-II, ACADO Toolkit) Direct collocation (e.g. DIRCOL) ... ... but advanced users often prefer to take the “NLP approach” (using e.g. AMPL) The user reformulates the OCP as an NLP Derivative information is generated automatically and passed to the NLP solver Advantages: Can formulate arbitrarily complex non-standard OCP:s User gets a better insight Drawback: Until now only for collocation methods CasADi — Joel Andersson Moritz Diehl

  18. CasADi What is CasADi? CasADi = Computer algebra system for Automatic Differentiation. An open-source (LGPL) symbolic framework for quick, yet efficient, implementation of derivative based algorithms for dynamic optimization CasADi — Joel Andersson Moritz Diehl

  19. CasADi What is CasADi? CasADi = Computer algebra system for Automatic Differentiation. An open-source (LGPL) symbolic framework for quick, yet efficient, implementation of derivative based algorithms for dynamic optimization Takes the NLP approach to solving optimal control problems and extends it to shooting methods (multiple shooting method in 30–50 lines) CasADi — Joel Andersson Moritz Diehl

  20. CasADi What is CasADi? CasADi = Computer algebra system for Automatic Differentiation. An open-source (LGPL) symbolic framework for quick, yet efficient, implementation of derivative based algorithms for dynamic optimization Takes the NLP approach to solving optimal control problems and extends it to shooting methods (multiple shooting method in 30–50 lines) www.casadi.org CasADi — Joel Andersson Moritz Diehl

  21. CasADi The core of CasADi A minimalistic Computer Algebra System (CAS) written in self-contained C++ CasADi — Joel Andersson Moritz Diehl

  22. CasADi The core of CasADi A minimalistic Computer Algebra System (CAS) written in self-contained C++ Matlab-like syntax “everything is a matrix” CasADi — Joel Andersson Moritz Diehl

  23. CasADi The core of CasADi A minimalistic Computer Algebra System (CAS) written in self-contained C++ Matlab-like syntax “everything is a matrix” Use from C++ or Python (soon also Octave) CasADi — Joel Andersson Moritz Diehl

  24. CasADi The core of CasADi A minimalistic Computer Algebra System (CAS) written in self-contained C++ Matlab-like syntax “everything is a matrix” Use from C++ or Python (soon also Octave) 8 flavors of automatic differentiation CasADi — Joel Andersson Moritz Diehl

  25. CasADi The core of CasADi A minimalistic Computer Algebra System (CAS) written in self-contained C++ Matlab-like syntax “everything is a matrix” Use from C++ or Python (soon also Octave) 8 flavors of automatic differentiation Forward or adjoint mode CasADi — Joel Andersson Moritz Diehl

  26. CasADi The core of CasADi A minimalistic Computer Algebra System (CAS) written in self-contained C++ Matlab-like syntax “everything is a matrix” Use from C++ or Python (soon also Octave) 8 flavors of automatic differentiation Forward or adjoint mode Directional derivatives or source-to-source transformation with new graph for Jacobian CasADi — Joel Andersson Moritz Diehl

  27. CasADi The core of CasADi A minimalistic Computer Algebra System (CAS) written in self-contained C++ Matlab-like syntax “everything is a matrix” Use from C++ or Python (soon also Octave) 8 flavors of automatic differentiation Forward or adjoint mode Directional derivatives or source-to-source transformation with new graph for Jacobian Scalar or matrix graph representation CasADi — Joel Andersson Moritz Diehl

Recommend


More recommend