# Introduction

The HamPath package [2] is a an open-source software developed to solve optimal control problems via indirect methods but also to study Hamiltonian systems. HamPath is developed since 2009 by members of the APO (Algorithmes Parallèles et Optimisation) team from Institut de Recherche en Informatique de Toulouse, jointly with colleagues from the Université de Bourgogne. HamPath is distributed under the *GNU Lesser General Public License*, and is free for both academic and industrial use.

The main use of HamPath is to study and solve optimal control problems depending on parameters and of the general form:

#### Keywords.

- Geometric optimal control;
- State and/or control constraints;
- Maximum principle;
- Simple and multiple shooting methods;
- Homotopy (or differential path following);
- Second order conditions of optimality (conjugate points);

#### From the user sight.

Applying the maximum principle leads to define a set of **Hamiltonians** and a **Boundary Value Problem**, which is described by a set of non linear equations, that can be grouped together in what we call the shooting equations.

HamPath compiles the **Fortran** codes of the (maximized) Hamiltonians and the shooting function (defined by the shooting equations) and produces a collection of **Matlab, Octave, Fortran or Python** functions (depending on the chosen user interface) which allows first of all to compute the solutions of the Hamiltonian systems and to solve the implemented shooting equations.

However, it is well known that the main difficulty to solve such problems – with indirect methods based on Newton algorithms – is to find a good initial guess. So a differential path following method has been implemented which makes HamPath the natural extension of the cotcot package [1]. It is also possible to compute Jacobi fields of the Hamiltonian systems to check order two conditions of optimality and look for conjugate points, as cotcot does.

#### Please Cite Us.

Since a lot of time and effort has gone into HamPath’s development, please cite the publication [2] if you are using HamPath for your own research.

# Presentation of the overall strategic and algorithmic approach

Let consider a simple optimal control problem with *q:=(x,v)* the state and with *a* a parameter:

where the initial and final times are fixed (*t _{0}=0* and

*t*) and the boundaries are fixed to

_{f}=1*q*and

_{0}:= q(0) = (-1,0)*q*. Define the

_{f}:= q(1) = (0,0)*pseudo-Hamiltonian*depending on

*a*:with

*n=2*the state dimension,

*p:=(p*and we fix

_{x},p_{v})*p*(normal case). The application of the

^{0}= -1*Pontryagin Maximum Principle*(PMP) tells us that the minimizing trajectories

*q(·)*are the projection of absolutely continuous

*extremals*

*z(·) := (q(·),p(·))*satisfying a.e.with

**Definition 1** *(Maximized Hamiltonian).*

the *maximized* (or true) *Hamiltonian*, where the optimal control isand where the *Hamiltonian system* is given by

**Definition 2** *(Exponential mapping). **For fixed z_{0} and T >= 0, we define in a neighborhood of (T,z_{0}) (if possible), *

*the following*as the trajectory

*exponential mapping**z(·)*at time

*t*satisfying the Hamiltonian system for every

*s*in

*[0,t]*, with

*z(0) = z*.

_{0}The minimizing curves *q(·)* are the projection of *BC-extremals*, *i.e. *extremals which satisfy the boundary conditions, and we can define the following *shooting function*:

**Definition 3** *(Shooting function).*

* *The *simple shooting method* consists in finding a zero of the simple shooting function *S _{a}*,

*i.e.*in solving

*S*. This is done by Newton type methods. A zero of the simple shooting function satisfies the necessary conditions of optimality given by the PMP.

_{a}(y) = 0**Remark 4. ***S _{a}* depends on

*a*, and we write

*S(y,a) := S*the

_{a}(y)*homotopic function*(instead of shooting function) when we consider the parameter

*a*as an

*independent variable*. With HamPath, it is possible to solve

*S(y,a) = 0*for

*a*in

*[0,1]*for instance, using differential path following methods. In this case, we say that

*a*is a homotopic parameter.

If we notethen the trajectory *q(·,q _{0},p_{0})* ceases to be optimal after the time

*t*if

_{c}*p*is a critical point of the mapping

_{0}*q(t*. In this case, we name

_{c},q_{0},·)*t*a conjugate time and

_{c}*q(t*the associated conjugate point. Let give the following definition.

_{c},q_{0},p_{0})**Definition 5** *(Jacobi field). **The differential equation on [0,t_{f}] *is called a

*Jacobi equation*, or

*variational system*, along the extremal

*z(·)*. A solution

*J(·)*of the Jacobi equation along

*z(·) is called a*

*Jacobi field*and we writeAs a conclusion, it comes that if

*t*is a conjugate time thenis not of full rank

_{c}*n*.

#### Summary of HamPath possibilities.

The idea of HamPath is to produce a collection of numerical functions in order to solve general optimal control problems. The user must only implement the maximized Hamiltonian (definition 1) and the shooting function (definition 3). The different numerical functions can be used to:

- compute the solutions of the
*exponential mapping*(definition 2); - solve the
*shooting equations*(definition 3); - compute the
*set of zeros*of a*homotopic function*(remark 4); - compute the
*Jacobi fields*(definition 5) and check if there exists any conjugate points.

#### Schematic view of HamPath.

In the following figure, the part below the doted lines is a fragment of the outputs of HamPath which is in the language chosen during the installation: it may be chosen among Fortran, Python, Matlab (only) or both Matlab and Octave. AD stands for Automatic Differentiation, RK for Runge-Kutta integrators used to solve ordinary differential equations, Newton for Newton-type methods to solve non-linear equations and QR for QR factorization.

# References

- [1]
- B. Bonnard, J.-B. Caillau & E. Trélat,

*Cotcot: short-reference manual. http://apo.enseeiht.fr/cotcot*,

Rapport de recherche RT/APO/05/1, Institut National Polytechnique de Toulouse, Toulouse, France (2005). - [2]
- J.-B. Caillau, O. Cots & J. Gergaud,

*HamPath: on solving optimal control problems by indirect and path following methods.*,

http://hampath.org.