|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // A loader for detector flows 00008 /****************************************************************************/ 00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors 00011 /****************************************************************************/ 00012 // 00013 // This program is free software; you can redistribute it and/or modify 00014 // it under the terms of the GNU General Public License as published by 00015 // the Free Software Foundation; either version 2 of the License, or 00016 // (at your option) any later version. 00017 // 00018 /****************************************************************************/ 00019 // =========================================================================== 00020 // included modules 00021 // =========================================================================== 00022 #ifdef _MSC_VER 00023 #include <windows_config.h> 00024 #else 00025 #include <config.h> 00026 #endif 00027 00028 #include <string> 00029 #include <fstream> 00030 #include <sstream> 00031 #include <utils/importio/LineReader.h> 00032 #include <utils/options/OptionsCont.h> 00033 #include <utils/common/IDSupplier.h> 00034 #include <utils/common/StringTokenizer.h> 00035 #include <utils/common/MsgHandler.h> 00036 #include <utils/common/FileHelpers.h> 00037 #include <utils/common/TplConvert.h> 00038 #include <utils/common/UtilExceptions.h> 00039 #include "RODFDetFlowLoader.h" 00040 00041 #ifdef CHECK_MEMORY_LEAKS 00042 #include <foreign/nvwa/debug_new.h> 00043 #endif // CHECK_MEMORY_LEAKS 00044 00045 00046 // =========================================================================== 00047 // method definitions 00048 // =========================================================================== 00049 RODFDetFlowLoader::RODFDetFlowLoader(const RODFDetectorCon& dets, 00050 RODFDetectorFlows& into, 00051 SUMOTime startTime, SUMOTime endTime, 00052 SUMOTime timeOffset, SUMOTime timeScale) throw() 00053 : myStorage(into), myTimeOffset(timeOffset), myTimeScale(timeScale), 00054 myStartTime(startTime), myEndTime(endTime), myDetectorContainer(dets), 00055 myHaveWarnedAboutOverridingBoundaries(false), myHaveWarnedAboutPartialDefs(false) {} 00056 00057 00058 00059 RODFDetFlowLoader::~RODFDetFlowLoader() throw() {} 00060 00061 00062 void 00063 RODFDetFlowLoader::read(const std::string& file) throw(IOError, ProcessError) { 00064 LineReader lr(file); 00065 // parse first line 00066 myLineHandler.reinit(lr.readLine(), ";", ";", true, true); 00067 // parse values 00068 while (lr.hasMore()) { 00069 std::string line = lr.readLine(); 00070 if (line.find(';')==std::string::npos) { 00071 continue; 00072 } 00073 myLineHandler.parseLine(line); 00074 try { 00075 std::string detName = myLineHandler.get("detector"); 00076 if (!myDetectorContainer.knows(detName)) { 00077 continue; 00078 } 00079 const SUMOTime time = TplConvert<char>::_2int((myLineHandler.get("time").c_str())) * myTimeScale - myTimeOffset; 00080 if (time<myStartTime||time>myEndTime) { 00081 if (!myHaveWarnedAboutOverridingBoundaries) { 00082 myHaveWarnedAboutOverridingBoundaries = true; 00083 WRITE_WARNING("At least one value lies beyond given time boundaries."); 00084 } 00085 continue; 00086 } 00087 FlowDef fd; 00088 fd.isLKW = 0; 00089 fd.qPKW = TplConvert<char>::_2SUMOReal(myLineHandler.get("qpkw").c_str()); 00090 fd.vPKW = TplConvert<char>::_2SUMOReal(myLineHandler.get("vpkw").c_str()); 00091 fd.qLKW = 0; 00092 if (myLineHandler.know("qLKW")) { 00093 fd.qLKW = TplConvert<char>::_2SUMOReal(myLineHandler.get("qlkw").c_str()); 00094 } 00095 fd.vLKW = 0; 00096 if (myLineHandler.know("vLKW")) { 00097 fd.vLKW = TplConvert<char>::_2SUMOReal(myLineHandler.get("vlkw").c_str()); 00098 } 00099 if (fd.qLKW<0) { 00100 fd.qLKW = 0; 00101 } 00102 if (fd.qPKW<0) { 00103 fd.qPKW = 0; 00104 } 00105 myStorage.addFlow(detName, time, fd); 00106 if (!myHaveWarnedAboutPartialDefs && !myLineHandler.hasFullDefinition()) { 00107 myHaveWarnedAboutPartialDefs = true; 00108 WRITE_WARNING("At least one line does not contain the correct number of columns."); 00109 } 00110 continue; 00111 } catch (UnknownElement&) {} catch (OutOfBoundsException&) {} catch (NumberFormatException&) {} 00112 throw ProcessError("The detector-flow-file '" + lr.getFileName() + "' is corrupt;\n" 00113 + " The following values must be supplied : 'Detector', 'Time', 'qPKW', 'vPKW'\n" 00114 + " The according column names must be given in the first line of the file."); 00115 } 00116 } 00117 00118 00119 /****************************************************************************/ 00120