Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2002-2024 German Aerospace Center (DLR) and others.
4 : // This program and the accompanying materials are made available under the
5 : // terms of the Eclipse Public License 2.0 which is available at
6 : // https://www.eclipse.org/legal/epl-2.0/
7 : // This Source Code may also be made available under the following Secondary
8 : // Licenses when the conditions for such availability set forth in the Eclipse
9 : // Public License 2.0 are satisfied: GNU General Public License, version 2
10 : // or later which is available at
11 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 : /****************************************************************************/
14 : /// @file SUMORouteLoaderControl.cpp
15 : /// @author Daniel Krajzewicz
16 : /// @author Michael Behrisch
17 : /// @author Jakob Erdmann
18 : /// @date Wed, 06 Nov 2002
19 : ///
20 : // Class responsible for loading of routes from some files
21 : /****************************************************************************/
22 : #include <config.h>
23 :
24 : #include <vector>
25 : #include <utils/common/StdDefs.h>
26 : #include "SUMORouteLoader.h"
27 : #include "SUMORouteLoaderControl.h"
28 :
29 :
30 : // ===========================================================================
31 : // method definitions
32 : // ===========================================================================
33 52488 : SUMORouteLoaderControl::SUMORouteLoaderControl(SUMOTime inAdvanceStepNo):
34 52488 : myFirstLoadTime(SUMOTime_MAX),
35 52488 : myCurrentLoadTime(-SUMOTime_MAX),
36 52488 : myInAdvanceStepNo(inAdvanceStepNo),
37 : myRouteLoaders(),
38 52488 : myLoadAll(inAdvanceStepNo <= 0),
39 52488 : myAllLoaded(false) {
40 52488 : }
41 :
42 :
43 49713 : SUMORouteLoaderControl::~SUMORouteLoaderControl() {
44 49713 : for (std::vector<SUMORouteLoader*>::iterator i = myRouteLoaders.begin();
45 91057 : i != myRouteLoaders.end(); ++i) {
46 41344 : delete (*i);
47 : }
48 49713 : }
49 :
50 :
51 : void
52 44104 : SUMORouteLoaderControl::add(SUMORouteLoader* loader) {
53 44104 : myRouteLoaders.push_back(loader);
54 44104 : }
55 :
56 :
57 : void
58 90320397 : SUMORouteLoaderControl::loadNext(SUMOTime step) {
59 : // check whether new vehicles shall be loaded
60 : // return if not
61 90320397 : if (myAllLoaded) {
62 : return;
63 : }
64 2008452 : if (myCurrentLoadTime > step) {
65 : return;
66 : }
67 63330 : const SUMOTime loadMaxTime = myLoadAll ? SUMOTime_MAX : MAX2(myCurrentLoadTime + myInAdvanceStepNo, step);
68 63330 : myCurrentLoadTime = SUMOTime_MAX;
69 : // load all routes for the specified time period
70 : bool furtherAvailable = false;
71 114965 : for (SUMORouteLoader* loader : myRouteLoaders) {
72 56462 : myCurrentLoadTime = MIN2(myCurrentLoadTime, loader->loadUntil(loadMaxTime));
73 51635 : if (loader->getFirstDepart() != -1) {
74 48716 : myFirstLoadTime = MIN2(myFirstLoadTime, loader->getFirstDepart());
75 : }
76 51635 : furtherAvailable |= loader->moreAvailable();
77 : }
78 58503 : if (myFirstLoadTime == SUMOTime_MAX) {
79 10005 : myFirstLoadTime = 0;
80 : }
81 58503 : myAllLoaded = !furtherAvailable;
82 : }
83 :
84 :
85 : /****************************************************************************/
|