def path_feasible(path, graph, init_soc): current_range_soc = init_soc for roadSeg in path: velocity = graph.node[roadSeg][ 'speed_urban'] * DECREASE_SPEED #this is modified such that if we install every then final_soc = 1 if start_soc = 1 distance = graph.node[roadSeg]['length'] * 0.000621371 * INCREASE_LENGTH current_range_soc = write_data.nextSOC_real_data( current_range_soc, distance, 1, velocity, False) return current_range_soc
def no_install_final_soc(graph, path): current_range_soc = 1 #INSTALL = False for roadSeg in path: INSTALL = False velocity = graph.node[roadSeg]['speed_urban'] distance = graph.node[roadSeg][ 'length'] * 0.00621371 #real soc no decrease or increase speed or distance current_range_soc = write_data.nextSOC_real_data( current_range_soc, distance, 1, velocity, INSTALL) return current_range_soc
def path_to_layeredGraph(graph, path, pathNumber, data, data_var, nLayers): #soure arcs next_node = roadSeg_to_node(path[0], nLayers) #Assume we start when fully charged #if not fully charged, we need to change next_node i.e (next_node + i) #data['arcs'] = "".join([data['arcs'], " (", str(pathNumber), ",source,", str(next_node), ")\n" ]) #data['weight'] = "".join([data['weight'], " ", str(pathNumber), " source ", str(next_node), " 0\n" ]) for i in range(nLayers): data_var['nodes'].add(next_node + i) #data['arcs'] = "".join([data['arcs'], " (", str(pathNumber), ",source,", str(next_node + i), ")\n" ]) #data['weight'] = "".join([data['weight'], " ", str(pathNumber), " source ", str(next_node + i), " 0\n" ]) data['arcs'].append("".join( [" (", str(pathNumber), ",source,", str(next_node + i), ")\n"])) data['weight'].append("".join( [" ", str(pathNumber), " source ", str(next_node + i), " 0\n"])) #destination arcs node = roadSeg_to_node(path[-1], nLayers) data_var['roadSegs'].add(path[-1]) for i in range(nLayers): data_var['nodes'].add(node + i) data['arcs'].append("".join( [" (", str(pathNumber), ",", str(node + i), ", destination) \n"])) data['weight'].append("".join( [" ", str(pathNumber), " ", str(node + i), " destination 0 \n"])) standard_soc = node_to_soc(node + i, nLayers) data['boundary_node_weights'].append("".join([ " ", str(pathNumber), " ", str(node + i), " ", str(standard_soc), "\n" ])) data['boundary_nodes'].append("".join( [" (", str(pathNumber), ",", str(node + i), ")\n"])) for i, roadSeg in enumerate(path[:-1]): len_path = len(path) data_var['roadSegs'].add(roadSeg) next_roadSeg = path[i + 1] start_node = roadSeg_to_node(roadSeg, nLayers) next_start_node = roadSeg_to_node(next_roadSeg, nLayers) for j in range(nLayers): current_node = start_node + j data_var['nodes'].add(current_node) current_standard_soc = node_to_soc(current_node, nLayers) if current_standard_soc < 1.0e-10: #boundary node data['arcs'].append("".join([ " (", str(pathNumber), ",", str(current_node), ",", " destination)\n" ])) data['weight'].append("".join([ " ", str(pathNumber), " ", str(current_node), " destination 0\n" ])) data['boundary_node_weights'].append("".join([ " ", str(pathNumber), " ", str(current_node), " ", str(-(len_path - 1 - i) / (len_path - 1)), "\n" ])) data['boundary_nodes'].append("".join( [" (", str(pathNumber), ",", str(current_node), ")\n"])) else: #INSTALL = True INSTALL = True velocity = graph.node[str(roadSeg - 2)]['speed_urban'] * DECREASE_SPEED distance = graph.node[str(roadSeg - 2)][ 'length'] * 0.00621371 * INCREASE_LENGTH + EPSILON_LENGTH current_range_soc = standard_soc_to_range_soc( current_standard_soc, soc_lower_bound) next_range_soc = write_data.nextSOC_real_data( current_range_soc, distance, 1, velocity, INSTALL) next_standard_soc = range_soc_to_standard_soc( next_range_soc, nLayers, soc_lower_bound) next_node_posn = position_in_layer(next_standard_soc, nLayers) next_node = next_start_node + next_node_posn data['arcs'].append("".join([ " (", str(pathNumber), ",", str(current_node), ",", str(next_node), ") \n" ])) data['weight'].append("".join([ " ", str(pathNumber), " ", str(current_node), " ", str(next_node), " 1\n" ])) #INSTALL = False INSTALL = False velocity = graph.node[str(roadSeg - 2)]['speed_urban'] * DECREASE_SPEED distance = graph.node[str(roadSeg - 2)][ 'length'] * 0.00621371 * INCREASE_LENGTH + EPSILON_LENGTH current_range_soc = standard_soc_to_range_soc( current_standard_soc, soc_lower_bound) next_range_soc = write_data.nextSOC_real_data( current_range_soc, distance, 1, velocity, INSTALL) next_standard_soc = range_soc_to_standard_soc( next_range_soc, nLayers, soc_lower_bound) next_node_posn = position_in_layer(next_standard_soc, nLayers) next_node = next_start_node + next_node_posn #print next_range_soc, next_standard_soc, next_node_posn, next_node data['arcs'].append("".join([ " (", str(pathNumber), ",", str(current_node), ",", str(next_node), ")\n" ])) data['weight'].append("".join([ " ", str(pathNumber), " ", str(current_node), " ", str(next_node), " 0\n" ])) #print current_standard_soc, current_range_soc, next_range_soc #Assume vehicle starts fully charged thus only one layer for first roadSeg if roadSeg == path[0]: break return data, data_var
def NodesOut_init(model, node, route_no): out = [] if route_no not in model.nodes_in_dic: #print 'cccc' model.nodes_in_dic[route_no] = {} model.nodes_in_dic[route_no][node] = [] elif node not in model.nodes_in_dic[route_no]: #print 'route_no: ', route_no, model.nodes_in_dic[route_no] #print 'dddd', node model.nodes_in_dic[route_no][node] = [] #print model.nodes_in_dic[route_no] if node == 'source': start_node = write_data.roadSeg_to_node(model.Routes[route_no][0], model.nLayers.value) for i in range(model.nLayers.value): out.append(start_node + i) if start_node + i not in model.nodes_in_dic[route_no]: model.nodes_in_dic[route_no][start_node + i] = [node] else: model.nodes_in_dic[route_no][start_node + i].append(node) elif node == 'destination': return out else: roadSeg = write_data.node_to_roadSeg(node, model.nLayers.value) if roadSeg not in model.Routes[route_no]: return out standard_soc = write_data.node_to_soc(node, model.nLayers.value) if standard_soc < 1.0e-10 and roadSeg != model.Routes[route_no][0]: out.append('destination') if 'destination' not in model.nodes_in_dic[route_no]: model.nodes_in_dic[route_no]['destination'] = [node] else: model.nodes_in_dic[route_no]['destination'].append(node) return out if roadSeg == model.Routes[route_no][-1]: out.append('destination') if 'destination' not in model.nodes_in_dic[route_no]: model.nodes_in_dic[route_no]['destination'] = [node] else: model.nodes_in_dic[route_no]['destination'].append(node) elif roadSeg == model.Routes[route_no][0]: next_roadSeg = model.Routes[route_no][1] next_start_node = write_data.roadSeg_to_node( next_roadSeg, model.nLayers.value) if node == write_data.roadSeg_to_node(roadSeg, model.nLayers.value): current_standard_soc = write_data.node_to_soc( node, model.nLayers.value) current_range_soc = standard_soc_to_range_soc( model, current_standard_soc) velocity = model.graph.node[str(roadSeg - 2)]['speed_urban'] * 0.01 distance = model.graph.node[str(roadSeg - 2)]['length'] * 0.00621371 INSTALL = True next_range_soc = write_data.nextSOC_real_data( current_range_soc, distance, 1, velocity, INSTALL) next_standard_soc = range_soc_to_standard_soc( model, next_range_soc) next_node_posn = write_data.position_in_layer( next_standard_soc, model.nLayers.value) next_node = next_start_node + next_node_posn out.append(next_node) if next_node not in model.nodes_in_dic[route_no]: model.nodes_in_dic[route_no][next_node] = [node] else: model.nodes_in_dic[route_no][next_node].append(node) INSTALL = False next_range_soc = write_data.nextSOC_real_data( current_range_soc, distance, 1, velocity, INSTALL) next_standard_soc = range_soc_to_standard_soc( model, next_range_soc) next_node_posn = write_data.position_in_layer( next_standard_soc, model.nLayers.value) next_node = next_start_node + next_node_posn out.append(next_node) #out.append(next_start_node) #out.append(next_start_node + 1) if next_node not in model.nodes_in_dic[route_no]: model.nodes_in_dic[route_no][next_node] = [node] else: model.nodes_in_dic[route_no][next_node].append(node) #print out ''' elif roadSeg == model.Routes[route_no][-2]: next_roadSeg = model.Routes[route_no][-1] next_start_node = write_data.roadSeg_to_node(next_roadSeg, model.nLayers.value) current_standard_soc = write_data.node_to_soc(node, model.nLayers.value) node_posn = write_data.position_in_layer(current_standard_soc, model.nLayers.value) out.append(next_start_node + node_posn) if next_start_node + node_posn not in model.nodes_in_dic[route_no]: model.nodes_in_dic[route_no][next_start_node + node_posn] = [node] else: model.nodes_in_dic[route_no][next_start_node + node_posn].append(node) ''' else: roadSeg_indx = model.Routes[route_no].index(roadSeg) next_roadSeg = model.Routes[route_no][roadSeg_indx + 1] next_start_node = write_data.roadSeg_to_node( next_roadSeg, model.nLayers.value) current_standard_soc = write_data.node_to_soc( node, model.nLayers.value) if current_standard_soc > 1.0e-10: #INSTALL = True INSTALL = True velocity = model.graph.node[str(roadSeg - 2)]['speed_urban'] * 0.01 distance = model.graph.node[str(roadSeg - 2)]['length'] * 0.00621371 current_range_soc = standard_soc_to_range_soc( model, current_standard_soc) next_range_soc = write_data.nextSOC_real_data( current_range_soc, distance, 1, velocity, INSTALL) next_standard_soc = range_soc_to_standard_soc( model, next_range_soc) next_node_posn = write_data.position_in_layer( next_standard_soc, model.nLayers.value) next_node = next_start_node + next_node_posn #print next_soc if node == 506112: print "\n \t", velocity, distance out.append(next_node) if next_node not in model.nodes_in_dic[route_no]: model.nodes_in_dic[route_no][next_node] = [node] else: model.nodes_in_dic[route_no][next_node].append(node) #INSTALL = False INSTALL = False velocity = model.graph.node[str(roadSeg - 2)]['speed_urban'] * 0.01 distance = model.graph.node[str(roadSeg - 2)]['length'] * 0.00621371 current_range_soc = standard_soc_to_range_soc( model, current_standard_soc) next_range_soc = write_data.nextSOC_real_data( current_range_soc, distance, 1, velocity, INSTALL) next_standard_soc = range_soc_to_standard_soc( model, next_range_soc) next_node_posn = write_data.position_in_layer( next_standard_soc, model.nLayers.value) next_node = next_start_node + next_node_posn #print next_soc if next_node != out[-1]: out.append(next_node) if next_node not in model.nodes_in_dic[route_no]: model.nodes_in_dic[route_no][next_node] = [node] else: model.nodes_in_dic[route_no][next_node].append(node) #model.nodes_in_dic[route_no][next_node].append(node) #print out return out
if __name__ == "__main__": soc_threshold = 0.9 #roadSegGraph = nx.read_graphml("roadSegGraph_968.graphml") #roadSegGraph = nx.read_graphml("roadSegGraph_110.graphml") #roadSegGraph = nx.read_graphml("roadSegGraph.graphml") roadSegGraph = nx.read_graphml("graph_data/lower_manhattan1_5.graphml") for edge in roadSegGraph.edges(): u, v = edge distance = roadSegGraph[u][v]['weight'] * 0.000621371 location = roadSegGraph.node[u]['location'] speed = roadSegGraph.node[u]['speed_urban'] * 0.01 time = distance / speed * 3600 roadSegGraph[u][v]['time'] = time next_soc_1 = write_data.nextSOC_real_data(0.5, distance, 1, speed, 1) next_soc_0 = write_data.nextSOC_real_data(0.5, distance, 1, speed, 0) print next_soc_0, next_soc_1, distance, speed, location #print distance, speed, 'time', time, roadSegGraph.node[u]['location'], roadSegGraph.node[u]['class'] nLayers = 11 budget = 11 largeNumber = 10**7 filename = 'smallbudget.dat' #number of routes num_routes = 1 pathNumber = 1 data, data_var = init_dataFile(nLayers, budget, num_routes, largeNumber) #rand_routes = random_routes(roadSegGraph)