|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // Loader for the of turning percentages and source/sink definitions 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 00021 // =========================================================================== 00022 // included modules 00023 // =========================================================================== 00024 #ifdef _MSC_VER 00025 #include <windows_config.h> 00026 #else 00027 #include <config.h> 00028 #endif 00029 00030 #include <set> 00031 #include <string> 00032 #include <utils/common/FileHelpers.h> 00033 #include <utils/xml/XMLSubSys.h> 00034 #include <utils/common/UtilExceptions.h> 00035 #include <utils/common/MsgHandler.h> 00036 #include <utils/common/UtilExceptions.h> 00037 #include <utils/common/TplConvert.h> 00038 #include <utils/common/ToString.h> 00039 #include <utils/xml/SUMOXMLDefinitions.h> 00040 #include <router/RONet.h> 00041 #include "ROJTREdge.h" 00042 #include "ROJTRTurnDefLoader.h" 00043 00044 #ifdef CHECK_MEMORY_LEAKS 00045 #include <foreign/nvwa/debug_new.h> 00046 #endif // CHECK_MEMORY_LEAKS 00047 00048 00049 // =========================================================================== 00050 // method definitions 00051 // =========================================================================== 00052 ROJTRTurnDefLoader::ROJTRTurnDefLoader(RONet& net) throw() 00053 : SUMOSAXHandler("turn-ratio-file"), myNet(net), 00054 myIntervalBegin(0), myIntervalEnd(SUMOTime_MAX), myEdge(0), 00055 myHaveWarnedAboutDeprecatedSources(false), 00056 myHaveWarnedAboutDeprecatedSinks(false), 00057 myHaveWarnedAboutDeprecatedFromEdge(false), 00058 myHaveWarnedAboutDeprecatedToEdge(false) {} 00059 00060 00061 ROJTRTurnDefLoader::~ROJTRTurnDefLoader() throw() {} 00062 00063 00064 void 00065 ROJTRTurnDefLoader::myStartElement(int element, 00066 const SUMOSAXAttributes& attrs) throw(ProcessError) { 00067 bool ok = true; 00068 switch (element) { 00069 case SUMO_TAG_INTERVAL: 00070 myIntervalBegin = attrs.getSUMOTimeReporting(SUMO_ATTR_BEGIN, 0, ok); 00071 myIntervalEnd = attrs.getSUMOTimeReporting(SUMO_ATTR_END, 0, ok); 00072 break; 00073 case SUMO_TAG_FROMEDGE__DEPRECATED: 00074 if (!myHaveWarnedAboutDeprecatedFromEdge) { 00075 myHaveWarnedAboutDeprecatedFromEdge = true; 00076 WRITE_WARNING("'" + toString(SUMO_TAG_FROMEDGE__DEPRECATED) + "' is deprecated; please use '" + toString(SUMO_TAG_FROMEDGE) + "'."); 00077 } 00078 case SUMO_TAG_FROMEDGE: 00079 beginFromEdge(attrs); 00080 break; 00081 case SUMO_TAG_TOEDGE__DEPRECATED: 00082 if (!myHaveWarnedAboutDeprecatedToEdge) { 00083 myHaveWarnedAboutDeprecatedToEdge = true; 00084 WRITE_WARNING("'" + toString(SUMO_TAG_TOEDGE__DEPRECATED) + "' is deprecated; please use '" + toString(SUMO_TAG_TOEDGE) + "'."); 00085 } 00086 case SUMO_TAG_TOEDGE: 00087 addToEdge(attrs); 00088 break; 00089 case SUMO_TAG_SINK: 00090 if (attrs.hasAttribute(SUMO_ATTR_EDGES)) { 00091 std::string edges = attrs.getStringReporting(SUMO_ATTR_EDGES, 0, ok); 00092 StringTokenizer st(edges, StringTokenizer::WHITECHARS); 00093 while (st.hasNext()) { 00094 std::string id = st.next(); 00095 ROEdge* edge = myNet.getEdge(id); 00096 if (edge==0) { 00097 throw ProcessError("The edge '" + id + "' declared as a sink is not known."); 00098 } 00099 edge->setType(ROEdge::ET_SINK); 00100 } 00101 } 00102 break; 00103 case SUMO_TAG_SOURCE: 00104 if (attrs.hasAttribute(SUMO_ATTR_EDGES)) { 00105 std::string edges = attrs.getStringReporting(SUMO_ATTR_EDGES, 0, ok); 00106 StringTokenizer st(edges, StringTokenizer::WHITECHARS); 00107 while (st.hasNext()) { 00108 std::string id = st.next(); 00109 ROEdge* edge = myNet.getEdge(id); 00110 if (edge==0) { 00111 throw ProcessError("The edge '" + id + "' declared as a source is not known."); 00112 } 00113 edge->setType(ROEdge::ET_SOURCE); 00114 } 00115 } 00116 break; 00117 default: 00118 break; 00119 } 00120 } 00121 00122 00123 void 00124 ROJTRTurnDefLoader::myCharacters(int element, 00125 const std::string& chars) throw(ProcessError) { 00126 switch (element) { 00127 case SUMO_TAG_SINK: { 00128 ROEdge* edge = myNet.getEdge(chars); 00129 if (edge==0) { 00130 throw ProcessError("The edge '" + chars + "' declared as a sink is not known."); 00131 } 00132 if (!myHaveWarnedAboutDeprecatedSinks) { 00133 myHaveWarnedAboutDeprecatedSinks = true; 00134 WRITE_WARNING("Using characters for sinks is deprecated; use attribute 'edges' instead."); 00135 } 00136 edge->setType(ROEdge::ET_SINK); 00137 } 00138 break; 00139 case SUMO_TAG_SOURCE: { 00140 ROEdge* edge = myNet.getEdge(chars); 00141 if (edge==0) { 00142 throw ProcessError("The edge '" + chars + "' declared as a source is not known."); 00143 } 00144 if (!myHaveWarnedAboutDeprecatedSources) { 00145 myHaveWarnedAboutDeprecatedSources = true; 00146 WRITE_WARNING("Using characters for sources is deprecated; use attribute 'edges' instead."); 00147 } 00148 edge->setType(ROEdge::ET_SOURCE); 00149 } 00150 break; 00151 default: 00152 break; 00153 } 00154 } 00155 00156 00157 void 00158 ROJTRTurnDefLoader::beginFromEdge(const SUMOSAXAttributes& attrs) throw() { 00159 myEdge = 0; 00160 bool ok = true; 00161 // get the id, report an error if not given or empty... 00162 std::string id = attrs.getStringReporting(SUMO_ATTR_ID, 0, ok); 00163 if (!ok) { 00164 return; 00165 } 00166 // 00167 myEdge = static_cast<ROJTREdge*>(myNet.getEdge(id)); 00168 if (myEdge==0) { 00169 WRITE_ERROR("The edge '" + id + "' is not known within the network (within a 'from-edge' tag)."); 00170 return; 00171 } 00172 } 00173 00174 00175 void 00176 ROJTRTurnDefLoader::addToEdge(const SUMOSAXAttributes& attrs) throw() { 00177 if (myEdge==0) { 00178 return; 00179 } 00180 bool ok = true; 00181 // get the id, report an error if not given or empty... 00182 std::string id = attrs.getStringReporting(SUMO_ATTR_ID, 0, ok); 00183 if (!ok) { 00184 return; 00185 } 00186 // 00187 ROJTREdge* edge = static_cast<ROJTREdge*>(myNet.getEdge(id)); 00188 if (edge==0) { 00189 WRITE_ERROR("The edge '" + id + "' is not known within the network (within a 'to-edge' tag)."); 00190 return; 00191 } 00192 SUMOReal probability = attrs.getSUMORealReporting(SUMO_ATTR_PROB, id.c_str(), ok); 00193 if (ok) { 00194 if (probability<0) { 00195 WRITE_ERROR("'probability' must be positive (in definition of to-edge '" + id + "')."); 00196 } else { 00197 myEdge->addFollowerProbability(edge, myIntervalBegin, myIntervalEnd, probability); 00198 } 00199 } 00200 } 00201 00202 00203 00204 /****************************************************************************/ 00205