def test_offramp_network():
    n = 5
    t = 15
    fw = CTMFreeway.standard(n)
    ic = InitialConditions.blank(n)
    bc = BoundaryConditions.blank(n, t)
    ic.mainline[:] = 2.0
    bc.demand[:, :4] = .3
    bc.split_ratios[:, :] = .8
    scen = Scenario(fw, ic, bc)
    IpOptSolver(n_iters=100).solve(CTMAdjoint(scen), scen.no_control().flatten())
Beispiel #2
0
def test_offramp_network():
    beta_op.beta = 200.0
    beta_op.factor = 1.000
    beta_op.beta_admm_factor = 1.000
    beta_op.inner_iters = 15
    beta = 10.0
    n = 5
    t = 15
    fw = CTMFreeway.standard(n)
    ic = InitialConditions.blank(n)
    bc = BoundaryConditions.blank(n, t)
    ic.mainline[:] = 2.0
    bc.demand[:, :4] = 0.3
    bc.split_ratios[:, :] = 0.8
    scen = Scenario(fw, ic, bc)
    print scen.ttt(scen.simulate())
    sln = CtmAdjointAdmm.from_full_scenario(scen, 2, beta=beta, n_iters=400).solve().density_summary()
Beispiel #3
0
def test_congestion():
    beta_op.beta = 50.0
    beta_op.factor = 1.02
    beta_op.factor = 1.000
    beta_op.beta_admm_factor = 1.000
    n, t = 4, 4
    scen_full = Scenario.blank(n, t)
    scen_full.ic.mainline[1] = 1.0
    scen_full.ic.mainline[2] = 1.8
    sln = CtmAdjointAdmm.from_full_scenario(scen_full, 2, beta=30.0, n_iters=400).solve()
    sln.density_summary()
    assert_less(sln.history.x[-1], 0.01)
    assert_less(sln.history.y[-1], 0.01)
Beispiel #4
0
def test_pass_info():
    beta_op.beta = 1.0
    beta_op.factor = 1.02
    beta_op.factor = 1.000
    beta_op.beta_admm_factor = 1.000
    n, t = 10, 10
    scen_full = Scenario.blank(n, t)
    scen_full.ic.mainline[0] = 0.5
    admm = CtmAdjointAdmm.from_full_scenario(scen_full, 5, beta=30.0, n_iters=400)
    d1 = admm.l_scen.simulate(admm.l_scen.no_control()).density
    d2 = admm.r_scen.simulate(admm.r_scen.no_control()).density
    sln = admm.solve()
    d3 = sln.l.fs(sln.l.construct_control(sln.cl)).density
    d4 = sln.r.fs(sln.r.construct_control(sln.cr)).density

    subplot(2, 2, 1)
    pcolor(d1, cmap="binary", vmin=0.0, vmax=1.0)
    xlabel("Time")
    ylabel("Space")
    title("Initial Upstream Subnetwork")
    colorbar()
    subplot(2, 2, 2)
    pcolor(d2, cmap="binary", vmin=0.0, vmax=1.0)
    xlabel("Time")
    ylabel("Space")
    title("Initial Downstream Subnetwork")
    colorbar()
    subplot(2, 2, 3)
    pcolor(d3, cmap="binary", vmin=0.0, vmax=1.0)
    xlabel("Time")
    ylabel("Space")
    title("Final Upstream Subnetwork")
    colorbar()
    subplot(2, 2, 4)
    pcolor(d4, cmap="binary", vmin=0.0, vmax=1.0)
    xlabel("Time")
    ylabel("Space")
    title("Final Downstream Subnetwork")
    colorbar()
    savefig("init-final.pdf")

    sln.density_summary()
    cl = sln.l.construct_control(sln.cl)
    cr = sln.r.construct_control(sln.cr)
    assert_array_almost_equal(cl[0][-2:, :], cr[0][:2, :])
    assert_array_almost_equal(cl[1], [0, 0, 0.5, 0], 2)
    assert_array_almost_equal(cr[1], [0, 0.5, 0, 0], 2)
    assert_almost_equals(sln.history.x[-1], 0.0, 2)
    assert_almost_equals(sln.history.y[-1], 0.0, 2)
Beispiel #5
0
def test_two_length():
    beta_op.beta = 50.0
    # beta_op.beta = 0.8
    beta_op.factor = 1.02
    beta_op.beta = 100.0
    beta_op.factor = 1.02
    beta_op.factor = 1.000
    beta = 100.0
    beta_op.beta_admm_factor = 1.000
    beta_op.inner_iters = 100
    n, t = 2, 2
    scen_full = Scenario.blank(n, t)
    scen_full.ic.mainline[1] = 0.5
    sln = CtmAdjointAdmm.from_full_scenario(scen_full, 1, beta=beta, n_iters=20).solve()
    sln.density_summary()
    cl = sln.l.construct_control(sln.cl)
    cr = sln.r.construct_control(sln.cr)
    assert_array_almost_equal(cl[0][-2:, :], cr[0][:2, :])
    assert_array_almost_equal(cl[1], [0, 0, 0.5, 0], 2)
    assert_array_almost_equal(cr[1], [0, 0.5, 0, 0], 2)
    assert_almost_equals(sln.history.x[-1], 0.0, 2)
    assert_almost_equals(sln.history.y[-1], 0.0, 2)
Beispiel #6
0
def test_smoother():
    beta_op.beta = 20.0
    beta_op.factor = 1.000
    beta_op.beta_admm_factor = 1.000
    beta_op.inner_iters = 30
    beta = 1.0
    n = 6
    t = 10
    fw = CTMFreeway.standard(n)
    ic = InitialConditions.blank(n)
    bc = BoundaryConditions.blank(n, t)
    ic.mainline[:] = 1.0
    ic.queue[0] = 0.5
    ic.queue[[3]] = 0.5
    bc.demand[0, :] = 0.5
    bc.demand[[1, 4], :2] = 0.3
    scen = Scenario(fw, ic, bc)
    print scen.ttt(scen.simulate())
    scen.simulate().plot()
    # IpOptSolver(n_iters=100).solve(CTMAdjoint(scen), scen.no_control().flatten())
    # u_star = AcceleratedGradient(n_iters=40, beta=50.0, lb=0.0, ub=1.0).solve(CTMAdjoint(scen),
    #                                                                         scen.no_control().transpose().flatten())
    #
    #
    # print scen.ttt(scen.simulate(u_star))
    # scen.simulate(u_star).plot()
    sln = CtmAdjointAdmm.from_full_scenario(scen, 3, beta=beta, n_iters=100).solve()
    u_star = sln.construct_control()
    sln.density_summary()
    print "###########"
    print CTMAdjoint(scen).j(scen.simulate(u_star), u_star)
    print scen.ttt(scen.simulate(u_star))
    u_star = AcceleratedGradient(n_iters=20, beta=20.0, lb=0.0, ub=1.0).solve(
        CTMAdjoint(scen), u_star.transpose().flatten()
    )
    print scen.ttt(scen.simulate(u_star))