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-2016 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 
39 // ===========================================================================
40 // method definitions
41 // ===========================================================================
43  myFirstLoadTime(SUMOTime_MAX),
44  myCurrentLoadTime(-SUMOTime_MAX),
45  myInAdvanceStepNo(inAdvanceStepNo),
46  myRouteLoaders(),
47  myLoadAll(inAdvanceStepNo <= 0),
48  myAllLoaded(false) {
49 }
50 
51 
53  for (std::vector<SUMORouteLoader*>::iterator i = myRouteLoaders.begin();
54  i != myRouteLoaders.end(); ++i) {
55  delete(*i);
56  }
57 }
58 
59 
60 void
62  myRouteLoaders.push_back(loader);
63 }
64 
65 
66 void
68  // check whether new vehicles shall be loaded
69  // return if not
70  if (myAllLoaded) {
71  return;
72  }
73  if (myCurrentLoadTime > step) {
74  return;
75  }
76  const SUMOTime loadMaxTime = myLoadAll ? SUMOTime_MAX : MAX2(myCurrentLoadTime + myInAdvanceStepNo, step);
78  // load all routes for the specified time period
79  bool furtherAvailable = false;
80  for (std::vector<SUMORouteLoader*>::iterator i = myRouteLoaders.begin(); i != myRouteLoaders.end(); ++i) {
81  myCurrentLoadTime = MIN2(myCurrentLoadTime, (*i)->loadUntil(loadMaxTime));
82  if ((*i)->getFirstDepart() != -1) {
83  myFirstLoadTime = MIN2(myFirstLoadTime, (*i)->getFirstDepart());
84  }
85  furtherAvailable |= (*i)->moreAvailable();
86  }
87  myAllLoaded = !furtherAvailable;
88 }
89 
90 
91 /****************************************************************************/
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:70
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:53
T MIN2(T a, T b)
Definition: StdDefs.h:64
long long int SUMOTime
Definition: TraCIDefs.h:52