def test_solver_2(self):
        # Frank-Wolfe from Algorithm 3 of Jaggi's paper (without aprox.)
        # already good improvement
        print 'test solver_2'
        graph = np.loadtxt('data/braess_net.csv', delimiter=',', skiprows=1)
        demand = np.loadtxt('data/braess_od.csv', delimiter=',', skiprows=1)
        demand = np.reshape(demand, (1, 3))
        f = solver_2(graph, demand, max_iter=100)
        self.check(f, np.array([1., 1., 0., 1., 1.]), 1e-3)

        # modify demand
        demand[0, 2] = 0.5
        f = solver_2(graph, demand)
        self.check(f, np.array([.5, .0, .5, .0, .5]), 1e-8)
    def test_solver_2(self):
        # Frank-Wolfe from Algorithm 3 of Jaggi's paper (without aprox.)
        # already good improvement
        print 'test solver_2'
        graph = np.loadtxt('data/braess_net.csv', delimiter=',', skiprows=1)
        demand = np.loadtxt('data/braess_od.csv', delimiter=',', skiprows=1)
        demand=np.reshape(demand, (1,3))
        f = solver_2(graph, demand, max_iter=100)
        self.check(f, np.array([1.,1.,0.,1.,1.]), 1e-3)

        # modify demand
        demand[0,2] = 0.5
        f = solver_2(graph, demand)
        self.check(f, np.array([.5,.0,.5,.0,.5]), 1e-8)
 def test_solver_sioux_falls_2(self):
     print 'test Frank-Wolfe on Sioux Falls 2'
     graph = np.loadtxt('data/SiouxFalls_net.csv', delimiter=',', skiprows=1)
     demand = np.loadtxt('data/SiouxFalls_od.csv', delimiter=',', skiprows=1)
     demand[:,2] = demand[:,2] / 4000
     f = solver_2(graph, demand, max_iter=1000, q=100)
     results = np.loadtxt('data/SiouxFalls_results.csv')
     self.check(f*4000, results, 1e-3)
 def test_solver_sioux_falls_2(self):
     print 'test Frank-Wolfe on Sioux Falls 2'
     graph = np.loadtxt('data/SiouxFalls_net.csv',
                        delimiter=',',
                        skiprows=1)
     demand = np.loadtxt('data/SiouxFalls_od.csv',
                         delimiter=',',
                         skiprows=1)
     demand[:, 2] = demand[:, 2] / 4000
     f = solver_2(graph, demand, max_iter=1000, q=100)
     results = np.loadtxt('data/SiouxFalls_results.csv')
     self.check(f * 4000, results, 1e-3)
 def test_solver_3(self):
     print 'test_solver_3'
     graph = np.loadtxt('data/braess_net.csv', delimiter=',', skiprows=1)
     demand = np.loadtxt('data/braess_od.csv', delimiter=',', skiprows=1)
     demand = np.reshape(demand, (1, 3))
     f = solver_3(graph, demand, max_iter=100)
     #print f
     self.check(f, np.array([1., 1., 0., 1., 1.]), 1e-1)
     # modify demand
     demand[0, 2] = 0.5
     f = solver_2(graph, demand)
     self.check(f, np.array([.5, .0, .5, .0, .5]), 1e-8)
 def test_solver_3(self):
     print 'test_solver_3'
     graph = np.loadtxt('data/braess_net.csv', delimiter=',', skiprows=1)
     demand = np.loadtxt('data/braess_od.csv', delimiter=',', skiprows=1)
     demand=np.reshape(demand, (1,3))
     f = solver_3(graph, demand, max_iter=100)
     #print f
     self.check(f, np.array([1.,1.,0.,1.,1.]), 1e-1)
     # modify demand
     demand[0,2] = 0.5
     f = solver_2(graph, demand)
     self.check(f, np.array([.5,.0,.5,.0,.5]), 1e-8)
示例#7
0
def braess_parametric_study():
    '''
    parametric study of heterogeneous game on the Braess network 
    '''
    g1, g2, d1, d2 = braess_heterogeneous(.0, 1.5)
    fs = solver_2(g1, d1, display=1)
    print '.0, 1.5'
    np.savetxt('data/braess/test_1.csv', fs, delimiter=',')
    g1, g2, d1, d2 = braess_heterogeneous(.5, 1.)
    fs = gauss_seidel([g1, g2], [d1, d2], solver_2, display=1)
    print '.5, 1.'
    np.savetxt('data/braess/test_2.csv', fs, delimiter=',')
    g1, g2, d1, d2 = braess_heterogeneous(.75, .75)
    fs = gauss_seidel([g1, g2], [d1, d2], solver_2, display=1)
    print '.75, .75'
    np.savetxt('data/braess/test_3.csv', fs, delimiter=',')
    g1, g2, d1, d2 = braess_heterogeneous(1., .5)
    fs = gauss_seidel([g1, g2], [d1, d2], solver_2, display=1)
    print '1., .5'
    np.savetxt('data/braess/test_4.csv', fs, delimiter=',')
    g1, g2, d1, d2 = braess_heterogeneous(1.5, .0)
    fs = solver_2(g2, d2, display=1)
    print '1.5, .0'
    np.savetxt('data/braess/test_5.csv', fs, delimiter=',')
def braess_parametric_study():
    '''
    parametric study of heterogeneous game on the Braess network 
    '''
    g1,g2,d1,d2 = braess_heterogeneous(.0, 1.5)
    fs = solver_2(g1, d1, display=1)
    print '.0, 1.5'
    np.savetxt('data/braess/test_1.csv', fs, delimiter=',')
    g1,g2,d1,d2 = braess_heterogeneous(.5, 1.)
    fs = gauss_seidel([g1,g2], [d1,d2], solver_2, display=1)
    print '.5, 1.'
    np.savetxt('data/braess/test_2.csv', fs, delimiter=',')
    g1,g2,d1,d2 = braess_heterogeneous(.75, .75)
    fs = gauss_seidel([g1,g2], [d1,d2], solver_2, display=1)
    print '.75, .75'
    np.savetxt('data/braess/test_3.csv', fs, delimiter=',')
    g1,g2,d1,d2 = braess_heterogeneous(1., .5)
    fs = gauss_seidel([g1,g2], [d1,d2], solver_2, display=1)
    print '1., .5'
    np.savetxt('data/braess/test_4.csv', fs, delimiter=',')
    g1,g2,d1,d2 = braess_heterogeneous(1.5, .0)
    fs = solver_2(g2, d2, display=1)
    print '1.5, .0'
    np.savetxt('data/braess/test_5.csv', fs, delimiter=',')