def test_solver(self):
        # Frank-Wolfe from Algorithm 1 of Jaggi's paper
        print 'test solver'
        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(graph, demand, max_iter=300)
        self.check(f, np.array([1.,1.,0.,1.,1.]), 1e-2)

        # modify demand
        demand[0,2] = 0.5
        f = solver(graph, demand)
        self.check(f, np.array([.5,.0,.5,.0,.5]), 1e-8)
 def test_solver_sioux_falls(self):
     print 'test Frank-Wolfe on Sioux Falls'
     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(graph, demand, max_iter=1000)
     results = np.loadtxt('data/SiouxFalls_results.csv')
     self.check(f*4000, results, 1e-3)
Beispiel #3
0
def test_anaheim(self):
    print 'test Frank-Wolfe on Anaheim'
    graph = np.loadtxt('data/Anaheim_net.csv', delimiter=',', skiprows=1)
    demand = np.loadtxt('data/Anaheim_od.csv', delimiter=',', skiprows=1)
    demand[:, 2] = demand[:, 2] / 4000
    f = solver(graph, demand, max_iter=1000)
    # print f.shape
    results = np.loadtxt('data/Anaheim_results.csv')
    print np.linalg.norm(f * 4000 - results) / np.linalg.norm(results)
Beispiel #4
0
def Cython_Func_LA():
    #graph = np.loadtxt('data/SiouxFalls_net.csv', delimiter=',', skiprows=1)
    #demand = np.loadtxt('data/SiouxFalls_od.csv', delimiter=',', skiprows=1)
    graph = np.loadtxt('data/LA_net.csv', delimiter=',', skiprows=1)
    demand = np.loadtxt('data/LA_od_2.csv', delimiter=',', skiprows=1)
    graph[10787, -1] = graph[10787, -1] / (1.5**4)
    graph[3348, -1] = graph[3348, -1] / (1.2**4)

    demand[:, 2] = 0.5 * demand[:, 2] / 4000
    #import pdb; pdb.set_trace()
    f = solver(graph, demand, max_iter=30)
    #results = np.loadtxt('data/SiouxFalls_results.csv')
    np.savetxt('data/la/LA_Cython.csv', f, delimiter=',')
def frank_wolfe_on_chicago():
    """
    Frank-Wolfe on Chicago with the inputs processed from:
    http://www.bgu.ac.il/~bargera/tntp/
    """
    graph, demand, node, features = load_chicago()
    results = np.loadtxt("data/Chicago_results.csv", delimiter=",", skiprows=1)
    demand[:, 2] = demand[:, 2] / 4000
    f = solver(graph, demand, max_iter=1000, display=1)
    # error: 0.00647753330249, time: 664.151s
    # f = solver_2(graph, demand, max_iter=1000, q=100, display=1)
    # error: 0.00646125552755, time: 664.678s
    # f = solver_3(graph, demand, max_iter=1000, q=200, display=1)
    # error: 0.00648532089623, time: 665.074s
    print np.linalg.norm(f * 4000 - results[:, 2]) / np.linalg.norm(results[:, 2])
Beispiel #6
0
def frank_wolfe_on_chicago():
    '''
    Frank-Wolfe on Chicago with the inputs processed from:
    http://www.bgu.ac.il/~bargera/tntp/
    '''
    graph, demand, node, features = load_chicago()
    results = np.loadtxt('data/Chicago_results.csv', delimiter=',', skiprows=1)     
    demand[:,2] = demand[:,2] / 4000
    f = solver(graph, demand, max_iter=1000, display=1)
    # error: 0.00647753330249, time: 664.151s
    # f = solver_2(graph, demand, max_iter=1000, q=100, display=1)
    # error: 0.00646125552755, time: 664.678s
    # f = solver_3(graph, demand, max_iter=1000, q=200, display=1)
    # error: 0.00648532089623, time: 665.074s
    print np.linalg.norm(f*4000 - results[:,2]) / np.linalg.norm(results[:,2])
def gauss_seidel(graphs, demands, solver, max_cycles=10, max_iter=100, \
    by_origin=False, q=10, display=0, past=10, stop=1e-8, eps=1e-8, \
    stop_cycle=None):
    # we are given a list of graphs and demands that are specific for different types of players
    # the gauss-seidel scheme updates cyclically for each type at a time
    if stop_cycle is None: 
        stop_cycle = stop
    g = construct_igraph(graphs[0])
    ods = [construct_od(d) for d in demands]
    types = len(graphs)
    fs = np.zeros((graphs[0].shape[0],types),dtype="float64")
    g2 = np.copy(graphs[0])
    K =  total_ff_costs_heterogeneous(graphs, g, ods)
    if K < eps:
        K = np.sum([np.sum(d[:,2]) for d in demands])
    elif display >= 1:
        print 'average free-flow travel time', \
            K / np.sum([np.sum(d[:,2]) for d in demands])

    for cycle in range(max_cycles):
        if display >= 1: print 'cycle:', cycle
        for i in range(types):
            # construct graph with updated latencies
            shift = np.sum(fs[:,range(i)+range(i+1,types)], axis=1)
            shift_graph(graphs[i], g2, shift)
            g.es["weight"] = g2[:,3].tolist()
            # update flow assignment for this type
            fs[:,i] = solver(g2, demands[i], g, ods[i], max_iter=max_iter, q=q, \
                display=display, past=past, stop=stop, eps=eps)
        # check if we have convergence
        r = residual(graphs, demands, g, ods, fs) / K
        if display >= 1:
            print 'error:', r
        if r < stop_cycle and r > 0:
            return fs
    return fs