Autopysta
Loading...
Searching...
No Matches
creator Class Referenceabstract

Base class for generating vehicles in a traffic simulation. More...

#include <creator.h>

Inheritance diagram for creator:
creator_martinez_jin_2020 fixed_demand_creator fixed_state_creator

Public Member Functions

virtual void validate_creator ()
 Validates the configuration of the creator.
 
virtual vehiclecreate (point *leader, bool immediate_follower=false)
 Creates a new vehicle based on the current leader's position.
 
virtual vehiclecreate_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 pointideal_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.
 
modelModel = nullptr
 Traffic model used to determine vehicle behavior.
 

Detailed Description

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.

Member Function Documentation

◆ create()

virtual vehicle * creator::create ( point * leader,
bool immediate_follower = false )
virtual

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.

Parameters
leaderThe point representing the leader's current state (position, speed).
immediate_followerWhether the new vehicle should follow immediately behind the leader.
Returns
A pointer to the created vehicle, or nullptr if no vehicle was created.

Reimplemented in creator_martinez_jin_2020.

◆ create_no_leader()

virtual vehicle * creator::create_no_leader ( int lane)
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.

Parameters
laneThe lane number in which to create the vehicle.
Returns
A pointer to the created vehicle, or nullptr if no vehicle was created.

Implemented in creator_martinez_jin_2020, fixed_demand_creator, and fixed_state_creator.

◆ ideal_conditions()

virtual point * creator::ideal_conditions ( point * leader)
protectedpure virtual

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.

Parameters
leaderThe point representing the current state (position and speed) of the leader vehicle.
Returns
A point representing the ideal conditions for the new vehicle.

◆ initial_state()

vector< vehicle * > creator::initial_state ( point * leader)

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.

Parameters
leaderThe manually-created leader vehicle.
Returns
A vector of pointers to the created vehicles.

◆ validate_creator()

virtual void creator::validate_creator ( )
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.


The documentation for this class was generated from the following file: