Beispiel #1
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 #2
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 #3
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)