A bilevel optimization is a type of mathematical program where one optimization problem (the lower-level optimization problem) is embedded inside another optimization problem (the upper-level optimization problem), and the lower-level optimization problem is constrained by the upper-level optimization problem [1]}. The hierarchical nature of bilevel or multi-level optimization makes it rather appropriate for solving complex optimization problems with more than one level, i.e., the coefficients of the lower level’s optimization problem are dependent on the upper level’s optimization results. In robotics, bilevel optimization has been deployed in optimal control [2]} and various kinds of robots’ motion planning [3]}, [4]}, [5]}. Sun et al. [6]} present a method using bilevel optimization to conduct trajectory optimization with optimal time allocation. The time allocation is solved in the upper-level problem and passed to the lower-level one as a parameter. The analytical gradients
of the optimal cost with respect to the time allocation are obtained with Karush–Kuhn–Tucker (KKT) conditions of the lower-level problem. Using the analytical gradient with line search, the cost in the upper-level problem is reduced, and the updated time allocation updates the parameters in the lower-level problem to generate the trajectory. In the bilevel optimization problem, the derivation of gradients is crucial. One method of obtaining gradients is by analyzing the sensitivity of the optimization problem [7]}. A similar approach for obtaining the analytical gradient of the solution of a QP with respect to the QP's parameters via implicit differentiation over the KKT condition is shown in [8]}.
