def I210_parametric_study(alphas): # load the network and its properties g_r, d, node, feat = load_I210_modified() # modify the costs on non routed network g_nr, small_capacity = multiply_cognitive_cost(g_r, feat, 3000., 100.) #divide the demand by 4000 to computationally optimize d[:,2] = d[:,2] / 4000. for alpha in alphas: if alpha == 0.0: print 'non-routed = 1.0, routed = 0.0' f_nr = solver_3(g_nr, d, max_iter=1000, stop=1e-3) fs=np.zeros((f_nr.shape[0],2)) fs[:,0]=f_nr elif alpha == 1.0: print 'non-routed = 0.0, routed = 1.0' f_r = solver_3(g_r, d, max_iter=1000, stop=1e-3) fs=np.zeros((f_r.shape[0],2)) fs[:,1]=f_r else: print 'non-routed = {}, routed = {}'.format(1-alpha, alpha) d_nr, d_r = heterogeneous_demand(d, alpha) fs = gauss_seidel([g_nr,g_r], [d_nr,d_r], solver_3, max_iter=1000, \ stop=1e-3, stop_cycle=1e-3, q=50, past=20) np.savetxt('data/I210_modified/test_{}.csv'.format(int(alpha*100)), fs, \ delimiter=',', header='f_nr,f_r')
def parametric_study(alphas, g, d, node, geometry, thres, cog_cost, output, \ stop=1e-2, stop_cycle=1e-2): g_nr, small_capacity = multiply_cognitive_cost(g, geometry, thres, cog_cost) if (type(alphas) is float) or (type(alphas) is int): alphas = [alphas] for alpha in alphas: #special case where in fact homogeneous game if alpha == 0.0: print 'non-routed = 1.0, routed = 0.0' f_nr = solver_3(g_nr, d, max_iter=1000, display=1, stop=stop) fs=np.zeros((f_nr.shape[0],2)) fs[:,0]=f_nr elif alpha == 1.0: print 'non-routed = 0.0, routed = 1.0' f_r = solver_3(g, d, max_iter=1000, display=1, stop=stop) fs=np.zeros((f_r.shape[0],2)) fs[:,1]=f_r #run solver else: print 'non-routed = {}, routed = {}'.format(1-alpha, alpha) d_nr, d_r = heterogeneous_demand(d, alpha) fs = gauss_seidel([g_nr,g], [d_nr,d_r], solver_3, max_iter=1000, \ display=1, stop=stop, stop_cycle=stop_cycle, q=50, past=20) np.savetxt(output.format(int(alpha*100)), fs, \ delimiter=',', header='f_nr,f_r')
def I210_parametric_study(alphas): # load the network and its properties g_r, d, node, feat = load_I210_modified() # modify the costs on non routed network g_nr, small_capacity = multiply_cognitive_cost(g_r, feat, 3000., 100.) #divide the demand by 4000 to computationally optimize d[:, 2] = d[:, 2] / 4000. for alpha in alphas: if alpha == 0.0: print 'non-routed = 1.0, routed = 0.0' f_nr = solver_3(g_nr, d, max_iter=1000, stop=1e-3) fs = np.zeros((f_nr.shape[0], 2)) fs[:, 0] = f_nr elif alpha == 1.0: print 'non-routed = 0.0, routed = 1.0' f_r = solver_3(g_r, d, max_iter=1000, stop=1e-3) fs = np.zeros((f_r.shape[0], 2)) fs[:, 1] = f_r else: print 'non-routed = {}, routed = {}'.format(1 - alpha, alpha) d_nr, d_r = heterogeneous_demand(d, alpha) fs = gauss_seidel([g_nr,g_r], [d_nr,d_r], solver_3, max_iter=1000, \ stop=1e-3, stop_cycle=1e-3, q=50, past=20) np.savetxt('data/I210_modified/test_{}.csv'.format(int(alpha*100)), fs, \ delimiter=',', header='f_nr,f_r')
def main(): for alpha in [.75]: # for alpha in np.linspace(0, .49, 50): # for alpha in np.linspace(.5, .99, 50): print "ALPHA:", alpha start_time2 = timeit.default_timer() 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) node = np.loadtxt('data/LA_node.csv', delimiter=',') features = extract_features('data/LA_net.txt') # graph = np.loadtxt('data/Chicago_net.csv', delimiter=',', skiprows=1) # demand = np.loadtxt('data/Chicago_od.csv', delimiter=',', skiprows=1) # node = np.loadtxt('data/Chicago_node.csv', delimiter=',', skiprows=1) # features = extract_features('data/ChicagoSketch_net.txt') # features = table in the format [[capacity, length, FreeFlowTime]] # alpha = .2 # also known as r thres = 1000. cog_cost = 3000. demand[:, 2] = 0.5 * demand[:, 2] / 4000 g_nr, small_capacity = multiply_cognitive_cost(graph, features, thres, cog_cost) d_nr, d_r = heterogeneous_demand(demand, alpha) fs, hs, n_d = fw_heterogeneous_1([graph, g_nr], [d_r, d_nr], alpha, max_iter=30, display=1) print n_d output = {'f': fs, 'h': hs, 'n_d': n_d} with open('graph_stuff/LA_net_od_2_alpha_{}.txt'.format(alpha), 'w') as outfile: # with open('graph_stuff/Chicago_net_od_2_alpha_{}.txt'.format(alpha), 'w') as outfile: outfile.write(pickle.dumps(output)) #end of timer elapsed2 = timeit.default_timer() - start_time2 print("Execution took %s seconds" % elapsed2)
def main(): start_time2 = timeit.default_timer() 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) alpha = .2 demand[:, 2] = 0.5 * demand[:, 2] / 4000 d_nr, d_r = heterogeneous_demand(demand, alpha) f, h = solver_3(graph, d_nr, d_r, max_iter=10, display=1) #end of timer elapsed2 = timeit.default_timer() - start_time2 print("Execution took %s seconds" % elapsed2) visualize_LA()
# graph = np.loadtxt('data/Chicago_net.csv', delimiter=',', skiprows=1) # demand = np.loadtxt('data/Chicago_od.csv', delimiter=',', skiprows=1) # node = np.loadtxt('data/Chicago_node.csv', delimiter=',', skiprows=1) # features = extract_features('data/ChicagoSketch_net.txt') # features = table in the format [[capacity, length, FreeFlowTime]] # alpha = .2 # also known as r thres = 1000. cog_cost = 3000. demand[:, 2] = 0.5 * demand[:, 2] / 4000 g_nr, small_capacity = multiply_cognitive_cost(graph, features, thres, cog_cost) d_nr, d_r = heterogeneous_demand(demand, alpha) fs, hs, n_d = fw_heterogeneous_1([graph, g_nr], [d_r, d_nr], alpha, max_iter=30, display=1) # print n_d output = {'f': fs, 'h': hs, 'n_d': n_d} with open('graph_stuff/LA_net_od_2_alpha_{}.txt'.format(alpha), 'w') as outfile: # with open('graph_stuff/Chicago_net_od_2_alpha_{}.txt'.format(alpha), 'w') as outfile: outfile.write(pickle.dumps(output)) #end of timer elapsed = timeit.default_timer() - start_time