-
Notifications
You must be signed in to change notification settings - Fork 0
/
public_train_generator.cpp
71 lines (63 loc) · 2.56 KB
/
public_train_generator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* train_generator.cpp
*
* Created on: Nov 29, 2015
* Author: pavel
*/
#include "public_train_generator.h"
#include "public_train.h"
#include "time_interval.h"
////////////////////////////////////////////////////////////////////////////////////////////////////
CPublicTrainGenerator::CPublicTrainGenerator(const std::string& trainTitle,
CStation& startStation,
CStation& targetStation,
CPublicTrainGenerator::Frequency frequency,
unsigned scheduleStartTime,
unsigned targetStationArrival,
unsigned averageDelay,
bool bStopsInMainStation,
unsigned mainStationArrival,
unsigned mainStationDeparture)
: CTrainGenerator(trainTitle, startStation, targetStation, frequency, scheduleStartTime,
targetStationArrival, averageDelay, bStopsInMainStation, mainStationArrival,
mainStationDeparture)
{}
CPublicTrainGenerator::~CPublicTrainGenerator()
{}
////////////////////////////////////////////////////////////////////////////////////////////////////
void CPublicTrainGenerator::Behavior()
{
// Check for exceptions
bool bExceptionalTime = false;
for(ScheduleExceptions::const_iterator it = m_ScheduleExceptions.begin();
it != m_ScheduleExceptions.end();
++it)
{
if((*it)->IsInInterval(Time))
{
bExceptionalTime = true;
break;
}
}
// Generate train
if(!bExceptionalTime)
{
// Compute concrete arrival and departure times
unsigned targetStationArrival = Time + m_ScheduleTargetStationArrival - m_ScheduleStartTime + CPublicTrain::GetBoardingTime();
unsigned mainStationArrival = Time + m_ScheduleMainStationArrival - m_ScheduleStartTime + CPublicTrain::GetBoardingTime();
unsigned mainStationDeparture = Time + m_ScheduleMainStationDeparture - m_ScheduleStartTime + CPublicTrain::GetBoardingTime();
/*
DBG_LOG_T(GetTrainTitle() << " targetStationArrival: " << CTimeInterval::MinutesToTime(targetStationArrival));
DBG_LOG_T(GetTrainTitle() << " mainStationArrival: " << CTimeInterval::MinutesToTime(mainStationArrival));
DBG_LOG_T(GetTrainTitle() << " mainStationDeparture: " << CTimeInterval::MinutesToTime(mainStationDeparture));
*/
// Generate train with delay
(new CPublicTrain(*this, Time + CPublicTrain::GetBoardingTime(), targetStationArrival,
mainStationArrival, mainStationDeparture))->Activate(Time + Exponential(m_AverageDelay));
}
// Repeat in future
if(m_Frequency != FREQ_ONCE)
{
Activate(Time + m_Frequency);
}
}