# Path: route_model/choice_set/generate_choice_set.py
# def generate_choice_set(G,chosen,choice_set_config,link_randomizer=None,time_dependent_relation=None,trip_time=None,ext_bound=None):
# 	
# 	config=choice_set_config
# 	
# 	if config['method']=='link_elimination':
# 		return le_generate(G,chosen,config)
# 		
# 	if config['method']=='doubly_stochastic':
# 		return ds_generate(G,chosen,config,link_randomizer,ext_bound,time_dependent_relation,trip_time)


import os, csv, sys
import route_model.misc as rm_misc
import route_model.input as rm_input
import route_model.output as rm_output
import route_model.choice_set.ds_generate as ds
import time
import random
import numpy
from optparse import OptionParser
from transport_network import TransportNetwork, create_pseudo_dual
from route_model.choice_set.generate_choice_set import generate_choice_set
from multiprocessing import Lock, Process, current_process, Queue


def param_worker(work_queue,done_queue,network,trip_data,master_config,trip_times,ext_bound,trip_ids):
	
	this_network=network.copy()
	
	#initialize link randomizer
	link_randomizer=None
	if master_config.choice_set_config['method']=='doubly_stochastic':
		link_randomizer=master_config.choice_set_config.get_link_randomizer(network,master_config)
	
	for kappa, sigma in iter(work_queue.get,'STOP'):

		link_randomizer.set_scl(kappa)
		link_randomizer.set_par(link_randomizer['zero']['par'],[1-sigma,1+sigma])
		link_randomizer.update_denoms()
		
		random.seed(0)
		idx=0
		overlap_sum=0
		for trip_id in trip_ids:
			idx=idx+1
			print time.asctime(time.localtime()), "-", current_process().name, "-",idx, ", k: ", kappa, ", s: ", sigma ,". trip_id: ", trip_id[0], ", sub_trip: ", trip_id[1], ", stage: ", trip_id[2]

# Path: route_model/choice_set/generate_choice_set.py
# def generate_choice_set(G,chosen,choice_set_config,link_randomizer=None,time_dependent_relation=None,trip_time=None,ext_bound=None):
# 	
# 	config=choice_set_config
# 	
# 	if config['method']=='link_elimination':
# 		return le_generate(G,chosen,config)
# 		
# 	if config['method']=='doubly_stochastic':
# 		return ds_generate(G,chosen,config,link_randomizer,ext_bound,time_dependent_relation,trip_time)


# Path: route_model/evaluate_parameters.py
import os, csv, sys
import route_model.misc as rm_misc
import route_model.input as rm_input
import route_model.output as rm_output
import route_model.choice_set.ds_generate as ds
import time
import random
import numpy
from optparse import OptionParser
from transport_network import TransportNetwork, create_pseudo_dual
from route_model.choice_set.generate_choice_set import generate_choice_set
from multiprocessing import Lock, Process, current_process, Queue



def param_worker(work_queue,done_queue,network,trip_data,master_config,trip_times,ext_bound,trip_ids):
	
	this_network=network.copy()
	
	#initialize link randomizer
	link_randomizer=None
	if master_config.choice_set_config['method']=='doubly_stochastic':
		link_randomizer=master_config.choice_set_config.get_link_randomizer(network,master_config)
	
	for kappa, sigma in iter(work_queue.get,'STOP'):

		link_randomizer.set_scl(kappa)
		link_randomizer.set_par(link_randomizer['zero']['par'],[1-sigma,1+sigma])
		link_randomizer.update_denoms()
		
		random.seed(0)
		idx=0
		overlap_sum=0
		for trip_id in trip_ids:
			idx=idx+1
			print time.asctime(time.localtime()), "-", current_process().name, "-",idx, ", k: ", kappa, ", s: ", sigma ,". trip_id: ", trip_id[0], ", sub_trip: ", trip_id[1], ", stage: ", trip_id[2]

			the_set,chosen_overlap=generate_choice_set(this_network,trip_data[trip_id],master_config.choice_set_config,link_randomizer,master_config['time_dependent_relation'],trip_times[trip_id[0]],ext_bound)