#print('dictTimeCost[vehicle]1',dictTimeCost[vehicle]) if not vehicle.isRunning(network.ts): continue vehicle.updateLocation( 1, delayType=STRATEGY) #update location in the lane for 1 SECOND! if (network.ts - vehicle.startTs).seconds % GAP_TS == 0: vehicle.changeLane(dictTimeCost[vehicle.id], 1, medianValueTime, countTime, NO_CHARGE) # print the vehicle information when it takes too long to finish its trip if (network.ts - vehicle.startTs).seconds > 1000: print("ts: ", (network.ts - vehicle.startTs).seconds) print("vehicle: ", vehicle) print("route: ", vehicle.bestLaneRoute) print(network.runningVehicleCount(), 'running') print(network.finishVehicleCount(), 'finished') y_running.append(network.runningVehicleCount()) y_stopping.append(network.finishVehicleCount()) if (i > 10 and i % 1000 == 0) or (network.runningVehicleCount() == 0 and network.finishVehicleCount() > 1000): # this part for output JSON file print("writing json file....") output = {} output["nodes"] = { n.id: serializeNode(n) for n in network.idNodeMap.values() } output["links"] = { l.id: serializeLink(l)
vehicle = network.idVehicleMap[vid] if not vehicle.isRunning(network.ts): continue vehicle.updateShortestPath() # update lane features network.updateLanes() # update vehicle location for vehicle in network.idVehicleMap.values(): if not vehicle.isRunning(network.ts): continue vehicle.updateLocation(timeStep) #update for 1 SECOND! # decision print(network.runningVehicleCount(), 'running') print(network.finishVehicleCount(), 'finished') # copy network to i+1 network_next = copy.deepcopy(network) network_next.ts += datetime.timedelta(seconds=timeStep) networks.append(network_next) def timestamp(dt): return dt.timestamp() if dt else None def serializeNode(node): return {'id': node.id, 'type': node.type, 'x': node.x, 'y': node.y}