def test_all_or_nothing(self):
        # load the data
        graph = np.loadtxt("data/braess_graph.csv", delimiter=",", skiprows=1)
        od = np.loadtxt("data/braess_od.csv", delimiter=",", skiprows=1)
        od = np.reshape(od, (1, 3))
        # all or nothing assignment
        L = all_or_nothing(graph, od)
        self.assertTrue(np.linalg.norm(L - np.array([2.0, 0.0, 2.0, 0.0, 2.0])) < eps)

        # modify graph
        graph[2, 3] = 1000.0
        graph[0, 3] = 1.0
        L = all_or_nothing(graph, od)
        self.assertTrue(np.linalg.norm(L - np.array([0.0, 2.0, 0.0, 0.0, 2.0])) < eps)
Exemplo n.º 2
0
 def test_all_or_nothing_2(self):
     # load the data
     graph = np.loadtxt('data/graph_test.csv', delimiter=',')
     # print graph
     od = np.loadtxt('data/od_test.csv', delimiter=',')
     od = np.reshape(od, (1, 3))
     L = all_or_nothing(graph, od)
Exemplo n.º 3
0
    def test_all_or_nothing(self):
        # load the data
        graph = np.loadtxt('data/braess_graph.csv', delimiter=',', skiprows=1)
        od = np.loadtxt('data/braess_od.csv', delimiter=',', skiprows=1)
        od = np.reshape(od, (1, 3))
        # all or nothing assignment
        L = all_or_nothing(graph, od)
        self.assertTrue(
            np.linalg.norm(L - np.array([2., 0., 2., 0., 2.])) < eps)

        # modify graph
        graph[2, 3] = 1000.
        graph[0, 3] = 1.
        L = all_or_nothing(graph, od)
        self.assertTrue(
            np.linalg.norm(L - np.array([0., 2., 0., 0., 2.])) < eps)
 def test_all_or_nothing_2(self):
     # load the data
     graph = np.loadtxt("data/graph_test.csv", delimiter=",")
     # print graph
     od = np.loadtxt("data/od_test.csv", delimiter=",")
     od = np.reshape(od, (1, 3))
     L = all_or_nothing(graph, od)
def search_direction(f, graph, g, demand):
    # computes the Frank-Wolfe step
    # g is just a canvas containing the link information and to be updated with 
    # the most recent edge costs
    x = np.power(f.reshape((f.shape[0],1)), np.array([0,1,2,3,4]))
    grad = np.einsum('ij,ij->i', x, graph[:,3:])
    g[:,3] = grad
    return all_or_nothing(g, demand), grad
Exemplo n.º 6
0
def search_direction(f, graph, g, demand):
    # computes the Frank-Wolfe step
    # g is just a canvas containing the link information and to be updated with
    # the most recent edge costs
    x = np.power(f.reshape((f.shape[0], 1)), np.array([0, 1, 2, 3, 4]))
    grad = np.einsum('ij,ij->i', x, graph[:, 3:])
    g[:, 3] = grad
    return all_or_nothing(g, demand), grad
def residual(graphs, demands, fs):
    links = int(np.max(graphs[0][:,0])+1)
    f = np.sum(fs, axis=1)
    x = np.power(f.reshape((links,1)), np.array([0,1,2,3,4]))
    r = 0.
    for i, (graph, demand) in enumerate(zip(graphs, demands)):
        g = np.copy(graph[:,:4])
        grad = np.einsum('ij,ij->i', x, graph[:,3:])
        g[:,3] = grad
        L = all_or_nothing(g, demand)
        r = r + grad.dot(fs[:,i] - L)
    return r
Exemplo n.º 8
0
def residual(graphs, demands, fs):
    links = int(np.max(graphs[0][:, 0]) + 1)
    f = np.sum(fs, axis=1)
    x = np.power(f.reshape((links, 1)), np.array([0, 1, 2, 3, 4]))
    r = 0.
    for i, (graph, demand) in enumerate(zip(graphs, demands)):
        g = np.copy(graph[:, :4])
        grad = np.einsum('ij,ij->i', x, graph[:, 3:])
        g[:, 3] = grad
        L = all_or_nothing(g, demand)
        r = r + grad.dot(fs[:, i] - L)
    return r
Exemplo n.º 9
0
def search_direction(f, graph, g, od):
    # computes the Frank-Wolfe step
    # g is just a canvas containing the link information and to be updated with
    # the most recent edge costs
    x = np.power(f.reshape((f.shape[0], 1)), np.array([0, 1, 2, 3, 4]))
    grad = np.einsum('ij,ij->i', x, graph[:, 3:])
    g.es["weight"] = grad.tolist()

    #start timer
    #start_time1 = timeit.default_timer()

    L = all_or_nothing(g, od)

    #end of timer
    #elapsed1 = timeit.default_timer() - start_time1
    #print ("all_or_nothing took  %s seconds" % elapsed1)

    return L, grad
Exemplo n.º 10
0
def total_free_flow_cost(g, demand):
    # computes the total cost under free flow travel times
    L = all_or_nothing(g, demand)
    return g[:,3].dot(L)
def total_free_flow_cost(g, demand):
    # computes the total cost under free flow travel times
    L = all_or_nothing(g, demand)
    return g[:,3].dot(L)
Exemplo n.º 12
0
def total_free_flow_cost(g, od):
    return np.array(g.es["weight"]).dot(all_or_nothing(g, od))
def total_ff_costs_heterogeneous(graphs, demands):
    return np.sum([g[:,3].dot(all_or_nothing(g[:,:4], d)) for g,d in zip(graphs, demands)])
Exemplo n.º 14
0
def total_ff_costs_heterogeneous(graphs, demands):
    return np.sum([
        g[:, 3].dot(all_or_nothing(g[:, :4], d))
        for g, d in zip(graphs, demands)
    ])