def __init__(self, vehicle_id: int = -1, cur_position: tuple = (0, 0), capacity: int = 1, boarded: list = list(), assigned: list = list(), dst_pos: tuple = None, position_id=-1, waypoint: WayPoint = WayPoint(), overall_time=0): self._vid = vehicle_id self._arr_time = 0 #i.e. all vehicles are assumed to be initialized at time 0 self._init_position = cur_position self._point_id = position_id self._waypoint = waypoint self._capacity = capacity '''Per-round Allocation related attributes''' self._cur_time = -1 self._cur_position = cur_position #i.e. current location of vehicles, to be updated per round self._available = None self._boarded_requests = list(boarded) self._assigned_requests = list( assigned ) #i.e. request list assigned before picked up, remove from list after pickup self._dst_position = dst_pos self._overall_time = overall_time '''Recording accumulated trips''' self._allocated_value1 = 0 self._active_timecost = 0
continue valid_data = REQ_DATA0[REQ_DATA0['trip_length'] >= MAX_WAITING_TIME] ORI_REQ_NUM = len(valid_data) print('NUMREQ from valid_data:', ORI_REQ_NUM) node_to_num = {} for node in set(valid_data['pickup_nodes']): num = len(valid_data[valid_data['pickup_nodes'] == node]) node_to_num[node] = num '''Removal of trips that possibly cause vehicles to be stuck for lengthened period''' if REMOVAL != 'None': pu_nodes = np.array(list(set(valid_data['pickup_nodes']))) valid_dest = {} for d_pid in set(valid_data['dropoff_nodes']): d_waypoint = WayPoint(d_pid, d_pid, 0, 0) dist_list = [ mapsystem.distance(d_waypoint, WayPoint(o_pid, o_pid, 0, 0)) for o_pid in pu_nodes ] num = sum([ node_to_num[node] for node in pu_nodes[np.array( dist_list) <= MAX_WAITING_TIME - period_length] ]) if num not in valid_dest.keys(): valid_dest[num] = [] valid_dest[num] += [d_pid]
def __init__(self, request_id: int, region: int = 0, origin: tuple = (0, 0), destination: tuple = (0, 0), request_time: int = 0, size: int = 1, length: float = None, pickup_time=None, max_wait_time=-1, max_delay=-1, maximum_dropoff_time=-1, assigned=False, picked=False, vehicle=-1, origin_id=-1, destination_id=-1, origin_waypoint: WayPoint = WayPoint(), destination_waypoint: WayPoint = WayPoint()): self._rid = request_id #i.e. request ID self._region = region #i.e. region ID self._origin = origin #i.e. coordinates of pickup location self._origin_id = origin_id self._origin_waypoint = origin_waypoint self._destination = destination #i.e. coordinates of dropoff location self._destination_id = destination_id self._destination_waypoint = destination_waypoint self._request_time = request_time #i.e. request arrival time, rounded down to its 30s self._size = size #i.e. number of passengers in the request self._trip_length = length #i.e. travelling time between pickup-dropoff location (node-based) if max_wait_time == -1: self._max_waiting_time = MAX_WAITING_TIME else: self._max_waiting_time = max_wait_time if max_delay == -1: self._max_delay = MAX_DELAY else: self._max_delay = max_delay self._max_dropoff_time = maximum_dropoff_time '''Allocation attributes''' self._assigned = assigned self._assign_time1 = None self._picked = picked self._pickup_time = pickup_time self._vehicle = vehicle self._finished = False self._finish_time = -1 self._dropoff_time = None self._delay = None self._wait = None '''Accumulated trip attributes''' self._trip_active = 0 self._trip_value = 0
pu_nodes = [] for i in range(len(taxi_csv.index)): pu_nodes += [closest_node(taxi_csv['pickup_coordinates'].iloc[i])] taxi_csv['pickup_nodes'] = pu_nodes do_nodes = [] for i in range(len(taxi_csv.index)): do_nodes += [closest_node(taxi_csv['dropoff_coordinates'].iloc[i])] taxi_csv['dropoff_nodes'] = do_nodes '''Adding in trip_length''' trip_length = [] for i in range(len(taxi_csv.index)): o_waypoint = WayPoint(pu_nodes[i], pu_nodes[i], 0, 0) d_waypoint = WayPoint(do_nodes[i], do_nodes[i], 0, 0) trip_length += [mapsystem.distance(o_waypoint, d_waypoint)] '''Categorize the trip length into bins of 60s''' bin_60 = [int((x - 30) // 60) for x in trip_length] for i in range(len(bin_60)): if bin_60[i] < 2: bin_60[i] = -1 else: bin_60[i] -= 2 taxi_csv.to_pickle( 'D:\\RIDESHARING\\NIPS19\\DataPreprocess\\RequestGenerator\\May_2013_HOUR17.pkl' ) '''Filter the request data (first 30s, within capacity of 4, trip length >= 400 secs)''' valid_data = taxi_csv
if NearbyNode.get(p) == None: NearbyNode[p] = [q] else: NearbyNode[p] += [q] mapsystem = MapSystem() mapsystem._node_dict = NodePos mapsystem._nearby_node = NearbyNode '''Update manhat_point with Neighbors column (-used in singlebatch experiment)''' node_in_areas = {} for n1 in set(manhat_edge['PointIndex1']): if n1 not in node_in_areas: node_in_areas[n1] = [] for n2 in manhat_point.index: if mapsystem.distance(WayPoint(n2, n2, 0, 0), WayPoint(n1, n1, 0, 0)) <= 210: node_in_areas[n1] += [n2] length = [] for n1 in node_in_areas.keys(): length += [len(node_in_areas[n1])] manhat_point['ExtendedNeighbors_210s_1'] = [ node_in_areas[i] for i in manhat_point.index ] manhat_point.to_pickle( 'D:\\RIDESHARING\\NIPS19\\DataPreprocess\\RoadNetwork\\manhat_point.pkl')
random.seed(seed) loc_id = np.random.choice(filter_init, TAXI_TOTAL_NUM - len(v_location_ACT), replace=False) v_location = [ manhat_point.loc[filter_init[i], 'Coordinate'] for i in range(len(loc_id)) ] #i.e. to initialize locations for LOW activity vehicles '''Reset V_STORAGE''' V_STORAGE = np.array([]) for loc in v_location_ACT: vid = len(V_STORAGE) newv = Vehicle(vid, loc, CAPACITY) newv._point_id = closest_node(newv._cur_position) newv._waypoint = WayPoint(newv._point_id, newv._point_id, 0, 0) newv._arr_time = 0 random.seed(vid + 1 + seed) newv._allocated_value1 = random.uniform( 200, 400) #i.e. set the HIGH historical active time V_STORAGE = np.append(V_STORAGE, newv) for loc in v_location: vid = len(V_STORAGE) newv = Vehicle(vid, loc, CAPACITY) newv._point_id = closest_node(newv._cur_position) newv._waypoint = WayPoint(newv._point_id, newv._point_id, 0, 0) newv._arr_time = 0