Esempio n. 1
0
            "dual_inf_tol": 1e-3,
            "constr_viol_tol": 1e-3,
            "compl_inf_tol": 1e-3,
            "linear_solver": "ma57",
            "max_iter": 100,
            "hessian_approximation": "exact",
        },
        return_objectives=True,
    )
    toc_ipopt = time() - tic

    # --- Show results --- #
    print("\n\n")
    print("Results using ACADOS")
    print(f"Final objective: {np.nansum(sol_obj_acados)}")
    analyse_acados = Objective.Printer(ocp_acados, sol_obj_acados)
    analyse_acados.by_function()
    print(f"Time to solve: {sol_acados['time_tot']}sec")
    print(f"")

    print(
        f"Results using Ipopt{'' if warm_start_ipopt_from_acados_solution else ' not'} warm started from ACADOS solution"
    )
    print(f"Final objective : {np.nansum(sol_obj_ipopt)}")
    analyse_ipopt = Objective.Printer(ocp_ipopt, sol_obj_ipopt)
    analyse_ipopt.by_function()
    print(f"Time to solve: {sol_ipopt['time_tot']}sec")
    print(f"")

    result_acados = ShowResult(ocp_acados, sol_acados)
    result_ipopt = ShowResult(ocp_ipopt, sol_ipopt)
Esempio n. 2
0
    toc = time() - tic
    print(f"Time to solve : {toc}sec")

    # --- Simulation --- #
    # It is not an optimal control, it only apply a Runge Kutta at each nodes
    Simulate.from_solve(ocp, sol, single_shoot=True)
    Simulate.from_data(ocp, Data.get_data(ocp, sol), single_shoot=False)

    # --- Access to all iterations  --- #
    if sol_iterations:  # If the processor is too fast, this will be empty since it is attached to the update function
        nb_iter = len(sol_iterations)
        third_iteration = sol_iterations[2]

    # --- Print objective cost  --- #
    print(f"Final objective value : {np.nansum(sol_obj)} \n")
    analyse = Objective.Printer(ocp, sol_obj)
    analyse.by_function()
    analyse.by_nodes()

    # --- Save result of get_data --- #
    ocp.save_get_data(
        sol, "pendulum.bob",
        sol_iterations)  # you don't have to specify the extension ".bob"

    # --- Load result of get_data --- #
    with open("pendulum.bob", "rb") as file:
        data = pickle.load(file)

    # --- Save the optimal control program and the solution --- #
    ocp.save(sol,
             "pendulum.bo")  # you don't have to specify the extension ".bo"