NeTrainSim 0.1.1 beta
The Open-Source Network Trains Simulator
 
Loading...
Searching...
No Matches
Train Class Reference

A train. More...

#include <train.h>

Inheritance diagram for Train:

Signals

void suddenAccelerationOccurred (std::string msg)
 report a sudden acceleration.
 
void slowSpeedOrStopped (std::string msg)
 report the trains is very slow or stopped
 

Public Member Functions

 Train (int simulatorID, string id, Vector< int > trainPath, double trainStartTime_sec, double frictionCoeff, Vector< std::shared_ptr< Locomotive > > locomotives, Vector< std::shared_ptr< Car > > cars, bool optimize, double desiredDecelerationRate_mPs=DefaultDesiredDecelerationRate, double operatorReactionTime_s=DefaultOperatorReactionTime, bool stopIfNoEnergy=DefaultStopIfNoEnergy, double maxAllowedJerk_mPcs=DefaultMaxAllowedJerk)
 This constructor initializes a train with the passed parameters.
 
 ~Train ()
 
void setTrainSimulatorID (int newID)
 
bool rechargeCarsBatteries (double timeStep, double EC_kwh, std::shared_ptr< Locomotive > &loco)
 recharge all train cars batteries.
 
Map< string, double > getTrainConsumedTank ()
 getTrainConsumedTank
 
void setTrainPath (Vector< int > path)
 set the train path.
 
double getMinFollowingTrainGap ()
 Gets minimum following train gap.
 
void setTrainsCurrentLinks (Vector< std::shared_ptr< NetLink > > newLinks)
 set the current links the train is spanning
 
double getCargoNetWeight ()
 Gets cargo net weight.
 
Map< TrainTypes::PowerType, int > LocTypeCount ()
 Locomotive type count.
 
Map< TrainTypes::CarType, int > carTypeCount ()
 car type count
 
Map< std::shared_ptr< TrainComponent >, double > getTrainCentroids ()
 This function returns the centroids of all vehicles in the train.
 
int getActiveLocomotivesNumber ()
 Gets active locomotives number.
 
double getBatteryEnergyConsumed ()
 Gets the battery energy consumed in kWh.
 
double getBatteryEnergyRegenerated ()
 Gets the battery energy regenerated in kWh.
 
double getBatteryNetEnergyConsumed ()
 Gets the battery energy consumed in kWh.
 
double getAverageLocomotivesBatteryStatus ()
 Gets average locomotives battery status.
 
double getAverageLocomotiveTankStatus ()
 Gets average locomotives tank status.
 
double getAverageTendersTankStatus ()
 Gets average tenders tank status.
 
double getAverageTendersBatteryStatus ()
 Gets average tenders battery status.
 
double getTrainTotalTorque ()
 Gets train total torque in tons x meters.
 
double getAverageTendersStatus ()
 Gets average tenders status.
 
void setTrainLength ()
 Sets train length.
 
void setTrainWeight ()
 Sets train weight.
 
void resetTrain ()
 Resets the train parameters.
 
void rearrangeTrain ()
 Rearrange train.
 
void updateGradesCurvatures (Vector< double > &LocsCurvature, Vector< double > &LocsGrade, Vector< double > &CarsCurvature, Vector< double > &CarsGrade)
 Updates the grades curvatures.
 
void updateGradesCurvatures (const Vector< double > &trainGrade, const Vector< double > &trainCurvature)
 Updates the grades curvatures.
 
double getTotalTractiveForce (double speed, double acceleration, bool optimize, double optimumThrottleLevel)
 Gets total tractive force.
 
double getTotalResistance (double speed)
 Gets total resistance.
 
double getAccelerationUpperBound (double speed, double acceleration, double freeFlowSpeed, bool optimize, double optimumThrottleLevel)
 Gets acceleration upper bound.
 
double getSafeGap (double initialGap, double speed, double freeFlowSpeed, double T_s, bool estimate)
 Gets safe gap.
 
double getNextTimeStepSpeed (double gap, double minGap, double speed, double freeFlowSpeed, double aMax, double T_s, double deltaT)
 Gets the next time step speed.
 
double getTimeToCollision (double gap, double minGap, double speed, double leaderSpeed)
 Gets time to collision.
 
double accelerate (double gap, double mingap, double speed, double acceleration, double leaderSpeed, double freeFlowSpeed, double deltaT, bool optimize, double throttleLevel=-1)
 Gets the acceleration of the train.
 
double accelerateConsideringJerk (double acceleration, double previousAcceleration, double jerk, double deltaT)
 Accelerate considering jerk.
 
double smoothAccelerate (double acceleration, double previousAccelerationValue, double alpha=0.2)
 Smooth the acceleration.
 
double speedUpDown (double previousSpeed, double acceleration, double deltaT, double freeFlowSpeed)
 Gets the speed of the train based on the acceleration.
 
double adjustAcceleration (double speed, double previousSpeed, double deltaT)
 Adjust acceleration.
 
void checkSuddenAccChange (double previousAcceleration, double currentAcceleration, double deltaT)
 Check sudden accumulate change.
 
double getStepAcceleration (double timeStep, double freeFlowSpeed, Vector< double > &gapToNextCriticalPoint, Vector< bool > &gapToNextCriticalPointType, Vector< double > &leaderSpeed)
 getStepDynamics
 
void moveTrain (double timeStep, double freeFlowSpeed, Vector< double > &gapToNextCriticalPoint, Vector< bool > &gapToNextCriticalPointType, Vector< double > &leaderSpeed)
 Move train forward.
 
pair< Vector< double >, double > getTractivePower (double speed, double acceleration, double resistanceForces)
 Gets tractive power.
 
void updateLocNotch ()
 Updates the location notch.
 
void immediateStop (double timeStep)
 Immediate stop.
 
void kickForwardADistance (double &distance)
 Kick forward a distance.
 
double getEnergyConsumption (double timeStep)
 Gets energy consumption.
 
void calculateEnergyConsumption (double timeStep, std::string currentRegion)
 Calculates the energy consumption.
 
double getTotalEnergyConsumption (double &timeStep, Vector< double > &usedTractivePower)
 Gets total energy consumption.
 
bool consumeEnergy (double &timeStep, double trainSpeed, Vector< double > &usedTractivePower)
 Consume energy.
 
void resetTrainEnergyConsumption ()
 Resets the train energy consumption.
 
std::pair< bool, double > consumeTendersEnergy (double timeStep, double trainSpeed, double EC_kwh, TrainTypes::PowerType powerType, double dieselConversionFactor=EC::DefaultDieselConversionFactor, double hydrogenConversionFactor=EC::DefaultHydrogenConversionFactor, double dieselDensity=EC::DefaultDieselDensity)
 Consume tenders energy.
 
Vector< std::shared_ptr< Car > > getActiveTanksOfType (TrainTypes::CarType cartype)
 Gets active tanks of type.
 
int getRechargableCarsNumber ()
 Gets rechargable cars number.
 
int getRechargableLocsNumber ()
 Gets rechargable locs number.
 
tuple< double, double, double > AStarOptimization (double prevSpeed, double currentSpeed, double currentAcceleration, double prevThrottle, Vector< double > vector_grade, Vector< double > vector_curvature, double freeSpeed_ms, double timeStep, Vector< double > u_leader, Vector< double > gapToNextCriticalPoint)
 This function adopts the A Star optimization to get the optimum throttle level.
 
double heuristicFunction (double distanceToEnd, double stepAcceleration, double stepSpeed, double timeStep, double resistance, double currentSpeed)
 The heuristic function for the A-Star algorithm.
 
double pickOptimalThrottleLevelAStar (Vector< double > throttleLevels, int lookAheadCounterToUpdate)
 Picks the optimal throttle level considering the A-Star optimization.
 
void calcTrainStats (Vector< double > listOfLinksFreeFlowSpeeds, double MinFreeFlow, double timeStep, std::string currentRegion)
 Calculates the train statistics.
 
double calculateAverage (double previousAverage, double currentTimeStepData, double timeStep)
 Finds the average of the given arguments.
 
double getDelayTimeStat (double freeflowSpeed, double timeStep)
 Gets delay time stat.
 
double getMaxDelayTimeStat (Vector< double > listOfLinksFreeFlowSpeeds, double timeStep)
 Gets maximum delay time stat.
 
double getStoppingTimeStat (Vector< double > listOfLinksFreeFlowSpeeds)
 Gets stopping time stat.
 
void resetTrainLookAhead ()
 reset train look ahead parameters
 
std::pair< double, Map< TrainTypes::PowerType, double > > getMaxProvidedEnergy (double &timeStep)
 getMaxProvidedEnergy
 
bool canProvideEnergy (double &EC, double &timeStep)
 check if the train can provide the required energy to move forward
 
void reducePower (double &reductionFactor)
 reducePower
 
void resetPowerRestriction ()
 resetPowerRestriction
 

Static Public Member Functions

static unsigned int getNumberOfTrainsInSimulator ()
 this function returns how many trains are loaded in the simulator
 

Public Attributes

const double g = 9.8066
 (Immutable) gravitational acceleration
 
double d_des
 The desired decceleration value.
 
double operatorReactionTime
 the perception reaction time of the train operator.
 
double totalLength
 Total length of the train.
 
double totalMass
 The total weight of the train in kg.
 
double totalEmptyMass = 0
 The total empty weight of the train.
 
double coefficientOfFriction = 0.9
 Coefficient of fricition between the trains' wheels and the track.
 
double maxJerk = 2.0
 Max allowable jerk (m/s^3) for the train.
 
double T_s
 Time to fully activate the brakes, considering the network signal speed equals speed of sound.
 
double trainStartTime
 Start time of the train to enter the network retrative to the beginning of the simulator.
 
double tripTime
 Total time spent between the train entering and leaving the network.
 
double trainTotalPathLength
 The total length of the path the train is suppost to be taking.
 
double travelledDistance
 Travelled distance of the train measured from the front tip of the train.
 
double virtualTravelledDistance
 Travelled distance of the train measured from the front tip of the train (virtual and does not affect train movement.
 
double currentSpeed
 The current speed of the train (at time t)
 
double previousSpeed
 The previous speed of the train (at time t-1)
 
double averageSpeed
 The average journey speed of the train from t = 0 to t.
 
double currentAcceleration
 The current acceleration of the train (at time t)
 
double previousAcceleration
 The previous acceleration of the train (at time t-1)
 
double averageAcceleration
 The average journey acceleration of the train from t = 0 to t.
 
double currentTractiveForce
 The current tractive forces the train is using in Newton.
 
double currentResistanceForces
 The current resistance forces on the train in Newton.
 
double currentUsedTractivePower
 The current used tractive power that the locomotives provides in kw.
 
double cumUsedTractivePower
 The cummulative used tractive power (work) that the locomotives provide in kw.
 
double optimumThrottleLevel
 The optimum throttle level that the train should go by to minimize its energy use.
 
double energyStat
 Total energy consumption (consumed + regenerated) at time step t.
 
double cumEnergyStat
 Cumulative total energy consumed till time step t.
 
double totalEConsumed
 Total energy consumpted only of the train till time t.
 
double totalERegenerated
 Energy regenerated of the train till time t.
 
double delayTimeStat
 The time the train is delayed at time step t, relative to min free flow speed of all spanned links.
 
double cumDelayTimeStat
 Cumulative total time delayed untill time step t, relative to min free flow speed of all spanned links.
 
double maxDelayTimeStat
 The time the train is delayed at time step t, relative to max free flow speed of all spanned links.
 
double cumMaxDelayTimeStat
 Total time delayed untill time step t, relative to max free flow speed of all spanned links.
 
double stoppedStat
 Statistic of the stoppings at time t.
 
double cumStoppedStat
 Statistic of stoppings untill time t.
 
double waitedTimeAtNode
 holds the waited time at any depot
 
pair< double, double > currentCoordinates
 Holds the current coordinates of the tip of the train.
 
std::shared_ptr< NetLinkcurrentFirstLink
 Holds the first link the train is on.
 
Map< std::shared_ptr< TrainComponent >, double > WeightCentroids
 Holds the centroid location mapped by the car/loco and relative to the tip of the train.
 
Map< int, double > LinkGradeDirection
 Grade of the links the train is taking and it is mapped by the link ID.
 
Map< TrainTypes::CarType, Vector< std::shared_ptr< Car > > > carsTypes
 Maps the train cars types.
 
Map< TrainTypes::CarType, Vector< std::shared_ptr< Car > > > ActiveCarsTypes
 Maps the train active cars types.
 
Map< string, double > cumRegionalConsumedEnergyStat
 Total energy consumed till time step t mapped by region.
 
Vector< std::shared_ptr< Car > > cars
 Holds all cars in the train.
 
Vector< std::shared_ptr< Locomotive > > locomotives
 Holds all locomotives in the train.
 
Vector< int > trainPath
 The predefined path of the train by the simulator node id.
 
Vector< std::shared_ptr< NetNode > > trainPathNodes
 The predefined path of the train by the node reference.
 
Vector< std::shared_ptr< NetLink > > currentLinks
 The spanned links the train is on.
 
Vector< Vector< double > > betweenNodesLengths
 Holds the computed distances between two nodes along the train's path.
 
Vector< double > linksCumLengths
 Holds the cummulative distance from the start of the train's path to each and every node in the path.
 
Vector< Vector< Map< int, double > > > LowerSpeedNodeIDs
 Holds the lower speed node ID's the train will have to reduce its speed at.
 
Vector< pair< double, double > > startEndPoints
 Holds both the start and end tips' coordinates of the train.
 
Vector< std::shared_ptr< NetLink > > previousLinks
 The previous links the train spanned before.
 
Vector< std::shared_ptr< TrainComponent > > trainVehicles
 holds the arrangement of the train and how locomotives and cars are arranged in that train.
 
Vector< std::shared_ptr< Locomotive > > ActiveLocos
 Maps the train active locomotives types.
 
Vector< double > currentUsedTractivePowerList
 The current used tractive power list.
 
Vector< double > throttleLevels
 The throttle levels that the train will go by.
 
string trainUserID
 The name of the train.
 
Vector< bool > trainStoppingStations
 The train stopping stations.
 
int nCars = 0
 Number of cars in the train.
 
int nlocs = 0
 Number of locomotives in the train.
 
int id
 The name of the train.
 
int previousNodeID
 The previous node ID the tip of the train just passed.
 
int LastTrainPointpreviousNodeID
 The previous node ID the last point of the train just passed.
 
int nextNodeID
 The next node the train is targetting.
 
int NoPowerCountStep
 Counts the number of steps the train could not move forward because of the lack of power source.
 
int lookAheadStepCounter
 The number of steps ahead the train is looking aheaf for optimization.
 
int lookAheadCounterToUpdate
 The number of steps ahead the train should update its optimization at.
 
bool stopTrainIfNoEnergy
 Change this to true if you want the train to stop if it runs out of energy.
 
bool isOn
 True if the train has energy, false if dead.
 
bool offloaded = false
 If the train is on the network, it is true, false otherwise.
 
bool reachedDestination = false
 True if the simulator reached its destination, false otherwise.
 
bool outOfEnergy = false
 True if the train ran out of energy.
 
bool loaded = false
 True if the train is loaded to the simulator, false otherwise.
 
bool optimize
 True if the train should optimize its energy consumption.
 

Static Public Attributes

static constexpr double speedOfSound = 343.0
 (Immutable) the speed of sound in m / s, this is an approximation of the brackes back propagation
 

Friends

ostream & operator<< (ostream &ostr, Train &train)
 Stream insertion operator.
 

Detailed Description

A train.

Author
Ahmed Aredah
Date
2/28/2023

Constructor & Destructor Documentation

◆ Train()

Train::Train ( int  simulatorID,
string  id,
Vector< int >  trainPath,
double  trainStartTime_sec,
double  frictionCoeff,
Vector< std::shared_ptr< Locomotive > >  locomotives,
Vector< std::shared_ptr< Car > >  cars,
bool  optimize,
double  desiredDecelerationRate_mPs = DefaultDesiredDecelerationRate,
double  operatorReactionTime_s = DefaultOperatorReactionTime,
bool  stopIfNoEnergy = DefaultStopIfNoEnergy,
double  maxAllowedJerk_mPcs = DefaultMaxAllowedJerk 
)

This constructor initializes a train with the passed parameters.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
simulatorIDsimulatorID A unique identifier for the node, it should start by 0 and increment by 1
idThe identifier.
trainPathFull pathname of the train file.
trainStartTime_secThe train start time security.
frictionCoeffThe friction coeff.
locomotivesThe locomotives.
carsThe cars.
optimizeTrue to optimize.
desiredDecelerationRate_mPs(Optional) The desired deceleration rate m ps.
operatorReactionTime_s(Optional) The operator reaction time s.
stopIfNoEnergy(Optional) True to stop if no energy.
isRunnigOffGrid(Optional) True if is runnig off grid, false if not.
maxAllowedJerk_mPcs(Optional) The maximum allowed jerk m pcs.

◆ ~Train()

Train::~Train ( )

Member Function Documentation

◆ accelerate()

double Train::accelerate ( double  gap,
double  mingap,
double  speed,
double  acceleration,
double  leaderSpeed,
double  freeFlowSpeed,
double  deltaT,
bool  optimize,
double  throttleLevel = -1 
)

Gets the acceleration of the train.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
gapThe gap.
mingapThe mingap.
speedThe speed.
accelerationThe acceleration.
leaderSpeedThe leader speed.
freeFlowSpeedThe free flow speed.
deltaTThe delta t.
optimizeTrue to optimize.
throttleLevel(Optional) The throttle level.
Returns
A double.

◆ accelerateConsideringJerk()

double Train::accelerateConsideringJerk ( double  acceleration,
double  previousAcceleration,
double  jerk,
double  deltaT 
)

Accelerate considering jerk.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
accelerationThe acceleration.
previousAccelerationThe previous acceleration.
jerkThe jerk.
deltaTThe delta t.
Returns
A double.

◆ adjustAcceleration()

double Train::adjustAcceleration ( double  speed,
double  previousSpeed,
double  deltaT 
)

Adjust acceleration.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
speedThe speed.
previousSpeedThe previous speed.
deltaTThe delta t.
Returns
A double.

◆ AStarOptimization()

tuple< double, double, double > Train::AStarOptimization ( double  prevSpeed,
double  currentSpeed,
double  currentAcceleration,
double  prevThrottle,
Vector< double >  vector_grade,
Vector< double >  vector_curvature,
double  freeSpeed_ms,
double  timeStep,
Vector< double >  u_leader,
Vector< double >  gapToNextCriticalPoint 
)

This function adopts the A Star optimization to get the optimum throttle level.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
prevSpeedThe previous speed.
currentSpeedThe current speed.
currentAccelerationThe current acceleration.
prevThrottleThe previous throttle.
vector_gradeThe vector grade.
vector_curvatureThe vector curvature.
freeSpeed_msThe free speed in milliseconds.
timeStepThe time step.
u_leaderThe leader.
gapToNextCriticalPointThe gap to next critical point.
Returns
A tuple<double,double,double>

◆ calcTrainStats()

void Train::calcTrainStats ( Vector< double >  listOfLinksFreeFlowSpeeds,
double  MinFreeFlow,
double  timeStep,
std::string  currentRegion 
)

Calculates the train statistics.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
listOfLinksFreeFlowSpeedsThe list of links free flow speeds.
MinFreeFlowThe minimum free flow.
timeStepThe time step.
currentRegionThe current region.

◆ calculateAverage()

double Train::calculateAverage ( double  previousAverage,
double  currentTimeStepData,
double  timeStep 
)

Finds the average of the given arguments.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
previousAverageThe previous average.
currentTimeStepDataInformation describing the current time step.
timeStepThe time step.
Returns
The calculated average.

◆ calculateEnergyConsumption()

void Train::calculateEnergyConsumption ( double  timeStep,
std::string  currentRegion 
)

Calculates the energy consumption.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
timeStepThe time step.
currentRegionThe current region.

◆ canProvideEnergy()

bool Train::canProvideEnergy ( double &  EC,
double &  timeStep 
)

check if the train can provide the required energy to move forward

Parameters
EC
timeStep
Returns

◆ carTypeCount()

Map< TrainTypes::CarType, int > Train::carTypeCount ( )

car type count

Author
Ahmed Aredah
Date
4/6/2023
Returns
A Map<TrainTypes::CarTypes,int>

◆ checkSuddenAccChange()

void Train::checkSuddenAccChange ( double  previousAcceleration,
double  currentAcceleration,
double  deltaT 
)

Check sudden accumulate change.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
previousAccelerationThe previous acceleration.
currentAccelerationThe current acceleration.
deltaTThe delta t.

◆ consumeEnergy()

bool Train::consumeEnergy ( double &  timeStep,
double  trainSpeed,
Vector< double > &  usedTractivePower 
)

Consume energy.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
[in,out]timeStepThe time step.
[in,out]usedTractivePowerThe used tractive power.
Returns
True if it succeeds, false if it fails.

◆ consumeTendersEnergy()

std::pair< bool, double > Train::consumeTendersEnergy ( double  timeStep,
double  trainSpeed,
double  EC_kwh,
TrainTypes::PowerType  powerType,
double  dieselConversionFactor = EC::DefaultDieselConversionFactor,
double  hydrogenConversionFactor = EC::DefaultHydrogenConversionFactor,
double  dieselDensity = EC::DefaultDieselDensity 
)

Consume tenders energy.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
EC_kwhThe ec kwh.
powerTypeType of the power.
dieselConversionFactor(Optional) The diesel conversion factor.
hydrogenConversionFactor(Optional) The hydrogen conversion factor.
dieselDensity(Optional) The diesel density.
Returns
True if it succeeds, false if it fails.

◆ getAccelerationUpperBound()

double Train::getAccelerationUpperBound ( double  speed,
double  acceleration,
double  freeFlowSpeed,
bool  optimize,
double  optimumThrottleLevel 
)

Gets acceleration upper bound.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
speedThe speed.
accelerationThe acceleration.
freeFlowSpeedThe free flow speed.
optimizeTrue to optimize.
optimumThrottleLevelThe optimum throttle level.
Returns
The acceleration upper bound.

◆ getActiveLocomotivesNumber()

int Train::getActiveLocomotivesNumber ( )

Gets active locomotives number.

Author
Ahmed Aredah
Date
2/28/2023
Returns
The active locomotives number.

◆ getActiveTanksOfType()

Vector< std::shared_ptr< Car > > Train::getActiveTanksOfType ( TrainTypes::CarType  cartype)

Gets active tanks of type.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
cartypeThe cartype.
Returns
The active tanks of type.

◆ getAverageLocomotivesBatteryStatus()

double Train::getAverageLocomotivesBatteryStatus ( )

Gets average locomotives battery status.

Author
Ahmed Aredah
Date
2/28/2023
Returns
The average locomotives battery status.

◆ getAverageLocomotiveTankStatus()

double Train::getAverageLocomotiveTankStatus ( )

Gets average locomotives tank status.

Author
Ahmed Aredah
Date
2/28/2023
Returns
The average locomotives tank status.

◆ getAverageTendersBatteryStatus()

double Train::getAverageTendersBatteryStatus ( )

Gets average tenders battery status.

Author
Ahmed Aredah
Date
2/28/2023
Returns
The average tenders battery status.

◆ getAverageTendersStatus()

double Train::getAverageTendersStatus ( )

Gets average tenders status.

Author
Ahmed Aredah
Date
2/28/2023
Returns
The average tenders status.

◆ getAverageTendersTankStatus()

double Train::getAverageTendersTankStatus ( )

Gets average tenders tank status.

Author
Ahmed Aredah
Date
2/28/2023
Returns
The average tenders tank status.

◆ getBatteryEnergyConsumed()

double Train::getBatteryEnergyConsumed ( )

Gets the battery energy consumed in kWh.

Gets the battery energy consumed only. it does not report the energy regenerated.

Author
Ahmed Aredah
Date
2/28/2023
Returns
the energy consumed in kWh.

◆ getBatteryEnergyRegenerated()

double Train::getBatteryEnergyRegenerated ( )

Gets the battery energy regenerated in kWh.

Author
Ahmed Aredah
Date
2/28/2023
Returns
the energy regenerated in kWh.

◆ getBatteryNetEnergyConsumed()

double Train::getBatteryNetEnergyConsumed ( )

Gets the battery energy consumed in kWh.

Gets the battery energy consumed and regenerated.

Author
Ahmed Aredah
Date
2/28/2023
Returns
the energy consumed in kWh.

◆ getCargoNetWeight()

double Train::getCargoNetWeight ( )

Gets cargo net weight.

Author
Ahmed Aredah
Date
2/28/2023
Returns
The cargo net weight.

◆ getDelayTimeStat()

double Train::getDelayTimeStat ( double  freeflowSpeed,
double  timeStep 
)

Gets delay time stat.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
freeflowSpeedThe freeflow speed.
timeStepThe time step.
Returns
The delay time stat.

◆ getEnergyConsumption()

double Train::getEnergyConsumption ( double  timeStep)

Gets energy consumption.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
timeStepThe time step.
Returns
The energy consumption.

◆ getMaxDelayTimeStat()

double Train::getMaxDelayTimeStat ( Vector< double >  listOfLinksFreeFlowSpeeds,
double  timeStep 
)

Gets maximum delay time stat.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
listOfLinksFreeFlowSpeedsThe list of links free flow speeds.
timeStepThe time step.
Returns
The maximum delay time stat.

◆ getMaxProvidedEnergy()

std::pair< double, Map< TrainTypes::PowerType, double > > Train::getMaxProvidedEnergy ( double &  timeStep)

getMaxProvidedEnergy

Parameters
timeStep
Returns

◆ getMinFollowingTrainGap()

double Train::getMinFollowingTrainGap ( )

Gets minimum following train gap.

Author
Ahmed Aredah
Date
2/28/2023
Returns
The minimum following train gap.

◆ getNextTimeStepSpeed()

double Train::getNextTimeStepSpeed ( double  gap,
double  minGap,
double  speed,
double  freeFlowSpeed,
double  aMax,
double  T_s,
double  deltaT 
)

Gets the next time step speed.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
gapThe gap.
minGapThe minimum gap.
speedThe speed.
freeFlowSpeedThe free flow speed.
aMaxThe maximum.
T_sThe s.
deltaTThe delta t.
Returns
The next time step speed.

◆ getNumberOfTrainsInSimulator()

unsigned int Train::getNumberOfTrainsInSimulator ( )
static

this function returns how many trains are loaded in the simulator

Author
Ahmed Aredah
Date
2/28/2023
Returns
The number of trains in simulator.

◆ getRechargableCarsNumber()

int Train::getRechargableCarsNumber ( )

Gets rechargable cars number.

Author
Ahmed Aredah
Date
2/28/2023
Returns
The rechargable cars number.

◆ getRechargableLocsNumber()

int Train::getRechargableLocsNumber ( )

Gets rechargable locs number.

Author
Ahmed Aredah
Date
2/28/2023
Returns
The rechargable locs number.

◆ getSafeGap()

double Train::getSafeGap ( double  initialGap,
double  speed,
double  freeFlowSpeed,
double  T_s,
bool  estimate 
)

Gets safe gap.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
initialGapThe initial gap.
speedThe speed.
freeFlowSpeedThe free flow speed.
T_sThe s.
estimateTrue to estimate.
Returns
The safe gap.

◆ getStepAcceleration()

double Train::getStepAcceleration ( double  timeStep,
double  freeFlowSpeed,
Vector< double > &  gapToNextCriticalPoint,
Vector< bool > &  gapToNextCriticalPointType,
Vector< double > &  leaderSpeed 
)

getStepDynamics

Parameters
timeStep
freeFlowSpeed
gapToNextCriticalPoint
gapToNextCriticalPointType
leaderSpeed
Returns

◆ getStoppingTimeStat()

double Train::getStoppingTimeStat ( Vector< double >  listOfLinksFreeFlowSpeeds)

Gets stopping time stat.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
listOfLinksFreeFlowSpeedsThe list of links free flow speeds.
Returns
The stopping time stat.

◆ getTimeToCollision()

double Train::getTimeToCollision ( double  gap,
double  minGap,
double  speed,
double  leaderSpeed 
)

Gets time to collision.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
gapThe gap.
minGapThe minimum gap.
speedThe speed.
leaderSpeedThe leader speed.
Returns
The time to collision.

◆ getTotalEnergyConsumption()

double Train::getTotalEnergyConsumption ( double &  timeStep,
Vector< double > &  usedTractivePower 
)

Gets total energy consumption.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
[in,out]timeStepThe time step.
[in,out]usedTractivePowerThe used tractive power.
Returns
The total energy consumption.

◆ getTotalResistance()

double Train::getTotalResistance ( double  speed)

Gets total resistance.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
speedThe speed.
Returns
The total resistance.

◆ getTotalTractiveForce()

double Train::getTotalTractiveForce ( double  speed,
double  acceleration,
bool  optimize,
double  optimumThrottleLevel 
)

Gets total tractive force.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
speedThe speed.
accelerationThe acceleration.
optimizeTrue to optimize.
optimumThrottleLevelThe optimum throttle level.
Returns
The total tractive force.

◆ getTractivePower()

pair< Vector< double >, double > Train::getTractivePower ( double  speed,
double  acceleration,
double  resistanceForces 
)

Gets tractive power.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
speedThe speed.
accelerationThe acceleration.
resistanceForcesThe resistance forces.
Returns
The tractive power.

◆ getTrainCentroids()

Map< std::shared_ptr< TrainComponent >, double > Train::getTrainCentroids ( )

This function returns the centroids of all vehicles in the train.

Author
Ahmed Aredah
Date
2/28/2023
Returns
The train centroids.

◆ getTrainConsumedTank()

Map< std::string, double > Train::getTrainConsumedTank ( )

getTrainConsumedTank

Returns
number of litters consumed from the tank.

◆ getTrainTotalTorque()

double Train::getTrainTotalTorque ( )

Gets train total torque in tons x meters.

Author
Ahmed Aredah
Date
2/28/2023
Returns
The train total torque.

◆ heuristicFunction()

double Train::heuristicFunction ( double  distanceToEnd,
double  stepAcceleration,
double  stepSpeed,
double  timeStep,
double  resistance,
double  currentSpeed 
)

The heuristic function for the A-Star algorithm.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
distanceToEndThe distance to end.
stepAccelerationThe step acceleration.
stepSpeedThe step speed.
timeStepThe time step.
resistanceThe resistance.
currentSpeedThe current speed.
Returns
A double.

◆ immediateStop()

void Train::immediateStop ( double  timeStep)

Immediate stop.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
timeStepThe time step.

◆ kickForwardADistance()

void Train::kickForwardADistance ( double &  distance)

Kick forward a distance.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
[in,out]distanceThe distance.

◆ LocTypeCount()

Map< TrainTypes::PowerType, int > Train::LocTypeCount ( )

Locomotive type count.

Author
Ahmed Aredah
Date
2/28/2023
Returns
A Map<TrainTypes::PowerType,int>

◆ moveTrain()

void Train::moveTrain ( double  timeStep,
double  freeFlowSpeed,
Vector< double > &  gapToNextCriticalPoint,
Vector< bool > &  gapToNextCriticalPointType,
Vector< double > &  leaderSpeed 
)

Move train forward.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
timeStepThe time step.
freeFlowSpeedThe free flow speed.
[in,out]gapToNextCriticalPointThe gap to next critical point.
[in,out]gapToNextCriticalPointTypeType of the gap to next critical point.
[in,out]leaderSpeedThe leader speed.

◆ pickOptimalThrottleLevelAStar()

double Train::pickOptimalThrottleLevelAStar ( Vector< double >  throttleLevels,
int  lookAheadCounterToUpdate 
)

Picks the optimal throttle level considering the A-Star optimization.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
throttleLevelsThe throttle levels.
lookAheadCounterToUpdateThe look ahead counter to update.
Returns
A double.

◆ rearrangeTrain()

void Train::rearrangeTrain ( )

Rearrange train.

Author
Ahmed Aredah
Date
2/28/2023

◆ rechargeCarsBatteries()

bool Train::rechargeCarsBatteries ( double  timeStep,
double  EC_kwh,
std::shared_ptr< Locomotive > &  loco 
)

recharge all train cars batteries.

Parameters
EC_kwh
Returns

◆ reducePower()

void Train::reducePower ( double &  reductionFactor)

reducePower

Parameters
reductionFactor

◆ resetPowerRestriction()

void Train::resetPowerRestriction ( )

resetPowerRestriction

◆ resetTrain()

void Train::resetTrain ( )

Resets the train parameters.

Author
Ahmed Aredah
Date
2/28/2023

◆ resetTrainEnergyConsumption()

void Train::resetTrainEnergyConsumption ( )

Resets the train energy consumption.

Author
Ahmed Aredah
Date
2/28/2023

◆ resetTrainLookAhead()

void Train::resetTrainLookAhead ( )

reset train look ahead parameters

◆ setTrainLength()

void Train::setTrainLength ( )

Sets train length.

Author
Ahmed Aredah
Date
2/28/2023

◆ setTrainPath()

void Train::setTrainPath ( Vector< int >  path)

set the train path.

Parameters
paththe new path of the simulator node ids.

◆ setTrainsCurrentLinks()

void Train::setTrainsCurrentLinks ( Vector< std::shared_ptr< NetLink > >  newLinks)

set the current links the train is spanning

Parameters
newLinks

◆ setTrainSimulatorID()

void Train::setTrainSimulatorID ( int  newID)

◆ setTrainWeight()

void Train::setTrainWeight ( )

Sets train weight.

Author
Ahmed Aredah
Date
2/28/2023

◆ slowSpeedOrStopped

void Train::slowSpeedOrStopped ( std::string  msg)
signal

report the trains is very slow or stopped

this is emitted when the train's speed is very slow either because the resistance is high or because the distance in front of the train is very small

Parameters
msg

◆ smoothAccelerate()

double Train::smoothAccelerate ( double  acceleration,
double  previousAccelerationValue,
double  alpha = 0.2 
)

Smooth the acceleration.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
accelerationThe acceleration.
previousAccelerationValueThe previous acceleration value.
alpha(Optional) The alpha.
Returns
A double.

◆ speedUpDown()

double Train::speedUpDown ( double  previousSpeed,
double  acceleration,
double  deltaT,
double  freeFlowSpeed 
)

Gets the speed of the train based on the acceleration.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
previousSpeedThe previous speed.
accelerationThe acceleration.
deltaTThe delta t.
freeFlowSpeedThe free flow speed.
Returns
A double.

◆ suddenAccelerationOccurred

void Train::suddenAccelerationOccurred ( std::string  msg)
signal

report a sudden acceleration.

this is emitted when the train's acceleration is larger than the jerk

Parameters
msgis the warning message

◆ updateGradesCurvatures() [1/2]

void Train::updateGradesCurvatures ( const Vector< double > &  trainGrade,
const Vector< double > &  trainCurvature 
)

Updates the grades curvatures.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
trainGradeThe train grade.
trainCurvatureThe train curvature.

◆ updateGradesCurvatures() [2/2]

void Train::updateGradesCurvatures ( Vector< double > &  LocsCurvature,
Vector< double > &  LocsGrade,
Vector< double > &  CarsCurvature,
Vector< double > &  CarsGrade 
)

Updates the grades curvatures.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
[in,out]LocsCurvatureThe locs curvature.
[in,out]LocsGradeThe locs grade.
[in,out]CarsCurvatureThe cars curvature.
[in,out]CarsGradeThe cars grade.

◆ updateLocNotch()

void Train::updateLocNotch ( )

Updates the location notch.

Author
Ahmed Aredah
Date
2/28/2023

Friends And Related Symbol Documentation

◆ operator<<

ostream & operator<< ( ostream &  ostr,
Train train 
)
friend

Stream insertion operator.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
[in,out]ostrThe ostr.
[in,out]trainThe train.
Returns
The shifted result.

Member Data Documentation

◆ ActiveCarsTypes

Map<TrainTypes::CarType, Vector<std::shared_ptr<Car> > > Train::ActiveCarsTypes

Maps the train active cars types.

◆ ActiveLocos

Vector<std::shared_ptr<Locomotive> > Train::ActiveLocos

Maps the train active locomotives types.

◆ averageAcceleration

double Train::averageAcceleration

The average journey acceleration of the train from t = 0 to t.

◆ averageSpeed

double Train::averageSpeed

The average journey speed of the train from t = 0 to t.

◆ betweenNodesLengths

Vector<Vector<double> > Train::betweenNodesLengths

Holds the computed distances between two nodes along the train's path.

◆ cars

Vector<std::shared_ptr<Car> > Train::cars

Holds all cars in the train.

◆ carsTypes

Map<TrainTypes::CarType, Vector<std::shared_ptr<Car> > > Train::carsTypes

Maps the train cars types.

◆ coefficientOfFriction

double Train::coefficientOfFriction = 0.9

Coefficient of fricition between the trains' wheels and the track.

◆ cumDelayTimeStat

double Train::cumDelayTimeStat

Cumulative total time delayed untill time step t, relative to min free flow speed of all spanned links.

◆ cumEnergyStat

double Train::cumEnergyStat

Cumulative total energy consumed till time step t.

◆ cumMaxDelayTimeStat

double Train::cumMaxDelayTimeStat

Total time delayed untill time step t, relative to max free flow speed of all spanned links.

◆ cumRegionalConsumedEnergyStat

Map<string, double> Train::cumRegionalConsumedEnergyStat

Total energy consumed till time step t mapped by region.

◆ cumStoppedStat

double Train::cumStoppedStat

Statistic of stoppings untill time t.

◆ cumUsedTractivePower

double Train::cumUsedTractivePower

The cummulative used tractive power (work) that the locomotives provide in kw.

◆ currentAcceleration

double Train::currentAcceleration

The current acceleration of the train (at time t)

◆ currentCoordinates

pair<double, double> Train::currentCoordinates

Holds the current coordinates of the tip of the train.

◆ currentFirstLink

std::shared_ptr<NetLink> Train::currentFirstLink

Holds the first link the train is on.

◆ currentLinks

Vector<std::shared_ptr<NetLink> > Train::currentLinks

The spanned links the train is on.

works as blocks

◆ currentResistanceForces

double Train::currentResistanceForces

The current resistance forces on the train in Newton.

◆ currentSpeed

double Train::currentSpeed

The current speed of the train (at time t)

◆ currentTractiveForce

double Train::currentTractiveForce

The current tractive forces the train is using in Newton.

◆ currentUsedTractivePower

double Train::currentUsedTractivePower

The current used tractive power that the locomotives provides in kw.

◆ currentUsedTractivePowerList

Vector<double> Train::currentUsedTractivePowerList

The current used tractive power list.

◆ d_des

double Train::d_des

The desired decceleration value.

◆ delayTimeStat

double Train::delayTimeStat

The time the train is delayed at time step t, relative to min free flow speed of all spanned links.

◆ energyStat

double Train::energyStat

Total energy consumption (consumed + regenerated) at time step t.

◆ g

const double Train::g = 9.8066

(Immutable) gravitational acceleration

◆ id

int Train::id

The name of the train.

◆ isOn

bool Train::isOn

True if the train has energy, false if dead.

◆ LastTrainPointpreviousNodeID

int Train::LastTrainPointpreviousNodeID

The previous node ID the last point of the train just passed.

◆ LinkGradeDirection

Map<int, double> Train::LinkGradeDirection

Grade of the links the train is taking and it is mapped by the link ID.

◆ linksCumLengths

Vector<double> Train::linksCumLengths

Holds the cummulative distance from the start of the train's path to each and every node in the path.

◆ loaded

bool Train::loaded = false

True if the train is loaded to the simulator, false otherwise.

◆ locomotives

Vector<std::shared_ptr<Locomotive> > Train::locomotives

Holds all locomotives in the train.

◆ lookAheadCounterToUpdate

int Train::lookAheadCounterToUpdate

The number of steps ahead the train should update its optimization at.

◆ lookAheadStepCounter

int Train::lookAheadStepCounter

The number of steps ahead the train is looking aheaf for optimization.

◆ LowerSpeedNodeIDs

Vector<Vector<Map<int, double> > > Train::LowerSpeedNodeIDs

Holds the lower speed node ID's the train will have to reduce its speed at.

◆ maxDelayTimeStat

double Train::maxDelayTimeStat

The time the train is delayed at time step t, relative to max free flow speed of all spanned links.

◆ maxJerk

double Train::maxJerk = 2.0

Max allowable jerk (m/s^3) for the train.

◆ nCars

int Train::nCars = 0

Number of cars in the train.

◆ nextNodeID

int Train::nextNodeID

The next node the train is targetting.

◆ nlocs

int Train::nlocs = 0

Number of locomotives in the train.

◆ NoPowerCountStep

int Train::NoPowerCountStep

Counts the number of steps the train could not move forward because of the lack of power source.

◆ offloaded

bool Train::offloaded = false

If the train is on the network, it is true, false otherwise.

◆ operatorReactionTime

double Train::operatorReactionTime

the perception reaction time of the train operator.

◆ optimize

bool Train::optimize

True if the train should optimize its energy consumption.

train trajectory will vary here.

◆ optimumThrottleLevel

double Train::optimumThrottleLevel

The optimum throttle level that the train should go by to minimize its energy use.

◆ outOfEnergy

bool Train::outOfEnergy = false

True if the train ran out of energy.

◆ previousAcceleration

double Train::previousAcceleration

The previous acceleration of the train (at time t-1)

◆ previousLinks

Vector<std::shared_ptr<NetLink> > Train::previousLinks

The previous links the train spanned before.

◆ previousNodeID

int Train::previousNodeID

The previous node ID the tip of the train just passed.

◆ previousSpeed

double Train::previousSpeed

The previous speed of the train (at time t-1)

◆ reachedDestination

bool Train::reachedDestination = false

True if the simulator reached its destination, false otherwise.

◆ speedOfSound

constexpr double Train::speedOfSound = 343.0
staticconstexpr

(Immutable) the speed of sound in m / s, this is an approximation of the brackes back propagation

◆ startEndPoints

Vector<pair<double, double> > Train::startEndPoints

Holds both the start and end tips' coordinates of the train.

◆ stoppedStat

double Train::stoppedStat

Statistic of the stoppings at time t.

◆ stopTrainIfNoEnergy

bool Train::stopTrainIfNoEnergy

Change this to true if you want the train to stop if it runs out of energy.

◆ T_s

double Train::T_s

Time to fully activate the brakes, considering the network signal speed equals speed of sound.

◆ throttleLevels

Vector<double> Train::throttleLevels

The throttle levels that the train will go by.

◆ totalEConsumed

double Train::totalEConsumed

Total energy consumpted only of the train till time t.

◆ totalEmptyMass

double Train::totalEmptyMass = 0

The total empty weight of the train.

◆ totalERegenerated

double Train::totalERegenerated

Energy regenerated of the train till time t.

◆ totalLength

double Train::totalLength

Total length of the train.

◆ totalMass

double Train::totalMass

The total weight of the train in kg.

◆ trainPath

Vector<int> Train::trainPath

The predefined path of the train by the simulator node id.

It is originally populated by the user node ids. the simulator replaces it by the simulator node ids.

◆ trainPathNodes

Vector<std::shared_ptr<NetNode> > Train::trainPathNodes

The predefined path of the train by the node reference.

◆ trainStartTime

double Train::trainStartTime

Start time of the train to enter the network retrative to the beginning of the simulator.

◆ trainStoppingStations

Vector<bool> Train::trainStoppingStations

The train stopping stations.

◆ trainTotalPathLength

double Train::trainTotalPathLength

The total length of the path the train is suppost to be taking.

◆ trainUserID

string Train::trainUserID

The name of the train.

◆ trainVehicles

Vector< std::shared_ptr<TrainComponent> > Train::trainVehicles

holds the arrangement of the train and how locomotives and cars are arranged in that train.

◆ travelledDistance

double Train::travelledDistance

Travelled distance of the train measured from the front tip of the train.

◆ tripTime

double Train::tripTime

Total time spent between the train entering and leaving the network.

◆ virtualTravelledDistance

double Train::virtualTravelledDistance

Travelled distance of the train measured from the front tip of the train (virtual and does not affect train movement.

it is only used for optimization.

◆ waitedTimeAtNode

double Train::waitedTimeAtNode

holds the waited time at any depot

◆ WeightCentroids

Map<std::shared_ptr<TrainComponent>, double> Train::WeightCentroids

Holds the centroid location mapped by the car/loco and relative to the tip of the train.