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