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