Skip to content

Commit

Permalink
fix #8353
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Dec 6, 2024
1 parent 7414bf1 commit 3f53ed1
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 18 deletions.
7 changes: 7 additions & 0 deletions src/duarouter/RODUAFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ RODUAFrame::addImportOptions() {

oc.doRegister("astar.save-landmark-distances", new Option_FileName());
oc.addDescription("astar.save-landmark-distances", "Processing", TL("Save lookup table for astar ALT-variant to the given file"));

oc.doRegister("scale", new Option_Float(1.));
oc.addDescription("scale", "Processing", TL("Scale demand by the given factor (by discarding or duplicating vehicles)"));

oc.doRegister("scale-suffix", new Option_String("."));
oc.addDescription("scale-suffix", "Processing", TL("Suffix to be added when creating ids for cloned vehicles"));

}


Expand Down
4 changes: 3 additions & 1 deletion src/router/RONet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ RONet::saveAndRemoveRoutesUntil(OptionsCont& options, const RORouterProvider& pr
myThreadPool.waitAll();
#endif
}
const double scale = options.exists("scale-suffix") ? options.getFloat("scale") : 1;
// write all vehicles (and additional structures)
while (myRoutables.size() != 0 || myContainers.size() != 0) {
// get the next vehicle, person or container
Expand All @@ -752,7 +753,8 @@ RONet::saveAndRemoveRoutesUntil(OptionsCont& options, const RORouterProvider& pr
// ok, check whether it has been routed
if (r->getRoutingSuccess()) {
// write the route
r->write(myRoutesOutput, myRouteAlternativesOutput, myTypesOutput, options);
int quota = getScalingQuota(scale, myWrittenRouteNo);
r->write(myRoutesOutput, myRouteAlternativesOutput, myTypesOutput, options, quota);
myWrittenRouteNo++;
} else {
myDiscardedRouteNo++;
Expand Down
11 changes: 9 additions & 2 deletions src/router/ROPerson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ ROPerson::computeRoute(const RORouterProvider& provider,


void
ROPerson::saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options) const {
ROPerson::saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options, int cloneIndex) const {
// write the person's vehicles
const bool writeTrip = options.exists("write-trips") && options.getBool("write-trips");
if (!writeTrip) {
Expand All @@ -469,7 +469,14 @@ ROPerson::saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAlterna
}

// write the person
getParameter().write(os, options, SUMO_TAG_PERSON);
if (cloneIndex == 0) {
getParameter().write(os, options, SUMO_TAG_PERSON);
} else {
SUMOVehicleParameter p = getParameter();
// @note id collisions may occur if scale-suffic occurs in other vehicle ids
p.id += options.getString("scale-suffix") + toString(cloneIndex);
p.write(os, options, SUMO_TAG_PERSON);
}

for (const PlanItem* const it : myPlan) {
it->saveAsXML(os, asAlternatives, writeTrip, options);
Expand Down
2 changes: 1 addition & 1 deletion src/router/ROPerson.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ class ROPerson : public RORoutable {
* @param[in] options to find out about defaults and whether exit times for the edges shall be written
* @exception IOError If something fails (not yet implemented)
*/
void saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options) const;
void saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options, int cloneIndex=0) const;

std::vector<PlanItem*>& getPlan() {
return myPlan;
Expand Down
22 changes: 12 additions & 10 deletions src/router/RORoutable.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,18 @@ class RORoutable {
* @exception IOError If something fails (not yet implemented)
*/
void write(OutputDevice* os, OutputDevice* const altos,
OutputDevice* const typeos, OptionsCont& options) const {
if (os != nullptr) {
if (altos == nullptr && typeos == nullptr) {
saveAsXML(*os, os, false, options);
} else {
saveAsXML(*os, typeos, false, options);
OutputDevice* const typeos, OptionsCont& options, int quota) const {
for (int i = 0; i < quota; i++) {
if (os != nullptr) {
if (altos == nullptr && typeos == nullptr) {
saveAsXML(*os, os, false, options, i);
} else {
saveAsXML(*os, typeos, false, options, i);
}
}
if (altos != nullptr) {
saveAsXML(*altos, typeos, true, options, i);
}
}
if (altos != nullptr) {
saveAsXML(*altos, typeos, true, options);
}
}

Expand All @@ -176,7 +178,7 @@ class RORoutable {
* @param[in] options to find out about defaults and whether exit times for the edges shall be written
* @exception IOError If something fails (not yet implemented)
*/
virtual void saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options) const = 0;
virtual void saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options, int cloneIndex=0) const = 0;


private:
Expand Down
12 changes: 9 additions & 3 deletions src/router/ROVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ ROVehicle::collectJumps(const ConstROEdgeVector& mandatory, std::set<ConstROEdge


void
ROVehicle::saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options) const {
ROVehicle::saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options, int cloneIndex) const {
if (typeos != nullptr && getType() != nullptr && !getType()->saved) {
getType()->write(*typeos);
getType()->saved = true;
Expand Down Expand Up @@ -268,8 +268,14 @@ ROVehicle::saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAltern
}
}
// write the vehicle (new style, with included routes)
getParameter().write(os, options, writeTrip ? SUMO_TAG_TRIP : SUMO_TAG_VEHICLE);

if (cloneIndex == 0) {
getParameter().write(os, options, writeTrip ? SUMO_TAG_TRIP : SUMO_TAG_VEHICLE);
} else {
SUMOVehicleParameter p = getParameter();
// @note id collisions may occur if scale-suffic occurs in other vehicle ids
p.id += options.getString("scale-suffix") + toString(cloneIndex);
p.write(os, options, writeTrip ? SUMO_TAG_TRIP : SUMO_TAG_VEHICLE);
}
// save the route
if (writeTrip) {
const ConstROEdgeVector edges = myRoute->getFirstRoute()->getEdgeVector();
Expand Down
2 changes: 1 addition & 1 deletion src/router/ROVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class ROVehicle : public RORoutable {
* @param[in] options to find out about defaults and whether exit times for the edges shall be written
* @exception IOError If something fails (not yet implemented)
*/
void saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options) const;
void saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options, int cloneIndex=0) const;


private:
Expand Down

0 comments on commit 3f53ed1

Please sign in to comment.