LCOV - code coverage report
Current view: top level - src/router - RORouteHandler.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 88.7 % 797 707
Test Date: 2026-10-12 15:53:19 Functions: 100.0 % 37 37

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-2026 German Aerospace Center (DLR) and others.
       4              : // This program and the accompanying materials are made available under the
       5              : // terms of the Eclipse Public License 2.0 which is available at
       6              : // https://www.eclipse.org/legal/epl-2.0/
       7              : // This Source Code may also be made available under the following Secondary
       8              : // Licenses when the conditions for such availability set forth in the Eclipse
       9              : // Public License 2.0 are satisfied: GNU General Public License, version 2
      10              : // or later which is available at
      11              : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
      12              : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
      13              : /****************************************************************************/
      14              : /// @file    RORouteHandler.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Jakob Erdmann
      17              : /// @author  Sascha Krieg
      18              : /// @author  Michael Behrisch
      19              : /// @date    Mon, 9 Jul 2001
      20              : ///
      21              : // Parser and container for routes during their loading
      22              : /****************************************************************************/
      23              : #include <config.h>
      24              : 
      25              : #include <string>
      26              : #include <map>
      27              : #include <vector>
      28              : #include <iostream>
      29              : #include <utils/iodevices/OutputDevice.h>
      30              : #include <utils/xml/SUMOSAXHandler.h>
      31              : #include <utils/xml/SUMOXMLDefinitions.h>
      32              : #include <utils/geom/GeoConvHelper.h>
      33              : #include <utils/common/FileHelpers.h>
      34              : #include <utils/common/MsgHandler.h>
      35              : #include <utils/common/StringTokenizer.h>
      36              : #include <utils/common/UtilExceptions.h>
      37              : #include <utils/options/OptionsCont.h>
      38              : #include <utils/vehicle/SUMOVehicleParserHelper.h>
      39              : #include <utils/xml/SUMOSAXReader.h>
      40              : #include <utils/xml/XMLSubSys.h>
      41              : #include <utils/iodevices/OutputDevice_String.h>
      42              : #include "RONet.h"
      43              : #include "ROEdge.h"
      44              : #include "ROLane.h"
      45              : #include "RORouteDef.h"
      46              : #include "RORouteHandler.h"
      47              : 
      48              : // ===========================================================================
      49              : // method definitions
      50              : // ===========================================================================
      51         4727 : RORouteHandler::RORouteHandler(RONet& net, const std::string& file,
      52              :                                const bool tryRepair,
      53              :                                const bool emptyDestinationsAllowed,
      54              :                                const bool ignoreErrors,
      55         4727 :                                const bool checkSchema) :
      56              :     SUMORouteHandler(file, checkSchema ? "routes" : "", true),
      57         9454 :     MapMatcher(OptionsCont::getOptions().getBool("mapmatch.junctions"),
      58         9454 :                OptionsCont::getOptions().getBool("mapmatch.taz"),
      59         4727 :                OptionsCont::getOptions().getFloat("mapmatch.distance"),
      60         4727 :                ignoreErrors ? MsgHandler::getWarningInstance() : MsgHandler::getErrorInstance()),
      61         4727 :     myNet(net),
      62         4727 :     myActiveRouteRepeat(0),
      63         4727 :     myActiveRoutePeriod(0),
      64         4727 :     myActivePlan(nullptr),
      65         4727 :     myActiveContainerPlan(nullptr),
      66         4727 :     myActiveContainerPlanSize(0),
      67         4727 :     myTryRepair(tryRepair),
      68         4727 :     myEmptyDestinationsAllowed(emptyDestinationsAllowed),
      69         4727 :     myErrorOutput(ignoreErrors ? MsgHandler::getWarningInstance() : MsgHandler::getErrorInstance()),
      70         4727 :     myBegin(string2time(OptionsCont::getOptions().getString("begin"))),
      71         4727 :     myKeepVTypeDist(OptionsCont::getOptions().getBool("keep-vtype-distributions")),
      72         9454 :     myUnsortedInput(OptionsCont::getOptions().exists("unsorted-input") && OptionsCont::getOptions().getBool("unsorted-input")),
      73         9339 :     myWriteFlows(OptionsCont::getOptions().exists("keep-flows") && OptionsCont::getOptions().getBool("keep-flows")),
      74         4727 :     myCurrentVTypeDistribution(nullptr),
      75         4727 :     myCurrentAlternatives(nullptr),
      76         4727 :     myUseTaz(OptionsCont::getOptions().getBool("with-taz")),
      77         4727 :     myWriteJunctions(OptionsCont::getOptions().exists("write-trips")
      78         9339 :                      && OptionsCont::getOptions().getBool("write-trips")
      79        29401 :                      && OptionsCont::getOptions().getBool("write-trips.junctions")) {
      80         4727 :     myActiveRoute.reserve(100);
      81         4727 : }
      82              : 
      83              : 
      84         9454 : RORouteHandler::~RORouteHandler() {
      85         4727 :     delete myCurrentAlternatives;
      86        14181 : }
      87              : 
      88              : 
      89              : void
      90         4113 : RORouteHandler::deleteActivePlanAndVehicleParameter() {
      91         4113 :     if (myActivePlan != nullptr) {
      92         3884 :         for (ROPerson::PlanItem* const it : *myActivePlan) {
      93          206 :             delete it;
      94              :         }
      95         3678 :         delete myActivePlan;
      96         3678 :         myActivePlan = nullptr;
      97              :     }
      98         4113 :     delete myActiveContainerPlan;
      99         4113 :     myActiveContainerPlan = nullptr;
     100         4113 :     delete myVehicleParameter;
     101         4113 :     myVehicleParameter = nullptr;
     102         4113 : }
     103              : 
     104              : 
     105              : void
     106       194564 : RORouteHandler::parseFromViaTo(SumoXMLTag tag, const SUMOSAXAttributes& attrs, bool& ok) {
     107       194564 :     const std::string element = toString(tag);
     108              :     myActiveRoute.clear();
     109       194564 :     bool useTaz = myUseTaz;
     110       194564 :     if (myUseTaz && !myVehicleParameter->wasSet(VEHPARS_FROM_TAZ_SET) && !myVehicleParameter->wasSet(VEHPARS_TO_TAZ_SET)) {
     111            0 :         WRITE_WARNINGF(TL("Taz usage was requested but no taz present in % '%'!"), element, myVehicleParameter->id);
     112              :         useTaz = false;
     113              :     }
     114              :     SUMOVehicleClass vClass = SVC_PASSENGER;
     115       194564 :     if (!myNet.getVTypeDistribution(myVehicleParameter->vtypeid)) {
     116       194494 :         SUMOVTypeParameter* type = myNet.getVehicleTypeSecure(myVehicleParameter->vtypeid);
     117       194494 :         if (type != nullptr) {
     118       194402 :             vClass = type->vehicleClass;
     119              :         }
     120              :     }
     121              :     // from-attributes
     122       194564 :     const std::string rid = "for " + element + " '" + myVehicleParameter->id + "'";
     123       210656 :     if ((useTaz || (!attrs.hasAttribute(SUMO_ATTR_FROM) && !attrs.hasAttribute(SUMO_ATTR_FROMXY) && !attrs.hasAttribute(SUMO_ATTR_FROMLONLAT))) &&
     124        32140 :             (attrs.hasAttribute(SUMO_ATTR_FROM_TAZ) || attrs.hasAttribute(SUMO_ATTR_FROM_JUNCTION))) {
     125        14989 :         const bool useJunction = attrs.hasAttribute(SUMO_ATTR_FROM_JUNCTION);
     126        15033 :         const std::string tazType = useJunction ? "junction" : "taz";
     127        15033 :         const std::string tazID = attrs.get<std::string>(useJunction ? SUMO_ATTR_FROM_JUNCTION : SUMO_ATTR_FROM_TAZ, myVehicleParameter->id.c_str(), ok, true);
     128        29978 :         const ROEdge* fromTaz = myNet.getEdge(tazID + "-source");
     129        14989 :         if (fromTaz == nullptr) {
     130           20 :             myErrorOutput->inform("Source " + tazType + " '" + tazID + "' not known for " + element + " '" + myVehicleParameter->id + "'!"
     131           10 :                                   + (useJunction ? JUNCTION_TAZ_MISSING_HELP : ""));
     132           10 :             ok = false;
     133        14979 :         } else if (fromTaz->getNumSuccessors() == 0 && tag != SUMO_TAG_PERSON) {
     134            0 :             myErrorOutput->inform("Source " + tazType + " '" + tazID + "' has no outgoing edges for " + element + " '" + myVehicleParameter->id + "'!");
     135            0 :             ok = false;
     136              :         } else {
     137        14979 :             myActiveRoute.push_back(fromTaz);
     138        14979 :             if (useJunction && tag != SUMO_TAG_PERSON && !myWriteJunctions) {
     139         7240 :                 myVehicleParameter->fromTaz = tazID;
     140         7240 :                 myVehicleParameter->parametersSet |= VEHPARS_FROM_TAZ_SET;
     141              :             }
     142              :         }
     143       179575 :     } else if (attrs.hasAttribute(SUMO_ATTR_FROMXY)) {
     144          125 :         parseGeoEdges(attrs.get<PositionVector>(SUMO_ATTR_FROMXY, myVehicleParameter->id.c_str(), ok), false, vClass, myActiveRoute, rid, true, ok);
     145          125 :         if (myMapMatchTAZ && ok) {
     146           25 :             myVehicleParameter->fromTaz = myActiveRoute.back()->getID();
     147           25 :             myVehicleParameter->parametersSet |= VEHPARS_FROM_TAZ_SET;
     148              :         }
     149       179450 :     } else if (attrs.hasAttribute(SUMO_ATTR_FROMLONLAT)) {
     150           30 :         parseGeoEdges(attrs.get<PositionVector>(SUMO_ATTR_FROMLONLAT, myVehicleParameter->id.c_str(), ok), true, vClass, myActiveRoute, rid, true, ok);
     151           30 :         if (myMapMatchTAZ && ok) {
     152            0 :             myVehicleParameter->fromTaz = myActiveRoute.back()->getID();
     153            0 :             myVehicleParameter->parametersSet |= VEHPARS_FROM_TAZ_SET;
     154              :         }
     155              :     } else {
     156       358840 :         parseEdges(attrs.getOpt<std::string>(SUMO_ATTR_FROM, myVehicleParameter->id.c_str(), ok), myActiveRoute, rid, ok);
     157              :     }
     158       194564 :     if (!attrs.hasAttribute(SUMO_ATTR_VIA) && !attrs.hasAttribute(SUMO_ATTR_VIALONLAT) && !attrs.hasAttribute(SUMO_ATTR_VIAXY)) {
     159       179901 :         myInsertStopEdgesAt = (int)myActiveRoute.size();
     160              :     }
     161              : 
     162              :     // via-attributes
     163              :     ConstROEdgeVector viaEdges;
     164       194564 :     if (attrs.hasAttribute(SUMO_ATTR_VIAXY)) {
     165           40 :         parseGeoEdges(attrs.get<PositionVector>(SUMO_ATTR_VIAXY, myVehicleParameter->id.c_str(), ok), false, vClass, viaEdges, rid, false, ok);
     166       194524 :     } else if (attrs.hasAttribute(SUMO_ATTR_VIALONLAT)) {
     167            5 :         parseGeoEdges(attrs.get<PositionVector>(SUMO_ATTR_VIALONLAT, myVehicleParameter->id.c_str(), ok), true, vClass, viaEdges, rid, false, ok);
     168       194519 :     } else if (attrs.hasAttribute(SUMO_ATTR_VIAJUNCTIONS)) {
     169           30 :         for (std::string junctionID : attrs.get<std::vector<std::string> >(SUMO_ATTR_VIAJUNCTIONS, myVehicleParameter->id.c_str(), ok)) {
     170           40 :             const ROEdge* viaSink = myNet.getEdge(junctionID + "-sink");
     171           20 :             if (viaSink == nullptr) {
     172            0 :                 myErrorOutput->inform("Junction-taz '" + junctionID + "' not found." + JUNCTION_TAZ_MISSING_HELP);
     173            0 :                 ok = false;
     174              :             } else {
     175           20 :                 viaEdges.push_back(viaSink);
     176              :             }
     177           10 :         }
     178              :     } else {
     179       389018 :         parseEdges(attrs.getOpt<std::string>(SUMO_ATTR_VIA, myVehicleParameter->id.c_str(), ok, "", true), viaEdges, rid, ok);
     180              :     }
     181       228195 :     for (const ROEdge* e : viaEdges) {
     182        33631 :         myActiveRoute.push_back(e);
     183        33631 :         myVehicleParameter->via.push_back(e->getID());
     184              :     }
     185              : 
     186              :     // to-attributes
     187       211535 :     if ((useTaz || (!attrs.hasAttribute(SUMO_ATTR_TO) && !attrs.hasAttribute(SUMO_ATTR_TOXY) && !attrs.hasAttribute(SUMO_ATTR_TOLONLAT))) &&
     188        33898 :             (attrs.hasAttribute(SUMO_ATTR_TO_TAZ) || attrs.hasAttribute(SUMO_ATTR_TO_JUNCTION))) {
     189        14974 :         const bool useJunction = attrs.hasAttribute(SUMO_ATTR_TO_JUNCTION);
     190        15018 :         const std::string tazType = useJunction ? "junction" : "taz";
     191        15018 :         const std::string tazID = attrs.get<std::string>(useJunction ? SUMO_ATTR_TO_JUNCTION : SUMO_ATTR_TO_TAZ, myVehicleParameter->id.c_str(), ok, true);
     192        29948 :         const ROEdge* toTaz = myNet.getEdge(tazID + "-sink");
     193        14974 :         if (toTaz == nullptr) {
     194            0 :             myErrorOutput->inform("Sink " + tazType + " '" + tazID + "' not known for " + element + " '" + myVehicleParameter->id + "'!"
     195            0 :                                   + (useJunction ? JUNCTION_TAZ_MISSING_HELP : ""));
     196            0 :             ok = false;
     197        14974 :         } else if (toTaz->getNumPredecessors() == 0 && tag != SUMO_TAG_PERSON) {
     198            0 :             myErrorOutput->inform("Sink " + tazType + " '" + tazID + "' has no incoming edges for " + element + " '" + myVehicleParameter->id + "'!");
     199            0 :             ok = false;
     200              :         } else {
     201        14974 :             myActiveRoute.push_back(toTaz);
     202        14974 :             if (useJunction && tag != SUMO_TAG_PERSON && !myWriteJunctions) {
     203         7240 :                 myVehicleParameter->toTaz = tazID;
     204         7240 :                 myVehicleParameter->parametersSet |= VEHPARS_TO_TAZ_SET;
     205              :             }
     206              :         }
     207       179590 :     } else if (attrs.hasAttribute(SUMO_ATTR_TOXY)) {
     208          125 :         parseGeoEdges(attrs.get<PositionVector>(SUMO_ATTR_TOXY, myVehicleParameter->id.c_str(), ok, true), false, vClass, myActiveRoute, rid, false, ok);
     209          125 :         if (myMapMatchTAZ && ok) {
     210           25 :             myVehicleParameter->toTaz = myActiveRoute.back()->getID();
     211           25 :             myVehicleParameter->parametersSet |= VEHPARS_TO_TAZ_SET;
     212              :         }
     213       179465 :     } else if (attrs.hasAttribute(SUMO_ATTR_TOLONLAT)) {
     214           30 :         parseGeoEdges(attrs.get<PositionVector>(SUMO_ATTR_TOLONLAT, myVehicleParameter->id.c_str(), ok, true), true, vClass, myActiveRoute, rid, false, ok);
     215           30 :         if (myMapMatchTAZ && ok) {
     216            0 :             myVehicleParameter->toTaz = myActiveRoute.back()->getID();
     217            0 :             myVehicleParameter->parametersSet |= VEHPARS_TO_TAZ_SET;
     218              :         }
     219              :     } else {
     220       358870 :         parseEdges(attrs.getOpt<std::string>(SUMO_ATTR_TO, myVehicleParameter->id.c_str(), ok, "", true), myActiveRoute, rid, ok);
     221              :     }
     222       194564 :     myActiveRouteID = "!" + myVehicleParameter->id;
     223       194564 :     if (myVehicleParameter->routeid == "") {
     224              :         myVehicleParameter->routeid = myActiveRouteID;
     225              :     }
     226       389128 : }
     227              : 
     228              : 
     229              : void
     230       638736 : RORouteHandler::myStartElement(int element,
     231              :                                const SUMOSAXAttributes& attrs) {
     232              :     try {
     233       638736 :         if (myActivePlan != nullptr && myActivePlan->empty() && myVehicleParameter->departProcedure == DepartDefinition::TRIGGERED && element != SUMO_TAG_RIDE && element != SUMO_TAG_PARAM) {
     234           15 :             throw ProcessError(TLF("Triggered departure for person '%' requires starting with a ride.", myVehicleParameter->id));
     235       638731 :         } else if (myActiveContainerPlan != nullptr && myActiveContainerPlanSize == 0 && myVehicleParameter->departProcedure == DepartDefinition::TRIGGERED && element != SUMO_TAG_TRANSPORT && element != SUMO_TAG_PARAM) {
     236           15 :             throw ProcessError(TLF("Triggered departure for container '%' requires starting with a transport.", myVehicleParameter->id));
     237              :         }
     238       638726 :         SUMORouteHandler::myStartElement(element, attrs);
     239       638301 :         bool ok = true;
     240       638301 :         switch (element) {
     241         3678 :             case SUMO_TAG_PERSON:
     242              :             case SUMO_TAG_PERSONFLOW: {
     243         3678 :                 myActivePlan = new std::vector<ROPerson::PlanItem*>();
     244         3678 :                 break;
     245              :             }
     246              :             case SUMO_TAG_RIDE:
     247              :                 break; // handled in addRide, called from SUMORouteHandler::myStartElement
     248           80 :             case SUMO_TAG_CONTAINER:
     249              :             case SUMO_TAG_CONTAINERFLOW:
     250           80 :                 myActiveContainerPlan = new OutputDevice_String(1);
     251           80 :                 myActiveContainerPlanSize = 0;
     252           80 :                 myActiveContainerPlan->openTag((SumoXMLTag)element);
     253           80 :                 (*myActiveContainerPlan) << attrs;
     254              :                 break;
     255           75 :             case SUMO_TAG_TRANSPORT:
     256              :             case SUMO_TAG_TRANSHIP:
     257           75 :                 if (myActiveContainerPlan == nullptr) {
     258           10 :                     throw ProcessError(TLF("Found % outside container element", toString((SumoXMLTag)element)));
     259              :                 }
     260              :                 // copy container elements
     261           70 :                 myActiveContainerPlan->openTag((SumoXMLTag)element);
     262           70 :                 (*myActiveContainerPlan) << attrs;
     263           70 :                 myActiveContainerPlan->closeTag();
     264           70 :                 myActiveContainerPlanSize++;
     265           70 :                 break;
     266         2819 :             case SUMO_TAG_FLOW:
     267         2819 :                 myActiveRouteProbability = DEFAULT_VEH_PROB;
     268         2819 :                 parseFromViaTo((SumoXMLTag)element, attrs, ok);
     269              :                 break;
     270       188077 :             case SUMO_TAG_TRIP:
     271       188077 :                 myActiveRouteProbability = DEFAULT_VEH_PROB;
     272       188077 :                 parseFromViaTo((SumoXMLTag)element, attrs, ok);
     273              :                 break;
     274              :             default:
     275              :                 break;
     276              :         }
     277          440 :     } catch (ProcessError&) {
     278          440 :         deleteActivePlanAndVehicleParameter();
     279          440 :         throw;
     280          440 :     }
     281       638296 : }
     282              : 
     283              : 
     284              : void
     285          115 : RORouteHandler::openVehicleTypeDistribution(const SUMOSAXAttributes& attrs) {
     286          115 :     bool ok = true;
     287          115 :     myCurrentVTypeDistributionID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
     288          115 :     if (ok) {
     289          115 :         myCurrentVTypeDistribution = new RandomDistributor<SUMOVTypeParameter*>();
     290          115 :         if (attrs.hasAttribute(SUMO_ATTR_VTYPES)) {
     291              :             std::vector<double> probs;
     292           60 :             if (attrs.hasAttribute(SUMO_ATTR_PROBS)) {
     293           20 :                 StringTokenizer st(attrs.get<std::string>(SUMO_ATTR_PROBS, myCurrentVTypeDistributionID.c_str(), ok));
     294           60 :                 while (st.hasNext()) {
     295           80 :                     probs.push_back(StringUtils::toDoubleSecure(st.next(), 1.0));
     296              :                 }
     297           20 :             }
     298           60 :             const std::string vTypes = attrs.get<std::string>(SUMO_ATTR_VTYPES, myCurrentVTypeDistributionID.c_str(), ok);
     299           60 :             StringTokenizer st(vTypes);
     300           60 :             int probIndex = 0;
     301          150 :             while (st.hasNext()) {
     302           90 :                 const std::string typeID = st.next();
     303           90 :                 const RandomDistributor<SUMOVTypeParameter*>* const dist = myNet.getVTypeDistribution(typeID);
     304              :                 if (dist != nullptr) {
     305           20 :                     const double distProb = ((int)probs.size() > probIndex ? probs[probIndex] : 1.) / dist->getOverallProb();
     306              :                     std::vector<double>::const_iterator probIt = dist->getProbs().begin();
     307           60 :                     for (SUMOVTypeParameter* const type : dist->getVals()) {
     308           40 :                         myCurrentVTypeDistribution->add(type, distProb * *probIt);
     309              :                         probIt++;
     310              :                     }
     311              :                 } else {
     312           70 :                     SUMOVTypeParameter* const type = myNet.getVehicleTypeSecure(typeID);
     313           70 :                     if (type == nullptr) {
     314           30 :                         myErrorOutput->inform("Unknown vehicle type '" + typeID + "' in distribution '" + myCurrentVTypeDistributionID + "'.");
     315              :                     } else {
     316           60 :                         const double prob = ((int)probs.size() > probIndex ? probs[probIndex] : type->defaultProbability);
     317           60 :                         myCurrentVTypeDistribution->add(type, prob);
     318              :                     }
     319              :                 }
     320           90 :                 probIndex++;
     321              :             }
     322           60 :             if (probs.size() > 0 && probIndex != (int)probs.size()) {
     323            0 :                 WRITE_WARNING("Got " + toString(probs.size()) + " probabilities for " + toString(probIndex) +
     324              :                               " types in vTypeDistribution '" + myCurrentVTypeDistributionID + "'");
     325              :             }
     326          120 :         }
     327              :     }
     328          115 : }
     329              : 
     330              : 
     331              : void
     332          115 : RORouteHandler::closeVehicleTypeDistribution() {
     333          115 :     if (myCurrentVTypeDistribution != nullptr) {
     334          115 :         if (myCurrentVTypeDistribution->getOverallProb() == 0) {
     335           10 :             delete myCurrentVTypeDistribution;
     336           30 :             myErrorOutput->inform("Vehicle type distribution '" + myCurrentVTypeDistributionID + "' is empty.");
     337          105 :         } else if (!myNet.addVTypeDistribution(myCurrentVTypeDistributionID, myCurrentVTypeDistribution)) {
     338            0 :             delete myCurrentVTypeDistribution;
     339            0 :             myErrorOutput->inform("Another vehicle type (or distribution) with the id '" + myCurrentVTypeDistributionID + "' exists.");
     340              :         }
     341          115 :         myCurrentVTypeDistribution = nullptr;
     342              :     }
     343          115 : }
     344              : 
     345              : 
     346              : void
     347       236884 : RORouteHandler::openRoute(const SUMOSAXAttributes& attrs) {
     348              :     myActiveRoute.clear();
     349       236884 :     myInsertStopEdgesAt = -1;
     350              :     // check whether the id is really necessary
     351              :     std::string rid;
     352       236884 :     if (myCurrentAlternatives != nullptr) {
     353       233908 :         myActiveRouteID = myCurrentAlternatives->getID();
     354       701724 :         rid =  "distribution '" + myCurrentAlternatives->getID() + "'";
     355         2976 :     } else if (myVehicleParameter != nullptr) {
     356              :         // ok, a vehicle is wrapping the route,
     357              :         //  we may use this vehicle's id as default
     358         1783 :         myVehicleParameter->routeid = myActiveRouteID = "!" + myVehicleParameter->id; // !!! document this
     359         1783 :         if (attrs.hasAttribute(SUMO_ATTR_ID)) {
     360            0 :             WRITE_WARNINGF(TL("Ids of internal routes are ignored (vehicle '%')."), myVehicleParameter->id);
     361              :         }
     362              :     } else {
     363         1193 :         bool ok = true;
     364         1193 :         myActiveRouteID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
     365         1193 :         if (!ok) {
     366           20 :             return;
     367              :         }
     368         3519 :         rid = "'" + myActiveRouteID + "'";
     369              :     }
     370       236864 :     if (myVehicleParameter != nullptr) { // have to do this here for nested route distributions
     371       703248 :         rid =  "for vehicle '" + myVehicleParameter->id + "'";
     372              :     }
     373       236864 :     bool ok = true;
     374       236864 :     if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
     375       473708 :         parseEdges(attrs.get<std::string>(SUMO_ATTR_EDGES, myActiveRouteID.c_str(), ok), myActiveRoute, rid, ok);
     376              :     }
     377       473728 :     myActiveRouteRefID = attrs.getOpt<std::string>(SUMO_ATTR_REFID, myActiveRouteID.c_str(), ok, "");
     378       236864 :     if (myActiveRouteRefID != "" && myNet.getRouteDef(myActiveRouteRefID) == nullptr) {
     379            0 :         myErrorOutput->inform("Invalid reference to route '" + myActiveRouteRefID + "' in route " + rid + ".");
     380              :     }
     381       236864 :     if (myCurrentAlternatives != nullptr && !attrs.hasAttribute(SUMO_ATTR_PROB)) {
     382           60 :         WRITE_WARNINGF(TL("No probability for route %, using default."), rid);
     383              :     }
     384       236864 :     myActiveRouteProbability = attrs.getOpt<double>(SUMO_ATTR_PROB, myActiveRouteID.c_str(), ok, DEFAULT_VEH_PROB);
     385       236864 :     if (ok && myActiveRouteProbability < 0) {
     386           30 :         myErrorOutput->inform("Invalid probability for route '" + myActiveRouteID + "'.");
     387              :     }
     388       236864 :     myActiveRouteColor = attrs.hasAttribute(SUMO_ATTR_COLOR) ? new RGBColor(attrs.get<RGBColor>(SUMO_ATTR_COLOR, myActiveRouteID.c_str(), ok)) : nullptr;
     389       236864 :     ok = true;
     390       236864 :     myActiveRouteRepeat = attrs.getOpt<int>(SUMO_ATTR_REPEAT, myActiveRouteID.c_str(), ok, 0);
     391       236864 :     myActiveRoutePeriod = attrs.getOptSUMOTimeReporting(SUMO_ATTR_CYCLETIME, myActiveRouteID.c_str(), ok, 0);
     392       236864 :     if (myActiveRouteRepeat > 0) {
     393              :         SUMOVehicleClass vClass = SVC_IGNORING;
     394           10 :         if (myVehicleParameter != nullptr) {
     395            0 :             SUMOVTypeParameter* type = myNet.getVehicleTypeSecure(myVehicleParameter->vtypeid);
     396            0 :             if (type != nullptr) {
     397            0 :                 vClass = type->vehicleClass;
     398              :             }
     399              :         }
     400           10 :         if (myActiveRoute.size() > 0 && !myActiveRoute.back()->isConnectedTo(*myActiveRoute.front(), vClass)) {
     401            0 :             myErrorOutput->inform("Disconnected route " + rid + " when repeating.");
     402              :         }
     403              :     }
     404       236864 :     myCurrentCosts = attrs.getOpt<double>(SUMO_ATTR_COST, myActiveRouteID.c_str(), ok, -1);
     405       236864 :     if (ok && myCurrentCosts != -1 && myCurrentCosts < 0) {
     406           30 :         myErrorOutput->inform("Invalid cost for route '" + myActiveRouteID + "'.");
     407              :     }
     408              : }
     409              : 
     410              : 
     411              : void
     412         2133 : RORouteHandler::openFlow(const SUMOSAXAttributes& /*attrs*/) {
     413              :     // currently unused
     414         2133 : }
     415              : 
     416              : 
     417              : void
     418          686 : RORouteHandler::openRouteFlow(const SUMOSAXAttributes& /*attrs*/) {
     419              :     // currently unused
     420          686 : }
     421              : 
     422              : 
     423              : void
     424       188077 : RORouteHandler::openTrip(const SUMOSAXAttributes& /*attrs*/) {
     425              :     // currently unused
     426       188077 : }
     427              : 
     428              : 
     429              : void
     430       426992 : RORouteHandler::closeRoute(const bool mayBeDisconnected) {
     431       426992 :     const bool mustReroute = myActiveRoute.size() == 0 && myActiveRouteStops.size() != 0;
     432              :     if (mustReroute) {
     433              :         // implicit route from stops
     434           25 :         for (const SUMOVehicleParameter::Stop& stop : myActiveRouteStops) {
     435           20 :             ROEdge* edge = myNet.getEdge(stop.edge);
     436           20 :             myActiveRoute.push_back(edge);
     437              :         }
     438              :     }
     439       426992 :     if (myActiveRoute.size() == 0) {
     440           30 :         if (myActiveRouteRefID != "" && myCurrentAlternatives != nullptr) {
     441           10 :             myCurrentAlternatives->addAlternativeDef(myNet.getRouteDef(myActiveRouteRefID));
     442            5 :             myActiveRouteID = "";
     443              :             myActiveRouteRefID = "";
     444           30 :             return;
     445              :         }
     446           25 :         if (myVehicleParameter != nullptr) {
     447           15 :             myErrorOutput->inform("The route for vehicle '" + myVehicleParameter->id + "' has no edges.");
     448              :         } else {
     449           60 :             myErrorOutput->inform("Route '" + myActiveRouteID + "' has no edges.");
     450              :         }
     451           25 :         myActiveRouteID = "";
     452              :         myActiveRouteStops.clear();
     453           25 :         return;
     454              :     }
     455       426962 :     if (myActiveRoute.size() == 1 && myActiveRoute.front()->isTazConnector()) {
     456            0 :         myErrorOutput->inform("The routing information for vehicle '" + myVehicleParameter->id + "' is insufficient.");
     457            0 :         myActiveRouteID = "";
     458              :         myActiveRouteStops.clear();
     459            0 :         return;
     460              :     }
     461       900682 :     if (!mayBeDisconnected && OptionsCont::getOptions().exists("no-internal-links") && !OptionsCont::getOptions().getBool("no-internal-links")) {
     462              :         // fix internal edges which did not get parsed
     463              :         const ROEdge* last = nullptr;
     464              :         ConstROEdgeVector fullRoute;
     465      1517012 :         for (const ROEdge* roe : myActiveRoute) {
     466      1280155 :             if (last != nullptr) {
     467      2544997 :                 for (const ROEdge* intern : last->getSuccessors()) {
     468      1501699 :                     if (intern->isInternal() && intern->getSuccessors().size() == 1 && intern->getSuccessors().front() == roe) {
     469            0 :                         fullRoute.push_back(intern);
     470              :                     }
     471              :                 }
     472              :             }
     473      1280155 :             fullRoute.push_back(roe);
     474              :             last = roe;
     475              :         }
     476       236857 :         myActiveRoute = fullRoute;
     477       236857 :     }
     478       426962 :     if (myActiveRouteRepeat > 0) {
     479              :         // duplicate route
     480           10 :         ConstROEdgeVector tmpEdges = myActiveRoute;
     481           10 :         auto tmpStops = myActiveRouteStops;
     482           30 :         for (int i = 0; i < myActiveRouteRepeat; i++) {
     483           20 :             myActiveRoute.insert(myActiveRoute.begin(), tmpEdges.begin(), tmpEdges.end());
     484          100 :             for (SUMOVehicleParameter::Stop stop : tmpStops) {
     485           80 :                 if (stop.until > 0) {
     486           40 :                     if (myActiveRoutePeriod <= 0) {
     487            0 :                         const std::string description = myVehicleParameter != nullptr
     488            0 :                                                         ?  "for vehicle '" + myVehicleParameter->id + "'"
     489            0 :                                                         :  "'" + myActiveRouteID + "'";
     490            0 :                         throw ProcessError(TLF("Cannot repeat stops with 'until' in route % because no cycleTime is defined.", description));
     491              :                     }
     492           40 :                     stop.until += myActiveRoutePeriod * (i + 1);
     493           40 :                     stop.arrival += myActiveRoutePeriod * (i + 1);
     494              :                 }
     495           80 :                 myActiveRouteStops.push_back(stop);
     496           80 :             }
     497              :         }
     498           10 :     }
     499       426962 :     std::shared_ptr<RORoute> route = std::make_shared<RORoute>(myActiveRouteID, myCurrentCosts, myActiveRouteProbability, myActiveRoute,
     500       426962 :                                      myActiveRouteColor, myActiveRouteStops);
     501              :     myActiveRoute.clear();
     502       426962 :     if (myCurrentAlternatives == nullptr) {
     503       193059 :         if (myNet.getRouteDef(myActiveRouteID) != nullptr) {
     504            0 :             if (myVehicleParameter != nullptr) {
     505            0 :                 myErrorOutput->inform("Another route for vehicle '" + myVehicleParameter->id + "' exists.");
     506              :             } else {
     507            0 :                 myErrorOutput->inform("Another route (or distribution) with the id '" + myActiveRouteID + "' exists.");
     508              :             }
     509              :             myActiveRouteID = "";
     510              :             myActiveRouteStops.clear();
     511              :             return;
     512              :         } else {
     513       193059 :             myCurrentAlternatives = new RORouteDef(myActiveRouteID, 0, mayBeDisconnected || myTryRepair, mayBeDisconnected);
     514       193059 :             myCurrentAlternatives->addLoadedAlternative(route);
     515       193059 :             myNet.addRouteDef(myCurrentAlternatives);
     516       193059 :             myCurrentAlternatives = nullptr;
     517              :         }
     518              :     } else {
     519       233903 :         myCurrentAlternatives->addLoadedAlternative(route);
     520              :     }
     521              :     myActiveRouteID = "";
     522              :     myActiveRouteStops.clear();
     523              : }
     524              : 
     525              : 
     526              : void
     527        92040 : RORouteHandler::openRouteDistribution(const SUMOSAXAttributes& attrs) {
     528              :     // check whether the id is really necessary
     529        92040 :     bool ok = true;
     530              :     std::string id;
     531        92040 :     if (myVehicleParameter != nullptr) {
     532              :         // ok, a vehicle is wrapping the route,
     533              :         //  we may use this vehicle's id as default
     534        90760 :         myVehicleParameter->routeid = id = "!" + myVehicleParameter->id; // !!! document this
     535        90760 :         if (attrs.hasAttribute(SUMO_ATTR_ID)) {
     536            0 :             WRITE_WARNINGF(TL("Ids of internal route distributions are ignored (vehicle '%')."), myVehicleParameter->id);
     537              :         }
     538              :     } else {
     539         1280 :         id = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
     540         1280 :         if (!ok) {
     541              :             return;
     542              :         }
     543              :     }
     544              :     // try to get the index of the last element
     545        92030 :     int index = attrs.getOpt<int>(SUMO_ATTR_LAST, id.c_str(), ok, 0);
     546        92030 :     if (ok && index < 0) {
     547           20 :         myErrorOutput->inform("Negative index of a route alternative (id='" + id + "').");
     548           10 :         return;
     549              :     }
     550              :     // build the alternative cont
     551        92020 :     myCurrentAlternatives = new RORouteDef(id, index, myTryRepair, false);
     552        92020 :     if (attrs.hasAttribute(SUMO_ATTR_ROUTES)) {
     553            0 :         ok = true;
     554            0 :         StringTokenizer st(attrs.get<std::string>(SUMO_ATTR_ROUTES, id.c_str(), ok));
     555            0 :         while (st.hasNext()) {
     556            0 :             const std::string routeID = st.next();
     557            0 :             const RORouteDef* route = myNet.getRouteDef(routeID);
     558            0 :             if (route == nullptr) {
     559            0 :                 myErrorOutput->inform("Unknown route '" + routeID + "' in distribution '" + id + "'.");
     560              :             } else {
     561            0 :                 myCurrentAlternatives->addAlternativeDef(route);
     562              :             }
     563              :         }
     564            0 :     }
     565              : }
     566              : 
     567              : 
     568              : void
     569        92020 : RORouteHandler::closeRouteDistribution() {
     570        92020 :     if (myCurrentAlternatives != nullptr) {
     571        92000 :         if (myCurrentAlternatives->getOverallProb() == 0) {
     572            0 :             myErrorOutput->inform("Route distribution '" + myCurrentAlternatives->getID() + "' is empty.");
     573            0 :             delete myCurrentAlternatives;
     574        92000 :         } else if (!myNet.addRouteDef(myCurrentAlternatives)) {
     575            0 :             myErrorOutput->inform("Another route (or distribution) with the id '" + myCurrentAlternatives->getID() + "' exists.");
     576            0 :             delete myCurrentAlternatives;
     577              :         } else {
     578       184000 :             if (myVehicleParameter != nullptr
     579       182885 :                     && (myUseTaz || OptionsCont::getOptions().getBool("junction-taz"))
     580        92190 :                     && (myVehicleParameter->wasSet(VEHPARS_FROM_TAZ_SET) ||
     581              :                         myVehicleParameter->wasSet(VEHPARS_TO_TAZ_SET))) {
     582              :                 // we are loading a rou.alt.xml, permit rerouting between taz
     583              :                 bool ok = true;
     584              :                 ConstROEdgeVector edges;
     585          190 :                 if (myVehicleParameter->fromTaz != "") {
     586              :                     const std::string tazID = myVehicleParameter->fromTaz;
     587          380 :                     const ROEdge* fromTaz = myNet.getEdge(tazID + "-source");
     588          190 :                     if (fromTaz == nullptr) {
     589            0 :                         myErrorOutput->inform("Source taz '" + tazID + "' not known for vehicle '" + myVehicleParameter->id + "'!");
     590              :                         ok = false;
     591          190 :                     } else if (fromTaz->getNumSuccessors() == 0) {
     592            0 :                         myErrorOutput->inform("Source taz '" + tazID + "' has no outgoing edges for vehicle '" + myVehicleParameter->id + "'!");
     593              :                         ok = false;
     594              :                     } else {
     595          190 :                         edges.push_back(fromTaz);
     596              :                     }
     597              :                 } else {
     598            0 :                     edges.push_back(myCurrentAlternatives->getOrigin());
     599              :                 }
     600          190 :                 if (myVehicleParameter->toTaz != "") {
     601              :                     const std::string tazID = myVehicleParameter->toTaz;
     602          380 :                     const ROEdge* toTaz = myNet.getEdge(tazID + "-sink");
     603          190 :                     if (toTaz == nullptr) {
     604            0 :                         myErrorOutput->inform("Sink taz '" + tazID + "' not known for vehicle '" + myVehicleParameter->id + "'!");
     605              :                         ok = false;
     606          190 :                     } else if (toTaz->getNumPredecessors() == 0) {
     607            0 :                         myErrorOutput->inform("Sink taz '" + tazID + "' has no incoming edges for vehicle '" + myVehicleParameter->id + "'!");
     608              :                         ok = false;
     609              :                     } else {
     610          190 :                         edges.push_back(toTaz);
     611              :                     }
     612              :                 } else {
     613            0 :                     edges.push_back(myCurrentAlternatives->getDestination());
     614              :                 }
     615          190 :                 if (ok) {
     616              :                     // negative probability indicates that this route should not be written
     617          380 :                     myCurrentAlternatives->addLoadedAlternative(std::make_shared<RORoute>(myCurrentAlternatives->getID(), 0, -1, edges, nullptr, myActiveRouteStops));
     618              :                 }
     619          190 :             }
     620              :         }
     621        92000 :         myCurrentAlternatives = nullptr;
     622              :     }
     623        92020 : }
     624              : 
     625              : 
     626              : void
     627       282237 : RORouteHandler::closeVehicle() {
     628       282237 :     checkLastDepart();
     629              :     // get the vehicle id
     630       282237 :     if (myVehicleParameter->departProcedure == DepartDefinition::GIVEN && myVehicleParameter->depart < myBegin) {
     631            5 :         mySkippedVehicles.insert(myVehicleParameter->id);
     632            5 :         return;
     633              :     }
     634              :     // get vehicle type
     635       282232 :     SUMOVTypeParameter* type = myNet.getVehicleTypeSecure(myVehicleParameter->vtypeid);
     636       282232 :     if (type == nullptr) {
     637          340 :         myErrorOutput->inform("The vehicle type '" + myVehicleParameter->vtypeid + "' for vehicle '" + myVehicleParameter->id + "' is not known.");
     638          170 :         type = myNet.getVehicleTypeSecure(DEFAULT_VTYPE_ID);
     639              :     } else {
     640       282062 :         if (!myKeepVTypeDist) {
     641              :             // fix the type id in case we used a distribution
     642       282057 :             myVehicleParameter->vtypeid = type->id;
     643              :         }
     644              :     }
     645       282232 :     if (type->vehicleClass == SVC_PEDESTRIAN) {
     646          150 :         WRITE_WARNINGF(TL("Vehicle type '%' with vClass=pedestrian should only be used for persons and not for vehicle '%'."), type->id, myVehicleParameter->id);
     647              :     }
     648              :     // get the route
     649       282232 :     RORouteDef* route = myNet.getRouteDef(myVehicleParameter->routeid);
     650       282197 :     if (route == nullptr) {
     651           70 :         myErrorOutput->inform("The route of the vehicle '" + myVehicleParameter->id + "' is not known.");
     652           35 :         return;
     653              :     }
     654       282197 :     if (MsgHandler::getErrorInstance()->wasInformed()) {
     655              :         return;
     656              :     }
     657       282012 :     const bool needCopy = route->getID()[0] != '!';
     658       282012 :     if (needCopy) {
     659         3216 :         route = route->copy("!" + myVehicleParameter->id, myVehicleParameter->depart);
     660              :     }
     661              :     // build the vehicle
     662       282012 :     ROVehicle* veh = new ROVehicle(*myVehicleParameter, route, type, &myNet, myErrorOutput);
     663       282012 :     if (myNet.addVehicle(myVehicleParameter->id, veh)) {
     664       282007 :         registerLastDepart();
     665            5 :     } else if (needCopy) {
     666            5 :         delete route;
     667              :     }
     668       282012 :     delete myVehicleParameter;
     669       282012 :     myVehicleParameter = nullptr;
     670              : }
     671              : 
     672              : 
     673              : void
     674         2657 : RORouteHandler::closeVType() {
     675         2657 :     if (myCurrentVTypeRef.empty()) {
     676         2607 :         myNet.addVehicleType(myCurrentVType);
     677         5214 :         if (OptionsCont::getOptions().isSet("restriction-params")) {
     678           30 :             const std::vector<std::string> paramKeys = OptionsCont::getOptions().getStringVector("restriction-params");
     679           30 :             myCurrentVType->cacheParamRestrictions(paramKeys);
     680           30 :         }
     681              :     }
     682         2657 :     if (myCurrentVTypeDistribution != nullptr) {
     683          110 :         if (myCurrentVTypeRef.empty()) {
     684           60 :             myCurrentVTypeDistribution->add(myCurrentVType, myCurrentVType->defaultProbability);
     685              :         } else {
     686           50 :             const RandomDistributor<SUMOVTypeParameter*>* const dist = myNet.getVTypeDistribution(myCurrentVTypeRef);
     687           10 :             if (dist != nullptr) {
     688           20 :                 const double distProb = (myCurrentVTypeProbability >= 0 ? myCurrentVTypeProbability : 1) / dist->getOverallProb();
     689              :                 std::vector<double>::const_iterator probIt = dist->getProbs().begin();
     690           30 :                 for (SUMOVTypeParameter* const type : dist->getVals()) {
     691           20 :                     myCurrentVTypeDistribution->add(type, distProb * *probIt);
     692              :                     probIt++;
     693              :                 }
     694              :             } else {
     695           40 :                 SUMOVTypeParameter* const type = myNet.getVehicleTypeSecure(myCurrentVTypeRef);
     696           40 :                 double probability = myCurrentVTypeProbability >= 0 ? myCurrentVTypeProbability : type->defaultProbability;
     697           40 :                 myCurrentVTypeDistribution->add(type, probability);
     698              :             }
     699              :         }
     700              :     }
     701         2657 :     myCurrentVType = nullptr;
     702         2657 : }
     703              : 
     704              : 
     705              : void
     706         3477 : RORouteHandler::closePerson() {
     707         3477 :     SUMOVTypeParameter* type = myNet.getVehicleTypeSecure(myVehicleParameter->vtypeid);
     708         3477 :     if (type == nullptr) {
     709            0 :         myErrorOutput->inform("The vehicle type '" + myVehicleParameter->vtypeid + "' for person '" + myVehicleParameter->id + "' is not known.");
     710            0 :         type = myNet.getVehicleTypeSecure(DEFAULT_PEDTYPE_ID);
     711              :     }
     712         3477 :     if (myActivePlan == nullptr || myActivePlan->empty()) {
     713           50 :         WRITE_WARNINGF(TL("Discarding person '%' because her plan is empty"), myVehicleParameter->id);
     714         3452 :     } else if (myVehicleParameter->departProcedure != DepartDefinition::GIVEN || myVehicleParameter->depart >= myBegin) {
     715         3442 :         ROPerson* person = new ROPerson(*myVehicleParameter, type);
     716         7114 :         for (ROPerson::PlanItem* item : *myActivePlan) {
     717         3672 :             person->getPlan().push_back(item);
     718              :         }
     719         3442 :         myActivePlan->clear();
     720         3442 :         if (myNet.addPerson(person)) {
     721         3442 :             checkLastDepart();
     722         3442 :             registerLastDepart();
     723              :         }
     724              :     }
     725         3477 :     deleteActivePlanAndVehicleParameter();
     726         3477 : }
     727              : 
     728              : 
     729              : void
     730          196 : RORouteHandler::closePersonFlow() {
     731              :     std::string typeID = DEFAULT_PEDTYPE_ID;
     732          196 :     if (myNet.getVehicleTypeSecure(myVehicleParameter->vtypeid) == nullptr) {
     733            0 :         myErrorOutput->inform("The vehicle type '" + myVehicleParameter->vtypeid + "' for personFlow '" + myVehicleParameter->id + "' is not known.");
     734              :     } else {
     735          196 :         typeID = myVehicleParameter->vtypeid;
     736              :     }
     737          196 :     if (myActivePlan == nullptr || myActivePlan->empty()) {
     738            0 :         WRITE_WARNINGF(TL("Discarding personFlow '%' because their plan is empty"), myVehicleParameter->id);
     739              :     } else {
     740          196 :         checkLastDepart();
     741              :         // instantiate all persons of this flow
     742              :         int i = 0;
     743          196 :         std::string baseID = myVehicleParameter->id;
     744          196 :         if (myWriteFlows) {
     745          160 :             addFlowPerson(typeID, myVehicleParameter->depart, baseID, i);
     746           36 :         } else if (myVehicleParameter->repetitionProbability > 0) {
     747            5 :             if (myVehicleParameter->repetitionEnd == SUMOTime_MAX) {
     748            0 :                 throw ProcessError(TLF("probabilistic personFlow '%' must specify end time", myVehicleParameter->id));
     749              :             } else {
     750           55 :                 for (SUMOTime t = myVehicleParameter->depart; t < myVehicleParameter->repetitionEnd; t += TIME2STEPS(1)) {
     751           50 :                     if (RandHelper::rand() < myVehicleParameter->repetitionProbability) {
     752           25 :                         addFlowPerson(typeID, t, baseID, i++);
     753              :                     }
     754              :                 }
     755              :             }
     756              :         } else {
     757           31 :             SUMOTime depart = myVehicleParameter->depart;
     758              :             // uniform sampling of departures from range is equivalent to poisson flow (encoded by negative offset)
     759           62 :             if (OptionsCont::getOptions().getBool("randomize-flows") && myVehicleParameter->repetitionOffset >= 0) {
     760              :                 std::vector<SUMOTime> departures;
     761            5 :                 const SUMOTime range = myVehicleParameter->repetitionNumber * myVehicleParameter->repetitionOffset;
     762           30 :                 for (int j = 0; j < myVehicleParameter->repetitionNumber; ++j) {
     763           25 :                     departures.push_back(depart + RandHelper::rand(range));
     764              :                 }
     765            5 :                 std::sort(departures.begin(), departures.end());
     766              :                 std::reverse(departures.begin(), departures.end());
     767           30 :                 for (; i < myVehicleParameter->repetitionNumber; i++) {
     768           25 :                     addFlowPerson(typeID, departures[i], baseID, i);
     769              :                     depart += myVehicleParameter->repetitionOffset;
     770              :                 }
     771            5 :             } else {
     772           26 :                 const bool triggered = myVehicleParameter->departProcedure == DepartDefinition::TRIGGERED;
     773           26 :                 if (myVehicleParameter->repetitionOffset < 0) {
     774              :                     // poisson: randomize first depart
     775            5 :                     myVehicleParameter->incrementFlow(1);
     776              :                 }
     777          236 :                 for (; i < myVehicleParameter->repetitionNumber && (triggered || depart + myVehicleParameter->repetitionTotalOffset <= myVehicleParameter->repetitionEnd); i++) {
     778          210 :                     addFlowPerson(typeID, depart + myVehicleParameter->repetitionTotalOffset, baseID, i);
     779          210 :                     if (myVehicleParameter->departProcedure != DepartDefinition::TRIGGERED) {
     780          210 :                         myVehicleParameter->incrementFlow(1);
     781              :                     }
     782              :                 }
     783              :             }
     784              :         }
     785              :     }
     786          196 :     deleteActivePlanAndVehicleParameter();
     787          196 : }
     788              : 
     789              : 
     790              : void
     791          420 : RORouteHandler::addFlowPerson(const std::string& typeID, SUMOTime depart, const std::string& baseID, int i) {
     792          420 :     SUMOVehicleParameter pars = *myVehicleParameter;
     793          840 :     pars.id = baseID + "." + toString(i);
     794          420 :     pars.depart = depart;
     795          420 :     const SUMOVTypeParameter* const type = myNet.getVehicleTypeSecure(typeID);
     796          420 :     if (!myKeepVTypeDist) {
     797          420 :         pars.vtypeid = type->id;
     798              :     }
     799          420 :     ROPerson* person = new ROPerson(pars, type);
     800          840 :     for (ROPerson::PlanItem* item : *myActivePlan) {
     801          420 :         person->getPlan().push_back(item->clone());
     802              :     }
     803          420 :     if (myNet.addPerson(person)) {
     804          420 :         if (i == 0) {
     805          196 :             registerLastDepart();
     806              :         }
     807              :     }
     808          420 : }
     809              : 
     810              : 
     811              : void
     812           45 : RORouteHandler::closeContainer() {
     813           45 :     myActiveContainerPlan->closeTag();
     814           45 :     if (myActiveContainerPlanSize > 0) {
     815           45 :         myNet.addContainer(myVehicleParameter->depart, myActiveContainerPlan->getString());
     816           45 :         checkLastDepart();
     817           45 :         registerLastDepart();
     818              :     } else {
     819            0 :         WRITE_WARNINGF(TL("Discarding container '%' because its plan is empty"), myVehicleParameter->id);
     820              :     }
     821           45 :     delete myVehicleParameter;
     822           45 :     myVehicleParameter = nullptr;
     823           45 :     delete myActiveContainerPlan;
     824           45 :     myActiveContainerPlan = nullptr;
     825           45 :     myActiveContainerPlanSize = 0;
     826           45 : }
     827              : 
     828              : 
     829           25 : void RORouteHandler::closeContainerFlow() {
     830           25 :     myActiveContainerPlan->closeTag();
     831           25 :     if (myActiveContainerPlanSize > 0) {
     832           25 :         myNet.addContainer(myVehicleParameter->depart, myActiveContainerPlan->getString());
     833           25 :         checkLastDepart();
     834           25 :         registerLastDepart();
     835              :     } else {
     836            0 :         WRITE_WARNINGF(TL("Discarding containerFlow '%' because its plan is empty"), myVehicleParameter->id);
     837              :     }
     838           25 :     delete myVehicleParameter;
     839           25 :     myVehicleParameter = nullptr;
     840           25 :     delete myActiveContainerPlan;
     841           25 :     myActiveContainerPlan = nullptr;
     842           25 :     myActiveContainerPlanSize = 0;
     843           25 : }
     844              : 
     845              : 
     846              : void
     847         2819 : RORouteHandler::closeFlow() {
     848         2819 :     checkLastDepart();
     849              :     // @todo: consider myScale?
     850         2819 :     if (myVehicleParameter->repetitionNumber == 0) {
     851            9 :         delete myVehicleParameter;
     852            9 :         myVehicleParameter = nullptr;
     853            9 :         return;
     854              :     }
     855              :     // let's check whether vehicles had to depart before the simulation starts
     856         2810 :     myVehicleParameter->repetitionsDone = 0;
     857         2810 :     const SUMOTime offsetToBegin = myBegin - myVehicleParameter->depart;
     858         2994 :     while (myVehicleParameter->repetitionTotalOffset < offsetToBegin) {
     859          186 :         myVehicleParameter->incrementFlow(1);
     860          186 :         if (myVehicleParameter->repetitionsDone == myVehicleParameter->repetitionNumber) {
     861            2 :             delete myVehicleParameter;
     862            2 :             myVehicleParameter = nullptr;
     863            2 :             return;
     864              :         }
     865              :     }
     866         2808 :     if (myNet.getVehicleTypeSecure(myVehicleParameter->vtypeid) == nullptr) {
     867           66 :         myErrorOutput->inform("The vehicle type '" + myVehicleParameter->vtypeid + "' for flow '" + myVehicleParameter->id + "' is not known.");
     868              :     }
     869         2808 :     if (myVehicleParameter->routeid[0] == '!' && myNet.getRouteDef(myVehicleParameter->routeid) == nullptr) {
     870         2031 :         closeRoute(true);
     871              :     }
     872         2808 :     if (myNet.getRouteDef(myVehicleParameter->routeid) == nullptr) {
     873            0 :         myErrorOutput->inform("The route '" + myVehicleParameter->routeid + "' for flow '" + myVehicleParameter->id + "' is not known.");
     874            0 :         delete myVehicleParameter;
     875            0 :         myVehicleParameter = nullptr;
     876            0 :         return;
     877              :     }
     878         2808 :     myActiveRouteID = "";
     879         2808 :     if (!MsgHandler::getErrorInstance()->wasInformed()) {
     880         5594 :         if (myNet.addFlow(myVehicleParameter, OptionsCont::getOptions().getBool("randomize-flows"))) {
     881         2792 :             registerLastDepart();
     882              :         } else {
     883           10 :             myErrorOutput->inform("Another flow with the id '" + myVehicleParameter->id + "' exists.");
     884            5 :             delete myVehicleParameter;
     885              :         }
     886              :     } else {
     887           11 :         delete myVehicleParameter;
     888              :     }
     889         2808 :     myVehicleParameter = nullptr;
     890         2808 :     myInsertStopEdgesAt = -1;
     891              : }
     892              : 
     893              : 
     894              : void
     895       188077 : RORouteHandler::closeTrip() {
     896       188077 :     closeRoute(true);
     897       188077 :     closeVehicle();
     898       188077 : }
     899              : 
     900              : 
     901              : const SUMOVehicleParameter::Stop*
     902         7073 : RORouteHandler::retrieveStoppingPlace(const SUMOSAXAttributes& attrs, const std::string& errorSuffix, std::string& id, const SUMOVehicleParameter::Stop* stopParam) {
     903              :     const SUMOVehicleParameter::Stop* toStop = nullptr;
     904         7073 :     SumoXMLTag tag = SUMO_TAG_NOTHING;
     905         7073 :     SUMOVehicleParserHelper::parseStopTag(attrs, stopParam, tag, id);
     906         7073 :     if (tag != SUMO_TAG_NOTHING) {
     907         3273 :         toStop = myNet.getStoppingPlace(id, tag);
     908         3273 :         if (toStop == nullptr) {
     909           12 :             myErrorOutput->inform(TLF("The % '%' is not known%", toString(tag), id, errorSuffix));
     910              :         }
     911              :     }
     912         7073 :     return toStop;
     913              : }
     914              : 
     915              : Parameterised*
     916         3335 : RORouteHandler::addStop(const SUMOSAXAttributes& attrs) {
     917              :     Parameterised* result = nullptr;
     918         3335 :     if (myActiveContainerPlan != nullptr) {
     919           20 :         myActiveContainerPlan->openTag(SUMO_TAG_STOP);
     920           20 :         (*myActiveContainerPlan) << attrs;
     921           20 :         myActiveContainerPlan->closeTag();
     922           20 :         myActiveContainerPlanSize++;
     923           20 :         return result;
     924              :     }
     925              :     std::string errorSuffix;
     926         3315 :     if (myActivePlan != nullptr) {
     927          450 :         errorSuffix = " in person '" + myVehicleParameter->id + "'.";
     928              :     } else if (myActiveContainerPlan != nullptr) {
     929              :         errorSuffix = " in container '" + myVehicleParameter->id + "'.";
     930         3165 :     } else if (myVehicleParameter != nullptr) {
     931         2814 :         errorSuffix = " in vehicle '" + myVehicleParameter->id + "'.";
     932              :     } else {
     933         6681 :         errorSuffix = " in route '" + myActiveRouteID + "'.";
     934              :     }
     935         3315 :     SUMOVehicleParameter::Stop stop;
     936         6630 :     bool ok = parseStop(stop, attrs, errorSuffix, myErrorOutput);
     937         3315 :     if (!ok) {
     938              :         return result;
     939              :     }
     940              :     // try to parse the assigned bus stop
     941         3315 :     const ROEdge* edge = nullptr;
     942              :     std::string stoppingPlaceID;
     943         3315 :     const SUMOVehicleParameter::Stop* stoppingPlace = retrieveStoppingPlace(attrs, errorSuffix, stoppingPlaceID, &stop);
     944              :     bool hasPos = false;
     945         3315 :     if (stoppingPlace != nullptr) {
     946         3049 :         stop.lane = stoppingPlace->lane;
     947         3049 :         stop.endPos = stoppingPlace->endPos;
     948         3049 :         stop.startPos = stoppingPlace->startPos;
     949        12196 :         edge = myNet.getEdge(SUMOXMLDefinitions::getEdgeIDFromLane(stop.lane));
     950              :     } else {
     951              :         // no, the lane and the position should be given
     952          266 :         stop.lane = attrs.getOpt<std::string>(SUMO_ATTR_LANE, nullptr, ok, "");
     953          266 :         stop.edge = attrs.getOpt<std::string>(SUMO_ATTR_EDGE, nullptr, ok, "");
     954          266 :         if (ok && stop.edge != "") {
     955           73 :             edge = myNet.getEdge(stop.edge);
     956           73 :             if (edge == nullptr) {
     957            8 :                 myErrorOutput->inform("The edge '" + stop.edge + "' for a stop is not known" + errorSuffix);
     958            4 :                 return result;
     959              :             }
     960          193 :         } else if (ok && stop.lane != "") {
     961          447 :             edge = myNet.getEdge(SUMOXMLDefinitions::getEdgeIDFromLane(stop.lane));
     962          149 :             if (edge == nullptr) {
     963            0 :                 myErrorOutput->inform("The lane '" + stop.lane + "' for a stop is not known" + errorSuffix);
     964            0 :                 return result;
     965              :             }
     966           44 :         } else if (ok && ((attrs.hasAttribute(SUMO_ATTR_X) && attrs.hasAttribute(SUMO_ATTR_Y))
     967           29 :                           || (attrs.hasAttribute(SUMO_ATTR_LON) && attrs.hasAttribute(SUMO_ATTR_LAT)))) {
     968              :             Position pos;
     969              :             bool geo = false;
     970           40 :             if (attrs.hasAttribute(SUMO_ATTR_X) && attrs.hasAttribute(SUMO_ATTR_Y)) {
     971           15 :                 pos = Position(attrs.get<double>(SUMO_ATTR_X, myVehicleParameter->id.c_str(), ok), attrs.get<double>(SUMO_ATTR_Y, myVehicleParameter->id.c_str(), ok));
     972              :             } else {
     973           25 :                 pos = Position(attrs.get<double>(SUMO_ATTR_LON, myVehicleParameter->id.c_str(), ok), attrs.get<double>(SUMO_ATTR_LAT, myVehicleParameter->id.c_str(), ok));
     974              :                 geo = true;
     975              :             }
     976           40 :             PositionVector positions;
     977           40 :             positions.push_back(pos);
     978              :             ConstROEdgeVector geoEdges;
     979              :             SUMOVehicleClass vClass = SVC_PASSENGER;
     980           40 :             if (!myNet.getVTypeDistribution(myVehicleParameter->vtypeid)) {
     981           40 :                 SUMOVTypeParameter* type = myNet.getVehicleTypeSecure(myVehicleParameter->vtypeid);
     982           40 :                 if (type != nullptr) {
     983           40 :                     vClass = type->vehicleClass;
     984              :                 }
     985              :             }
     986           40 :             parseGeoEdges(positions, geo, vClass, geoEdges, myVehicleParameter->id, true, ok, true);
     987           40 :             if (ok) {
     988           40 :                 edge = geoEdges.front();
     989              :                 hasPos = true;
     990           40 :                 if (geo) {
     991           25 :                     GeoConvHelper::getFinal().x2cartesian_const(pos);
     992              :                 }
     993           40 :                 stop.parametersSet |= STOP_END_SET;
     994           40 :                 stop.endPos = edge->getLanes()[0]->getShape().nearest_offset_to_point2D(pos, false);
     995              :             } else {
     996              :                 return result;
     997              :             }
     998           44 :         } else if (!ok || (stop.lane == "" && stop.edge == "")) {
     999            4 :             myErrorOutput->inform("A stop must be placed on a bus stop, a container stop, a parking area, an edge or a lane" + errorSuffix);
    1000            4 :             return result;
    1001              :         }
    1002              :         if (!hasPos) {
    1003          218 :             stop.endPos = attrs.getOpt<double>(SUMO_ATTR_ENDPOS, nullptr, ok, edge->getLength());
    1004              :         }
    1005          258 :         stop.startPos = attrs.getOpt<double>(SUMO_ATTR_STARTPOS, nullptr, ok, stop.endPos - 2 * POSITION_EPS);
    1006          332 :         const bool friendlyPos = attrs.getOpt<bool>(SUMO_ATTR_FRIENDLY_POS, nullptr, ok, !attrs.hasAttribute(SUMO_ATTR_STARTPOS) && !attrs.hasAttribute(SUMO_ATTR_ENDPOS));
    1007          258 :         const double endPosOffset = edge->isInternal() ? edge->getNormalBefore()->getLength() : 0;
    1008          258 :         if (!ok || (checkStopPos(stop.startPos, stop.endPos, edge->getLength() + endPosOffset, POSITION_EPS, friendlyPos) != SUMORouteHandler::StopPos::STOPPOS_VALID)) {
    1009            0 :             myErrorOutput->inform("Invalid start or end position for stop" + errorSuffix);
    1010            0 :             return result;
    1011              :         }
    1012              :     }
    1013         3307 :     stop.edge = edge->getID();
    1014         3307 :     if (myActivePlan != nullptr) {
    1015          150 :         ROPerson::addStop(*myActivePlan, stop, edge);
    1016          150 :         result = myActivePlan->back()->getStopParameters();
    1017         3157 :     } else if (myVehicleParameter != nullptr) {
    1018          930 :         myVehicleParameter->stops.push_back(stop);
    1019          930 :         result = &myVehicleParameter->stops.back();
    1020              :     } else {
    1021         2227 :         myActiveRouteStops.push_back(stop);
    1022              :         result = &myActiveRouteStops.back();
    1023              :     }
    1024         3307 :     if (myInsertStopEdgesAt >= 0) {
    1025          642 :         myActiveRoute.insert(myActiveRoute.begin() + myInsertStopEdgesAt, edge);
    1026          642 :         myInsertStopEdgesAt++;
    1027              :     }
    1028              :     return result;
    1029         3315 : }
    1030              : 
    1031              : 
    1032              : void
    1033          130 : RORouteHandler::addRide(const SUMOSAXAttributes& attrs) {
    1034          130 :     bool ok = true;
    1035          130 :     std::vector<ROPerson::PlanItem*>& plan = *myActivePlan;
    1036          130 :     const std::string pid = myVehicleParameter->id;
    1037              : 
    1038              :     const ROEdge* from = nullptr;
    1039              :     const ROEdge* to = nullptr;
    1040          130 :     parseFromViaTo(SUMO_TAG_PERSON, attrs, ok);
    1041          140 :     if (attrs.hasAttribute(SUMO_ATTR_FROM) || attrs.hasAttribute(SUMO_ATTR_FROM_JUNCTION) || attrs.hasAttribute(SUMO_ATTR_FROM_TAZ)
    1042          140 :             || attrs.hasAttribute(SUMO_ATTR_FROMLONLAT) || attrs.hasAttribute(SUMO_ATTR_FROMXY)) {
    1043          125 :         if (ok) {
    1044          125 :             from = myActiveRoute.front();
    1045              :         }
    1046            5 :     } else if (plan.empty()) {
    1047            0 :         myErrorOutput->inform("The start edge for person '" + pid + "' is not known.");
    1048            0 :         return;
    1049              :     }
    1050              :     std::string stoppingPlaceID;
    1051          260 :     const SUMOVehicleParameter::Stop* stop = retrieveStoppingPlace(attrs, " for ride of person '" + myVehicleParameter->id + "'", stoppingPlaceID);
    1052          130 :     if (stop != nullptr) {
    1053          105 :         to = myNet.getEdge(SUMOXMLDefinitions::getEdgeIDFromLane(stop->lane));
    1054              :     } else {
    1055          100 :         if (attrs.hasAttribute(SUMO_ATTR_TO) || attrs.hasAttribute(SUMO_ATTR_TO_JUNCTION) || attrs.hasAttribute(SUMO_ATTR_TO_TAZ)
    1056          100 :                 || attrs.hasAttribute(SUMO_ATTR_TOLONLAT) || attrs.hasAttribute(SUMO_ATTR_TOXY)) {
    1057           95 :             to = myActiveRoute.back();
    1058              :         } else {
    1059            0 :             myErrorOutput->inform("The to edge is missing within a ride of '" + myVehicleParameter->id + "'.");
    1060            0 :             return;
    1061              :         }
    1062              :     }
    1063          130 :     double arrivalPos = attrs.getOpt<double>(SUMO_ATTR_ARRIVALPOS, myVehicleParameter->id.c_str(), ok,
    1064              :                         stop == nullptr ? std::numeric_limits<double>::infinity() : stop->endPos);
    1065          130 :     const std::string lines = attrs.getOpt<std::string>(SUMO_ATTR_LINES, pid.c_str(), ok, LINE_ANY);
    1066          260 :     const std::string group = attrs.getOpt<std::string>(SUMO_ATTR_GROUP, pid.c_str(), ok, "");
    1067              : 
    1068          130 :     if (plan.empty() && myVehicleParameter->departProcedure == DepartDefinition::TRIGGERED) {
    1069           45 :         StringTokenizer st(lines);
    1070           90 :         if (st.size() != 1 || st.get(0) == LINE_ANY) {
    1071            0 :             myErrorOutput->inform("Triggered departure for person '" + pid + "' requires a unique lines value.");
    1072            0 :             return;
    1073              :         }
    1074           45 :         const std::string vehID = st.front();
    1075           45 :         if (myNet.knowsVehicle(vehID)) {
    1076           25 :             const SUMOTime vehDepart = myNet.getDeparture(vehID);
    1077           25 :             if (vehDepart == -1) {
    1078            0 :                 myErrorOutput->inform("Cannot use triggered vehicle '" + vehID + "' in triggered departure for person '" + pid + "'.");
    1079            0 :                 return;
    1080              :             }
    1081           25 :             myVehicleParameter->depart = vehDepart + 1; // write person after vehicle
    1082              :         } else {
    1083              :             if (mySkippedVehicles.count(vehID) == 0) {
    1084           20 :                 myErrorOutput->inform("Unknown vehicle '" + vehID + "' in triggered departure for person '" + pid + "'.");
    1085           10 :                 return;
    1086              :             }
    1087           10 :             myVehicleParameter->departProcedure = DepartDefinition::GIVEN; // make sure the person gets skipped due to depart time
    1088              :         }
    1089           45 :     }
    1090          120 :     ROPerson::addRide(plan, from, to, lines, arrivalPos, stoppingPlaceID, group);
    1091              : }
    1092              : 
    1093              : 
    1094              : void
    1095           40 : RORouteHandler::addTransport(const SUMOSAXAttributes& attrs) {
    1096           40 :     if (myActiveContainerPlan != nullptr && myActiveContainerPlanSize == 0 && myVehicleParameter->departProcedure == DepartDefinition::TRIGGERED) {
    1097           15 :         bool ok = true;
    1098              :         const std::string pid = myVehicleParameter->id;
    1099           15 :         const std::string desc = attrs.get<std::string>(SUMO_ATTR_LINES, pid.c_str(), ok);
    1100           20 :         StringTokenizer st(desc);
    1101           15 :         if (st.size() != 1) {
    1102            0 :             throw ProcessError(TLF("Triggered departure for container '%' requires a unique lines value.", pid));
    1103              :         }
    1104           15 :         const std::string vehID = st.front();
    1105           15 :         if (!myNet.knowsVehicle(vehID)) {
    1106              :             if (mySkippedVehicles.count(vehID) == 0) {
    1107           15 :                 throw ProcessError("Unknown vehicle '" + vehID + "' in triggered departure for container '" + pid + "'.");
    1108              :             }
    1109              :             return;
    1110              :         }
    1111           10 :         SUMOTime vehDepart = myNet.getDeparture(vehID);
    1112           10 :         if (vehDepart == -1) {
    1113            0 :             throw ProcessError("Cannot use triggered vehicle '" + vehID + "' in triggered departure for container '" + pid + "'.");
    1114              :         }
    1115           10 :         myVehicleParameter->depart = vehDepart + 1; // write container after vehicle
    1116           15 :     }
    1117              : }
    1118              : 
    1119              : 
    1120              : void
    1121           40 : RORouteHandler::addTranship(const SUMOSAXAttributes& /*attrs*/) {
    1122           40 : }
    1123              : 
    1124              : 
    1125              : void
    1126       790293 : RORouteHandler::parseEdges(const std::string& desc, ConstROEdgeVector& into,
    1127              :                            const std::string& rid, bool& ok) {
    1128      3250287 :     for (StringTokenizer st(desc); st.hasNext();) {
    1129      1669701 :         const std::string id = st.next();
    1130      1669701 :         const ROEdge* edge = myNet.getEdge(id);
    1131      1669701 :         if (edge == nullptr) {
    1132          102 :             myErrorOutput->inform("The edge '" + id + "' within the route " + rid + " is not known.");
    1133           51 :             ok = false;
    1134              :         } else {
    1135      1669650 :             into.push_back(edge);
    1136              :         }
    1137       790293 :     }
    1138       790293 : }
    1139              : 
    1140              : 
    1141              : void
    1142         3538 : RORouteHandler::parseWalkPositions(const SUMOSAXAttributes& attrs, const std::string& personID,
    1143              :                                    const ROEdge* /*fromEdge*/, const ROEdge*& toEdge,
    1144              :                                    double& departPos, double& arrivalPos, std::string& busStopID,
    1145              :                                    const ROPerson::PlanItem* const lastStage, bool& ok) {
    1146         3538 :     const std::string description = "walk or personTrip of '" + personID + "'.";
    1147         3538 :     if (attrs.hasAttribute(SUMO_ATTR_DEPARTPOS)) {
    1148            0 :         WRITE_WARNING(TL("The attribute departPos is no longer supported for walks, please use the person attribute, the arrivalPos of the previous step or explicit stops."));
    1149              :     }
    1150         3538 :     departPos = myVehicleParameter->departPos;
    1151         3538 :     if (lastStage != nullptr) {
    1152          170 :         departPos = lastStage->getDestinationPos();
    1153              :     }
    1154              : 
    1155         3538 :     busStopID = attrs.getOpt<std::string>(SUMO_ATTR_BUS_STOP, nullptr, ok, "");
    1156              : 
    1157         3538 :     const SUMOVehicleParameter::Stop* bs = retrieveStoppingPlace(attrs, description, busStopID);
    1158         3538 :     if (bs != nullptr) {
    1159          465 :         toEdge = myNet.getEdge(SUMOXMLDefinitions::getEdgeIDFromLane(bs->lane));
    1160          155 :         arrivalPos = (bs->startPos + bs->endPos) / 2;
    1161              :     }
    1162         3538 :     if (toEdge != nullptr) {
    1163         3538 :         if (attrs.hasAttribute(SUMO_ATTR_ARRIVALPOS)) {
    1164          258 :             arrivalPos = SUMOVehicleParserHelper::parseWalkPos(SUMO_ATTR_ARRIVALPOS,
    1165          258 :                          myHardFail, description, toEdge->getLength(),
    1166          516 :                          attrs.get<std::string>(SUMO_ATTR_ARRIVALPOS, description.c_str(), ok));
    1167              :         }
    1168              :     } else {
    1169            0 :         throw ProcessError(TLF("No destination edge for %.", description));
    1170              :     }
    1171         3538 : }
    1172              : 
    1173              : 
    1174              : void
    1175         3538 : RORouteHandler::addPersonTrip(const SUMOSAXAttributes& attrs) {
    1176         3538 :     bool ok = true;
    1177         3538 :     const char* const id = myVehicleParameter->id.c_str();
    1178              :     assert(!attrs.hasAttribute(SUMO_ATTR_EDGES));
    1179              :     const ROEdge* from = nullptr;
    1180         3538 :     const ROEdge* to = nullptr;
    1181         3538 :     parseFromViaTo(SUMO_TAG_PERSON, attrs, ok);
    1182         3538 :     myInsertStopEdgesAt = -1;
    1183         4218 :     if (attrs.hasAttribute(SUMO_ATTR_FROM) || attrs.hasAttribute(SUMO_ATTR_FROM_JUNCTION) || attrs.hasAttribute(SUMO_ATTR_FROM_TAZ)
    1184         3723 :             || attrs.hasAttribute(SUMO_ATTR_FROMLONLAT) || attrs.hasAttribute(SUMO_ATTR_FROMXY)) {
    1185         3373 :         if (ok) {
    1186         3358 :             from = myActiveRoute.front();
    1187              :         }
    1188          165 :     } else if (myActivePlan->empty()) {
    1189            0 :         throw ProcessError(TLF("Start edge not defined for person '%'.", myVehicleParameter->id));
    1190              :     } else {
    1191          165 :         from = myActivePlan->back()->getDestination();
    1192              :     }
    1193         4198 :     if (attrs.hasAttribute(SUMO_ATTR_TO) || attrs.hasAttribute(SUMO_ATTR_TO_JUNCTION) || attrs.hasAttribute(SUMO_ATTR_TO_TAZ)
    1194         3713 :             || attrs.hasAttribute(SUMO_ATTR_TOLONLAT) || attrs.hasAttribute(SUMO_ATTR_TOXY)) {
    1195         3383 :         to = myActiveRoute.back();
    1196              :     } // else, to may also be derived from stopping place
    1197              : 
    1198         3538 :     const SUMOTime duration = attrs.getOptSUMOTimeReporting(SUMO_ATTR_DURATION, id, ok, -1);
    1199         3538 :     if (attrs.hasAttribute(SUMO_ATTR_DURATION) && duration <= 0) {
    1200            0 :         throw ProcessError(TLF("Non-positive walking duration for '%'.", myVehicleParameter->id));
    1201              :     }
    1202              : 
    1203         3538 :     double departPos = 0;
    1204         3538 :     double arrivalPos = std::numeric_limits<double>::infinity();
    1205              :     std::string busStopID;
    1206         3538 :     const ROPerson::PlanItem* const lastStage = myActivePlan->empty() ? nullptr : myActivePlan->back();
    1207         3538 :     parseWalkPositions(attrs, myVehicleParameter->id, from, to, departPos, arrivalPos, busStopID, lastStage, ok);
    1208              : 
    1209         3538 :     const std::string modes = attrs.getOpt<std::string>(SUMO_ATTR_MODES, id, ok, "");
    1210         7076 :     const std::string group = attrs.getOpt<std::string>(SUMO_ATTR_GROUP, id, ok, "");
    1211              :     SVCPermissions modeSet = 0;
    1212         9770 :     for (StringTokenizer st(modes); st.hasNext();) {
    1213         2694 :         const std::string mode = st.next();
    1214         2694 :         if (mode == "car") {
    1215          855 :             modeSet |= SVC_PASSENGER;
    1216         1839 :         } else if (mode == "taxi") {
    1217          105 :             modeSet |= SVC_TAXI;
    1218         1734 :         } else if (mode == "bicycle") {
    1219           15 :             modeSet |= SVC_BICYCLE;
    1220         1719 :         } else if (mode == "public") {
    1221         1719 :             modeSet |= SVC_BUS;
    1222              :         } else {
    1223            0 :             throw InvalidArgument("Unknown person mode '" + mode + "'.");
    1224              :         }
    1225         3538 :     }
    1226         3538 :     const std::string types = attrs.getOpt<std::string>(SUMO_ATTR_VTYPES, id, ok, "");
    1227         3538 :     double walkFactor = attrs.getOpt<double>(SUMO_ATTR_WALKFACTOR, id, ok, OptionsCont::getOptions().getFloat("persontrip.walkfactor"));
    1228         3538 :     if (ok) {
    1229         3523 :         const std::string originStopID = myActivePlan->empty() ?  "" : myActivePlan->back()->getStopDest();
    1230         3523 :         ROPerson::addTrip(*myActivePlan, myVehicleParameter->id, from, to, modeSet, types,
    1231              :                           departPos, originStopID, arrivalPos, busStopID, walkFactor, group);
    1232         3523 :         myParamStack.push_back(myActivePlan->back());
    1233              :     }
    1234         3538 : }
    1235              : 
    1236              : 
    1237              : void
    1238         1324 : RORouteHandler::addWalk(const SUMOSAXAttributes& attrs) {
    1239              :     // parse walks from->to as person trips
    1240         1324 :     if (attrs.hasAttribute(SUMO_ATTR_EDGES) || attrs.hasAttribute(SUMO_ATTR_ROUTE)) {
    1241              :         // XXX allow --repair?
    1242           90 :         bool ok = true;
    1243           90 :         if (attrs.hasAttribute(SUMO_ATTR_ROUTE)) {
    1244           15 :             const std::string routeID = attrs.get<std::string>(SUMO_ATTR_ROUTE, myVehicleParameter->id.c_str(), ok);
    1245           30 :             RORouteDef* routeDef = myNet.getRouteDef(routeID);
    1246           15 :             const std::shared_ptr<const RORoute> route = routeDef != nullptr ? routeDef->getFirstRoute() : nullptr;
    1247           15 :             if (route == nullptr) {
    1248            0 :                 throw ProcessError("The route '" + routeID + "' for walk of person '" + myVehicleParameter->id + "' is not known.");
    1249              :             }
    1250           15 :             myActiveRoute = route->getEdgeVector();
    1251              :         } else {
    1252              :             myActiveRoute.clear();
    1253          300 :             parseEdges(attrs.get<std::string>(SUMO_ATTR_EDGES, myVehicleParameter->id.c_str(), ok), myActiveRoute, " walk for person '" + myVehicleParameter->id + "'", ok);
    1254              :         }
    1255           90 :         const char* const objId = myVehicleParameter->id.c_str();
    1256           90 :         const double duration = attrs.getOpt<double>(SUMO_ATTR_DURATION, objId, ok, -1);
    1257           90 :         if (attrs.hasAttribute(SUMO_ATTR_DURATION) && duration <= 0) {
    1258            0 :             throw ProcessError(TLF("Non-positive walking duration for '%'.", myVehicleParameter->id));
    1259              :         }
    1260           90 :         const double speed = attrs.getOpt<double>(SUMO_ATTR_SPEED, objId, ok, -1.);
    1261           90 :         if (attrs.hasAttribute(SUMO_ATTR_SPEED) && speed <= 0) {
    1262            0 :             throw ProcessError(TLF("Non-positive walking speed for '%'.", myVehicleParameter->id));
    1263              :         }
    1264              :         double departPos = 0.;
    1265              :         double arrivalPos = std::numeric_limits<double>::infinity();
    1266           90 :         if (attrs.hasAttribute(SUMO_ATTR_DEPARTPOS)) {
    1267            0 :             WRITE_WARNING(TL("The attribute departPos is no longer supported for walks, please use the person attribute, the arrivalPos of the previous step or explicit stops."));
    1268              :         }
    1269           90 :         if (attrs.hasAttribute(SUMO_ATTR_ARRIVALPOS)) {
    1270           40 :             arrivalPos = SUMOVehicleParserHelper::parseWalkPos(SUMO_ATTR_ARRIVALPOS, myHardFail, objId, myActiveRoute.back()->getLength(), attrs.get<std::string>(SUMO_ATTR_ARRIVALPOS, objId, ok));
    1271              :         }
    1272              :         std::string stoppingPlaceID;
    1273           90 :         const std::string errorSuffix = " for walk of person '" + myVehicleParameter->id + "'";
    1274           90 :         retrieveStoppingPlace(attrs, errorSuffix, stoppingPlaceID);
    1275           90 :         if (ok) {
    1276           90 :             ROPerson::addWalk(*myActivePlan, myActiveRoute, duration, speed, departPos, arrivalPos, stoppingPlaceID);
    1277           90 :             myParamStack.push_back(myActivePlan->back());
    1278              :         }
    1279              :     } else {
    1280         1234 :         addPersonTrip(attrs);
    1281              :     }
    1282         1324 : }
    1283              : 
    1284              : 
    1285              : void
    1286           95 : RORouteHandler::initLaneTree(NamedRTree* tree) {
    1287         7571 :     for (const auto& edgeItem : myNet.getEdgeMap()) {
    1288        14099 :         for (ROLane* lane : edgeItem.second->getLanes()) {
    1289         6623 :             Boundary b = lane->getShape().getBoxBoundary();
    1290         6623 :             const float cmin[2] = {(float) b.xmin(), (float) b.ymin()};
    1291         6623 :             const float cmax[2] = {(float) b.xmax(), (float) b.ymax()};
    1292         6623 :             tree->Insert(cmin, cmax, lane);
    1293              :         }
    1294              :     }
    1295           95 : }
    1296              : 
    1297              : 
    1298              : ROEdge*
    1299          620 : RORouteHandler::retrieveEdge(const std::string& id) {
    1300          620 :     return myNet.getEdge(id);
    1301              : }
    1302              : 
    1303              : 
    1304              : const SUMOVTypeParameter*
    1305         2617 : RORouteHandler::getVTypeParameter(const std::string& refid) {
    1306         2617 :     if (refid == "") {
    1307              :         return nullptr;
    1308              :     }
    1309           20 :     if (!myNet.knowsVType(refid)) {
    1310            0 :         myErrorOutput->inform(TLF("Unknown vehicle type '%'.", refid));
    1311            0 :         return nullptr;
    1312              :     }
    1313           20 :     return myNet.getVehicleTypeSecure(refid);
    1314              : }
    1315              : 
    1316              : 
    1317              : bool
    1318       288764 : RORouteHandler::checkLastDepart() {
    1319       288764 :     if (!myUnsortedInput) {
    1320       287752 :         return SUMORouteHandler::checkLastDepart();
    1321              :     }
    1322              :     return true;
    1323              : }
    1324              : 
    1325              : 
    1326              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1