SUMO - Simulation of Urban MObility
SUMORouteLoaderControl.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2002-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // Class responsible for loading of routes from some files
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <vector>
33 #include <utils/common/StdDefs.h>
34 #include "SUMORouteLoader.h"
35 #include "SUMORouteLoaderControl.h"
36 
37 
38 // ===========================================================================
39 // method definitions
40 // ===========================================================================
42  myFirstLoadTime(SUMOTime_MAX),
43  myCurrentLoadTime(-SUMOTime_MAX),
44  myInAdvanceStepNo(inAdvanceStepNo),
45  myRouteLoaders(),
46  myLoadAll(inAdvanceStepNo <= 0),
47  myAllLoaded(false) {
48 }
49 
50 
52  for (std::vector<SUMORouteLoader*>::iterator i = myRouteLoaders.begin();
53  i != myRouteLoaders.end(); ++i) {
54  delete(*i);
55  }
56 }
57 
58 
59 void
61  myRouteLoaders.push_back(loader);
62 }
63 
64 
65 void
67  // check whether new vehicles shall be loaded
68  // return if not
69  if (myAllLoaded) {
70  return;
71  }
72  if (myCurrentLoadTime > step) {
73  return;
74  }
75  const SUMOTime loadMaxTime = myLoadAll ? SUMOTime_MAX : MAX2(myCurrentLoadTime + myInAdvanceStepNo, step);
77  // load all routes for the specified time period
78  bool furtherAvailable = false;
79  for (std::vector<SUMORouteLoader*>::iterator i = myRouteLoaders.begin(); i != myRouteLoaders.end(); ++i) {
80  myCurrentLoadTime = MIN2(myCurrentLoadTime, (*i)->loadUntil(loadMaxTime));
81  if ((*i)->getFirstDepart() != -1) {
82  myFirstLoadTime = MIN2(myFirstLoadTime, (*i)->getFirstDepart());
83  }
84  furtherAvailable |= (*i)->moreAvailable();
85  }
86  myAllLoaded = !furtherAvailable;
87 }
88 
89 
90 /****************************************************************************/
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
void add(SUMORouteLoader *loader)
add another loader
T MAX2(T a, T b)
Definition: StdDefs.h:73
const SUMOTime myInAdvanceStepNo
the number of routes to read in forward
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
#define SUMOTime_MAX
Definition: TraCIDefs.h:52
T MIN2(T a, T b)
Definition: StdDefs.h:67
long long int SUMOTime
Definition: TraCIDefs.h:51