예제 #1
0
def test_multi_split():
    scen, control = test_ctm.small_scenario()
    adjoint_left = ctm_admm.AdmmCTMAdjoint(scen, True)
    adjoint_right = ctm_admm.AdmmCTMAdjoint(scen, False)
    problem = CtmAdmm([adjoint_left, adjoint_right], 100)
    from multi_agent_admm import settings
    settings.beta = .7
    problem.solve()
    problem.plot_history()
예제 #2
0
def test_no_ramp():
    scen, control = test_ctm.small_scenario()
    set_cells_left = [1]
    set_ramps_left = []
    adjoint_left = ctm_admm.AdmmCTMAdjoint(scen, set_cells_left, set_ramps_left)
    set_cells_right = [0]
    set_ramps_right = []
    adjoint_right = ctm_admm.AdmmCTMAdjoint(scen, set_cells_right, set_ramps_right)
    sln = CtmAdmm([adjoint_left, adjoint_right])
    sln.solve()
예제 #3
0
def test_no_congestion_network():
    flow = 0.1
    fd = FundamentalDiagram(1.,1.,1.)
    n = 3
    T = 5
    links = [CTMCell(fd, 1.0, 1.0) for _ in range(n)]
    fw = CTMFreeway(links)
    q0 = numpy.zeros(n)
    q0[0]= flow
    ic = InitialConditions(numpy.zeros(n), q0)
    bc  = BoundaryConditions(numpy.ones((n, T)) * 0.0, numpy.ones((n,T)))
    q = numpy.zeros(n)
    ic2 = InitialConditions(numpy.zeros(n), q)
    scen = Scenario(fw, ic, bc)
    scen2 = Scenario(fw, ic2, bc)


    #nf = 4
    #links_full = CTMFreeway([CTMCell(fd, 1., 1.) for _ in range(nf)])
    #q = numpy.zeros(nf)
    #q[0] = flow
    #icf = InitialConditions(numpy.zeros(nf), q)
    #bcf = BoundaryConditions(numpy.zeros((nf, T)), numpy.ones((nf, T)))
    #scenf = Scenario(links_full, icf, bcf)
    #scen.plot()
    #scen2.plot()
    #scenf.plot()

    adjoint_left = ctm_admm.AdmmCTMAdjoint(scen, True)
    adjoint_right = ctm_admm.AdmmCTMAdjoint(scen2, False)
    problem = CtmAdmm([adjoint_left, adjoint_right], 50)
    adjoint_left.fs(adjoint_left.construct_control(problem.graph.nodes()[0].x)).plot()
    adjoint_right.fs(adjoint_right.construct_control(problem.graph.nodes()[1].x)).plot()
    from multi_agent_admm import settings

    settings.beta = .5
    problem.solve()
    adjoint_left.fs(adjoint_left.construct_control(problem.graph.nodes()[0].x)).plot()
    adjoint_right.fs(adjoint_right.construct_control(problem.graph.nodes()[1].x)).plot()

    from pylab import plot, show, hold

    plot([h[2] for h in problem.graph.edges()[0].history])
    hold(True)
    plot([h[3] for h in problem.graph.edges()[0].history])
    show()