def create_csv_from_choice_sets(choice_sets,trip_ids,pathname,linkname): """create two linked csv tables containing path links and path ids for viewing in GIS""" linkfile=open(linkname,'w') link_writer=csv.writer(linkfile,lineterminator='\r') pathfile=open(pathname,'w') path_writer=csv.writer(pathfile,lineterminator='\r') link_writer.writerow(['link_id','occ_id','trip_id','path_id','a','b']) path_writer.writerow(['occ_id','trip_id','path_id','orig','dest']) for k in range(len(choice_sets)): curset=choice_sets[k] for i in range(len(curset)): prelimpath=curset[i] if type(prelimpath[1])==type((1,2)): curpath=get_orig_path(prelimpath) else: curpath=prelimpath path_writer.writerow([str(k),trip_ids[k],str(i),curpath[0],curpath[-1]]) for j in range(len(curpath)-1): link_writer.writerow([str(j),str(k),trip_ids[k],str(i),curpath[j],curpath[j+1]]) linkfile.close() pathfile.close()
def create_csv_from_choice_sets(choice_sets, trip_ids, pathname, linkname): """create two linked csv tables containing path links and path ids for viewing in GIS""" linkfile = open(linkname, 'w') link_writer = csv.writer(linkfile, lineterminator='\r') pathfile = open(pathname, 'w') path_writer = csv.writer(pathfile, lineterminator='\r') link_writer.writerow(['link_id', 'occ_id', 'trip_id', 'path_id', 'a', 'b']) path_writer.writerow(['occ_id', 'trip_id', 'path_id', 'orig', 'dest']) for k in range(len(choice_sets)): curset = choice_sets[k] for i in range(len(curset)): prelimpath = curset[i] if type(prelimpath[1]) == type((1, 2)): curpath = get_orig_path(prelimpath) else: curpath = prelimpath path_writer.writerow( [str(k), trip_ids[k], str(i), curpath[0], curpath[-1]]) for j in range(len(curpath) - 1): link_writer.writerow([ str(j), str(k), trip_ids[k], str(i), curpath[j], curpath[j + 1] ]) linkfile.close() pathfile.close()
def path_size(G, choice_sets, choice_set_config): result = [] config = choice_set_config the_network = G if G.orig_network is not None: the_network = G.orig_network for path_list in choice_sets: temp = [] hashes = [] lengths = [] for cur_path in path_list: use_path = cur_path if G.orig_network is not None: use_path = get_orig_path(cur_path) cur_hash = {} cur_length = 0 for i in range(len(use_path) - 1): cur_hash[(use_path[i], use_path[i + 1])] = the_network[ use_path[i]][use_path[i + 1]][config['overlap_var']] cur_length = cur_length + cur_hash[(use_path[i], use_path[i + 1])] hashes.append(cur_hash) lengths.append(cur_length) min_length = min(lengths) for i in range(len(path_list)): PS = 0 for a in hashes[i]: delta_sum = 0 for j in range(len(path_list)): if a in hashes[j]: delta_sum = delta_sum + min_length / lengths[j] PS = PS + hashes[i][a] / lengths[i] / delta_sum temp.append(PS) result.append(temp) return result
def path_size(G,choice_sets,choice_set_config): result=[] config=choice_set_config the_network=G if G.orig_network is not None: the_network=G.orig_network for path_list in choice_sets: temp=[] hashes=[]; lengths=[] for cur_path in path_list: use_path=cur_path if G.orig_network is not None: use_path=get_orig_path(cur_path) cur_hash={} cur_length=0 for i in range(len(use_path)-1): cur_hash[(use_path[i],use_path[i+1])]=the_network[use_path[i]][use_path[i+1]][config['overlap_var']] cur_length=cur_length+cur_hash[(use_path[i],use_path[i+1])] hashes.append(cur_hash) lengths.append(cur_length) min_length=min(lengths) for i in range(len(path_list)): PS=0 for a in hashes[i]: delta_sum=0 for j in range(len(path_list)): if a in hashes[j]: delta_sum=delta_sum+min_length/lengths[j] PS=PS+hashes[i][a]/lengths[i]/delta_sum temp.append(PS) result.append(temp) return result