SUMO - Simulation of Urban MObility

MSRouteLoaderControl.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00008 // Class responsible for loading of routes from some files
00009 /****************************************************************************/
00010 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00011 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00012 /****************************************************************************/
00013 //
00014 //   This file is part of SUMO.
00015 //   SUMO is free software: you can redistribute it and/or modify
00016 //   it under the terms of the GNU General Public License as published by
00017 //   the Free Software Foundation, either version 3 of the License, or
00018 //   (at your option) any later version.
00019 //
00020 /****************************************************************************/
00021 
00022 
00023 // ===========================================================================
00024 // included modules
00025 // ===========================================================================
00026 #ifdef _MSC_VER
00027 #include <windows_config.h>
00028 #else
00029 #include <config.h>
00030 #endif
00031 
00032 #include <vector>
00033 #include "MSRouteLoader.h"
00034 #include "MSRouteLoaderControl.h"
00035 
00036 #ifdef CHECK_MEMORY_LEAKS
00037 #include <foreign/nvwa/debug_new.h>
00038 #endif // CHECK_MEMORY_LEAKS
00039 
00040 
00041 // ===========================================================================
00042 // method definitions
00043 // ===========================================================================
00044 MSRouteLoaderControl::MSRouteLoaderControl(MSNet&,
00045         int inAdvanceStepNo,
00046         LoaderVector loader)
00047     : myLastLoadTime(-inAdvanceStepNo),
00048       myInAdvanceStepNo(inAdvanceStepNo),
00049       myRouteLoaders(loader),
00050       myAllLoaded(false) {
00051     myLoadAll = myInAdvanceStepNo <= 0;
00052     myAllLoaded = false;
00053     myLastLoadTime = -1 * (int) myInAdvanceStepNo;
00054     // initialize all used loaders
00055     for (LoaderVector::iterator i = myRouteLoaders.begin();
00056             i != myRouteLoaders.end(); ++i) {
00057         (*i)->init();
00058     }
00059 }
00060 
00061 
00062 MSRouteLoaderControl::~MSRouteLoaderControl() {
00063     for (LoaderVector::iterator i = myRouteLoaders.begin();
00064             i != myRouteLoaders.end(); ++i) {
00065         delete(*i);
00066     }
00067 }
00068 
00069 
00070 void
00071 MSRouteLoaderControl::loadNext(SUMOTime step) {
00072     // check whether new vehicles shall be loaded
00073     //  return if not
00074     if ((myLoadAll && myAllLoaded) || (myLastLoadTime >= 0 && myLastLoadTime/*+myInAdvanceStepNo*/ >= step)) {
00075         return;
00076     }
00077     // load all routes for the specified time period
00078     SUMOTime run = step;
00079     bool furtherAvailable = true;
00080     for (;
00081             furtherAvailable &&
00082             (myLoadAll || run <= step + (SUMOTime) myInAdvanceStepNo);
00083             run++) {
00084         furtherAvailable = false;
00085         for (LoaderVector::iterator i = myRouteLoaders.begin();
00086                 i != myRouteLoaders.end(); ++i) {
00087             if ((*i)->moreAvailable()) {
00088                 (*i)->loadUntil(run);
00089             }
00090             furtherAvailable |= (*i)->moreAvailable();
00091         }
00092     }
00093     // no further loading when all was loaded
00094     if (myLoadAll || !furtherAvailable) {
00095         myAllLoaded = true;
00096     }
00097     // set the step information
00098     myLastLoadTime = run - 1;
00099 }
00100 
00101 
00102 
00103 /****************************************************************************/
00104 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines