def two_step_test(ind_obs, delaytype):
    """Estimate then determine the optimal toll pricing
    1. Estimate the delay function 
    2. Compute the optimal toll pricing using the estimated latency function
    3. Compute the real effect of the toll pricing on the true model
    """
    # 1. Estimate
    error, theta = experiment(ind_obs, delaytype, display=True)
    # 2. Compute the optimal toll pricing using the estimated latency function
    tolls, tolls_collected, so_costs, costs, ue_costs = test_toll_pricing(theta, True, [1e-6])
    # 3. Compute the real effect of the toll pricing on the true model
    tolls_collected2, so_costs2, costs2, ue_costs2 = [], [], [], []
    if delaytype == 'Hyperbolic': g1, g2, g3, g4 = los_angeles((3.5, 3.0), 'Hyperbolic')
    if delaytype == 'Polynomial': g1, g2, g3, g4 = los_angeles(matrix([0.0, 0.0, 0.0, 0.15]), 'Polynomial')
    for toll, graph in zip(tolls, [g2,g3,g4]):
        Aeq, beq, ffdelays, pm, type = ue.get_data(graph)
        data = (Aeq, beq, ffdelays, pm, type)
        cost, x = tp.compute_cost(data, toll)
        costs2.append(cost) # tolled equilibrium
        tolls_collected2.append((toll.T*x)[0])
        ue_costs2.append(tp.compute_cost(data)[0]) # ue equilibrium
        so_costs2.append(tp.compute_cost(data, 0.0, True)[0]) # so equilibrium
    print 'toll collected:', tolls_collected, tolls_collected2
    print 'SO total travel time:', so_costs, so_costs2
    print 'tolled total travel time:', costs, costs2
    print 'UE total travel time:', ue_costs, ue_costs2
def experiment(indlinks_obs, delaytype, noise=0.0, display=False, soft=1000.0):
    """find parameters that minimizes the distance between x^obs_true in NOISY case
    and x^obs generated by each candidate function with PARTIAL observation
    
    Parameters
    ----------
    indlinks_obs: indices of the observed links
    delaytype: type of the delay
    noise: std of the noise added to the measured link flows, ff delays, OD demands
    display: if True, display results
    soft: weight put on the observation
    """
    if delaytype == 'Polynomial': true_theta = coef
    if delaytype == 'Hyperbolic': true_theta = (a,b)
    print 'generate graph...'
    g1, g2, g3, g4 = los_angeles(true_theta, delaytype)
    print 'compute ue...'
    l1, l2, l3, l4 = ue.solver(g1, update=True), ue.solver(g2, update=True), \
        ue.solver(g3, update=True), ue.solver(g4, update=True)
    c1 = sum([link.delay*link.flow for link in g1.links.values()])
    c2 = sum([link.delay*link.flow for link in g2.links.values()])
    c3 = sum([link.delay*link.flow for link in g3.links.values()])
    c4 = sum([link.delay*link.flow for link in g4.links.values()])
    print 'ue costs: ', c1, c2, c3, c4
    obs = [g1.indlinks[id] for id in indlinks_obs]
    obs = [int(i) for i in list(np.sort(obs))]
    x1,x2,x3,x4 = l1,l2,l3,l4
    if noise > 0.0:
        x1, x2, x3, x4 = add_noise(l1,noise), add_noise(l2,noise), add_noise(l3,noise), add_noise(l4,noise)
        g1, g2, g3, g4 = los_angeles(true_theta, 'Polynomial', noise)
    theta, xs = invopt.main_solver([g1,g2,g3,g4], [x1[obs],x2[obs],x3[obs],x4[obs]], obs, degree, soft)
    u, v = matrix([l1,l2,l3,l4]), matrix(xs)
    error = np.linalg.norm(u-v, 1) / np.linalg.norm(u, 1)
    if display: display_results(error, true_theta, [theta], delaytype)
    return error, theta
Esempio n. 3
0
def two_step_test(ind_obs, delaytype):
    """Estimate then determine the optimal toll pricing
    1. Estimate the delay function 
    2. Compute the optimal toll pricing using the estimated latency function
    3. Compute the real effect of the toll pricing on the true model
    """
    # 1. Estimate
    error, theta = experiment(ind_obs, delaytype, display=True)
    # 2. Compute the optimal toll pricing using the estimated latency function
    tolls, tolls_collected, so_costs, costs, ue_costs = test_toll_pricing(
        theta, True, [1e-6])
    # 3. Compute the real effect of the toll pricing on the true model
    tolls_collected2, so_costs2, costs2, ue_costs2 = [], [], [], []
    if delaytype == 'Hyperbolic':
        g1, g2, g3, g4 = los_angeles((3.5, 3.0), 'Hyperbolic')
    if delaytype == 'Polynomial':
        g1, g2, g3, g4 = los_angeles(matrix([0.0, 0.0, 0.0, 0.15]),
                                     'Polynomial')
    for toll, graph in zip(tolls, [g2, g3, g4]):
        Aeq, beq, ffdelays, pm, type = ue.get_data(graph)
        data = (Aeq, beq, ffdelays, pm, type)
        cost, x = tp.compute_cost(data, toll)
        costs2.append(cost)  # tolled equilibrium
        tolls_collected2.append((toll.T * x)[0])
        ue_costs2.append(tp.compute_cost(data)[0])  # ue equilibrium
        so_costs2.append(tp.compute_cost(data, 0.0, True)[0])  # so equilibrium
    print 'toll collected:', tolls_collected, tolls_collected2
    print 'SO total travel time:', so_costs, so_costs2
    print 'tolled total travel time:', costs, costs2
    print 'UE total travel time:', ue_costs, ue_costs2
Esempio n. 4
0
def experiment_estimation(indlinks_obs, delaytype, degree):
    """Demonstrate multi-objective optimization for structural estimation
    1. Generate the graph of L.A.
    2. Generate synthetic data in UE
    3. Apply multi-objective solver
    
    Parameters
    ----------
    indlinks_obs = indices of the observed links
    delaytype: type of the delay
    display: if True, display results
    """
    if delaytype == 'Polynomial': true_theta = coef
    if delaytype == 'Hyperbolic': true_theta = (a, b)
    g1, g2, g3, g4 = los_angeles(true_theta, delaytype)
    x1, x2, x3, x4 = ue.solver(g1), ue.solver(g2), ue.solver(g3), ue.solver(g4)
    obs = [g1.indlinks[id] for id in indlinks_obs]
    obs = [int(i) for i in list(np.sort(obs))]
    w_multi = [0.001, .01, .1, .5, .9, .99,
               0.999]  # weight on the observation residual
    r_gap, r_obs, x_est, thetas = invopt.multi_objective_solver(
        [g1, g2, g3, g4], [x1[obs], x2[obs], x3[obs], x4[obs]], obs, degree,
        w_multi)
    print r_gap
    print r_obs
    u = matrix([x1, x2, x3, x4])
    r_est = [np.linalg.norm(u - x, 1) / np.linalg.norm(u, 1) for x in x_est]
    print r_est
    display_results(r_est[4], true_theta, [thetas[4]], delaytype, w_multi[4])
Esempio n. 5
0
def experiment_toll_pricing(ws_so, ws_toll):
    """Demonstrate multi-objective optimization for toll pricing model
    1. Generate the graph of L.A.
    2. Run multi-objective solver
    3. Post-process results
    4. Print results
    
    Parameters
    ----------
    ws_so: list of weights for so objective
    ws_toll: list of weight for toll objective
    """
    graph = los_angeles(coef, 'Polynomial')[3]
    r_gap, toll_est, loss_est, toll_res, loss_res, toll = tp.multi_objective_solver(
        graph, coef, ws_so, ws_toll)
    for i in range(len(ws_so)):
        for j in range(len(ws_toll)):
            if r_gap[i, j] < 0.0: r_gap[i, j] = 0.0
            if toll_est[i, j] < 0.0: toll_est[i, j] = 0.0
            if loss_est[i, j] < 0.0: loss_est[i, j] = 0.0
            if toll_res[i, j] < 0.0: toll_res[i, j] = 0.0
            if loss_res[i, j] < 0.0: loss_res[i, j] = 0.0
    print r_gap
    print toll_est
    print loss_est
    print toll_res
    print loss_res
def experiment_estimation(indlinks_obs, delaytype, degree):
    """Demonstrate multi-objective optimization for structural estimation
    1. Generate the graph of L.A.
    2. Generate synthetic data in UE
    3. Apply multi-objective solver
    
    Parameters
    ----------
    indlinks_obs = indices of the observed links
    delaytype: type of the delay
    display: if True, display results
    """
    if delaytype == 'Polynomial': true_theta = coef
    if delaytype == 'Hyperbolic': true_theta = (a,b)
    g1, g2, g3, g4 = los_angeles(true_theta, delaytype)
    x1, x2, x3, x4 = ue.solver(g1), ue.solver(g2), ue.solver(g3), ue.solver(g4)
    obs = [g1.indlinks[id] for id in indlinks_obs]
    obs = [int(i) for i in list(np.sort(obs))]
    w_multi = [0.001, .01, .1, .5, .9, .99, 0.999] # weight on the observation residual
    r_gap, r_obs, x_est, thetas = invopt.multi_objective_solver([g1,g2,g3,g4], [x1[obs],x2[obs],x3[obs],x4[obs]], obs, degree, w_multi)
    print r_gap
    print r_obs
    u = matrix([x1,x2,x3,x4])
    r_est = [np.linalg.norm(u-x, 1) / np.linalg.norm(u, 1) for x in x_est]
    print r_est
    display_results(r_est[4], true_theta, [thetas[4]], delaytype, w_multi[4])
def test_toll_pricing(theta, display=False, ws=[1e-8, 1e-6, 1e-4]):
    """Test the toll pricing model
    1. compute optimal toll
    2. compute tolled_ue, ue, so total travel times
    3. display results
    """
    g1, g2, g3, g4 = los_angeles(theta, 'Polynomial')
    tolls, tolls_collected, costs, ue_costs, so_costs, weights = [], [], [], [], [], []
    for graph in [g2,g3,g4]:
        ffdelays, slopes = graph.get_ffdelays(), graph.get_slopes()
        Aeq, beq = ue.constraints(graph)
        pm = invopt.compute_coefs(ffdelays, slopes, theta)
        data = (Aeq, beq, ffdelays, pm, 'Polynomial')
        toll, cost, toll_collected, weight = tp.main_solver(graph, theta, ws)
        tolls.append(toll)
        tolls_collected.append(toll_collected)
        weights.append(weight)
        costs.append(tp.compute_cost(data, toll)[0]) # tolled equilibrium
        ue_costs.append(tp.compute_cost(data)[0]) # ue equilibrium
        so_costs.append(tp.compute_cost(data, 0.0, True)[0]) # so equilibrium
    if display:
        print 'toll collected:', tolls_collected
        print 'SO total travel time:', so_costs
        print 'tolled total travel time:', costs
        print 'UE total travel time:', ue_costs
        print 'weight:', weights
    return tolls, tolls_collected, so_costs, costs, ue_costs
Esempio n. 8
0
def test_toll_pricing(theta, display=False, ws=[1e-8, 1e-6, 1e-4]):
    """Test the toll pricing model
    1. compute optimal toll
    2. compute tolled_ue, ue, so total travel times
    3. display results
    """
    g1, g2, g3, g4 = los_angeles(theta, 'Polynomial')
    tolls, tolls_collected, costs, ue_costs, so_costs, weights = [], [], [], [], [], []
    for graph in [g2, g3, g4]:
        ffdelays, slopes = graph.get_ffdelays(), graph.get_slopes()
        Aeq, beq = ue.constraints(graph)
        pm = invopt.compute_coefs(ffdelays, slopes, theta)
        data = (Aeq, beq, ffdelays, pm, 'Polynomial')
        toll, cost, toll_collected, weight = tp.main_solver(graph, theta, ws)
        tolls.append(toll)
        tolls_collected.append(toll_collected)
        weights.append(weight)
        costs.append(tp.compute_cost(data, toll)[0])  # tolled equilibrium
        ue_costs.append(tp.compute_cost(data)[0])  # ue equilibrium
        so_costs.append(tp.compute_cost(data, 0.0, True)[0])  # so equilibrium
    if display:
        print 'toll collected:', tolls_collected
        print 'SO total travel time:', so_costs
        print 'tolled total travel time:', costs
        print 'UE total travel time:', ue_costs
        print 'weight:', weights
    return tolls, tolls_collected, so_costs, costs, ue_costs
def experiment_toll_pricing(ws_so, ws_toll):
    """Demonstrate multi-objective optimization for toll pricing model
    1. Generate the graph of L.A.
    2. Run multi-objective solver
    3. Post-process results
    4. Print results
    
    Parameters
    ----------
    ws_so: list of weights for so objective
    ws_toll: list of weight for toll objective
    """
    graph = los_angeles(coef, 'Polynomial')[3]
    r_gap, toll_est, loss_est, toll_res, loss_res, toll = tp.multi_objective_solver(graph, coef, ws_so, ws_toll)
    for i in range(len(ws_so)):
        for j in range(len(ws_toll)):
            if r_gap[i,j] < 0.0: r_gap[i,j]=0.0
            if toll_est[i,j] < 0.0: toll_est[i,j]=0.0
            if loss_est[i,j] < 0.0: loss_est[i,j]=0.0
            if toll_res[i,j] < 0.0: toll_res[i,j]=0.0
            if loss_res[i,j] < 0.0: loss_res[i,j]=0.0
    print r_gap
    print toll_est
    print loss_est
    print toll_res
    print loss_res
Esempio n. 10
0
def generate_wp(demand=3, data=None, draw=False, voronoi=False, path=None):
    """Generate waypoints following the map of L.A. and draw the map
    
    Parameters:
    ----------
    demand: OD demand
    data: (N0, N1, scale, regions, res, margin)
        N0: number of background samples
        N1: number of samples on links
        regions: list of regions, regions[k] = (geometry, N_region)
        res: (n1, n2) s.t. the width is divided into n1 cells and the height into n2 cells
        margin: margin around each cell
    draw: if True, draw graph and Voronoi
    voronoi: if voronoi = draw voronoi cells
    
    Return value:
    ------------
    graph: Graph of L.A.
    WP: waypoint object with waypoints following the map of L.A.
    """
    if data is None:
        N0, N1, scale, regions, res, margin = 20, 40, 0.2, [
            ((3.5, 0.5, 6.5, 3.0), 20)
        ], (12, 6), 2.0
    else:
        N0, N1, scale, regions, res, margin = data
    graph = los_angeles(theta, 'Polynomial', path=path)[demand]
    WP = w.sample_waypoints(graph, N0, N1, scale, regions)
    WP.build_partition(res, margin)
    if draw: WP.draw_waypoints(graph, voronoi=voronoi)
    return graph, WP
Esempio n. 11
0
def test1():
    g = los_angeles()[0]
    print g.links.values()[23].delay
    sink = 20
    sources = [od[0] for od in g.ODs.keys() if od[1]==sink]
    As = sh.mainKSP(g, sources, sink, 10)
    for s in sources:
        print len(As[s]), As[s]
def main():
    theta = matrix([0.0, 0.0, 0.0, 0.15, 0.0, 0.0])
    graph = los_angeles()[3]
    ind_obs = {}
    ind_obs[0] = graph.indlinks.keys()
    ind_obs[1] = [(36,37,1), (13,14,1), (17,8,1), (24,17,1), (28,22,1), (14,13,1), (17,24,1), (24,40,1), (14,21,1), (16,23,1)]
    ind_obs[2] = [(17,24,1), (24,40,1), (14,21,1), (16,23,1)]
    ind_obs[3] = [(10,9,1), (19,18,1), (4,5,1), (29,21,1)]
    
    test_toll_pricing(theta, True)
Esempio n. 13
0
def main():
    theta = matrix([0.0, 0.0, 0.0, 0.15, 0.0, 0.0])
    graph = los_angeles()[3]
    ind_obs = {}
    ind_obs[0] = graph.indlinks.keys()
    ind_obs[1] = [(36, 37, 1), (13, 14, 1), (17, 8, 1), (24, 17, 1),
                  (28, 22, 1), (14, 13, 1), (17, 24, 1), (24, 40, 1),
                  (14, 21, 1), (16, 23, 1)]
    ind_obs[2] = [(17, 24, 1), (24, 40, 1), (14, 21, 1), (16, 23, 1)]
    ind_obs[3] = [(10, 9, 1), (19, 18, 1), (4, 5, 1), (29, 21, 1)]

    test_toll_pricing(theta, True)
def draw_tolls():
    """Draw tolls"""
    graph = los_angeles(coef, 'Polynomial')[3]
    w_so = [1e2]
    w_toll =[1e-2]
    r_gap, toll_est, loss_est, toll_res, loss_res, toll = tp.multi_objective_solver(graph, coef, w_so, w_toll)
    print toll
    print r_gap
    print toll_est
    print loss_est
    print toll_res
    print loss_res
Esempio n. 15
0
def get_paths(SO, K, demand, return_paths=True, ffdelays=False, path=None, save_data=False, savepath=None):
    """This experiment does the following tests:
    1. compute the UE/SO link flows using node-link formulation 
    2. get the link delays for the UE/SO link flow
    3. find the K-shortest paths for these delays/marginal delays (used ones under UE/SO)
    4. add these paths to the network
    5. compute the UE/SO path flows using link-path formulation
    6. check if we get the same UE/SO link flow
    
    Parameters:
    -----------
    SO: if False, compute the UE, if True, compute the SO
    K: number of shortest paths
    demand: choice of OD demand
    return_paths: if True, return paths
    ffdelays: if True the k-shortest paths are obtained from ff delays
    
    Return value:
    ------------
    """
    print 'generate graph with demand', demand
    g = los_angeles(theta, 'Polynomial', path=path)[demand]
    if ffdelays: paths = get_shortest_paths(g, K)
    print 'compute UE'
    l1 = ue.solver(g, update=True, SO=SO)
    d1 = sum([link.delay*link.flow for link in g.links.values()])
    if SO:
        for link in g.links.values():
            link.delay = link.ffdelay*(1+0.75*(link.flow*link.delayfunc.slope)**4)
    print 'get {} shortest paths'.format(K)
    if not ffdelays: paths = get_shortest_paths(g, K)
    if return_paths: return paths
    for p in paths: g.add_path_from_nodes(p)
    g.visualize(general=True)
    print 'Generate link-path incidence matrix'
    P = path_solver.linkpath_incidence(g)
    x_true = path_solver.solver(g, update=True, SO=SO)[0]
    l2 = P*x_true
    d2 = sum([p.delay*p.flow for p in g.paths.values()])
    if save_data:
        U, f = path_solver.path_to_OD_simplex(g)
        if savepath is None: savepath = 'data.pkl'
        data = {}
        data['U'] = np.array(matrix(U))
        data['f'] = np.array(f).flatten()
        data['A'] = np.array(matrix(P))
        data['b'] = np.array(l2).flatten()
        data['x_true'] = np.array(x_true).flatten()
        pickle.dump( data, open(savepath, "wb" ) )
    #for i in range(P2.shape[0]):
    #    print np.sum(P2[i,:])
    return d1,d2,paths
Esempio n. 16
0
def draw_tolls():
    """Draw tolls"""
    graph = los_angeles(coef, 'Polynomial')[3]
    w_so = [1e2]
    w_toll = [1e-2]
    r_gap, toll_est, loss_est, toll_res, loss_res, toll = tp.multi_objective_solver(
        graph, coef, w_so, w_toll)
    print toll
    print r_gap
    print toll_est
    print loss_est
    print toll_res
    print loss_res
Esempio n. 17
0
def experiment(indlinks_obs, delaytype, noise=0.0, display=False, soft=1000.0):
    """find parameters that minimizes the distance between x^obs_true in NOISY case
    and x^obs generated by each candidate function with PARTIAL observation
    
    Parameters
    ----------
    indlinks_obs: indices of the observed links
    delaytype: type of the delay
    noise: std of the noise added to the measured link flows, ff delays, OD demands
    display: if True, display results
    soft: weight put on the observation
    """
    if delaytype == 'Polynomial': true_theta = coef
    if delaytype == 'Hyperbolic': true_theta = (a, b)
    print 'generate graph...'
    g1, g2, g3, g4 = los_angeles(true_theta, delaytype)
    print 'compute ue...'
    l1, l2, l3, l4 = ue.solver(g1, update=True), ue.solver(g2, update=True), \
        ue.solver(g3, update=True), ue.solver(g4, update=True)
    c1 = sum([link.delay * link.flow for link in g1.links.values()])
    c2 = sum([link.delay * link.flow for link in g2.links.values()])
    c3 = sum([link.delay * link.flow for link in g3.links.values()])
    c4 = sum([link.delay * link.flow for link in g4.links.values()])
    print 'ue costs: ', c1, c2, c3, c4
    obs = [g1.indlinks[id] for id in indlinks_obs]
    obs = [int(i) for i in list(np.sort(obs))]
    x1, x2, x3, x4 = l1, l2, l3, l4
    if noise > 0.0:
        x1, x2, x3, x4 = add_noise(l1, noise), add_noise(l2, noise), add_noise(
            l3, noise), add_noise(l4, noise)
        g1, g2, g3, g4 = los_angeles(true_theta, 'Polynomial', noise)
    theta, xs = invopt.main_solver([g1, g2, g3, g4],
                                   [x1[obs], x2[obs], x3[obs], x4[obs]], obs,
                                   degree, soft)
    u, v = matrix([l1, l2, l3, l4]), matrix(xs)
    error = np.linalg.norm(u - v, 1) / np.linalg.norm(u, 1)
    if display: display_results(error, true_theta, [theta], delaytype)
    return error, theta
Esempio n. 18
0
def test_helper(demand, paths):
    g = los_angeles(theta, 'Polynomial')[demand]
    for p in paths: g.add_path_from_nodes(p)
    P = path_solver.linkpath_incidence(g)
    g.visualize(general=True)
    l1 = ue.solver(g, update=True)
    d1 = sum([link.delay*link.flow for link in g.links.values()])
    l2 = P*path_solver.solver(g, update=True)
    d2 = sum([p.delay*p.flow for p in g.paths.values()])
    l3 = ue.solver(g, update=True, SO=True)
    d3 = sum([link.delay*link.flow for link in g.links.values()])
    l4 = P*path_solver.solver(g, update=True, SO=True)
    d4 = sum([p.delay*p.flow for p in g.paths.values()])
    return l1,l2,l3,l4,d1,d2,d3,d4
Esempio n. 19
0
def draw_los_angeles():
    graph = los_angeles()[0]
    link_ids = {}
    link_ids[0] = graph.indlinks.keys()
    link_ids[1] = [(36,37,1), (13,14,1), (17,8,1), (24,17,1), (28,22,1), (14,13,1), (17,24,1), (24,40,1), (14,21,1), (16,23,1)]
    link_ids[2] = [(17,24,1), (24,40,1), (14,21,1), (16,23,1)]
    link_ids[3] = [(10,9,1), (19,18,1), (4,5,1), (29,21,1)]
    #d.draw(graph)
    #d.draw(graph, nodes=False)
    #print graph.indlinks
    #for k in range(4): d.draw(graph, link_ids[k], nodes=False)
    #d.draw_ODs(graph, 22)
    # link ids for CDC 2015: [65, 86, 87, 88, 99]
    #link_ids = [(6, 5, 1), (36, 16, 1), (23, 22, 1), (16, 15, 1), (17, 36, 1)]
    link_ids = [(43,24,1), (24,37,1), (37,23,1), (23,22,1), (42,17,1), (17,36,1), (36,16,1), (16,15,1), (9,41,1), (41,8,1), (8,35,1), (35,7,1)]
    for id in link_ids: print graph.indlinks[id]
    d.draw(graph, link_ids, nodes=False)
Esempio n. 20
0
def test2(delaytype):
    if delaytype == 'Polynomial': theta = matrix([0.0, 0.0, 0.0, 0.15, 0.0, 0.0])
    if delaytype == 'Hyperbolic': theta = (3.5, 3.0)
    g = los_angeles(theta, delaytype)[3]
    n = g.numlinks
    l, x = ue.solver(g, update=True, full=True)
    d.draw_delays(g, x[:n])
    d.draw_delays(g, x[n:2*n])
    d.draw_delays(g, x[2*n:])
    #print l
    print max(mul(l,g.get_slopes()))
    print 'cost UE:', sum([link.delay*link.flow for link in g.links.values()])
    l2, x2 = ue.solver(g, update=True, full=True, SO=True)
    d.draw_delays(g, x2[:n])
    d.draw_delays(g, x2[n:2*n])
    d.draw_delays(g, x2[2*n:])
    #print l2
    print max(mul(l2,g.get_slopes()))
    print 'cost SO:', sum([link.delay*link.flow for link in g.links.values()])
Esempio n. 21
0
def test_feasible_pathflows(SO, demand, random=False):
    """Test function feasible_pathflows"""
    paths = find_UESOpaths(SO)
    g = los_angeles(theta, 'Polynomial')[demand]
    l1 = ue.solver(g, update=True, SO=SO)
    d1 = sum([link.delay*link.flow for link in g.links.values()])
    for p in paths: g.add_path_from_nodes(p)
    g.visualize(general=True)
    P = linkpath_incidence(g)
    l2 = P*path_solver.solver(g, update=True, SO=SO, random=random)
    d2 = sum([p.delay*p.flow for p in g.paths.values()])
    ind_obs, ls, ds = {}, [], []
    ind_obs[0] = g.indlinks.keys()
    ind_obs[1] = [(36,37,1), (13,14,1), (17,8,1), (24,17,1), (28,22,1), (14,13,1), (17,24,1), (24,40,1), (14,21,1), (16,23,1)]
    ind_obs[2] = [(17,24,1), (24,40,1), (14,21,1), (16,23,1)]
    for i in range(len(ind_obs)):
        obs = [g.indlinks[id] for id in ind_obs[i]]
        obs = [int(i) for i in list(np.sort(obs))]
        ls.append(P*path_solver.feasible_pathflows(g, l1[obs], obs, True))
        ds.append(sum([p.delay*p.flow for p in g.paths.values()]))
    print d1,d2,ds
    print np.linalg.norm(l1-l2), [np.linalg.norm(l1-ls[i]) for i in range(len(ind_obs))]
Esempio n. 22
0
def find_UESOpaths(SO, return_paths=True, random=False, path=None):
    """
    1. take the union for all optimum shortest paths for UE/SO
    2. compute UE/SO using node-link and link-path formulation for all demands
    3. compare results
    
    Parameters:
    -----------
    SO: if False, compute the UE, if True, compute the SO
    return_paths: if True, do only step 1 and return paths, if False, do steps 2 and 3
    """
    paths, ls, ds, ps = [], [], [], []
    if SO: K = [0,0,0,10] #[2, 2, 4, 7]
    else: K = [0,0,0,5] #[2, 2, 2, 3] [5,5,5,5]
    for i in range(4):
        tmp = get_paths(SO, K[i], i, path=path)
        for p in tmp:
            if p not in paths: paths.append(p)
    if return_paths: return paths
    for i in range(4):
        g = los_angeles(theta, 'Polynomial')[i]
        for p in paths: g.add_path_from_nodes(p)
        P = linkpath_incidence(g)
        g.visualize(general=True)
        l1 = ue.solver(g, update=True, SO=SO)
        d1 = sum([link.delay*link.flow for link in g.links.values()])
        p_flows = path_solver.solver(g, update=True, SO=SO, random=random)
        l2 = P*p_flows
        d2 = sum([p.delay*p.flow for p in g.paths.values()])
        ls.append([l1,l2])
        ds.append([d1,d2])
        ps.append(p_flows)
    for i in range(4):
        print np.linalg.norm(ls[i][0] - ls[i][1])
        print ds[i][0], ds[i][1]
    print len(paths)
'''


import numpy as np
import ue_solver as ue
import inverse_opt as invopt
from generate_graph import los_angeles
import matplotlib.pyplot as plt
from cvxopt import matrix
import toll_pricing as tp
from inverse_opt_test import display_results


a, b = 3.5, 3.0
coef = matrix([0.0, 0.0, 0.0, 0.15, 0.0, 0.0])
graph = los_angeles(coef, 'Polynomial')[0]


def experiment_estimation(indlinks_obs, delaytype, degree):
    """Demonstrate multi-objective optimization for structural estimation
    1. Generate the graph of L.A.
    2. Generate synthetic data in UE
    3. Apply multi-objective solver
    
    Parameters
    ----------
    indlinks_obs = indices of the observed links
    delaytype: type of the delay
    display: if True, display results
    """
    if delaytype == 'Polynomial': true_theta = coef
Esempio n. 24
0
Experiments for ECC 2015
'''

import numpy as np
import ue_solver as ue
import inverse_opt as invopt
from generate_graph import los_angeles
import matplotlib.pyplot as plt
from cvxopt import matrix
import toll_pricing as tp
from inverse_opt_test import display_results

a, b = 3.5, 3.0
coef = matrix([0.0, 0.0, 0.0, 0.15, 0.0, 0.0])
graph = los_angeles(coef, 'Polynomial')[0]


def experiment_estimation(indlinks_obs, delaytype, degree):
    """Demonstrate multi-objective optimization for structural estimation
    1. Generate the graph of L.A.
    2. Generate synthetic data in UE
    3. Apply multi-objective solver
    
    Parameters
    ----------
    indlinks_obs = indices of the observed links
    delaytype: type of the delay
    display: if True, display results
    """
    if delaytype == 'Polynomial': true_theta = coef