def frank_wolfe_on_I210():
    '''
    Frank-Wolfe on I210
    '''    
    graph = np.loadtxt('data/I210_attack_net.csv', delimiter=',', skiprows=1)
    demand = np.loadtxt('data/I210_od.csv', delimiter=',', skiprows=1)
    demand[:,2] = 1. * demand[:,2] / 4000 
    # run solver
    f = solver_3(graph, demand, max_iter=1000, q=50, display=1, stop=1e-2)
    # display cost
    for a,b in zip(cost(f, graph), f*4000): print a,b
    # visualization
    node = np.loadtxt('data/I210_node.csv', delimiter=',', skiprows=1)
    # extract features: 'capacity', 'length', 'fftt'
    feat = extract_features('data/I210_attack_Sketch_net.csv')
    ratio = cost_ratio(f, graph)
    # merge features with the cost ratios
    features = np.zeros((feat.shape[0],4))
    features[:,:3] = feat
    features[:,3] = ratio
    # join features with (lat1,lon1,lat2,lon2)
    links = process_links(graph, node, features)
    color = features[:,3] # we choose the costs
    names = ['capacity', 'length', 'fftt', 'tt_over_fftt']
    geojson_link(links, names, color)
Пример #2
0
def frank_wolfe_on_I210():
    '''
    Frank-Wolfe on I210
    '''
    graph = np.loadtxt('data/I210_attack_net.csv', delimiter=',', skiprows=1)
    demand = np.loadtxt('data/I210_od.csv', delimiter=',', skiprows=1)
    demand[:, 2] = 1. * demand[:, 2] / 4000
    # run solver
    f = solver_3(graph, demand, max_iter=1000, q=50, display=1, stop=1e-2)
    # display cost
    for a, b in zip(cost(f, graph), f * 4000):
        print a, b
    # visualization
    node = np.loadtxt('data/I210_node.csv', delimiter=',', skiprows=1)
    # extract features: 'capacity', 'length', 'fftt'
    feat = extract_features('data/I210_attack_Sketch_net.csv')
    ratio = cost_ratio(f, graph)
    # merge features with the cost ratios
    features = np.zeros((feat.shape[0], 4))
    features[:, :3] = feat
    features[:, 3] = ratio
    # join features with (lat1,lon1,lat2,lon2)
    links = process_links(graph, node, features)
    color = features[:, 3]  # we choose the costs
    names = ['capacity', 'length', 'fftt', 'tt_over_fftt']
    geojson_link(links, names, color)
Пример #3
0
def visualize_result_ratio_study(fileName, ratio, name, mode):
    net, demand, node, features = load_network_data(name)
    #Loading the flow per link resulting from frank-wolfe
    f = np.loadtxt(fileName, delimiter=',', skiprows=0)

    #Location of the features
    featureLocation = 'data/' + name + '_net.txt'
    features = np.zeros((f.shape[0], 4))
    features[:, :3] = extract_features(featureLocation)

    #Multiply the flow obtained by 4000 since we initially divided by 4000 before frank-wolfs
    f = np.divide(f * 4000, features[:, 0])
    features[:, 3] = f
    links = process_links(net, node, features, in_order=True)

    #creates color array used to visulized the links
    #values useful in differenciating links based of flow on links
    color = 2.0 * f + 1.0

    #Keeping track of the percentage of congestion
    links_congested = len(color[np.where(color >= 3)])
    percentage_of_congestion = float(links_congested) / float(len(color))
    print("congestion is at %3f " % percentage_of_congestion)

    geojson_link_Scenario_Study(
        ratio, links, ['capacity', 'length', 'fftt', 'flow_over_capacity'],
        color, name, mode)
def visualize_LA_result():
    net, demand, node = load_LA()
    f = np.loadtxt('data/LA_output.csv', delimiter=',', skiprows=0)
    features = np.zeros((f.shape[0], 4))
    features[:,:3] = extract_features('data/LA_net.txt')
    f = np.divide(f, features[:,0])
    features[:,3] = f
    links = process_links(net, node, features, in_order=True)
    color = 2.0*f + 1.0
    geojson_link(links, ['capacity', 'length', 'fftt', 'flow_over_capacity'], color)
def visualize_LA_capacity():
    graph, demand, node = load_LA()
    features = extract_features('data/LA_net.txt')
    links = process_links(graph, node, features, in_order=True)
    color = features[:, 0]  # we choose to color by the capacities
    names = ['capacity', 'length', 'fftt']
    # color = 2.1 * features[:,0] / 2000.
    color = 2. * (features[:, 0] <= 900.) + 5. * (features[:, 0] > 900.)
    weight = (features[:, 0] <= 900.) + 3. * (features[:, 0] > 900.)
    geojson_link(links, names, color, weight)
def visualize_LA_capacity():
    graph, demand, node = load_LA()
    features = extract_features('data/LA_net.txt')
    links = process_links(graph, node, features, in_order=True)
    color = features[:,0] # we choose to color by the capacities
    names = ['capacity', 'length', 'fftt']
    # color = 2.1 * features[:,0] / 2000.
    color = 2.*(features[:,0] <= 900.) + 5.*(features[:,0] > 900.)
    weight = (features[:,0] <= 900.) + 3.*(features[:,0] > 900.)
    geojson_link(links, names, color, weight)
def visualize_links_by_city(city):
    # visualize the links from a specific city
    graph, demand, node, features = load_LA_3()
    linkToCity = np.genfromtxt('data/LA/link_to_cities.csv', delimiter=',', \
        skiprows=1, dtype='str')
    links = process_links(graph, node, features, in_order=True)
    names = ['capacity', 'length', 'fftt']
    color = 3 * (linkToCity[:, 1] == city)
    color = color + 10 * (features[:, 0] > 900.)
    weight = (features[:, 0] <= 900.) + 3. * (features[:, 0] > 900.)
    geojson_link(links, names, color, weight)
def visualize_links_by_city(city):
    # visualize the links from a specific city
    graph, demand, node, features = load_LA_3()
    linkToCity = np.genfromtxt('data/LA/link_to_cities.csv', delimiter=',', \
        skiprows=1, dtype='str')
    links = process_links(graph, node, features, in_order=True)
    names = ['capacity', 'length', 'fftt']
    color = 3*(linkToCity[:,1] == city)
    color = color + 10*(features[:,0] > 900.)
    weight = (features[:,0] <= 900.) + 3.*(features[:,0] > 900.)
    geojson_link(links, names, color, weight)
def visualize_LA_result():
    net, demand, node = load_LA()
    f = np.loadtxt('data/LA_output.csv', delimiter=',', skiprows=0)
    features = np.zeros((f.shape[0], 4))
    features[:, :3] = extract_features('data/LA_net.txt')
    f = np.divide(f, features[:, 0])
    features[:, 3] = f
    links = process_links(net, node, features, in_order=True)
    color = 2.0 * f + 1.0
    geojson_link(links, ['capacity', 'length', 'fftt', 'flow_over_capacity'],
                 color)
def chicago_ratio_r_nr():
    """
    study the test_*.csv files generated by chicago_parametric_study()
    in particular, visualize the ratio each type of users on each link
    """
    fs = np.loadtxt("data/test_3.csv", delimiter=",", skiprows=0)
    ratio = np.divide(fs[:, 0], np.maximum(np.sum(fs, axis=1), 1e-8))
    net, demand, node, geometry = load_chicago()
    features = np.zeros((fs.shape[0], 4))
    features[:, :3] = geometry
    features[:, 3] = ratio
    links = process_links(net, node, features)
    color = 5.0 * ratio  # we choose the ratios of nr over r+nr
    geojson_link(links, ["capacity", "length", "fftt", "r_non_routed"], color)
Пример #11
0
def chicago_ratio_r_nr():
    '''
    study the test_*.csv files generated by chicago_parametric_study()
    in particular, visualize the ratio each type of users on each link
    '''
    fs = np.loadtxt('data/test_3.csv', delimiter=',', skiprows=0)
    ratio = np.divide(fs[:, 0], np.maximum(np.sum(fs, axis=1), 1e-8))
    net, demand, node, geometry = load_chicago()
    features = np.zeros((fs.shape[0], 4))
    features[:, :3] = geometry
    features[:, 3] = ratio
    links = process_links(net, node, features)
    color = 5. * ratio  # we choose the ratios of nr over r+nr
    geojson_link(links, ['capacity', 'length', 'fftt', 'r_non_routed'], color)
Пример #12
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 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)
Пример #14
0
def visualize_LA():
    net, demand, node = load_LA()
    f = np.loadtxt('data/la/LA_Cython.csv', delimiter=',', skiprows=0)
    features = np.zeros((f.shape[0], 4))
    features[:, :3] = extract_features('data/LA_net.txt')
    #import pdb; pdb.set_trace()
    f = np.divide(f * 4000, features[:, 0])
    features[:, 3] = f
    links = process_links(net, node, features, in_order=True)
    #creates color array used to visulized the links
    #values useful in differenciating links based of flow on links
    color = 2.0 * f + 1.0
    #congestion = f/features[:,0]    #determines the congestion levels of links
    geojson_link(links, ['capacity', 'length', 'fftt', 'flow_over_capacity'],
                 color)
Пример #15
0
def I210_ratio_r_total():
    '''
    study the test_*.csv files generated by I210_parametric_study()
    in particular, visualize the ratio each type of users on each link
    '''
    fs = np.loadtxt('data/test_50.csv', delimiter=',', skiprows=0)
    ratio = np.divide(fs[:, 1], np.maximum(np.sum(fs, axis=1), 1e-8))
    net = np.loadtxt('data/I210_net.csv', delimiter=',', skiprows=1)
    node = np.loadtxt('data/I210_node.csv', delimiter=',', skiprows=1)
    geometry = extract_features('data/I210Sketch_net.csv')
    features = np.zeros((fs.shape[0], 4))
    features[:, :3] = geometry
    features[:, 3] = ratio
    links = process_links(net, node, features)
    color = 2 * ratio  # we choose the ratios of nr over r+nr
    geojson_link(links, ['capacity', 'length', 'fftt', 'r_routed'], color)
def visualize_LA_flow_variation(only_local=False):
    '''
    visualize the variations in link flows
    '''
    net, demand, node, geom = load_LA_2()
    data = np.loadtxt("data/LA/link_variation.csv", delimiter=',', skiprows=1)
    links = process_links(data[:,:3], node, data[:,[0,3,4,5,6,19,20,21]], \
        in_order=True)
    names = ['link_id','capacity','length','fftt','local','max_id','inc','dec']
    color = (data[:,19] - 1.) / 2.
    weight = (data[:,6] == 1.) + 3.*(data[:,6] == 0.)
    if only_local:
        links = links[weight==1.0, :]
        color = color[weight==1.0]
        weight = weight[weight==1.0]
    geojson_link(links, names, color, weight)
def I210_ratio_r_total():
    '''
    study the test_*.csv files generated by I210_parametric_study()
    in particular, visualize the ratio each type of users on each link
    '''
    fs = np.loadtxt('data/test_50.csv', delimiter=',', skiprows=0)
    ratio = np.divide(fs[:,1], np.maximum(np.sum(fs, axis=1), 1e-8))
    net = np.loadtxt('data/I210_net.csv', delimiter=',', skiprows=1)
    node = np.loadtxt('data/I210_node.csv', delimiter=',', skiprows=1)
    geometry = extract_features('data/I210Sketch_net.csv')
    features = np.zeros((fs.shape[0], 4))
    features[:,:3] = geometry
    features[:,3] = ratio
    links = process_links(net, node, features)
    color = 2 * ratio # we choose the ratios of nr over r+nr
    geojson_link(links, ['capacity', 'length', 'fftt', 'r_routed'], color)
def capacities_of_chicago():
    """
    visualize capacities in the network of Chicago
    """
    net, demand, node, features = load_chicago()
    links = process_links(net, node, features)
    color = features[:, 0] / 2000.0  # we choose the capacity
    new_links = []
    new_color = []
    # remove the high capacity links
    for row in range(links.shape[0]):
        if features[row, 0] < 49500.0:
            new_links.append(links[row, :].tolist())
            new_color.append(color[row])
    color = np.array(new_color)
    weight = (color <= 1.0) + 4.0 * (color > 1.0)
    geojson_link(np.array(new_links), ["capacity", "length", "fftt"], color, weight)
def I210_ratio_r_nr(alpha):
    '''
    study the test_*.csv files generated by chicago_parametric_study()
    in particular, visualize the ratio each type of users on each link

    #ratio of non-routed over total for each link 
    '''
    fs = np.loadtxt('data/I210/test_{}.csv'.format(int(alpha*100)), delimiter=',', skiprows=0)
    ratio = np.divide(fs[:,1], np.maximum(np.sum(fs, axis=1), 1e-8))

    net, demand, node, geometry = load_I210()
    features = np.zeros((fs.shape[0], 4))
    features[:,:3] = geometry
    features[:,3] = ratio

    links = process_links(net, node, features, in_order=True)
    color = 5. * ratio # we choose the ratios of nr over r+nr
    geojson_link(links, ['capacity', 'length', 'fftt', 'r_non_routed'], color)
Пример #20
0
def capacities_of_chicago():
    '''
    visualize capacities in the network of Chicago
    '''
    net, demand, node, features = load_chicago()
    links = process_links(net, node, features)
    color = features[:, 0] / 2000.  # we choose the capacity
    new_links = []
    new_color = []
    # remove the high capacity links
    for row in range(links.shape[0]):
        if features[row, 0] < 49500.:
            new_links.append(links[row, :].tolist())
            new_color.append(color[row])
    color = np.array(new_color)
    weight = (color <= 1.0) + 4. * (color > 1.0)
    geojson_link(np.array(new_links), ['capacity', 'length', 'fftt'],
                 color, weight)
def chicago_flow_over_capacity():
    """
    study the test_*.csv files generated by chicago_parametric_study()
    visualize flow/calacity for each edge
    """
    net, demand, node, geometry = load_chicago()
    # f = np.loadtxt('data/test_1.csv', delimiter=',', skiprows=0)
    fs = np.loadtxt("data/test_2.csv", delimiter=",", skiprows=0)
    # fs = np.loadtxt('data/test_3.csv', delimiter=',', skiprows=0)
    # fs = np.loadtxt('data/test_4.csv', delimiter=',', skiprows=0)
    # f = np.loadtxt('data/test_5.csv', delimiter=',', skiprows=0)
    f = np.sum(fs, axis=1)
    features = np.zeros((f.shape[0], 4))
    features[:, :3] = geometry
    f = np.divide(f, features[:, 0] / 4000.0)
    features[:, 3] = f
    links = process_links(net, node, features)
    color = 2.0 * f + 1.0
    geojson_link(links, ["capacity", "length", "fftt", "flow_over_capacity"], color)
Пример #22
0
def chicago_flow_over_capacity():
    '''
    study the test_*.csv files generated by chicago_parametric_study()
    visualize flow/calacity for each edge
    '''
    net, demand, node, geometry = load_chicago()
    # f = np.loadtxt('data/test_1.csv', delimiter=',', skiprows=0)
    fs = np.loadtxt('data/test_2.csv', delimiter=',', skiprows=0)
    # fs = np.loadtxt('data/test_3.csv', delimiter=',', skiprows=0)
    # fs = np.loadtxt('data/test_4.csv', delimiter=',', skiprows=0)
    # f = np.loadtxt('data/test_5.csv', delimiter=',', skiprows=0)
    f = np.sum(fs, axis=1)
    features = np.zeros((f.shape[0], 4))
    features[:,:3] = geometry
    f = np.divide(f, features[:,0]/4000.0)
    features[:,3] = f
    links = process_links(net, node, features)
    color = 2.0*f + 1.0
    geojson_link(links, ['capacity', 'length', 'fftt', 'flow_over_capacity'], color)
def chicago_tt_over_fftt():
    """
    study the test_*.csv files generated by chicago_parametric_study()
    visualize tt/fftt for each edge
    """
    net, demand, node, geometry = load_chicago()
    g_nr, small_capacity = add_cognitive_cost(net, geometry, 2000.0, 1000.0)
    # f = np.loadtxt('data/test_0.csv', delimiter=',', skiprows=0)
    alpha = 0.01
    fs = np.loadtxt("data/test_{}.csv".format(int(100.0 * alpha)), delimiter=",", skiprows=0)
    # f = np.loadtxt('data/test_100.csv', delimiter=',', skiprows=0)
    f = np.sum(fs, axis=1)
    costs = cost_ratio(f, net)
    features = np.zeros((f.shape[0], 4))
    features[:, :3] = geometry
    features[:, 3] = costs
    links = process_links(net, node, features)
    color = (costs - 1.0) * 2.0 + 1.0
    geojson_link(links, ["capacity", "length", "fftt", "tt_over_fftt"], color)
Пример #24
0
def chicago_tt_over_fftt():
    '''
    study the test_*.csv files generated by chicago_parametric_study()
    visualize tt/fftt for each edge
    '''
    net, demand, node, geometry = load_chicago()
    g_nr, small_capacity = add_cognitive_cost(net, geometry, 2000., 1000.)
    # f = np.loadtxt('data/test_0.csv', delimiter=',', skiprows=0)
    alpha = 0.01
    fs = np.loadtxt('data/test_{}.csv'.format(int(100.*alpha)), delimiter=',', skiprows=0)
    # f = np.loadtxt('data/test_100.csv', delimiter=',', skiprows=0)
    f = np.sum(fs, axis=1)
    costs = cost_ratio(f, net)
    features = np.zeros((f.shape[0], 4))
    features[:,:3] = geometry
    features[:,3] = costs
    links = process_links(net, node, features)
    color = (costs - 1.0) * 2.0 + 1.0
    geojson_link(links, ['capacity', 'length', 'fftt', 'tt_over_fftt'], color)
Пример #25
0
def I210_ratio_r_nr(alpha):
    '''
    study the test_*.csv files generated by chicago_parametric_study()
    in particular, visualize the ratio each type of users on each link
    ratio of non-routed over total for each link
    '''
    fs = np.loadtxt(
        'data/I210/test_{}.csv'.format(int(alpha * 100)),
        delimiter=',', skiprows=0)
    ratio = np.divide(fs[:, 1], np.maximum(np.sum(fs, axis=1), 1e-8))

    net, demand, node, geometry = load_I210()
    features = np.zeros((fs.shape[0], 4))
    features[:, :3] = geometry
    features[:, 3] = ratio

    links = process_links(net, node, features, in_order=True)
    color = 5. * ratio  # we choose the ratios of nr over r+nr
    geojson_link(links, ['capacity', 'length', 'fftt', 'r_non_routed'], color)
def visualize_LA_flow_variation(only_local=False):
    '''
    visualize the variations in link flows
    '''
    net, demand, node, geom = load_LA_2()
    data = np.loadtxt("data/LA/link_variation.csv", delimiter=',', skiprows=1)
    links = process_links(data[:,:3], node, data[:,[0,3,4,5,6,19,20,21]], \
        in_order=True)
    names = [
        'link_id', 'capacity', 'length', 'fftt', 'local', 'max_id', 'inc',
        'dec'
    ]
    color = (data[:, 19] - 1.) / 2.
    weight = (data[:, 6] == 1.) + 3. * (data[:, 6] == 0.)
    if only_local:
        links = links[weight == 1.0, :]
        color = color[weight == 1.0]
        weight = weight[weight == 1.0]
    geojson_link(links, names, color, weight)
def visualize_LA_result_Scenario_Study(fileName, ratio):
    net, demand, node = load_LA()
    f = np.loadtxt(fileName, delimiter=',', skiprows=0)
    features = np.zeros((f.shape[0], 4))
    features[:, :3] = extract_features('data/LA_net.txt')
    #features[:,:3] = extract_features('data/ChicagoRegional_net.txt')
    f = np.divide(f * 4000, features[:, 0])
    features[:, 3] = f
    links = process_links(net, node, features, in_order=True)
    #creates color array used to visulized the links
    #values useful in differenciating links based of flow on links
    color = 2.0 * f + 1.0

    #Keeping track of the percentage of congestion
    links_congested = len(color[np.where(color >= 3)])
    percentage_of_congestion = float(links_congested) / float(len(color))
    print("congestion is at %3f " % percentage_of_congestion)
    geojson_link_Scenario_Study(
        ratio, links, ['capacity', 'length', 'fftt', 'flow_over_capacity'],
        color)
Пример #28
0
def visualize_LA_total_flows(alpha, only_local=False):
    '''
    visualize total flow in L.A. using total_link_flows.csv as input
    '''
    net, demand, node, geom = load_LA_2()
    f = np.loadtxt('data/LA/total_link_flows.csv', delimiter=',', skiprows=1)
    names = ['link_id', 'capacity', 'length', 'fftt', 'local', 'flow']
    features = np.zeros((f.shape[0], 6))
    features[:, 0] = net[:, 0]
    features[:, 1:4] = geom
    features[:, 4] = f[:, 6]
    features[:, 5] = f[:, 7 + int(alpha / 10.)]
    links = process_links(net, node, features, in_order=True)
    color = features[:, 5] * 10.
    color = color + (color > 0.0)
    weight = (features[:, 1] <= 900.) + 2. * (features[:, 1] > 900.)
    if only_local:
        links = links[weight == 1.0, :]
        color = color[weight == 1.0]
        weight = weight[weight == 1.0]
    geojson_link(links, names, color, weight)
def visualize_LA_total_flows(alpha, only_local=False):
    '''
    visualize total flow in L.A. using total_link_flows.csv as input
    '''
    net, demand, node, geom = load_LA_2()
    f = np.loadtxt('data/LA/total_link_flows.csv', delimiter=',', \
        skiprows=1)
    names = ['link_id', 'capacity', 'length', 'fftt', 'local', 'flow']
    features = np.zeros((f.shape[0], 6))
    features[:,0] = net[:,0]
    features[:,1:4] = geom
    features[:,4] = f[:,6]
    features[:,5] = f[:,7+int(alpha/10.)]
    links = process_links(net, node, features, in_order=True)
    color = features[:,5] * 10.
    color = color + (color > 0.0)
    weight = (features[:,1] <= 900.) + 2.*(features[:,1] > 900.)
    if only_local:
        links = links[weight==1.0, :]
        color = color[weight==1.0]
        weight = weight[weight==1.0]
    geojson_link(links, names, color, weight)
Пример #30
0
def visual(alpha):
    '''
    study the test_*.csv files generated by chicago_parametric_study()
    in particular, visualize the ratio each type of users on each link

    #ratio of non-routed over total for each link 
    '''
    fs = np.loadtxt('data/I210/test_{}.csv'.format(int(alpha * 100)),
                    delimiter=',',
                    skiprows=0)

    f_total = 4000 * np.sum(fs, axis=1)
    color = np.zeros(len(f_total))

    v_max = 30000
    v_thres = 6000

    for i in range(len(f_total)):
        if f_total[i] <= v_thres:
            color[i] = 1
        # elif f_total[i]<=2*v_thres:
        #     color[i]=2
        # elif f_total[i]<=3*v_thres:
        #     color[i]=3
        # elif f_total[i]<=4*v_thres:
        #     color[i]=4
        else:
            color[i] = 5

    print(np.mean(color))

    net, demand, node, geometry = load_I210()
    features = np.zeros((fs.shape[0], 4))
    features[:, :3] = geometry
    features[:, 3] = f_total

    links = process_links(net, node, features, in_order=True)
    #color = 5. * ratio # we choose the ratios of nr over r+nr
    geojson_link(links, ['capacity', 'length', 'fftt', 'r_non_routed'], color)
def visual(alpha):
    '''
    study the test_*.csv files generated by chicago_parametric_study()
    in particular, visualize the ratio each type of users on each link

    #ratio of non-routed over total for each link 
    '''
    fs = np.loadtxt('data/I210/test_{}.csv'.format(int(alpha*100)), delimiter=',', skiprows=0)

    f_total = 4000*np.sum(fs, axis=1)
    color = np.zeros(len(f_total))

    v_max= 30000
    v_thres = 6000

    for i in range(len(f_total)):
        if f_total[i]<=v_thres:
            color[i]=1
        # elif f_total[i]<=2*v_thres:
        #     color[i]=2
        # elif f_total[i]<=3*v_thres:
        #     color[i]=3
        # elif f_total[i]<=4*v_thres:
        #     color[i]=4
        else:
            color[i]=5     



    print(np.mean(color))

    net, demand, node, geometry = load_I210()
    features = np.zeros((fs.shape[0], 4))
    features[:,:3] = geometry
    features[:,3] = f_total

    links = process_links(net, node, features, in_order=True)
    #color = 5. * ratio # we choose the ratios of nr over r+nr
    geojson_link(links, ['capacity', 'length', 'fftt', 'r_non_routed'], color)
Пример #32
0
            '{}/{}_net_od_2_alpha_0.{:02d}.txt'.format(dash_data, prefix, 50),
            'r') as infile:
        run = pickle.loads(infile.read())
    fs = run['f']
    f = np.array([l[0] + l[1] for l in fs])
    if net == 'la':
        node = np.loadtxt('data/LA_node.csv', delimiter=',')
        features = np.zeros((f.shape[0], 4))
        features[:, :3] = extract_features('data/LA_net.txt')
    elif net == 'chicago':
        node = np.loadtxt('data/Chicago_node.csv', delimiter=',', skiprows=1)
        features = np.zeros((f.shape[0], 4))
        features[:, :3] = extract_features('data/ChicagoSketch_net.txt')
    f = np.divide(f * 4000, features[:, 0])
    features[:, 3] = f
    links = process_links(graph, node, features, in_order=True)

    link2coord = {}
    for i in range(len(links)):
        link2coord[i] = {
            'origin': [links[i, 0], links[i, 1]],
            'destination': [links[i, 2], links[i, 3]],
        }
    with open('{}/link_coord.json'.format(out_data), 'w') as f:
        json.dump(link2coord, f, indent=0)

nds = []
index = 0
path2id = {}
id2path = {}
for alpha in range(0, 100):
def I210_capacities():
    net, demand, node, features = load_I210()
    links = process_links(net, node, features)
    color = 2.*(features[:,0] <= 3000.) + 5.*(features[:,0] > 3000.)
    weight = (features[:,0] <= 3000.) + 2.*(features[:,0] > 3000.)
    geojson_link(links, ['capacity', 'length', 'fftt'], color, 2.*weight)
Пример #34
0
def I210_capacities():
    net, demand, node, features = load_I210()
    links = process_links(net, node, features)
    color = 2. * (features[:, 0] <= 3000.) + 5. * (features[:, 0] > 3000.)
    weight = (features[:, 0] <= 3000.) + 2. * (features[:, 0] > 3000.)
    geojson_link(links, ['capacity', 'length', 'fftt'], color, 2. * weight)