Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
592 changes: 546 additions & 46 deletions Stable Dynamic & Beckman/Plot.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Stable Dynamic & Beckman/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# parsers = 'vladik'
# parsers = 'tntpd'
parsers = 'custom'
parsers = 'tntp'
# parsers = 'custom'

vl_links_file = '../data/vl_links'
vl_trips_file = '../data/vl_trips'
Expand Down
16 changes: 11 additions & 5 deletions Stable Dynamic & Beckman/data_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@

pd.set_option('display.max_columns', None)

TNTP_TRIPS_FNAME = '../data/Custom_trips.tntp' # '../data/SiouxFalls_trips.tntp'
TNTP_NET_FNAME = '../data/Custom_trips.tntp' # '../data/SiouxFalls_net.tntp'

# TNTP_TRIPS_FNAME = '../data/Custom_trips.tntp' #
TNTP_TRIPS_FNAME = '../data/SiouxFalls_trips.tntp'
# TNTP_NET_FNAME = '../data/Custom_trips.tntp'
TNTP_NET_FNAME = '../data/SiouxFalls_net.tntp'

# TODO: DOCUMENTATION!!!
class DataHandler:
Expand Down Expand Up @@ -177,8 +178,13 @@ def GetLW_dicts(parser):
return L_dict, W_dict

@staticmethod
def save_input_data_to_res(graph_data, L_dict, W_dict):
root = 'KEV_res/input_data/'
def save_input_data_to_res(graph_data, L_dict, W_dict, tax_enabled = None):
if tax_enabled is None:
root = 'KEV_res/input_data/'
elif tax_enabled:
root = 'KEV_res_taxes/input_data/'
else:
root = 'KEV_res_no_taxes/input_data/'
with open(root + 'graph_data.pickle', 'wb') as fp:
pickle.dump(graph_data, fp)
with open(root + 'L_dict.json', 'w') as fp:
Expand Down
17 changes: 14 additions & 3 deletions Stable Dynamic & Beckman/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _index_nodes(graph_table, graph_correspondences, fill_corrs=True):
inds_to_nodes = dict(zip(range(len(nodes)), nodes))
return inds_to_nodes, correspondences, table

def find_equilibrium(self, solver_name='ustm', composite=True, solver_kwargs={}, base_flows=None):
def find_equilibrium(self, solver_name='ustm', composite=True, solver_kwargs={}, base_flows=None, use_taxes=False):
if solver_name == 'fwm':
solver_func = fwm.frank_wolfe_method
starting_msg = 'Frank-Wolfe method...'
Expand Down Expand Up @@ -81,8 +81,12 @@ def find_equilibrium(self, solver_name='ustm', composite=True, solver_kwargs={},

phi_big_oracle = oracles.PhiBigOracle(self.graph, self.graph_correspondences)

h_oracle = oracles.HOracle(self.graph.initial_times, self.graph.capacities,
rho=self.rho, mu=self.mu)
if use_taxes:
h_oracle = oracles.HTaxesOracle(self.graph.initial_times, self.graph.capacities,
rho=self.rho, mu=self.mu)
else:
h_oracle = oracles.HOracle(self.graph.initial_times, self.graph.capacities,
rho=self.rho, mu=self.mu)
primal_dual_calculator = dfc.PrimalDualCalculator(phi_big_oracle, h_oracle,
self.graph.initial_times, self.graph.capacities,
rho=self.rho, mu=self.mu, base_flows=base_flows)
Expand Down Expand Up @@ -124,6 +128,13 @@ def prox_func(grad, point, A):
# print('att! ', subg_t, np.shape(subg_t))
result['subg'] = subg_t

if use_taxes:
if self.mu == 0:
result['taxes'] = result['times'] - self.graph.initial_times
else:
result['taxes'] = self.rho * self.graph.initial_times / self.mu * \
(result['flows'] / self.graph.capacities) ** (1 / self.mu)

for source in self.graph_correspondences:
targets = self.graph_correspondences[source]['targets']
travel_times, pred_map = self.graph.shortest_distances(source, targets, result['times'])
Expand Down
26 changes: 15 additions & 11 deletions Stable Dynamic & Beckman/multi-stage-new.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
sink_num_iter, sink_eps = 25000, 10 ** (-8)
INF_COST = 100
INF_TIME = 1e10

USE_TAXES = True

def get_times_inverse_func(capacity, times, rho=0.15, mu=0.25):
capacities = capacity.to_numpy()
Expand All @@ -42,7 +42,7 @@ def get_LW(L_dict, W_dict, new_to_old):
columns=['init_node', 'term_node', 'capacity', 'free_flow_time'])

L_dict, W_dict = handler.GetLW_dicts(eval(f'handler.{parsers}_corr_parser'))
handler.save_input_data_to_res(graph_data, L_dict, W_dict)
handler.save_input_data_to_res(graph_data, L_dict, W_dict, USE_TAXES)

handler = dh.DataHandler()

Expand All @@ -62,7 +62,7 @@ def get_LW(L_dict, W_dict, new_to_old):
graph_data, model)
T = handler.T_matrix_from_dict(T_dict, empty_corr_matrix.shape, old_to_new)

for ms_i in range(12):
for ms_i in range(114):

print('iteration: ', ms_i)

Expand All @@ -87,9 +87,9 @@ def get_LW(L_dict, W_dict, new_to_old):
solver_kwargs = {'eps_abs': eps_abs,
'max_iter': max_iter}

result = model.find_equilibrium(solver_name='ustm', composite=True,
result = model.find_equilibrium(solver_name='wda', composite=True,
solver_kwargs=solver_kwargs,
base_flows=alpha * graph_data['graph_table']['capacity'])
base_flows=alpha * graph_data['graph_table']['capacity'], use_taxes=USE_TAXES)

model.graph.update_flow_times(result['times'])

Expand All @@ -104,9 +104,13 @@ def get_LW(L_dict, W_dict, new_to_old):

subg = result['subg']

np.savetxt('KEV_res/multi/flows/' + str(ms_i) + '_flows.txt', result['flows'], delimiter=' ')
np.savetxt('KEV_res/multi/times/' + str(ms_i) + '_time.txt', result['times'], delimiter=' ')
np.savetxt('KEV_res/multi/corr_matrix/' + str(ms_i) + '_corr_matrix.txt', rec, delimiter=' ')
np.savetxt('KEV_res/multi/inverse_func/' + str(ms_i) + '_inverse_func.txt', flows_inverse_func,
delimiter=' ')
np.savetxt('KEV_res/multi/subg/' + str(ms_i) + '_nabla_func.txt', subg, delimiter=' ')
if USE_TAXES:
root = 'KEV_res_taxes/'
else:
root = 'KEV_res_no_taxes/'
np.savetxt(root + 'multi/flows/' + str(ms_i) + '_flows.txt', result['flows'], delimiter=' ')
np.savetxt(root + 'multi/times/' + str(ms_i) + '_time.txt', result['times'], delimiter=' ')
np.savetxt(root + 'multi/corr_matrix/' + str(ms_i) + '_corr_matrix.txt', rec, delimiter=' ')
np.savetxt(root + 'multi/inverse_func/' + str(ms_i) + '_inverse_func.txt', flows_inverse_func,
delimiter=' ')
np.savetxt(root + '/multi/subg/' + str(ms_i) + '_nabla_func.txt', subg, delimiter=' ')
Loading