activity module

class activity.Activity(label: str, start_time: int, duration: int, end_time: Optional[int] = None, mode: Optional[str] = None, location: Optional[Union[Tuple, str]] = None, prev_act: Optional[str] = None, next_act: Optional[str] = None, early: Optional[float] = None, late: Optional[float] = None, short: Optional[float] = None, long: Optional[float] = None)[source]

Bases: object

This class creates an “activity” unit to be used in the estimation process. A list of activities constitutes a schedule. Activity objects can be easily created with the ActivityFactory class.

  • label: unique label of the activity

  • start_time: discrete start time (int)

  • duration: discrete duration (int)

  • end_time: discrete end time (int)

  • mode : mode of transportation of the associated travel

  • next_act: next activity in the schedule object

  • prev_act: previous activity in the schedule object

  • early: deviation from preferred start time (early)

  • late: deviation from preferred start time (late)

  • short: deviation from preferred duration (short)

  • long: deviation from preferred duration (long)

  • boundary_inf: lower bound for feasible start time

  • boundary_sup: upper bound for feasible end travel_time

  • Getters and setters for protected attributes

  • compute_utility: computed utility function for activity

compute_utility(params: Dict, reference_act: List = ['home', 'dawn', 'dusk'])[source]

Computes the activity-specific utility function.

Parameters:
  • params (Dictionary of parameters to be used in the utility function) –

  • reference_act (List of label(s) of the reference activity (default is home)) –

Returns:

V

Return type:

value of the utility function

property duration
property end_time
property label
property location
property mode
property next_act
property prev_act
property start_time
class activity.ActivityFactory[source]

Bases: object

This class creates and Activity object.

  • create: creates object from Activity class

create(label: Optional[str] = None, random: bool = False, list_act: List = ['home', 'work', 'education', 'shopping', 'errands_services', 'leisure', 'escort', 'business_trip'], **kwargs) Activity[source]

Creates an object from the Activity class.

-label: label of the activity to create -random: if True, creates a random activity -list_act: list of possible activity labels -**kwargs: other keywords arguments that will be passed to the Activity constructor.

class activity.Schedule(list_act: Optional[List] = None, total_dur: int = 24, start: int = 0, end: int = 24, discretization: float = 0.016666666666666666, travel_time_mat: Optional[Dict] = None)[source]

Bases: object

This class stores schedules of activity objects.

-list_act: list of Activity objects representing the activities in the schedule -total_dur: total schedule duration, default is 24h -start: start time of the schedule (default: Oh - midnight) -end: end time of the schedule (default: 24h ) -discretization: schedule discretization in hours, default: 1/60 h -feasibility: boolean that indicates if the schedule is feasible -travel_time_mat: matrix of travel times -anchor_nodes: time points in the schedule where operators changes will be applied. Default: at every hour for empty schedules -all_starts: list of the start times of every activity in the schedule -all_locations: list of the locations of every activity in the schedule -all_labels: list of the labels of every activity in the schedule -list_modes: list of the possible modes of transportation

activity_colors(list_act: Optional[List] = None, palette: str = 'colorblind') List[source]

Match each activity from list to a color from the input palette. Useful to keep consistent colors across visualizations

  • list_act: list of activity all_labels

  • palette; name of matplotlib/searborn color palette.

property anchor_nodes
compute_utility(params: Dict, rnd_term: Optional[float] = None)[source]

Computes utility of full schedule, given utility parameters

Parameters:
  • params (Dictionary of utility parameters) –

  • rnd_term (random term to add to the utility function) –

Returns:

utility

Return type:

utility function of the schedule

property discretization
property end
property feasibility
get_home_location()[source]

Returns the location identified as home.

get_travel_time(origin: Union[Tuple, str, int], destination: Union[Tuple, str, int], mode: str) float[source]

Extract OD travel time.

Parameters:
  • origin (ID of the origin (must be a valid key in the travel time matrix)) –

  • destination (ID of the destination (must be a valid key in the travel time matrix)) –

  • mode (mode of transportation (must be a valid key in the travel time matrix)) –

Returns:

tt

Return type:

travel time in hours

property list_act
output(plot: bool = False, **kwargs) DataFrame[source]

This method creates a formatted pandas DataFrame of the schedule.

plot: if True, plots schedule **kwargs: keyword arguments to be passed to the plotting function

df: DataFrame

plot(list_act: Optional[List] = None, title: Optional[str] = None, figure_size: List = [20, 3], **kwargs)[source]

Plots given schedule.

-list_act: Default list of activities (for activity colors) - title: plot title - figure_size: size of the matplotlib figure - kwargs: other keyword arguments for matplotlib’s functions

property start
streamline() None[source]

This function checks that the schedule is valid in terms of continuity (e.g. no gaps in time or space)

property total_dur
property travel_time_mat
update()[source]

Updates variables when the activities change.

which_activity(time: float) Activity[source]

Returns activity that is happening at a given time

class activity.Travel[source]

Bases: Activity

This class defines the specific Travel activity.