Example #1
0
def frank_wolfe_on_chicago_2():
    '''
    Frank-Wolfe on Chicago with the inputs processed from:
    http://www.bgu.ac.il/~bargera/tntp/
    but we multiply the demand by 2 to have more congestion
    '''
    graph, demand, node, features = load_chicago()
    results = np.loadtxt('data/Chicago_results_2.csv', delimiter=',')
    demand[:, 2] = demand[:, 2] / 2000  # technically, it's 2*demand/4000
    # f = solver(graph, demand, max_iter=1000, display=1, stop=1e-2)
    # f = solver_2(graph, demand, max_iter=1000, q=100, display=1, stop=1e-2)
    f = solver_3(graph, demand, max_iter=1000, q=50, display=1, stop=1e-2)
    print np.linalg.norm(f * 4000 - results) / np.linalg.norm(results)
    print average_cost(f, graph, demand)
def frank_wolfe_on_chicago_2():
    """
    Frank-Wolfe on Chicago with the inputs processed from:
    http://www.bgu.ac.il/~bargera/tntp/
    but we multiply the demand by 2 to have more congestion
    """
    graph, demand, node, features = load_chicago()
    results = np.loadtxt("data/Chicago_results_2.csv", delimiter=",")
    demand[:, 2] = demand[:, 2] / 2000  # technically, it's 2*demand/4000
    # f = solver(graph, demand, max_iter=1000, display=1, stop=1e-2)
    # f = solver_2(graph, demand, max_iter=1000, q=100, display=1, stop=1e-2)
    f = solver_3(graph, demand, max_iter=1000, q=50, display=1, stop=1e-2)
    print np.linalg.norm(f * 4000 - results) / np.linalg.norm(results)
    print average_cost(f, graph, demand)
def visualize_equilibrium_in_chicago():
    """
    visualize costs in the network of Chicago
    """
    net, demand, node, f = load_chicago()
    flow = np.loadtxt("data/Chicago_results_2.csv", delimiter=",")
    # flow = np.loadtxt('data/Chicago_results.csv', delimiter=',', skiprows=1)[:,2]
    print average_cost(flow / 4000.0, net)
    costs = cost_ratio(flow / 4000.0, net)
    features = np.zeros((f.shape[0], 4))
    features[:, :3] = f
    features[:, 3] = costs
    links = process_links(net, node, features)
    color = features[:, 3] - 1.0  # we choose the costs
    geojson_link(links, ["capacity", "length", "fftt", "tt_over_fftt"], color)
Example #4
0
def visualize_equilibrium_in_chicago():
    '''
    visualize costs in the network of Chicago
    '''
    net, demand, node, f = load_chicago()
    flow = np.loadtxt('data/Chicago_results_2.csv', delimiter=',')
    # flow = np.loadtxt('data/Chicago_results.csv', delimiter=',', skiprows=1)[:,2]
    print average_cost(flow/4000., net, demand)
    costs = cost_ratio(flow/4000., net)
    features = np.zeros((f.shape[0],4))
    features[:,:3] = f
    features[:,3] = costs
    links = process_links(net, node, features)
    color = features[:,3] - 1.0 # we choose the costs
    geojson_link(links, ['capacity', 'length', 'fftt', 'tt_over_fftt'], color)
 def test_average_cost(self):
     net = np.loadtxt('data/braess_net.csv', delimiter=',', skiprows=1)
     net[:, 5] = np.array([2.] * 5)
     flow = np.array([0., 1., 2., 3., 4.])
     od = np.array([[0, 0, 0.], [0, 0, 1.], [0, 0, 2.], [0, 0, 3.],
                    [0, 0, 4.]])
     self.assertTrue(
         np.linalg.norm(average_cost(flow, net, od) - 22.) < 1e-8)
 def test_average_cost(self):
     net = np.loadtxt('data/braess_net.csv', delimiter=',', skiprows=1)
     net[:,5] = np.array([2.]*5)
     flow = np.array([0., 1., 2., 3., 4.])
     od = np.array([[0,0,0.],[0,0,1.],[0,0,2.],[0,0,3.],[0,0,4.]])
     self.assertTrue(np.linalg.norm(average_cost(flow, net, od) - 22.) < 1e-8)