SUMO - Simulation of Urban MObility
SUMORouteLoaderControl.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Class responsible for loading of routes from some files
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2002-2015 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <vector>
34 #include <utils/common/StdDefs.h>
35 #include "SUMORouteLoader.h"
36 #include "SUMORouteLoaderControl.h"
37 
38 #ifdef CHECK_MEMORY_LEAKS
39 #include <foreign/nvwa/debug_new.h>
40 #endif // CHECK_MEMORY_LEAKS
41 
42 
43 // ===========================================================================
44 // method definitions
45 // ===========================================================================
47  myFirstLoadTime(SUMOTime_MAX),
48  myCurrentLoadTime(-SUMOTime_MAX),
49  myInAdvanceStepNo(inAdvanceStepNo),
50  myRouteLoaders(),
51  myLoadAll(inAdvanceStepNo <= 0),
52  myAllLoaded(false) {
53 }
54 
55 
57  for (std::vector<SUMORouteLoader*>::iterator i = myRouteLoaders.begin();
58  i != myRouteLoaders.end(); ++i) {
59  delete(*i);
60  }
61 }
62 
63 
64 void
66  myRouteLoaders.push_back(loader);
67 }
68 
69 
70 void
72  // check whether new vehicles shall be loaded
73  // return if not
74  if (myAllLoaded) {
75  return;
76  }
77  if (myCurrentLoadTime > step) {
78  return;
79  }
80  const SUMOTime loadMaxTime = myLoadAll ? SUMOTime_MAX : MAX2(myCurrentLoadTime + myInAdvanceStepNo, step);
82  // load all routes for the specified time period
83  bool furtherAvailable = false;
84  for (std::vector<SUMORouteLoader*>::iterator i = myRouteLoaders.begin(); i != myRouteLoaders.end(); ++i) {
85  myCurrentLoadTime = MIN2(myCurrentLoadTime, (*i)->loadUntil(loadMaxTime));
86  if ((*i)->getFirstDepart() != -1) {
87  myFirstLoadTime = MIN2(myFirstLoadTime, (*i)->getFirstDepart());
88  }
89  furtherAvailable |= (*i)->moreAvailable();
90  }
91  myAllLoaded = !furtherAvailable;
92 }
93 
94 
95 /****************************************************************************/
void loadNext(SUMOTime step)
loads the next routes up to and including the given time step
std::vector< SUMORouteLoader * > myRouteLoaders
the list of route loaders
SUMOTime myInAdvanceStepNo
the number of routes to read in forward
void add(SUMORouteLoader *loader)
add another loader
T MAX2(T a, T b)
Definition: StdDefs.h:74
SUMOTime myFirstLoadTime
the first time step for which vehicles were loaded
SUMORouteLoaderControl(SUMOTime inAdvanceStepNo)
constructor
SUMOTime myCurrentLoadTime
the time step up to which vehicles were loaded
T MIN2(T a, T b)
Definition: StdDefs.h:68
#define SUMOTime_MAX
Definition: SUMOTime.h:44
int SUMOTime
Definition: SUMOTime.h:43