Skip to content

Commit

Permalink
fix: remove wrong imports (#72)
Browse files Browse the repository at this point in the history
remove journey imports in Operator class
  • Loading branch information
leo-desbureaux-tellae authored Oct 20, 2022
1 parent 541f96f commit 7ece11d
Showing 1 changed file with 0 additions and 233 deletions.
233 changes: 0 additions & 233 deletions starling_sim/basemodel/agent/operators/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@
points_in_zone,
json_load,
load_schema,
validate_against_schema,
SimulationError,
)
from starling_sim.utils.paths import (
gtfs_feeds_folder,
schemas_folder,
scenario_agent_input_filepath,
)
from starling_sim.utils.constants import STOP_POINT_POPULATION, ADD_STOPS_COLUMNS
from starling_sim_tellae.basemodel.agent.journeys import *

import pandas as pd
from typing import Union
Expand Down Expand Up @@ -745,235 +741,6 @@ def new_service_vehicle(self, feature):

return new_service_vehicle

# evaluation of a set of user journeys using operator service

def user_journeys(
self, origin, destination, parameters, objective_time, objective_type="start_after"
):
"""
Compute a list of journeys using the operator's transport system.
Journeys from origin to destination are computed according to the
operator service, using routers or other itinerary tools.
The parameters are also used to adjust the journeys characteristics.
The objective type is either "start_after" or "arrive_before", which correspond
to the way the journeys will be computed. The objective time specifies the value
of this start or arrival time.
A journey is represented as a DataFrame (see journeys.py).
:param origin: origin position
:param destination: destination position
:param parameters: dict of parameters.
:param objective_time: value of the start or arrival time
:param objective_type: way of computing journeys, either "start_after" or "arrive_before"
Default is "start_after".
:return: a list of journeys represented by DataFrames
"""

try:
if objective_type == "start_after":
journeys = self.start_after_journeys(
origin, destination, objective_time, parameters
)
elif objective_type == "arrive_before":
journeys = self.arrive_before_journeys(
origin, destination, objective_time, parameters
)
else:
message = "Journey objective type '{}' is not supported. Try 'start_after' or 'arrive_before'".format(
objective_type
)
self.log_message(message, 30)
raise SimulationError(message)
except NotImplementedError:
self.log_message(
"Evaluation of '{}' journeys is not implemented for this operator".format(
objective_type
),
30,
)
raise SimulationError(
"'{}' journeys are not available for {}".format(
objective_type, self.__class__.__name__
)
)

journeys = self.post_process_journeys(journeys, parameters)

return journeys

def start_after_journeys(self, origin, destination, objective_time, parameters):
"""
Evaluate a list of 'start_after' journeys for the given conditions.
:param origin:
:param destination:
:param objective_time:
:param parameters:
:return: list of journeys
"""

departures, arrivals = start_after_end_points(
self, origin, destination, objective_time, parameters
)

# check tables are not empty
if len(departures) == 0:
self.log_message("Origin position too far from service zone")
return []
if len(arrivals) == 0:
self.log_message("Destination position too far from service zone")
return []

arrival_stops = arrivals["with_stop"].values

journeys = self.enumerate_start_after_journeys(departures, arrival_stops, parameters)

journeys = add_arrival(journeys, arrivals)

return journeys

def arrive_before_journeys(self, origin, destination, objective_time, parameters):
"""
Evaluate a list of 'arrive_before' journeys for the given conditions.
:param origin:
:param destination:
:param objective_time:
:param parameters:
:return: list of journeys
"""

departures, arrivals = arrive_before_end_points(
self, origin, destination, objective_time, parameters
)

# check tables are not empty
if len(departures) == 0:
self.log_message("Origin position too far from service zone")
return []
if len(arrivals) == 0:
self.log_message("Destination position too far from service zone")
return []

departure_stops = departures["stop_id"].values

journeys = self.enumerate_arrive_before_journeys(departure_stops, arrivals, parameters)

journeys = add_departure(journeys, departures)

return journeys

def enumerate_start_after_journeys(self, departures, arrival_stops, parameters):
"""
Enumerate a list of journeys for the given departures and arrival stops.
See start_after_journeys method.
:param departures:
:param arrival_stops:
:param parameters:
:return: list of journeys
"""
raise NotImplementedError()

def enumerate_arrive_before_journeys(self, departure_stops, arrivals, parameters):
"""
Enumerate a list of journeys for the given departures and arrival stops.
See arrive_before_journeys method.
:param departure_stops:
:param arrivals:
:param parameters:
:return: list of journeys
"""
raise NotImplementedError()

def post_process_journeys(self, journeys, parameters):
return journeys

def relevant_stop_points(self, origin, destination, parameters):
"""
Get relevant service stop points for the journey end points and parameters.
:param origin: origin position
:param destination: destination position
:param parameters: journey parameters
:return: (list of origin stops, list of destination stops)
"""

max_nearest_stops = parameters["max_nearest_stops"]
max_distance = parameters["max_distance_nearest_stops"]

# get the n closest (euclidean) stops to both positions (with a max distance)
origin_stop_points = self.sim.environment.euclidean_n_closest(
position=origin,
obj_list=self.stopPoints.values(),
n=max_nearest_stops,
maximum_distance=max_distance,
)
destination_stop_points = self.sim.environment.euclidean_n_closest(
position=destination,
obj_list=self.stopPoints.values(),
n=max_nearest_stops,
maximum_distance=max_distance,
)

return origin_stop_points, destination_stop_points

def journey_from_request(self, trip_request: TripRequest, route_type):
"""
Create a journey row corresponding to the given TripRequest.
:param trip_request:
:param route_type:
:return:
"""
journey_row = pd.DataFrame(
[
{
"stop_id": trip_request.dropoff.stopPoint,
"nb_trips": 1,
"min_arrival_time": trip_request.dropoff.arrivalTime,
"with_stop": trip_request.pickup.stopPoint,
"with_trip": trip_request.tripId,
"with_departure": trip_request.pickup.departureTime,
"route_id": None,
"route_type": route_type,
"request": trip_request.id,
"operator": self.id,
}
]
)

return journey_row

def confirm_journey_(self, journey, agent, parameters):
"""
Confirm the journey choice of the agent and assign its requests if necessary.
The request assignment may not be immediate, so the confirmation can take some time.
:param journey:
:param agent:
:param parameters:
:return: boolean indicating if the chosen journey can be executed
"""

yield self.execute_process(self.spend_time_(0))

return True

# utils

def evaluate_time_window(self, base_time: int, time_window: int):
Expand Down

0 comments on commit 7ece11d

Please sign in to comment.