AS-RTI benchmark: Understanding of Cost Calculation

Hi :wave:

In AS-RTI-acados/pendulum_benchmark.py at 4349509154b127b4c36ef95ebef839351e494692 路 FreyJo/AS-RTI-acados 路 GitHub, may I ask what terminal_cost_state is here? And why does cost_total need to add terminal_cost_state item?

def add_total_cost_to_results(results):
    x_end = results['x_traj'][-1]
    terminal_cost_state = x_end[-1]
    x_og_vec = np.expand_dims(x_end[:dummy_model_params.nx_original], axis=1)
    terminal_cost_term = (x_og_vec.T @ dummy_mpc_params.P @ x_og_vec)[0][0]
    # intermediate terminal cost
    # i_mid = int(results['x_traj'].shape[0]/2)
    # x_mid = results['x_traj'][i_mid]
    # x_og_vec = np.expand_dims(x_mid[:dummy_model_params.nx_original], axis=1)
    # intermediate_terminal_cost_term = (x_og_vec.T @ dummy_mpc_params.P @ x_og_vec)[0][0]
    results['cost_total'] = terminal_cost_state + terminal_cost_term
    return results

Looking forward to your response锛乀hank you!

Hi,
for the simulation, we used a cost state to very accurately integrate the cost term over the simulation, this is terminal_cost_state here.
Additionally, we added the terminal_cost_term, which is the terminal cost of the OCP evaluated at the final state of the simulation.
Best,
Jonathan