Eclipse 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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // Class responsible for loading of routes from some files
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include <vector>
26 #include <utils/common/StdDefs.h>
27 #include "SUMORouteLoader.h"
28 #include "SUMORouteLoaderControl.h"
29 
30 
31 // ===========================================================================
32 // method definitions
33 // ===========================================================================
35  myFirstLoadTime(SUMOTime_MAX),
36  myCurrentLoadTime(-SUMOTime_MAX),
37  myInAdvanceStepNo(inAdvanceStepNo),
38  myRouteLoaders(),
39  myLoadAll(inAdvanceStepNo <= 0),
40  myAllLoaded(false) {
41 }
42 
43 
45  for (std::vector<SUMORouteLoader*>::iterator i = myRouteLoaders.begin();
46  i != myRouteLoaders.end(); ++i) {
47  delete (*i);
48  }
49 }
50 
51 
52 void
54  myRouteLoaders.push_back(loader);
55 }
56 
57 
58 void
60  // check whether new vehicles shall be loaded
61  // return if not
62  if (myAllLoaded) {
63  return;
64  }
65  if (myCurrentLoadTime > step) {
66  return;
67  }
68  const SUMOTime loadMaxTime = myLoadAll ? SUMOTime_MAX : MAX2(myCurrentLoadTime + myInAdvanceStepNo, step);
70  // load all routes for the specified time period
71  bool furtherAvailable = false;
72  for (std::vector<SUMORouteLoader*>::iterator i = myRouteLoaders.begin(); i != myRouteLoaders.end(); ++i) {
73  myCurrentLoadTime = MIN2(myCurrentLoadTime, (*i)->loadUntil(loadMaxTime));
74  if ((*i)->getFirstDepart() != -1) {
75  myFirstLoadTime = MIN2(myFirstLoadTime, (*i)->getFirstDepart());
76  }
77  furtherAvailable |= (*i)->moreAvailable();
78  }
79  myAllLoaded = !furtherAvailable;
80 }
81 
82 
83 /****************************************************************************/
MIN2
T MIN2(T a, T b)
Definition: StdDefs.h:73
SUMORouteLoader
Definition: SUMORouteLoader.h:42
SUMORouteLoaderControl::loadNext
void loadNext(SUMOTime step)
loads the next routes up to and including the given time step
Definition: SUMORouteLoaderControl.cpp:59
SUMORouteLoaderControl::myRouteLoaders
std::vector< SUMORouteLoader * > myRouteLoaders
the list of route loaders
Definition: SUMORouteLoaderControl.h:84
SUMORouteLoaderControl::myInAdvanceStepNo
const SUMOTime myInAdvanceStepNo
the number of routes to read in forward
Definition: SUMORouteLoaderControl.h:81
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
SUMORouteLoaderControl::add
void add(SUMORouteLoader *loader)
add another loader
Definition: SUMORouteLoaderControl.cpp:53
SUMORouteLoaderControl::myFirstLoadTime
SUMOTime myFirstLoadTime
the first time step for which vehicles were loaded
Definition: SUMORouteLoaderControl.h:75
MAX2
T MAX2(T a, T b)
Definition: StdDefs.h:79
SUMORouteLoaderControl::SUMORouteLoaderControl
SUMORouteLoaderControl(SUMOTime inAdvanceStepNo)
constructor
Definition: SUMORouteLoaderControl.cpp:34
SUMORouteLoaderControl::myCurrentLoadTime
SUMOTime myCurrentLoadTime
the time step up to which vehicles were loaded
Definition: SUMORouteLoaderControl.h:78
SUMORouteLoaderControl::~SUMORouteLoaderControl
~SUMORouteLoaderControl()
destructor
Definition: SUMORouteLoaderControl.cpp:44
SUMORouteLoaderControl::myAllLoaded
bool myAllLoaded
Definition: SUMORouteLoaderControl.h:87
SUMORouteLoaderControl.h
SUMORouteLoaderControl::myLoadAll
bool myLoadAll
information whether all routes shall be loaded and whether they were loaded
Definition: SUMORouteLoaderControl.h:87
config.h
StdDefs.h
SUMOTime_MAX
#define SUMOTime_MAX
Definition: SUMOTime.h:35
SUMORouteLoader.h