6#ifndef NeTrainSim_Train_h
7#define NeTrainSim_Train_h
11#include "../util/vector.h"
14#include "../util/map.h"
50 static unsigned int NumberOfTrainsInSimulator;
52 static constexpr double DefaultDesiredDecelerationRate = 0.2;
54 static constexpr double DefaultOperatorReactionTime = 1.0;
56 static constexpr bool DefaultStopIfNoEnergy =
false;
58 static constexpr double DefaultMaxAllowedJerk = 2.0;
60 static constexpr double DefaultMinFollowingGap = 2.0;
62 static constexpr int DefaultLookAheadCounterToUpdate = 1;
64 static constexpr int DefaultLookAheadCounter = 1;
74 const double g = 9.8066;
265 double desiredDecelerationRate_mPs = DefaultDesiredDecelerationRate,
266 double operatorReactionTime_s = DefaultOperatorReactionTime,
267 bool stopIfNoEnergy = DefaultStopIfNoEnergy,
268 double maxAllowedJerk_mPcs = DefaultMaxAllowedJerk);
579 double getSafeGap(
double initialGap,
double speed,
double freeFlowSpeed,
double T_s,
bool estimate);
598 double aMax,
double T_s,
double deltaT);
613 double getTimeToCollision(
double gap,
double minGap,
double speed,
double leaderSpeed);
633 double accelerate(
double gap,
double mingap,
double speed,
double acceleration,
double leaderSpeed,
634 double freeFlowSpeed,
double deltaT,
bool optimize,
double throttleLevel = -1);
663 double smoothAccelerate(
double acceleration,
double previousAccelerationValue,
double alpha = 0.2);
745 pair<Vector<double>,
double>
getTractivePower(
double speed,
double acceleration,
double resistanceForces);
847 double dieselConversionFactor = EC::DefaultDieselConversionFactor,
848 double hydrogenConversionFactor = EC::DefaultHydrogenConversionFactor,
849 double dieselDensity = EC::DefaultDieselDensity);
923 double heuristicFunction(
double distanceToEnd,
double stepAcceleration,
double stepSpeed,
924 double timeStep,
double resistance,
double currentSpeed);
968 double calculateAverage(
double previousAverage,
double currentTimeStepData,
double timeStep);
1071 double get_acceleration_an11(
double u_hat,
double speed,
double TTC_s,
double frictionCoef);
1086 double get_acceleration_an12(
double u_hat,
double speed,
double T_s,
double amax);
1098 double get_beta1(
double an11);
1112 double get_acceleration_an13(
double beta1,
double an11,
double an12);
1128 double get_acceleration_an14(
double speed,
double leaderSpeed,
double T_s,
double amax,
double frictionCoef);
1152 double get_acceleration_an1(
double beta2,
double an13,
double an14);
1164 double get_gamma(
double speedDiff);
1212 double get_acceleration_an2(
double gap,
double minGap,
double speed,
double leaderSpeed,
double T_s,
double frictionCoef);
A map.
Definition map.h:26
The NetLink class represents a network link in a simulation.
Definition netlink.h:36
The NetNode class represents a network node in a simulation.
Definition netnode.h:35
A train.
Definition train.h:42
double totalEConsumed
Total energy consumpted only of the train till time t.
Definition train.h:132
Vector< std::shared_ptr< Car > > cars
Holds all cars in the train.
Definition train.h:169
Map< string, double > getTrainConsumedTank()
getTrainConsumedTank
Definition train.cpp:185
void calculateEnergyConsumption(double timeStep, std::string currentRegion)
Calculates the energy consumption.
Definition train.cpp:1033
double getDelayTimeStat(double freeflowSpeed, double timeStep)
Gets delay time stat.
Definition train.cpp:717
int lookAheadStepCounter
The number of steps ahead the train is looking aheaf for optimization.
Definition train.h:222
double stoppedStat
Statistic of the stoppings at time t.
Definition train.h:144
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.
Definition train.cpp:975
int nCars
Number of cars in the train.
Definition train.h:207
double trainStartTime
Start time of the train to enter the network retrative to the beginning of the simulator.
Definition train.h:93
double getCargoNetWeight()
Gets cargo net weight.
Definition train.cpp:236
double currentUsedTractivePower
The current used tractive power that the locomotives provides in kw.
Definition train.h:122
double averageSpeed
The average journey speed of the train from t = 0 to t.
Definition train.h:110
double getAverageLocomotivesBatteryStatus()
Gets average locomotives battery status.
Definition train.cpp:135
Vector< double > linksCumLengths
Holds the cummulative distance from the start of the train's path to each and every node in the path.
Definition train.h:183
double maxDelayTimeStat
The time the train is delayed at time step t, relative to max free flow speed of all spanned links.
Definition train.h:140
void resetTrainEnergyConsumption()
Resets the train energy consumption.
Definition train.cpp:876
double getAverageTendersBatteryStatus()
Gets average tenders battery status.
Definition train.cpp:166
void resetTrain()
Resets the train parameters.
Definition train.cpp:1154
void moveTrain(double timeStep, double freeFlowSpeed, Vector< double > &gapToNextCriticalPoint, Vector< bool > &gapToNextCriticalPointType, Vector< double > &leaderSpeed)
Move train forward.
Definition train.cpp:641
Vector< bool > trainStoppingStations
The train stopping stations.
Definition train.h:203
double getTrainTotalTorque()
Gets train total torque in tons x meters.
Definition train.cpp:181
Map< string, double > cumRegionalConsumedEnergyStat
Total energy consumed till time step t mapped by region.
Definition train.h:165
string trainUserID
The name of the train.
Definition train.h:200
void immediateStop(double timeStep)
Immediate stop.
Definition train.cpp:658
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.
Definition train.cpp:513
Vector< Vector< Map< int, double > > > LowerSpeedNodeIDs
Holds the lower speed node ID's the train will have to reduce its speed at.
Definition train.h:185
Map< TrainTypes::CarType, Vector< std::shared_ptr< Car > > > carsTypes
Maps the train cars types.
Definition train.h:161
~Train()
Definition train.cpp:75
double getBatteryNetEnergyConsumed()
Gets the battery energy consumed in kWh.
Definition train.cpp:127
double cumMaxDelayTimeStat
Total time delayed untill time step t, relative to max free flow speed of all spanned links.
Definition train.h:142
double energyStat
Total energy consumption (consumed + regenerated) at time step t.
Definition train.h:128
void setTrainPath(Vector< int > path)
set the train path.
Definition train.cpp:83
void checkSuddenAccChange(double previousAcceleration, double currentAcceleration, double deltaT)
Check sudden accumulate change.
Definition train.cpp:564
bool offloaded
If the train is on the network, it is true, false otherwise.
Definition train.h:232
void setTrainLength()
Sets train length.
Definition train.cpp:316
std::pair< double, Map< TrainTypes::PowerType, double > > getMaxProvidedEnergy(double &timeStep)
getMaxProvidedEnergy
Definition train.cpp:1079
Vector< std::shared_ptr< TrainComponent > > trainVehicles
holds the arrangement of the train and how locomotives and cars are arranged in that train.
Definition train.h:191
bool loaded
True if the train is loaded to the simulator, false otherwise.
Definition train.h:238
double heuristicFunction(double distanceToEnd, double stepAcceleration, double stepSpeed, double timeStep, double resistance, double currentSpeed)
The heuristic function for the A-Star algorithm.
Definition train.cpp:825
Map< int, double > LinkGradeDirection
Grade of the links the train is taking and it is mapped by the link ID.
Definition train.h:159
double getTotalResistance(double speed)
Gets total resistance.
Definition train.cpp:388
void kickForwardADistance(double &distance)
Kick forward a distance.
Definition train.cpp:666
static unsigned int getNumberOfTrainsInSimulator()
this function returns how many trains are loaded in the simulator
Definition train.cpp:204
Vector< pair< double, double > > startEndPoints
Holds both the start and end tips' coordinates of the train.
Definition train.h:187
int nextNodeID
The next node the train is targetting.
Definition train.h:217
void calcTrainStats(Vector< double > listOfLinksFreeFlowSpeeds, double MinFreeFlow, double timeStep, std::string currentRegion)
Calculates the train statistics.
Definition train.cpp:682
double maxJerk
Max allowable jerk (m/s^3) for the train.
Definition train.h:89
double accelerateConsideringJerk(double acceleration, double previousAcceleration, double jerk, double deltaT)
Accelerate considering jerk.
Definition train.cpp:546
Vector< double > throttleLevels
The throttle levels that the train will go by.
Definition train.h:197
double cumEnergyStat
Cumulative total energy consumed till time step t.
Definition train.h:130
double getBatteryEnergyRegenerated()
Gets the battery energy regenerated in kWh.
Definition train.cpp:119
int lookAheadCounterToUpdate
The number of steps ahead the train should update its optimization at.
Definition train.h:224
Vector< std::shared_ptr< NetLink > > previousLinks
The previous links the train spanned before.
Definition train.h:189
Map< TrainTypes::PowerType, int > LocTypeCount()
Locomotive type count.
Definition train.cpp:244
double totalLength
Total length of the train.
Definition train.h:80
void resetPowerRestriction()
resetPowerRestriction
Definition train.cpp:899
Vector< std::shared_ptr< NetNode > > trainPathNodes
The predefined path of the train by the node reference.
Definition train.h:176
void suddenAccelerationOccurred(std::string msg)
report a sudden acceleration.
double cumStoppedStat
Statistic of stoppings untill time t.
Definition train.h:146
double getStoppingTimeStat(Vector< double > listOfLinksFreeFlowSpeeds)
Gets stopping time stat.
Definition train.cpp:723
bool reachedDestination
True if the simulator reached its destination, false otherwise.
Definition train.h:234
double optimumThrottleLevel
The optimum throttle level that the train should go by to minimize its energy use.
Definition train.h:126
void slowSpeedOrStopped(std::string msg)
report the trains is very slow or stopped
Vector< Vector< double > > betweenNodesLengths
Holds the computed distances between two nodes along the train's path.
Definition train.h:180
bool consumeEnergy(double &timeStep, double trainSpeed, Vector< double > &usedTractivePower)
Consume energy.
Definition train.cpp:924
double tripTime
Total time spent between the train entering and leaving the network.
Definition train.h:95
void setTrainSimulatorID(int newID)
Definition train.cpp:79
int previousNodeID
The previous node ID the tip of the train just passed.
Definition train.h:213
double getAccelerationUpperBound(double speed, double acceleration, double freeFlowSpeed, bool optimize, double optimumThrottleLevel)
Gets acceleration upper bound.
Definition train.cpp:411
double getAverageTendersTankStatus()
Gets average tenders tank status.
Definition train.cpp:151
double currentResistanceForces
The current resistance forces on the train in Newton.
Definition train.h:120
double adjustAcceleration(double speed, double previousSpeed, double deltaT)
Adjust acceleration.
Definition train.cpp:560
void updateLocNotch()
Updates the location notch.
Definition train.cpp:371
double getAverageLocomotiveTankStatus()
Gets average locomotives tank status.
Definition train.cpp:143
double virtualTravelledDistance
Travelled distance of the train measured from the front tip of the train (virtual and does not affect...
Definition train.h:104
double totalERegenerated
Energy regenerated of the train till time t.
Definition train.h:134
Map< std::shared_ptr< TrainComponent >, double > getTrainCentroids()
This function returns the centroids of all vehicles in the train.
Definition train.cpp:222
double getNextTimeStepSpeed(double gap, double minGap, double speed, double freeFlowSpeed, double aMax, double T_s, double deltaT)
Gets the next time step speed.
Definition train.cpp:430
double getMaxDelayTimeStat(Vector< double > listOfLinksFreeFlowSpeeds, double timeStep)
Gets maximum delay time stat.
Definition train.cpp:709
Vector< std::shared_ptr< Car > > getActiveTanksOfType(TrainTypes::CarType cartype)
Gets active tanks of type.
Definition train.cpp:359
const double g
(Immutable) gravitational acceleration
Definition train.h:74
double currentAcceleration
The current acceleration of the train (at time t)
Definition train.h:112
std::shared_ptr< NetLink > currentFirstLink
Holds the first link the train is on.
Definition train.h:155
double delayTimeStat
The time the train is delayed at time step t, relative to min free flow speed of all spanned links.
Definition train.h:136
double cumDelayTimeStat
Cumulative total time delayed untill time step t, relative to min free flow speed of all spanned link...
Definition train.h:138
double currentTractiveForce
The current tractive forces the train is using in Newton.
Definition train.h:118
double getMinFollowingTrainGap()
Gets minimum following train gap.
Definition train.cpp:107
pair< Vector< double >, double > getTractivePower(double speed, double acceleration, double resistanceForces)
Gets tractive power.
Definition train.cpp:846
void setTrainWeight()
Sets train weight.
Definition train.cpp:326
friend ostream & operator<<(ostream &ostr, Train &train)
Stream insertion operator.
double speedUpDown(double previousSpeed, double acceleration, double deltaT, double freeFlowSpeed)
Gets the speed of the train based on the acceleration.
Definition train.cpp:555
double getAverageTendersStatus()
Gets average tenders status.
Vector< double > currentUsedTractivePowerList
The current used tractive power list.
Definition train.h:195
void setTrainsCurrentLinks(Vector< std::shared_ptr< NetLink > > newLinks)
set the current links the train is spanning
Definition train.cpp:905
double d_des
The desired decceleration value.
Definition train.h:76
double operatorReactionTime
the perception reaction time of the train operator.
Definition train.h:78
static constexpr double speedOfSound
(Immutable) the speed of sound in m / s, this is an approximation of the brackes back propagation
Definition train.h:72
bool rechargeCarsBatteries(double timeStep, double EC_kwh, std::shared_ptr< Locomotive > &loco)
recharge all train cars batteries.
Definition train.cpp:1008
double averageAcceleration
The average journey acceleration of the train from t = 0 to t.
Definition train.h:116
double getTotalEnergyConsumption(double &timeStep, Vector< double > &usedTractivePower)
Gets total energy consumption.
Definition train.cpp:882
bool isOn
True if the train has energy, false if dead.
Definition train.h:230
double previousSpeed
The previous speed of the train (at time t-1)
Definition train.h:108
void updateGradesCurvatures(Vector< double > &LocsCurvature, Vector< double > &LocsGrade, Vector< double > &CarsCurvature, Vector< double > &CarsGrade)
Updates the grades curvatures.
double travelledDistance
Travelled distance of the train measured from the front tip of the train.
Definition train.h:99
int id
The name of the train.
Definition train.h:211
double getEnergyConsumption(double timeStep)
Gets energy consumption.
double getSafeGap(double initialGap, double speed, double freeFlowSpeed, double T_s, bool estimate)
Gets safe gap.
Definition train.cpp:419
Vector< std::shared_ptr< Locomotive > > locomotives
Holds all locomotives in the train.
Definition train.h:171
int getActiveLocomotivesNumber()
Gets active locomotives number.
Definition train.cpp:94
int nlocs
Number of locomotives in the train.
Definition train.h:209
double trainTotalPathLength
The total length of the path the train is suppost to be taking.
Definition train.h:97
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.
Definition train.cpp:763
Vector< int > trainPath
The predefined path of the train by the simulator node id.
Definition train.h:174
double previousAcceleration
The previous acceleration of the train (at time t-1)
Definition train.h:114
Vector< std::shared_ptr< Locomotive > > ActiveLocos
Maps the train active locomotives types.
Definition train.h:193
int getRechargableLocsNumber()
Gets rechargable locs number.
Definition train.cpp:753
double getTotalTractiveForce(double speed, double acceleration, bool optimize, double optimumThrottleLevel)
Gets total tractive force.
Definition train.cpp:399
double getBatteryEnergyConsumed()
Gets the battery energy consumed in kWh.
Definition train.cpp:111
double coefficientOfFriction
Coefficient of fricition between the trains' wheels and the track.
Definition train.h:87
double cumUsedTractivePower
The cummulative used tractive power (work) that the locomotives provide in kw.
Definition train.h:124
pair< double, double > currentCoordinates
Holds the current coordinates of the tip of the train.
Definition train.h:151
bool outOfEnergy
True if the train ran out of energy.
Definition train.h:236
double calculateAverage(double previousAverage, double currentTimeStepData, double timeStep)
Finds the average of the given arguments.
Definition train.cpp:704
int LastTrainPointpreviousNodeID
The previous node ID the last point of the train just passed.
Definition train.h:215
void rearrangeTrain()
Rearrange train.
Definition train.cpp:270
double pickOptimalThrottleLevelAStar(Vector< double > throttleLevels, int lookAheadCounterToUpdate)
Picks the optimal throttle level considering the A-Star optimization.
Definition train.cpp:837
double getStepAcceleration(double timeStep, double freeFlowSpeed, Vector< double > &gapToNextCriticalPoint, Vector< bool > &gapToNextCriticalPointType, Vector< double > &leaderSpeed)
getStepDynamics
Definition train.cpp:573
Map< std::shared_ptr< TrainComponent >, double > WeightCentroids
Holds the centroid location mapped by the car/loco and relative to the tip of the train.
Definition train.h:157
double getTimeToCollision(double gap, double minGap, double speed, double leaderSpeed)
Gets time to collision.
Definition train.cpp:441
int getRechargableCarsNumber()
Gets rechargable cars number.
Definition train.cpp:743
double waitedTimeAtNode
holds the waited time at any depot
Definition train.h:148
void reducePower(double &reductionFactor)
reducePower
Definition train.cpp:893
double currentSpeed
The current speed of the train (at time t)
Definition train.h:106
Map< TrainTypes::CarType, int > carTypeCount()
car type count
Definition train.cpp:257
Map< TrainTypes::CarType, Vector< std::shared_ptr< Car > > > ActiveCarsTypes
Maps the train active cars types.
Definition train.h:163
int NoPowerCountStep
Counts the number of steps the train could not move forward because of the lack of power source.
Definition train.h:220
double totalMass
The total weight of the train in kg.
Definition train.h:82
bool optimize
True if the train should optimize its energy consumption.
Definition train.h:240
void resetTrainLookAhead()
reset train look ahead parameters
Definition train.cpp:1149
double T_s
Time to fully activate the brakes, considering the network signal speed equals speed of sound.
Definition train.h:91
bool canProvideEnergy(double &EC, double &timeStep)
check if the train can provide the required energy to move forward
Definition train.cpp:1131
bool stopTrainIfNoEnergy
Change this to true if you want the train to stop if it runs out of energy.
Definition train.h:228
double smoothAccelerate(double acceleration, double previousAccelerationValue, double alpha=0.2)
Smooth the acceleration.
Definition train.cpp:551
Vector< std::shared_ptr< NetLink > > currentLinks
The spanned links the train is on.
Definition train.h:178
double totalEmptyMass
The total empty weight of the train.
Definition train.h:84
A vector.
Definition vector.h:24
Definition energyconsumption.cpp:6
_PowerType
Values that represent power types.
Definition traintypes.h:168
_CarType
Values that represent car types.
Definition traintypes.h:23