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