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 53016 : SUMORouteLoaderControl::SUMORouteLoaderControl(SUMOTime inAdvanceStepNo):
34 53016 : myFirstLoadTime(SUMOTime_MAX),
35 53016 : myCurrentLoadTime(-SUMOTime_MAX),
36 53016 : myInAdvanceStepNo(inAdvanceStepNo),
37 : myRouteLoaders(),
38 53016 : myLoadAll(inAdvanceStepNo <= 0),
39 53016 : myAllLoaded(false) {
40 53016 : }
41 :
42 :
43 50073 : SUMORouteLoaderControl::~SUMORouteLoaderControl() {
44 50073 : for (std::vector<SUMORouteLoader*>::iterator i = myRouteLoaders.begin();
45 91768 : i != myRouteLoaders.end(); ++i) {
46 41695 : delete (*i);
47 : }
48 50073 : }
49 :
50 :
51 : void
52 44622 : SUMORouteLoaderControl::add(SUMORouteLoader* loader) {
53 44622 : myRouteLoaders.push_back(loader);
54 44622 : }
55 :
56 :
57 : void
58 93906237 : SUMORouteLoaderControl::loadNext(SUMOTime step) {
59 : // check whether new vehicles shall be loaded
60 : // return if not
61 93906237 : if (myAllLoaded) {
62 : return;
63 : }
64 2011501 : if (myCurrentLoadTime > step) {
65 : return;
66 : }
67 63912 : const SUMOTime loadMaxTime = myLoadAll ? SUMOTime_MAX : MAX2(myCurrentLoadTime + myInAdvanceStepNo, step);
68 63912 : myCurrentLoadTime = SUMOTime_MAX;
69 : // load all routes for the specified time period
70 : bool furtherAvailable = false;
71 115959 : for (SUMORouteLoader* loader : myRouteLoaders) {
72 57037 : myCurrentLoadTime = MIN2(myCurrentLoadTime, loader->loadUntil(loadMaxTime));
73 52047 : if (loader->getFirstDepart() != -1) {
74 49108 : myFirstLoadTime = MIN2(myFirstLoadTime, loader->getFirstDepart());
75 : }
76 52047 : furtherAvailable |= loader->moreAvailable();
77 : }
78 58922 : if (myFirstLoadTime == SUMOTime_MAX) {
79 10032 : myFirstLoadTime = 0;
80 : }
81 58922 : myAllLoaded = !furtherAvailable;
82 : }
83 :
84 :
85 : SUMORouteLoader*
86 42 : SUMORouteLoaderControl::getFirstLoader() const {
87 42 : if (myRouteLoaders.size() > 0) {
88 42 : return myRouteLoaders.front();
89 : }
90 : return nullptr;
91 : }
92 :
93 : /****************************************************************************/
|