Skip to content

Commit

Permalink
refactoring router names to have everything in one place #12
Browse files Browse the repository at this point in the history
  • Loading branch information
behrisch committed Dec 21, 2023
1 parent f821400 commit 86c0ad2
Show file tree
Hide file tree
Showing 23 changed files with 152 additions and 74 deletions.
6 changes: 3 additions & 3 deletions src/libsumo/Simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ Simulation::findIntermodalRoute(const std::string& from, const std::string& to,
throw TraCIException("Invalid arrival position " + toString(arrivalPos) + " for edge '" + to + "'.");
}
double minCost = std::numeric_limits<double>::max();
MSNet::MSIntermodalRouter& router = MSNet::getInstance()->getIntermodalRouter(0, routingMode);
MSTransportableRouter& router = MSNet::getInstance()->getIntermodalRouter(0, routingMode);
for (SUMOVehicleParameter* vehPar : pars) {
std::vector<TraCIStage> resultCand;
SUMOVehicle* vehicle = nullptr;
Expand All @@ -704,11 +704,11 @@ Simulation::findIntermodalRoute(const std::string& from, const std::string& to,
vehicle->setChosenSpeedFactor(type->getSpeedFactor().getParameter()[0]);
}
}
std::vector<MSNet::MSIntermodalRouter::TripItem> items;
std::vector<MSTransportableRouter::TripItem> items;
if (router.compute(fromEdge, toEdge, departPos, "", arrivalPos, destStop,
speed * walkFactor, vehicle, modeSet, departStep, items, externalFactor)) {
double cost = 0;
for (std::vector<MSNet::MSIntermodalRouter::TripItem>::iterator it = items.begin(); it != items.end(); ++it) {
for (std::vector<MSTransportableRouter::TripItem>::iterator it = items.begin(); it != items.end(); ++it) {
if (!it->edges.empty()) {
resultCand.push_back(TraCIStage((it->line == "" ? STAGE_WALKING : STAGE_DRIVING), it->vType, it->line, it->destStop));
for (const MSEdge* e : it->edges) {
Expand Down
1 change: 1 addition & 0 deletions src/microsim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ set(microsim_STAT_SRCS
MSRoute.h
MSRouteHandler.cpp
MSRouteHandler.h
MSRouterDefs.h
MSStop.cpp
MSStop.h
MSStoppingPlace.cpp
Expand Down
12 changes: 5 additions & 7 deletions src/microsim/MSEdgeControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <utils/router/SUMOAbstractRouter.h>
#include <utils/router/RouterProvider.h>
#include <utils/vehicle/SUMOVehicle.h>
#include <microsim/MSRouterDefs.h>

#include <utils/foxtools/MFXSynchQue.h>
#include <utils/foxtools/MFXSynchSet.h>
Expand All @@ -54,12 +55,8 @@
// ===========================================================================
// class declarations
// ===========================================================================
class MSEdge;
class MSLane;
class MSJunction;
class OutputDevice;

typedef std::vector<MSEdge*> MSEdgeVector;

// ===========================================================================
// class definitions
Expand All @@ -81,8 +78,6 @@ typedef std::vector<MSEdge*> MSEdgeVector;
class MSEdgeControl {

public:
typedef RouterProvider<MSEdge, MSLane, MSJunction, SUMOVehicle> MSRouterProvider;

/** @brief Constructor
*
* Builds LaneUsage information for each lane and assigns them to lanes.
Expand Down Expand Up @@ -251,9 +246,12 @@ class MSEdgeControl {
}
return false;
}
SUMOAbstractRouter<MSEdge, SUMOVehicle>& getRouter(SUMOVehicleClass svc) const {
MSVehicleRouter& getRouter(SUMOVehicleClass svc) const {
return myRouterProvider->getVehicleRouter(svc);
}
MSTransportableRouter& getIntermodalRouter() const {
return myRouterProvider->getIntermodalRouter();
}
virtual ~WorkerThread() {
stop();
delete myRouterProvider;
Expand Down
2 changes: 1 addition & 1 deletion src/microsim/MSInsertionControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ MSInsertionControl::getPendingEmits(const MSLane* lane) {


void
MSInsertionControl::adaptIntermodalRouter(MSNet::MSIntermodalRouter& router) const {
MSInsertionControl::adaptIntermodalRouter(MSTransportableRouter& router) const {
// fill the public transport router with pre-parsed public transport lines
for (const Flow& f : myFlows) {
if (f.pars->line != "") {
Expand Down
6 changes: 4 additions & 2 deletions src/microsim/MSInsertionControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
#include <vector>
#include <map>
#include <string>
#include "MSNet.h"
#include <set>
#include <microsim/MSRouterDefs.h>
#include "MSVehicleContainer.h"


Expand All @@ -35,6 +36,7 @@
// ===========================================================================
class MSVehicle;
class MSVehicleControl;
class SUMOVehicle;
class SUMOVehicleParameter;


Expand Down Expand Up @@ -151,7 +153,7 @@ class MSInsertionControl {
/// @brief return the number of pending emits for the given lane
int getPendingEmits(const MSLane* lane);

void adaptIntermodalRouter(MSNet::MSIntermodalRouter& router) const;
void adaptIntermodalRouter(MSTransportableRouter& router) const;

/// @brief compute (optional) random offset to the departure time
SUMOTime computeRandomDepartOffset() const;
Expand Down
34 changes: 17 additions & 17 deletions src/microsim/MSNet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1462,7 +1462,7 @@ MSNet::existTractionSubstation(const std::string& substationId) {
}


SUMOAbstractRouter<MSEdge, SUMOVehicle>&
MSVehicleRouter&
MSNet::getRouterTT(const int rngIndex, const MSEdgeVector& prohibited) const {
if (myRouterTT.count(rngIndex) == 0) {
const std::string routingAlgorithm = OptionsCont::getOptions().getString("routing-algorithm");
Expand All @@ -1480,7 +1480,7 @@ MSNet::getRouterTT(const int rngIndex, const MSEdgeVector& prohibited) const {
}


SUMOAbstractRouter<MSEdge, SUMOVehicle>&
MSVehicleRouter&
MSNet::getRouterEffort(const int rngIndex, const MSEdgeVector& prohibited) const {
if (myRouterEffort.count(rngIndex) == 0) {
myRouterEffort[rngIndex] = new DijkstraRouter<MSEdge, SUMOVehicle>(MSEdge::getAllEdges(), true, &MSNet::getEffort, &MSNet::getTravelTime, false, nullptr, true);
Expand All @@ -1490,7 +1490,7 @@ MSNet::getRouterEffort(const int rngIndex, const MSEdgeVector& prohibited) const
}


MSNet::MSPedestrianRouter&
MSPedestrianRouter&
MSNet::getPedestrianRouter(const int rngIndex, const MSEdgeVector& prohibited) const {
if (myPedestrianRouter.count(rngIndex) == 0) {
myPedestrianRouter[rngIndex] = new MSPedestrianRouter();
Expand All @@ -1500,48 +1500,48 @@ MSNet::getPedestrianRouter(const int rngIndex, const MSEdgeVector& prohibited) c
}


MSNet::MSIntermodalRouter&
MSTransportableRouter&
MSNet::getIntermodalRouter(const int rngIndex, const int routingMode, const MSEdgeVector& prohibited) const {
const OptionsCont& oc = OptionsCont::getOptions();
const int key = rngIndex * oc.getInt("thread-rngs") + routingMode;
if (myIntermodalRouter.count(key) == 0) {
int carWalk = 0;
for (const std::string& opt : oc.getStringVector("persontrip.transfer.car-walk")) {
if (opt == "parkingAreas") {
carWalk |= MSIntermodalRouter::Network::PARKING_AREAS;
carWalk |= MSTransportableRouter::Network::PARKING_AREAS;
} else if (opt == "ptStops") {
carWalk |= MSIntermodalRouter::Network::PT_STOPS;
carWalk |= MSTransportableRouter::Network::PT_STOPS;
} else if (opt == "allJunctions") {
carWalk |= MSIntermodalRouter::Network::ALL_JUNCTIONS;
carWalk |= MSTransportableRouter::Network::ALL_JUNCTIONS;
}
}
// XXX there is currently no reason to combine multiple values, thus getValueString rather than getStringVector
const std::string& taxiDropoff = oc.getValueString("persontrip.transfer.taxi-walk");
const std::string& taxiPickup = oc.getValueString("persontrip.transfer.walk-taxi");
if (taxiDropoff == "") {
if (MSDevice_Taxi::getTaxi() != nullptr) {
carWalk |= MSIntermodalRouter::Network::TAXI_DROPOFF_ANYWHERE;
carWalk |= MSTransportableRouter::Network::TAXI_DROPOFF_ANYWHERE;
}
} else if (taxiDropoff == "ptStops") {
carWalk |= MSIntermodalRouter::Network::TAXI_DROPOFF_PT;
carWalk |= MSTransportableRouter::Network::TAXI_DROPOFF_PT;
} else if (taxiDropoff == "allJunctions") {
carWalk |= MSIntermodalRouter::Network::TAXI_DROPOFF_ANYWHERE;
carWalk |= MSTransportableRouter::Network::TAXI_DROPOFF_ANYWHERE;
}
if (taxiPickup == "") {
if (MSDevice_Taxi::getTaxi() != nullptr) {
carWalk |= MSIntermodalRouter::Network::TAXI_PICKUP_ANYWHERE;
carWalk |= MSTransportableRouter::Network::TAXI_PICKUP_ANYWHERE;
}
} else if (taxiPickup == "ptStops") {
carWalk |= MSIntermodalRouter::Network::TAXI_PICKUP_PT;
carWalk |= MSTransportableRouter::Network::TAXI_PICKUP_PT;
} else if (taxiPickup == "allJunctions") {
carWalk |= MSIntermodalRouter::Network::TAXI_PICKUP_ANYWHERE;
carWalk |= MSTransportableRouter::Network::TAXI_PICKUP_ANYWHERE;
}
const std::string routingAlgorithm = OptionsCont::getOptions().getString("routing-algorithm");
double taxiWait = STEPS2TIME(string2time(OptionsCont::getOptions().getString("persontrip.taxi.waiting-time")));
if (routingMode == libsumo::ROUTING_MODE_COMBINED) {
myIntermodalRouter[key] = new MSIntermodalRouter(MSNet::adaptIntermodalRouter, carWalk, taxiWait, routingAlgorithm, routingMode, new FareModul());
myIntermodalRouter[key] = new MSTransportableRouter(MSNet::adaptIntermodalRouter, carWalk, taxiWait, routingAlgorithm, routingMode, new FareModul());
} else {
myIntermodalRouter[key] = new MSIntermodalRouter(MSNet::adaptIntermodalRouter, carWalk, taxiWait, routingAlgorithm, routingMode);
myIntermodalRouter[key] = new MSTransportableRouter(MSNet::adaptIntermodalRouter, carWalk, taxiWait, routingAlgorithm, routingMode);
}
}
myIntermodalRouter[key]->prohibit(prohibited);
Expand All @@ -1550,7 +1550,7 @@ MSNet::getIntermodalRouter(const int rngIndex, const int routingMode, const MSEd


void
MSNet::adaptIntermodalRouter(MSIntermodalRouter& router) {
MSNet::adaptIntermodalRouter(MSTransportableRouter& router) {
double taxiWait = STEPS2TIME(string2time(OptionsCont::getOptions().getString("persontrip.taxi.waiting-time")));
// add access to all parking areas
EffortCalculator* const external = router.getExternalEffort();
Expand All @@ -1575,7 +1575,7 @@ MSNet::adaptIntermodalRouter(MSIntermodalRouter& router) {
myInstance->getInsertionControl().adaptIntermodalRouter(router);
myInstance->getVehicleControl().adaptIntermodalRouter(router);
// add access to transfer from walking to taxi-use
if ((router.getCarWalkTransfer() & MSIntermodalRouter::Network::TAXI_PICKUP_ANYWHERE) != 0) {
if ((router.getCarWalkTransfer() & MSTransportableRouter::Network::TAXI_PICKUP_ANYWHERE) != 0) {
for (MSEdge* edge : myInstance->getEdgeControl().getEdges()) {
if ((edge->getPermissions() & SVC_PEDESTRIAN) != 0 && (edge->getPermissions() & SVC_TAXI) != 0) {
router.getNetwork()->addCarAccess(edge, SVC_TAXI, taxiWait);
Expand Down
20 changes: 8 additions & 12 deletions src/microsim/MSNet.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <utils/common/NamedRTree.h>
#include <utils/router/SUMOAbstractRouter.h>
#include <mesosim/MESegment.h>
#include "MSRouterDefs.h"
#include "MSJunction.h"


Expand Down Expand Up @@ -109,9 +110,6 @@ class MSNet : public Parameterised {
SIMSTATE_TOO_MANY_TELEPORTS
};

typedef PedestrianRouter<MSEdge, MSLane, MSJunction, MSVehicle> MSPedestrianRouter;
typedef IntermodalRouter<MSEdge, MSLane, MSJunction, SUMOVehicle> MSIntermodalRouter;

/// @brief collision tracking
struct Collision {
std::string victim;
Expand Down Expand Up @@ -764,14 +762,12 @@ class MSNet : public Parameterised {
/* @brief get the router, initialize on first use
* @param[in] prohibited The vector of forbidden edges (optional)
*/
SUMOAbstractRouter<MSEdge, SUMOVehicle>& getRouterTT(const int rngIndex,
const MSEdgeVector& prohibited = MSEdgeVector()) const;
SUMOAbstractRouter<MSEdge, SUMOVehicle>& getRouterEffort(const int rngIndex,
const MSEdgeVector& prohibited = MSEdgeVector()) const;
MSVehicleRouter& getRouterTT(const int rngIndex, const MSEdgeVector& prohibited = MSEdgeVector()) const;
MSVehicleRouter& getRouterEffort(const int rngIndex, const MSEdgeVector& prohibited = MSEdgeVector()) const;
MSPedestrianRouter& getPedestrianRouter(const int rngIndex, const MSEdgeVector& prohibited = MSEdgeVector()) const;
MSIntermodalRouter& getIntermodalRouter(const int rngIndex, const int routingMode = 0, const MSEdgeVector& prohibited = MSEdgeVector()) const;
MSTransportableRouter& getIntermodalRouter(const int rngIndex, const int routingMode = 0, const MSEdgeVector& prohibited = MSEdgeVector()) const;

static void adaptIntermodalRouter(MSIntermodalRouter& router);
static void adaptIntermodalRouter(MSTransportableRouter& router);


/// @brief return whether the network contains internal links
Expand Down Expand Up @@ -1014,10 +1010,10 @@ class MSNet : public Parameterised {
* @note we provide one member for every switchable router type
* because the class structure makes it inconvenient to use a superclass
*/
mutable std::map<int, SUMOAbstractRouter<MSEdge, SUMOVehicle>*> myRouterTT;
mutable std::map<int, SUMOAbstractRouter<MSEdge, SUMOVehicle>*> myRouterEffort;
mutable std::map<int, MSVehicleRouter*> myRouterTT;
mutable std::map<int, MSVehicleRouter*> myRouterEffort;
mutable std::map<int, MSPedestrianRouter*> myPedestrianRouter;
mutable std::map<int, MSIntermodalRouter*> myIntermodalRouter;
mutable std::map<int, MSTransportableRouter*> myIntermodalRouter;

/// @brief An RTree structure holding lane IDs
mutable std::pair<bool, NamedRTree> myLanesRTree;
Expand Down
42 changes: 42 additions & 0 deletions src/microsim/MSRouterDefs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/****************************************************************************/
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
// Copyright (C) 2007-2023 German Aerospace Center (DLR) and others.
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0/
// This Source Code 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
/****************************************************************************/
/// @file MSRouterDefs.h
/// @author Michael Behrisch
/// @date 2023-12-21
///
// Type definitions for routers in the microsim context
/****************************************************************************/
#pragma once
#include <config.h>

#include <memory>
#include <utils/router/SUMOAbstractRouter.h>
#include <utils/router/RouterProvider.h>


// ===========================================================================
// class declarations and typedefs
// ===========================================================================
class MSEdge;
class MSLane;
class MSJunction;
class MSRoute;
class SUMOVehicle;

typedef std::vector<MSEdge*> MSEdgeVector;
typedef std::shared_ptr<const MSRoute> ConstMSRoutePtr;
typedef RouterProvider<MSEdge, MSLane, MSJunction, SUMOVehicle> MSRouterProvider;
typedef SUMOAbstractRouter<MSEdge, SUMOVehicle> MSVehicleRouter;
typedef IntermodalRouter<MSEdge, MSLane, MSJunction, SUMOVehicle> MSTransportableRouter;
typedef PedestrianRouter<MSEdge, MSLane, MSJunction, SUMOVehicle> MSPedestrianRouter;
4 changes: 3 additions & 1 deletion src/microsim/MSVehicleContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
#include <vector>
#include <iostream>

#include <utils/common/SUMOTime.h>


// ===========================================================================
// class declarations
// ===========================================================================
class MSVehicle;
class SUMOVehicle;


// ===========================================================================
Expand Down
3 changes: 2 additions & 1 deletion src/microsim/MSVehicleControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,12 +565,13 @@ MSVehicleControl::getTeleportCount() const {


void
MSVehicleControl::adaptIntermodalRouter(MSNet::MSIntermodalRouter& router) const {
MSVehicleControl::adaptIntermodalRouter(MSTransportableRouter& router) const {
for (const SUMOVehicle* const veh : myPTVehicles) {
// add single vehicles with line attribute which are not part of a flow
ConstMSRoutePtr const route = MSRoute::dictionary(veh->getParameter().routeid);
router.getNetwork()->addSchedule(veh->getParameter(), route == nullptr ? nullptr : &route->getStops());
}
}


/****************************************************************************/
6 changes: 2 additions & 4 deletions src/microsim/MSVehicleControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <utils/distribution/RandomDistributor.h>
#include <utils/common/SUMOTime.h>
#include <utils/common/SUMOVehicleClass.h>
#include "MSNet.h"
#include <microsim/MSRouterDefs.h>


// ===========================================================================
Expand All @@ -48,8 +48,6 @@ class MSVehicleType;
class OutputDevice;
class MSEdge;

typedef std::shared_ptr<const MSRoute> ConstMSRoutePtr;


// ===========================================================================
// class definitions
Expand Down Expand Up @@ -543,7 +541,7 @@ class MSVehicleControl {
return myMinDecelerationRail;
}

void adaptIntermodalRouter(MSNet::MSIntermodalRouter& router) const;
void adaptIntermodalRouter(MSTransportableRouter& router) const;

/// @brief sets the demand scaling factor
void setScale(double scale) {
Expand Down
1 change: 1 addition & 0 deletions src/microsim/devices/MSDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <set>
#include <random>
#include <microsim/MSMoveReminder.h>
#include <microsim/MSNet.h>
#include <microsim/MSVehicleType.h>
#include <microsim/MSVehicleControl.h>
#include <utils/common/Named.h>
Expand Down
2 changes: 1 addition & 1 deletion src/microsim/devices/MSDevice_StationFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
/****************************************************************************/
#include <config.h>

#include <microsim/MSEdge.h>
#include <microsim/MSNet.h>
#include <microsim/MSLane.h>
#include <microsim/MSStop.h>
#include <microsim/MSVehicleControl.h>
#include <microsim/output/MSDetectorControl.h>
Expand Down

0 comments on commit 86c0ad2

Please sign in to comment.