Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/web/docs/duarouter.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ Such a *routeDistribution* is used during [dynamic user assignment
(DUA)](Demand/Dynamic_User_Assignment.md) but can also be loaded
directly into [sumo](sumo.md).

With **--named-routes**, stops declared on a named input route stay on the corresponding named output route, including after repair. Their arrival and until times remain relative to each departure. Stops declared on a vehicle or flow stay with that demand item.

## Options

You may use a XML schema definition file for setting up a duarouter
Expand Down
22 changes: 21 additions & 1 deletion src/router/RORoute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "RORoute.h"
#include "ROHelper.h"
#include <utils/common/iodevices/OutputDevice.h>
#include <utils/sysframe/XMLHelpers.h>


// ===========================================================================
Expand Down Expand Up @@ -146,7 +147,7 @@ RORoute::writeXMLDefinition(OutputDevice& dev, const ROVehicle* const veh,
const bool asAlternatives,
const bool withExitTimes,
const bool withLength,
const std::string& id) const {
const std::string& id, const StopParVector* stops) const {
dev.openTag(SUMO_TAG_ROUTE);
if (id != "") {
dev.writeAttr(SUMO_ATTR_ID, id);
Expand Down Expand Up @@ -181,9 +182,28 @@ RORoute::writeXMLDefinition(OutputDevice& dev, const ROVehicle* const veh,
}
dev.writeAttr("routeLength", length);
}
if (stops != nullptr) {
writeNamedRouteStops(dev, *stops);
}
dev.closeTag();
return dev;
}


void
RORoute::writeNamedRouteStops(OutputDevice& dev, const StopParVector& stops) {
for (const auto& stop : stops) {
// An explicit zero matters when a vehicle stop is inserted before a route stop.
if (stop.index == 0) {
stop.write(dev, false);
dev.writeAttr(SUMO_ATTR_INDEX, 0);
XMLHelpers::writeParams(dev, stop);
dev.closeTag();
} else {
stop.write(dev);
}
}
}


/****************************************************************************/
5 changes: 4 additions & 1 deletion src/router/RORoute.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class RORoute : public Named {
writeXMLDefinition(OutputDevice& dev, const ROVehicle* const veh,
const bool withCosts, const bool asAlternatives,
const bool withExitTimes, const bool withLength,
const std::string& id = "") const;
const std::string& id = "", const StopParVector* stops = nullptr) const;

/** @brief add additional vehicles/probability
*/
Expand All @@ -195,6 +195,9 @@ class RORoute : public Named {
*/
void addStopOffset(const SUMOTime offset);

/// @brief Write the stops of a named route or its vehicle in their original insertion order.
static void writeNamedRouteStops(OutputDevice& dev, const StopParVector& stops);

/// @brief return edges that shall be written in the route definition
ConstROEdgeVector getNormalEdges() const;

Expand Down
60 changes: 45 additions & 15 deletions src/router/ROVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <utils/vehicle/SUMOVTypeParameter.h>
#include <utils/options/OptionsCont.h>
#include <utils/common/iodevices/OutputDevice.h>
#include <utils/common/iodevices/OutputDevice_String.h>
#include <utils/sysframe/XMLHelpers.h>
#include "RORouteDef.h"
#include "RORoute.h"
Expand All @@ -44,7 +45,7 @@
// ===========================================================================
// static members
// ===========================================================================
std::map<ConstROEdgeVector, std::string> ROVehicle::mySavedRoutes;
std::map<ROVehicle::NamedRouteKey, std::string> ROVehicle::mySavedRoutes;

// ===========================================================================
// method definitions
Expand All @@ -56,26 +57,43 @@ ROVehicle::ROVehicle(const SUMOVehicleParameter& pars,
myRoute(route),
myJumpTime(-1) {
getParameter().stops.clear();
if (route != nullptr && route->getFirstRoute() != nullptr) {
for (StopParVector::const_iterator s = route->getFirstRoute()->getStops().begin(); s != route->getFirstRoute()->getStops().end(); ++s) {
addStop(*s, net, errorHandler);
const auto firstRoute = route != nullptr ? route->getFirstRoute() : nullptr;
if (firstRoute != nullptr) {
const auto& stops = firstRoute->getStops();
const auto& options = OptionsCont::getOptions();
const bool preserveNamedStops = !stops.empty() && !pars.routeid.empty() && pars.routeid.front() != '!'
&& options.exists("named-routes") && options.getBool("named-routes");
const auto* original = preserveNamedStops ? net->getRouteDef(pars.routeid) : nullptr;
const auto stopTemplate = original != nullptr ? original->getFirstRoute() : nullptr;
if (stopTemplate != nullptr && stopTemplate->getStops().size() == stops.size()) {
myNamedRouteStops = std::make_unique<NamedRouteStops>();
}
for (size_t i = 0; i < stops.size(); ++i) {
if (addStop(stops[i], net, errorHandler) && myNamedRouteStops != nullptr) {
myNamedRouteStops->route.push_back(stopTemplate->getStops()[i]);
}
}
}
for (StopParVector::const_iterator s = pars.stops.begin(); s != pars.stops.end(); ++s) {
addStop(*s, net, errorHandler);
if (myNamedRouteStops != nullptr && myNamedRouteStops->route.empty()) {
myNamedRouteStops.reset();
}
for (const auto& stop : pars.stops) {
if (addStop(stop, net, errorHandler) && myNamedRouteStops != nullptr) {
myNamedRouteStops->vehicle.push_back(stop);
}
}
}


void
bool
ROVehicle::addStop(const SUMOVehicleParameter::Stop& stopPar, const RONet* net, MsgHandler* errorHandler) {
const ROEdge* stopEdge = net->getEdge(stopPar.edge);
assert(stopEdge != 0); // was checked when parsing the stop
if (stopEdge->prohibits(this)) {
if (errorHandler != nullptr) {
errorHandler->informf(TL("Stop edge '%' does not allow vehicle '%'."), stopEdge->getID(), getID());
}
return;
return false;
}
// where to insert the stop
StopParVector::iterator iter = getParameter().stops.begin();
Expand Down Expand Up @@ -103,6 +121,7 @@ ROVehicle::addStop(const SUMOVehicleParameter::Stop& stopPar, const RONet* net,
myJumpTime += stopPar.jump;
}
}
return true;
}


Expand Down Expand Up @@ -268,15 +287,22 @@ ROVehicle::saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAltern
const bool writeLength = options.exists("route-length") && options.getBool("route-length");
const bool writeFlow = options.exists("keep-flows") && options.getBool("keep-flows") && isPartOfFlow();

const auto* namedStops = writeNamedRoute && !writeTrip ? myNamedRouteStops.get() : nullptr;
std::string routeID;
if (writeNamedRoute) {
ConstROEdgeVector edges = myRoute->getUsedRoute()->getNormalEdges();
auto it = mySavedRoutes.find(edges);
const auto usedRoute = myRoute->getUsedRoute();
NamedRouteKey key(usedRoute->getNormalEdges(), "");
if (namedStops != nullptr) {
OutputDevice_String stopXML;
RORoute::writeNamedRouteStops(stopXML, namedStops->route);
key.second = stopXML.getString();
}
const auto it = mySavedRoutes.find(key);
if (it == mySavedRoutes.end()) {
routeID = "r" + toString(mySavedRoutes.size());
myRoute->getUsedRoute()->writeXMLDefinition(os, this, writeCosts, false, writeExit,
writeLength, routeID);
mySavedRoutes[edges] = routeID;
usedRoute->writeXMLDefinition(os, this, writeCosts, false, writeExit, writeLength, routeID,
namedStops == nullptr ? nullptr : &namedStops->route);
mySavedRoutes.emplace(std::move(key), routeID);
} else {
routeID = it->second;
}
Expand Down Expand Up @@ -390,8 +416,12 @@ ROVehicle::saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAltern
} else {
myRoute->writeXMLDefinition(os, this, asAlternatives, writeExit, writeCosts, writeLength);
}
for (StopParVector::const_iterator stop = getParameter().stops.begin(); stop != getParameter().stops.end(); ++stop) {
stop->write(os);
if (namedStops != nullptr) {
RORoute::writeNamedRouteStops(os, namedStops->vehicle);
} else {
for (const auto& stop : getParameter().stops) {
stop.write(os);
}
}
XMLHelpers::writeParams(os, getParameter());
os.closeTag();
Expand Down
15 changes: 12 additions & 3 deletions src/router/ROVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <string>
#include <iostream>
#include <memory>
#include <utils/common/StdDefs.h>
#include <utils/common/SUMOTime.h>
#include <utils/vehicle/SUMOVehicleParameter.h>
Expand Down Expand Up @@ -148,7 +149,7 @@ class ROVehicle : public RORoutable {
* @param[in] stopPar the stop parameters
* @param[in] net pointer to the network, used for edge retrieval
*/
void addStop(const SUMOVehicleParameter::Stop& stopPar,
bool addStop(const SUMOVehicleParameter::Stop& stopPar,
const RONet* net, MsgHandler* errorHandler);

/// @brief update departEdge / arrivalEdge
Expand All @@ -161,8 +162,16 @@ class ROVehicle : public RORoutable {
/// @brief Whether this vehicle has any jumps defined
SUMOTime myJumpTime;

/// @brief map of all routes that were already saved with a name
static std::map<ConstROEdgeVector, std::string> mySavedRoutes;
/// @brief Accepted route-relative and vehicle-specific stops in input order.
struct NamedRouteStops {
StopParVector route;
StopParVector vehicle;
};
std::unique_ptr<NamedRouteStops> myNamedRouteStops;

/// @brief Reuse a written route only when its edges and stops match.
using NamedRouteKey = std::pair<ConstROEdgeVector, std::string>;
static std::map<NamedRouteKey, std::string> mySavedRoutes;

private:
/// @brief Invalidated copy constructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- generated on 10/02/13 10:36:54 by SUMO duarouter Version dev-SVN-r14787
<!-- generated on 2026-12-03T20:14:50.290652+00:00 by Eclipse SUMO duarouter v1.28.0
This data file and the accompanying materials
are made available under the terms of the Eclipse Public License v2.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v20.html
SPDX-License-Identifier: EPL-2.0
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/duarouterConfiguration.xsd">
This file may also be made available under the following Secondary
Licenses when the conditions for such availability set forth in the Eclipse
Public License 2.0 are satisfied: GNU General Public License, version 2
or later which is available at
https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
<duarouterConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/duarouterConfiguration.xsd">

<input>
<net-file value="input_net.net.xml"/>
Expand All @@ -15,27 +20,41 @@ SPDX-License-Identifier: EPL-2.0

<output>
<output-file value="routes.rou.xml"/>
<named-routes value="true"/>
<write-license value="true"/>
</output>

<processing>
<repair value="true"/>
</processing>

<report>
<xml-validation value="never"/>
<no-step-log value="true"/>
</report>

</configuration>
</duarouterConfiguration>
-->

<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/routes_file.xsd">
<vehicle id="0" depart="0.00">
<routeDistribution last="0">
<route cost="125.90" probability="1.00000000" edges="beg middle end rend"/>
</routeDistribution>
<stop lane="middle_0"/>
<stop lane="middle_0" arrival="12.00" until="20.00"/>
</vehicle>
<vehicle id="1" depart="5.00">
<routeDistribution last="0">
<route cost="125.90" probability="1.00000000" edges="beg middle end rend"/>
</routeDistribution>
<stop lane="middle_0" arrival="17.00" until="25.00"/>
<stop lane="end_0" until="90.00"/>
</vehicle>
<vehicle id="1" depart="0.00">
<vehicle id="2" depart="6.00">
<routeDistribution last="0">
<route cost="125.90" probability="1.00000000" edges="beg middle end rend"/>
</routeDistribution>
<stop lane="middle_0"/>
<stop lane="end_0"/>
<stop lane="beg_0" duration="1.00"/>
<stop lane="middle_0" arrival="38.00" until="46.00"/>
</vehicle>
</routes>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Warning: Repaired route of vehicle '0'.
Warning: Repaired route of vehicle '1'.
Warning: Repaired route of vehicle '2'.
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/routes_file.xsd">
<route id="r1" edges="beg middle end rend">
<stop lane="middle_0"/>
<route id="r1" edges="beg end rend">
<stop lane="middle_0" arrival="12" until="20"/>
</route>
<route id="r2" edges="beg end rend">
<stop lane="middle_0" arrival="32" until="40"/>
</route>
<vehicle id="0" depart="0" route="r1"/>
<vehicle id="1" depart="0" route="r1">
<stop lane="end_0"/>
<vehicle id="1" depart="5" route="r1">
<stop lane="end_0" until="90"/>
</vehicle>
<vehicle id="2" depart="6" route="r2">
<stop lane="beg_0" index="0" duration="1"/>
</vehicle>
</routes>
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
--net-file=input_net.net.xml --route-files=input_routes.rou.xml -o routes.rou.xml
--named-routes
--repair
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- generated on 2026-03-18T09:38:40.717759+01:00 by Eclipse SUMO duarouter v1_26_0+0681-24276172851
<!-- generated on 2026-12-03T20:14:50.290284+00:00 by Eclipse SUMO duarouter v1.28.0
This data file and the accompanying materials
are made available under the terms of the Eclipse Public License v2.0
which accompanies this distribution, and is available at
Expand All @@ -24,6 +24,10 @@ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
<write-license value="true"/>
</output>

<processing>
<repair value="true"/>
</processing>

<report>
<xml-validation value="never"/>
<no-step-log value="true"/>
Expand All @@ -33,12 +37,17 @@ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
-->

<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/routes_file.xsd">
<route id="r0" edges="beg middle end rend"/>
<vehicle id="0" depart="0.00" route="r0">
<stop lane="middle_0"/>
<route id="r0" edges="beg middle end rend">
<stop lane="middle_0" arrival="12.00" until="20.00"/>
</route>
<vehicle id="0" depart="0.00" route="r0"/>
<vehicle id="1" depart="5.00" route="r0">
<stop lane="end_0" until="90.00"/>
</vehicle>
<vehicle id="1" depart="0.00" route="r0">
<stop lane="middle_0"/>
<stop lane="end_0"/>
<route id="r1" edges="beg middle end rend">
<stop lane="middle_0" arrival="32.00" until="40.00"/>
</route>
<vehicle id="2" depart="6.00" route="r1">
<stop lane="beg_0" duration="1.00" index="0"/>
</vehicle>
</routes>
Loading