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 /****************************************************************************/
long long int SUMOTime
Definition: SUMOTime.h:35
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:80
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
T MIN2(T a, T b)
Definition: StdDefs.h:74
#define SUMOTime_MAX
Definition: SUMOTime.h:36
bool myLoadAll
information whether all routes shall be loaded and whether they were loaded