예제 #1
0
def moon_lander_mpo(moon_lander_ocp):
    mpo, post = mp.solve(moon_lander_ocp,
                         n_segments=20,
                         poly_orders=3,
                         scheme="LGR",
                         plot=False)
    mpo = mp.mpopt(moon_lander_ocp, 20, 3)
    mpo.validate()

    return mpo
예제 #2
0
ocp = mp.OCP(n_states=1, n_controls=1, n_phases=1)

ocp.dynamics[0] = lambda x, u, t: [-x[0] * x[0] * x[0] + u[0]]
ocp.running_costs[0] = lambda x, u, t: 0.5 * (x[0] * x[0] + u[0] * u[0])
ocp.terminal_constraints[0] = lambda xf, tf, x0, t0: [xf[0] - 1.0]

ocp.x00[0] = 1
ocp.lbtf[0] = ocp.ubtf[0] = 1000.0
ocp.scale_t = 1 / 1000.0

ocp.validate()

if __name__ == "__main__":
    seg, p = 15, 15
    mpo = mp.mpopt(ocp, seg, p)
    sol = mpo.solve()
    post = mpo.process_results(sol, plot=True)
    mp.plt.title(
        f"non-adaptive solution segments = {mpo.n_segments} poly={mpo.poly_orders[0]}"
    )

    mpo = mp.mpopt_h_adaptive(ocp, seg, p)
    sol = mpo.solve(max_iter=3,
                    mpopt_options={
                        "method": "residual",
                        "sub_method": "merge_split"
                    })
    post = mpo.process_results(sol, plot=True)
    mp.plt.title(
        f"Adaptive solution: merge_split : segments = {mpo.n_segments} poly={mpo.poly_orders[0]}"
예제 #3
0

ocp.terminal_constraints[0] = terminal_constraints0

ocp.tf0[0] = 4.0
ocp.x00[0] = [10.0, -2.0]
ocp.lbx[0] = [-20.0, -20.0]
ocp.ubx[0] = [20.0, 20.0]
ocp.lbu[0] = 0
ocp.ubu[0] = 3
ocp.lbtf[0], ocp.ubtf[0] = 3, 5

ocp.validate()

if __name__ == "__main__":
    mpo = mp.mpopt(ocp, 5, 4)
    sol = mpo.solve()
    post = mpo.process_results(sol, plot=True)
    mp.plt.title(
        f"non-adaptive solution segments = {mpo.n_segments} poly={mpo.poly_orders[0]}"
    )

    mpo = mp.mpopt_h_adaptive(ocp, 10, 4)
    sol = mpo.solve(max_iter=3,
                    mpopt_options={
                        "method": "residual",
                        "sub_method": "merge_split"
                    })
    post = mpo.process_results(sol, plot=True)
    mp.plt.title(
        f"Adaptive solution: merge_split : segments = {mpo.n_segments} poly={mpo.poly_orders[0]}"
예제 #4
0
def van_der_pol_mpo_cgl(van_der_pol_ocp):
    mpo = mp.mpopt(van_der_pol_ocp, 1, 15, "CGL")
    mpo.validate()

    return mpo
예제 #5
0
def van_der_pol_mpo(van_der_pol_ocp):
    mpo = mp.mpopt(van_der_pol_ocp, 1, 15, "LGR")
    mpo.validate()

    return mpo
예제 #6
0
def two_phase_schwartz_mpo(two_phase_schwartz_ocp):
    mpo = mp.mpopt(two_phase_schwartz_ocp, 1, 15, "LGL")
    mpo.validate()

    return mpo
예제 #7
0
def hyper_sensitive_mpo(hyper_sensitive_ocp):
    mpo = mp.mpopt(hyper_sensitive_ocp, 15, 15)
    mpo.validate()

    return mpo
예제 #8
0
def test_mpo(test_ocp):
    mpo = mp.mpopt(test_ocp)
    mpo.validate()

    return mpo
예제 #9
0
ocp.lbtf = np.array([[t1], [t2], [t3], [t4 - 100]])
ocp.ubtf = np.array([[t1], [t2], [t3], [t4 + 100]])

# Event constraint bounds on states : State continuity/disc.
lbe0 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -6 * mdrySrb]
lbe1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -3 * mdrySrb]
lbe2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -mdryFirst]
ocp.lbe = np.array([lbe0, lbe1, lbe2])
ocp.ube = np.array([lbe0, lbe1, lbe2])
ocp.validate()

# Solve with drag disables
ocp.dynamics = get_dynamics(0)

if __name__ == "__main__":
    mpo = mp.mpopt(ocp, 1, 11)
    sol = mpo.solve()

    # Solve with drag enabled and initial guess
    ocp.dynamics = get_dynamics(1)
    ocp.validate()

    mpo._ocp = ocp
    sol = mpo.solve(sol,
                    reinitialize_nlp=True,
                    nlp_solver_options={"ipopt.acceptable_tol": 1e-6})
    print("Final mass : ", round(-sol["f"].full()[0, 0] * m0, 4))

    mp.post_process._INTERPOLATION_NODES_PER_SEG = 200
    # Post processing
    post = mpo.process_results(sol, plot=False, scaling=False)