|
Autopysta
|
Base class for generating vehicles in a traffic simulation. More...
#include <creator.h>
Public Member Functions | |
| virtual void | validate_creator () |
| Validates the configuration of the creator. | |
| virtual vehicle * | create (point *leader, bool immediate_follower=false) |
| Creates a new vehicle based on the current leader's position. | |
| virtual vehicle * | create_no_leader (int lane)=0 |
| Creates a new vehicle in an empty lane. | |
| vector< vehicle * > | initial_state (point *leader) |
| Initializes vehicles in the first simulation timestep. | |
Protected Member Functions | |
| virtual point * | ideal_conditions (point *leader)=0 |
| Defines the ideal conditions for creating a new vehicle. | |
Protected Attributes | |
| int | max_vehs = INT_MAX |
| Maximum number of vehicles that can be created. | |
| int | n_vehs = 0 |
| Counter for the number of vehicles created so far. | |
| model * | Model = nullptr |
| Traffic model used to determine vehicle behavior. | |
Base class for generating vehicles in a traffic simulation.
The creator class defines the logic for creating new vehicles either at the start of the simulation or during runtime. It handles the vehicle creation process based on specified models, parameters, and traffic conditions (such as gaps between vehicles). Derived classes should implement specific creation logic.
Creates a new vehicle based on the current leader's position.
This method checks whether it is possible to create a new vehicle based on the leader's state. If so, it generates a new vehicle at an appropriate position relative to the leader. If immediate_follower is true, the new vehicle will be placed just behind the leader; otherwise, it will start at the beginning of the lane.
| leader | The point representing the leader's current state (position, speed). |
| immediate_follower | Whether the new vehicle should follow immediately behind the leader. |
nullptr if no vehicle was created. Reimplemented in creator_martinez_jin_2020.
|
pure virtual |
Creates a new vehicle in an empty lane.
This method creates a new vehicle in a lane that has no leading vehicle. It is meant to be used for initializing lanes with vehicles at the beginning of the simulation or adding vehicles dynamically when no leader is present.
| lane | The lane number in which to create the vehicle. |
nullptr if no vehicle was created. Implemented in creator_martinez_jin_2020, fixed_demand_creator, and fixed_state_creator.
Defines the ideal conditions for creating a new vehicle.
This method computes the optimal starting position and behavior of a new vehicle based on the position and speed of a leader vehicle. The derived classes must implement the specific logic for defining these conditions.
| leader | The point representing the current state (position and speed) of the leader vehicle. |
Initializes vehicles in the first simulation timestep.
This method is used to create and position vehicles during the first timestep of the simulation. It generates vehicles behind a manually-created leading vehicle and populates the lane with vehicles based on the traffic model.
| leader | The manually-created leader vehicle. |
|
virtual |
Validates the configuration of the creator.
This method validates the configurations of the creator, such as ensuring that the maximum number of vehicles and the model are properly set. This ensures that vehicle creation follows the expected limits and behavior.
Reimplemented in creator_martinez_jin_2020, fixed_demand_creator, and fixed_state_creator.