I feel this is a clever approach. Additionally, a more convenient way is to not call statements like ocp.cost.W_e and ocp.cost.yref_e when constructing the solver. By default, it will not need to consider various quantities related to the last point (the virtual point). Also, although external costs are troublesome to use, it can help validate the previous “virtual point” method. This is because *cost_expr_ext_cost_e seems to allow specifying the cost expression for just the last point separately. We can compare the results from the two methods to see if they are close.