\chapter{Trajectory Optimization} \label{traj_optimization} \section{Optimization of Boundary Value Problems} An approach is necessary, in trajectory optimization and many other fields, to optimize highly non-linear, unpredictable systems such as this. The field that developed to approach this problem is known as Non-Linear Programming (NLP) Optimization. A Non-Linear Programming Problem is defined by an attempt to optimize a function $f(\vec{x})$, subject to constraints $\vec{g}(\vec{x}) \le 0$ and $\vec{h}(\vec{x}) = 0$ where $n$ is a positive integer, $x$ is any subset of $R^n$, $g$ and $h$ can be vector valued functions of any size, and at least one of $f$, $g$, and $h$ must be non-linear. There are, however, two categories of approaches to solving an NLP. The first category, indirect methods, involve declaring a set of necessary and/or sufficient conditions for optimality. These conditions then allow the problem to be reformulated as a two point boundary value problem. Solving this boundary value problem involves determining a control law for the optimal path. Indirect approaches for spacecraft trajectory optimization have given us the Primer Vector Theory\cite{jezewski1975primer}. The other category is the direct methods. In a direct optimization problem, the cost function itself provides a value that an iterative numerical optimizer can measure itself against. The optimal solution is then found by varying the inputs $x$ until the cost function is reduced to a minimum value, often determined by its derivative jacobian. A number of tools have been developed to optimize NLPs via this direct method in the general case. Both of these methods have been applied to the problem of low-thrust interplanetary trajectory optimization \cite{Casalino2007IndirectOM} to find local optima over low-thrust control laws. It has often been found that indirect methods are more difficult to converge and require a better initial guess than the direct methods. However, they also require less parameters to describe the trajectory, since the solution of a boundary value problem doesn't require discretization of the control states. In this implementation, robustness is incredibly valuable, as the Monotonic Basin Hopping algorithm, discussed later, is leveraged to attempt to find all minima basins in the solution space by ``hopping'' around with different initial guesses. It is, therefore, important that the optimization routine be robust to poor initial guesses. Therefore, a direct optimization method was leveraged by transcribing the problem into an NLP and using IPOPT to find the local minima. \subsubsection{Non-Linear Solvers} One of the most common packages for the optimization of NLP problems is SNOPT\cite{gill2005snopt}, which is a proprietary package written primarily using a number of Fortran libraries by the Systems Optimization Laboratory at Stanford University. It uses a sparse sequential quadratic programming algorithm as its back-end optimization scheme. Another common NLP optimization packages (and the one used in this implementation) is the Interior Point Optimizer or IPOPT\cite{wachter2006implementation}. It uses an Interior Point Linesearch Filter Method and was developed as an open-source project by the organization COIN-OR under the Eclipse Public License. Both of these methods utilize similar approaches to solve general constrained non-linear problems iteratively. Both of them can make heavy use of derivative Jacobians and Hessians to improve the convergence speed and both have been ported for use in a number of programming languages, including in Julia, which was used for this project. This is by no means an exhaustive list, as there are a number of other optimization libraries that utilize a massive number of different algorithms. For the most part, the libraries that port these are quite modular in the sense that multiple algorithms can be tested without changing much source code. \subsubsection{Interior Point Linesearch Method} As mentioned above, this project utilized IPOPT which leveraged an Interior Point Linesearch method. A linesearch algorithm is one which attempts to find the optimum of a non-linear problem by first taking an initial guess $x_k$. The algorithm then determines a step direction (in this case through the use of either automatic differentiation or finite differencing to calculate the derivatives of the cost function) and a step length. The linesearch algorithm then continues to step the initial guess, now labeled $x_{k+1}$ after the addition of the ``step'' vector and iterates this process until predefined termination conditions are met. In this case, the IPOPT algorithm was used, not as an optimizer, but as a solver. For reasons that will be explained in the algorithm description in Section~\ref{algorithm} it was sufficient merely that the non-linear constraints were met, therefore optimization (in the particular step in which IPOPT was used) was unnecessary. \subsubsection{Shooting Schemes for Solving a Two-Point Boundary Value Problem} One straightforward approach to trajectory corrections is a single shooting algorithm, which propagates a state, given some control variables forward in time to the epoch of interest. The controls over this time period are then modified in an iterative process, using the correction scheme, until the target state and the propagated state matches. As an example, we can consider the Two-Point Boundary Value Problem (TPBVP) defined by: \begin{equation} y''(t) = f(t, y(t), y'(t)), y(t_0) = y_0, y(t_f) = y_f \end{equation} \noindent We can then redefine the problem as an initial-value problem: \begin{equation} y''(t) = f(t, y(t), y'(t)), y(t_0) = y_0, y'(t_0) = x \end{equation} \noindent With $y(t,x)$ as a solution to that problem. Furthermore, if $y(t_f, x) = y_f$, then the solution to the initial-value problem is also the solution to the TPBVP as well. Therefore, we can use a root-finding algorithm, such as the bisection method, Newton's Method, or even Laguerre's method, to find the roots of: \begin{equation} F(x) = y(t_f, x) - y_f \end{equation} \noindent To find the solution to the IVP at $x_0$, $y(t_f, x_0)$ which also provides a solution to the TPBVP. This technique for solving a Two-Point Boundary Value Problem can be visualized in Figure~\ref{single_shoot_fig}. \begin{figure}[H] \centering \includegraphics[width=\textwidth]{fig/single_shoot} \caption{Visualization of a single shooting technique over a trajectory arc} \label{single_shoot_fig} \end{figure} In this example, the initial trajectory is the green arc, which contains a certain control thrust $\Delta V_{init}$ and is propagated for a certain amount of time and results in the end state $x_{init}$. The target state $x_{final}$ can be achieved by varying the control and propagating forward in time until this final state is achieved. This type of shooting algorithm can be quite useful for simple cases such as this one. However, some problems require the use of a more flexible algorithm. In these cases, sometimes a multiple-shooting algorithm can provide that flexibility and reduced sensitivity. In a multiple shooting algorithm, rather than having a single target point at which the propagated state is compared, the target orbit is broken down into multiple arcs, then end of each of which can be seen as a separate target. At each of these points we can then define a separate control, which may include the states themselves. The end state of each arc and the beginning state of the next must then be equal for a valid arc (with the exception of velocity discontinuities if allowed for maneuvers at that point), as well as the final state matching the target final state. \begin{figure}[H] \centering \includegraphics[width=\textwidth]{fig/multiple_shoot} \caption{Visualization of a multiple shooting technique over a trajectory arc} \label{multiple_shoot_fig} \end{figure} In this example, it can be seen that there are now more constraints (places where the states need to match up, creating an $x_{error}$ term) as well as control variables (the $\Delta V$ terms in the figure). This technique actually lends itself very well to low-thrust arcs and, in fact, Sims-Flanagan Transcribed low-thrust arcs in particular, because there actually are control thrusts to be optimized at a variety of different points along the orbit. This is, however, not an exhaustive description of ways that multiple shooting can be used to optimize a trajectory, simply the most convenient for low-thrust arcs. \section{Monotonic Basin Hopping Algorithms} The techniques discussed thus far are useful for finding local optima. However, we would also like to traverse the search space in an attempt to determine the global optima over the entire search space. One approach to this would be to discretize the search space and test each point as an input to a local optimization scheme. In order to achieve sufficient coverage of the search space, however, this often requires long processing times in a high-dimensional environment. To solve this problem, a technique was described by Wales and Doye in 1997 \cite{wales1997global} called a basin-hopping algorithm. This algorithm performs a random perturbation of the input states, optimizes using a local optimizer, then either accepts the new coordinates and performs a further perturbation, or rejects them and tests a new set of randomly-generated inputs. This allows the algorithm to test many different regions of the search space in order to determine which ``basins'' contain local optima. If these local optima are found, the algorithm can attempt to improve the local optima based on parameters defined by the algorithm designer (by perturbation and re-applying the local optimization scheme) or search for a new basin in the search space.