Path: blob/main/src/utils/vehicle/SUMORouteLoaderControl.cpp
169678 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2002-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file SUMORouteLoaderControl.cpp14/// @author Daniel Krajzewicz15/// @author Michael Behrisch16/// @author Jakob Erdmann17/// @date Wed, 06 Nov 200218///19// Class responsible for loading of routes from some files20/****************************************************************************/21#include <config.h>2223#include <vector>24#include <utils/common/StdDefs.h>25#include "SUMORouteLoader.h"26#include "SUMORouteLoaderControl.h"272829// ===========================================================================30// method definitions31// ===========================================================================32SUMORouteLoaderControl::SUMORouteLoaderControl(SUMOTime inAdvanceStepNo):33myFirstLoadTime(SUMOTime_MAX),34myCurrentLoadTime(-SUMOTime_MAX),35myInAdvanceStepNo(inAdvanceStepNo),36myRouteLoaders(),37myLoadAll(inAdvanceStepNo <= 0),38myAllLoaded(false) {39}404142SUMORouteLoaderControl::~SUMORouteLoaderControl() {43for (std::vector<SUMORouteLoader*>::iterator i = myRouteLoaders.begin();44i != myRouteLoaders.end(); ++i) {45delete (*i);46}47}484950void51SUMORouteLoaderControl::add(SUMORouteLoader* loader) {52myRouteLoaders.push_back(loader);53}545556void57SUMORouteLoaderControl::loadNext(SUMOTime step) {58// check whether new vehicles shall be loaded59// return if not60if (myAllLoaded) {61return;62}63if (myCurrentLoadTime > step) {64return;65}66const SUMOTime loadMaxTime = myLoadAll ? SUMOTime_MAX : MAX2(myCurrentLoadTime + myInAdvanceStepNo, step);67myCurrentLoadTime = SUMOTime_MAX;68// load all routes for the specified time period69bool furtherAvailable = false;70for (SUMORouteLoader* loader : myRouteLoaders) {71myCurrentLoadTime = MIN2(myCurrentLoadTime, loader->loadUntil(loadMaxTime));72if (loader->getFirstDepart() != -1) {73myFirstLoadTime = MIN2(myFirstLoadTime, loader->getFirstDepart());74}75furtherAvailable |= loader->moreAvailable();76}77if (myFirstLoadTime == SUMOTime_MAX) {78myFirstLoadTime = 0;79}80myAllLoaded = !furtherAvailable;81}828384SUMORouteLoader*85SUMORouteLoaderControl::getFirstLoader() const {86if (myRouteLoaders.size() > 0) {87return myRouteLoaders.front();88}89return nullptr;90}9192/****************************************************************************/939495