75template<
class E,
class L,
class N,
class V>
82 typedef std::pair<_IntermodalEdge*, _IntermodalEdge*>
EdgePair;
89 IntermodalNetwork(
const std::vector<E*>& edges,
const bool pedestrianOnly,
const int carWalkTransfer = 0)
91#ifdef IntermodalRouter_DEBUG_NETWORK
92 std::cout <<
"initIntermodalNetwork\n";
95 bool haveSeenWalkingArea =
false;
96 for (
const E*
const edge : edges) {
97 if (edge->isTazConnector()) {
104 const L* lane = getSidewalk<E, L>(edge);
106 if (edge->isWalkingArea()) {
112 haveSeenWalkingArea =
true;
120 if (!edge->isWalkingArea()) {
130 for (
const E*
const edge : edges) {
131 if (edge->isTazConnector() || edge->isInternal()) {
134 if (haveSeenWalkingArea) {
136 if (!pedestrianOnly && getSidewalk<E, L>(edge) ==
nullptr) {
137 const N*
const node = edge->getToJunction();
144 for (
const N*
const node : {
145 edge->getFromJunction(), edge->getToJunction()
155 for (
const E*
const edge : edges) {
156 if (edge->isTazConnector()) {
160 const E* other = edge->getOtherTazConnector();
163 for (
const E* out : edge->getSuccessors()) {
164 if (out->isNormal()) {
169 for (
const E* in : edge->getPredecessors()) {
170 if (in->isNormal()) {
177 const L*
const sidewalk = getSidewalk<E, L>(edge);
178 if (sidewalk ==
nullptr) {
184#ifdef IntermodalRouter_DEBUG_NETWORK
185 std::cout <<
" building connections from " << sidewalk->getID() <<
"\n";
187 if (haveSeenWalkingArea) {
188 const std::vector<std::pair<const L*, const E*> > outgoing = sidewalk->getOutgoingViaLanes();
192 bool hasWalkingArea =
false;
193 for (
const auto& target : outgoing) {
194 if (target.first->getEdge().isWalkingArea()) {
195 hasWalkingArea =
true;
199 for (
const auto& target : outgoing) {
200 const E*
const targetEdge = &(target.first->getEdge());
201 const bool used = (target.first == getSidewalk<E, L>(targetEdge)
202 && (!hasWalkingArea || targetEdge->isWalkingArea()));
203#ifdef IntermodalRouter_DEBUG_NETWORK
204 const L* potTarget = getSidewalk<E, L>(targetEdge);
205 std::cout <<
" lane=" << (potTarget == 0 ?
"NULL" : potTarget->getID()) << (used ?
"(used)" :
"") <<
"\n";
209 pair.first->addSuccessor(targetPair.first);
210 targetPair.second->addSuccessor(pair.second);
211#ifdef IntermodalRouter_DEBUG_NETWORK
212 std::cout <<
" " << pair.first->getID() <<
" -> " << targetPair.first->getID() <<
"\n";
213 std::cout <<
" " << targetPair.second->getID() <<
" -> " << pair.second->getID() <<
"\n";
222 if (toNodeConn !=
nullptr) {
224 const std::vector<std::pair<const L*, const E*> > outgoing = sidewalk->getOutgoingViaLanes();
225 double minViaLength = std::numeric_limits<double>::max();
226 const E* minVia =
nullptr;
227 for (
const auto& target : outgoing) {
228 if (target.second !=
nullptr && target.second->getLength() < minViaLength) {
229 minViaLength = target.second->getLength();
230 minVia = target.second;
233 EdgePair interVia = std::make_pair(
nullptr,
nullptr);
234 if (minVia !=
nullptr) {
237 interVia = it->second;
240 if (!haveSeenWalkingArea) {
242 pair.first->addSuccessor(toNodeConn, interVia.first);
247 if (fromNodeConn !=
nullptr) {
248 if (!haveSeenWalkingArea) {
253 if (!edge->isWalkingArea()) {
260 pair.first->addSuccessor(endConnector);
261 pair.second->addSuccessor(endConnector);
262#ifdef IntermodalRouter_DEBUG_NETWORK
263 std::cout <<
" " << startConnector->
getID() <<
" -> " << pair.first->getID() <<
"\n";
264 std::cout <<
" " << startConnector->
getID() <<
" -> " << pair.second->getID() <<
"\n";
265 std::cout <<
" " << pair.first->getID() <<
" -> " << endConnector->
getID() <<
"\n";
266 std::cout <<
" " << pair.second->getID() <<
" -> " << endConnector->
getID() <<
"\n";
273 for (
typename std::vector<_IntermodalEdge*>::iterator it =
myEdges.begin(); it !=
myEdges.end(); ++it) {
298 typename std::map<const E*, EdgePair>::const_iterator it =
myBidiLookup.find(e);
301 throw ProcessError(
TLF(
"Edge '%' not found in intermodal network.'", e->getID()));
308 typename std::map<const E*, std::vector<_IntermodalEdge*> >::const_iterator it =
myDepartLookup.find(e);
310 throw ProcessError(
TLF(
"Depart edge '%' not found in intermodal network.", e->getID()));
314 double bestDist = std::numeric_limits<double>::max();
317 if (pos >=
split->getStartPos() - POSITION_EPS && pos <=
split->getEndPos() + POSITION_EPS) {
319 if (dist < bestDist) {
325 assert(best !=
nullptr);
329 const std::vector<_IntermodalEdge*>& splitList = it->second;
330 typename std::vector<_IntermodalEdge*>::const_iterator splitIt = splitList.begin();
331 double totalLength = 0.;
332 while (splitIt + 1 != splitList.end() && totalLength + (*splitIt)->getLength() < pos) {
342 typename std::map<const E*, std::vector<_IntermodalEdge*> >::const_iterator it =
myDepartLookup.find(e);
344 throw ProcessError(
TLF(
"Depart edge '%' not found in intermodal network.", e->getID()));
346 if (splitIndex >= (
int)it->second.size()) {
347 throw ProcessError(
"Split index " +
toString(splitIndex) +
" invalid for depart edge '" + e->getID() +
"' .");
349 return it->second[splitIndex];
354 typename std::map<const E*, std::vector<_IntermodalEdge*> >::const_iterator it =
myArrivalLookup.find(e);
356 throw ProcessError(
TLF(
"Arrival edge '%' not found in intermodal network.", e->getID()));
358 const std::vector<_IntermodalEdge*>& splitList = it->second;
359 typename std::vector<_IntermodalEdge*>::const_iterator splitIt = splitList.begin();
360 double totalLength = 0.;
361 while (splitIt != splitList.end() && totalLength + (*splitIt)->getLength() < pos) {
362 totalLength += (*splitIt)->getLength();
375 typename std::map<const N*, _IntermodalEdge*>::const_iterator it =
myWalkingConnectorLookup.find(e->getToJunction());
377 const L*
const sidewalk = getSidewalk<E, L>(e);
378 if (e->isInternal() || sidewalk == 0) {
381 for (
const auto& target : sidewalk->getOutgoingViaLanes()) {
382 if (target.first->getEdge().isWalkingArea()) {
392 for (
const E*
const edge : edges) {
401 for (
const auto& suc : edgePair.first->getViaSuccessors()) {
404 if (sucCarEdge !=
nullptr) {
418 for (
const E*
const out : edgePair.first->getToJunction()->getOutgoing()) {
419 if (!out->isInternal() && !out->isTazConnector() && getSidewalk<E, L>(out) != 0) {
423 for (
const E*
const in : edgePair.first->getToJunction()->getIncoming()) {
424 if (!in->isInternal() && !in->isTazConnector() && getSidewalk<E, L>(in) != 0) {
437 for (
const E*
const out : edgePair.first->getToJunction()->getOutgoing()) {
438 if (!out->isInternal() && !out->isTazConnector() && getSidewalk<E, L>(out) != 0) {
442 for (
const E*
const in : edgePair.first->getToJunction()->getIncoming()) {
443 if (!in->isInternal() && !in->isTazConnector() && getSidewalk<E, L>(in) != 0) {
510 void addAccess(
const std::string& stopId,
const E* stopEdge,
const double startPos,
const double endPos,
const double length,
const SumoXMLTag category,
bool isAccess,
double taxiWait) {
511 assert(stopEdge !=
nullptr);
516 const double pos = (startPos + endPos) / 2.;
517#ifdef IntermodalRouter_DEBUG_ACCESS
518 std::cout <<
"addAccess stopId=" << stopId <<
" stopEdge=" << stopEdge->getID() <<
" pos=" << pos <<
" length=" << length <<
" tag=" <<
toString(category)
519 <<
" access=" << isAccess <<
" tWait=" << taxiWait <<
"\n";
526 const L* lane = getSidewalk<E, L>(stopEdge);
527 if (lane !=
nullptr) {
528 const std::pair<_IntermodalEdge*, _IntermodalEdge*>& pair =
getBothDirections(stopEdge);
531 const int splitIndex =
findSplitIndex(pair.first, pos, relPos, needSplit);
533 splitEdge(pair.first, splitIndex, fwdSplit, relPos, length, needSplit, stopConn);
535 splitEdge(pair.second, splitIndex, backSplit, relPos, length, needSplit, stopConn,
false);
541 splitEdge(
myCarLookup[stopEdge], splitIndex, carSplit, relPos, length, needSplit, stopConn,
true,
false, transferCarWalk);
544 if (carSplit !=
nullptr && (transferCarWalk || transferTaxiWalk)) {
550 if (transferCarWalk) {
555 }
else if (transferTaxiWalk) {
560 if (carSplit !=
nullptr && transferWalkTaxi && !isAccess) {
569 const std::vector<_IntermodalEdge*>& backSplitList =
myAccessSplits[pair.second];
570 _IntermodalEdge*
const backBeforeSplit = backSplitList[backSplitList.size() - 2 - splitIndex];
578 if (carSplit !=
nullptr) {
592 if (carSplit !=
nullptr) {
603 std::vector<_IntermodalEdge*>& splitList =
myDepartLookup[stopEdge];
604 assert(splitList.size() > 0);
605 typename std::vector<_IntermodalEdge*>::iterator splitIt = splitList.begin();
606 while (splitIt != splitList.end() && startPos > (*splitIt)->getEndPos()) {
609 splitList.insert(splitIt, stopConn);
611 if (!isAccess && (transferWalkTaxi || transferCarWalk || transferTaxiWalk)) {
615 const int splitIndex =
findSplitIndex(carEdge, pos, relPos, needSplit);
618 splitEdge(carEdge, splitIndex, carSplit, relPos, length, needSplit, stopConn,
true,
false,
false);
620 if (transferCarWalk || transferTaxiWalk) {
623 if (transferCarWalk) {
628 }
else if (transferTaxiWalk) {
632 if (transferWalkTaxi) {
645 std::vector<SUMOVehicleParameter::Stop> validStops;
646 if (addStops !=
nullptr) {
652 if (newUntil >= lastUntil) {
653 validStops.push_back(stop);
654 validStops.back().until = newUntil;
655 lastUntil = newUntil;
665 validStops.push_back(stop);
666 lastUntil = stop.until;
668 if (stop.busstop !=
"" && stop.until >= 0) {
673 if (validStops.size() < 2 && pars.
line !=
"taxi") {
674 WRITE_WARNINGF(
TL(
"Not using public transport line '%' for routing persons. It has less than two usable stops."), pars.
line);
678 typename std::vector<_PTEdge*>& lineEdges =
myPTLines[pars.
line];
679 if (lineEdges.empty()) {
685 Position stopPos = E::getStopPosition(s);
686 if (lastStop !=
nullptr) {
692 lineEdges.push_back(newEdge);
698 if (pars.
line !=
"taxi" && validStops.front().busstop == validStops.back().busstop) {
702 if (validStops.size() != lineEdges.size() + 1) {
703 WRITE_WARNINGF(
"Number of stops for public transport line '%' does not match earlier definitions, ignoring schedule.", pars.
line);
706 if (lineEdges.front()->getEntryStop() !=
myStopConnections[validStops.front().busstop]) {
707 WRITE_WARNINGF(
"Different stop for '%' compared to earlier definitions, ignoring schedule.", pars.
line);
710 typename std::vector<_PTEdge*>::const_iterator lineEdge = lineEdges.begin();
711 typename std::vector<SUMOVehicleParameter::Stop>::const_iterator s = validStops.begin() + 1;
712 for (; s != validStops.end(); ++s, ++lineEdge) {
714 WRITE_WARNINGF(
"Different stop for '%' compared to earlier definitions, ignoring schedule.", pars.
line);
718 SUMOTime lastTime = validStops.front().until;
719 if (lineEdges.front()->hasSchedule(lastTime)) {
722 for (lineEdge = lineEdges.begin(), s = validStops.begin() + 1; lineEdge != lineEdges.end(); ++lineEdge, ++s) {
734 assert(edge !=
nullptr);
741 pedestrianEdges.first->addSuccessor(access);
742 pedestrianEdges.second->addSuccessor(access);
779 if (splitList !=
myAccessSplits.end() && !splitList->second.empty()) {
781 if (relPos < split->getLength() + POSITION_EPS) {
784 relPos -=
split->getLength();
787 assert(splitIndex < (
int)splitList->second.size());
788 if (splitIndex + 1 < (
int)splitList->second.size() && fabs(relPos - splitList->second[splitIndex]->getLength()) < POSITION_EPS) {
808 _IntermodalEdge* afterSplit,
const double relPos,
const double length,
const bool needSplit,
809 _IntermodalEdge*
const stopConn,
const bool forward =
true,
const bool addExit =
true,
const bool addEntry =
true) {
810 std::vector<_IntermodalEdge*>& splitList =
myAccessSplits[toSplit];
811 if (splitList.empty()) {
812 splitList.push_back(toSplit);
815 splitIndex = (int)splitList.size() - 1 - splitIndex;
832 const std::string newID = beforeSplit->
getID();
834 afterSplit->
setID(newID);
836 splitList.insert(splitList.begin() + splitIndex + 1, afterSplit);
839 afterSplit = splitList[splitIndex + 1];
875 std::map<const E*, _IntermodalEdge*, ComparatorNumericalIdLess>
myCarLookup;
878 std::map<std::string, std::vector<_PTEdge*> >
myPTLines;
ModeChangeOptions
where mode changes are possible
@ TAXI_DROPOFF_ANYWHERE
taxi customer may exit anywhere
@ PT_STOPS
public transport stops and access
@ TAXI_PICKUP_ANYWHERE
taxi customer may be picked up anywhere
@ TAXI_PICKUP_PARKING_AREAS
taxi customer may be picked up at parking areas
@ TAXI_DROPOFF_PT
taxi customer may exit at public transport stops
@ TAXI_DROPOFF_PARKING_AREAS
taxi customer may exit at parking areas
@ ALL_JUNCTIONS
junctions with edges allowing the additional mode
@ TAXI_PICKUP_PT
taxi customer may be picked up at public transport stops
@ PARKING_AREAS
parking areas
std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)
#define WRITE_WARNINGF(...)
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
const SVCPermissions SVCAll
all VClasses are allowed
long long int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
@ SVC_TAXI
vehicle is a taxi
@ SVC_PEDESTRIAN
pedestrian
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_BUS_STOP
A bus stop.
@ SUMO_TAG_PARKING_AREA
A parking area.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
the access edge connecting different modes that is given to the internal router (SUMOAbstractRouter)
the car edge type that is given to the internal router (SUMOAbstractRouter)
the base edge type that is given to the internal router (SUMOAbstractRouter)
const E * getEdge() const
void setLength(const double length)
void transferSuccessors(IntermodalEdge *to)
bool removeSuccessor(const IntermodalEdge *const edge)
void addSuccessor(IntermodalEdge *const s, IntermodalEdge *const via=nullptr)
double getLength() const
required by DijkstraRouter et al for external effort computation
int getNumericalID() const
virtual double getEndPos() const
the intermodal network storing edges, connections and the mappings to the "real" edges
_IntermodalEdge * getWalkingConnector(const E *e) const
Returns the outgoing pedestrian edge, which is either a walking area or a walking connector.
const std::vector< _IntermodalEdge * > & getAllEdges()
_IntermodalEdge * getArrivalConnector(const E *e, const int splitIndex=0) const
Returns the arriving intermodal connector at the given split offset.
PublicTransportEdge< E, L, N, V > _PTEdge
_IntermodalEdge * getCarEdge(const E *e) const
Returns the associated car edge.
std::map< const E *, _IntermodalEdge *, ComparatorNumericalIdLess > myCarLookup
retrieve the car edge for the given input edge E
void addCarAccess(const E *edge, SUMOVehicleClass svc, double traveltime)
Adds access edges for transfering from walking to vehicle use.
void addAccess(const std::string &stopId, const E *stopEdge, const double startPos, const double endPos, const double length, const SumoXMLTag category, bool isAccess, double taxiWait)
Adds access edges for stopping places to the intermodal network.
std::map< const E *, std::vector< _IntermodalEdge * > > myArrivalLookup
retrieve the arrival edges for the given input edge E
std::map< const N *, _IntermodalEdge * > myWalkingConnectorLookup
the walking connector edge (fake walking area)
std::map< std::string, _IntermodalEdge * > myStopConnections
retrieve the representing edge for the given stopping place
std::map< _IntermodalEdge *, std::vector< _IntermodalEdge * > > myAccessSplits
retrieve the splitted edges for the given "original"
_IntermodalEdge * getStopEdge(const std::string &stopId) const
Returns the associated stop edge.
const int myCarWalkTransfer
void addEdge(_IntermodalEdge *edge)
std::vector< _IntermodalEdge * > myEdges
the edge dictionary
AccessEdge< E, L, N, V > _AccessEdge
IntermodalNetwork & operator=(const IntermodalNetwork &s)
Invalidated assignment operator.
std::map< const E *, EdgePair > myBidiLookup
retrieve the forward and backward edge for the given input edge E
std::set< std::string > myLoopedLines
looped lines need extra checking when building itineraries
bool isLooped(const std::string lineID) const
std::map< std::string, std::vector< _PTEdge * > > myPTLines
retrieve the public transport edges for the given line
void addRestrictedCarExit(_IntermodalEdge *from, _IntermodalEdge *to, SVCPermissions vehicleRestriction)
Adds access edges for transfering from driving to walking that are only usable by a particular vehicl...
void addConnectors(_IntermodalEdge *const depConn, _IntermodalEdge *const arrConn, const int index)
const EdgePair & getBothDirections(const E *e) const
Returns the pair of forward and backward edge.
int findSplitIndex(_IntermodalEdge *const toSplit, const double pos, double &relPos, bool &needSplit) const
Returns where to insert or use the split edge.
void addCarEdges(const std::vector< E * > &edges, double taxiWait)
PedestrianEdge< E, L, N, V > _PedestrianEdge
void splitEdge(_IntermodalEdge *const toSplit, int splitIndex, _IntermodalEdge *afterSplit, const double relPos, const double length, const bool needSplit, _IntermodalEdge *const stopConn, const bool forward=true, const bool addExit=true, const bool addEntry=true)
Splits an edge (if necessary) and connects it to a stopping edge.
IntermodalNetwork(const std::vector< E * > &edges, const bool pedestrianOnly, const int carWalkTransfer=0)
_IntermodalEdge * getArrivalEdge(const E *e, const double pos) const
Returns the arriving intermodal edge.
IntermodalEdge< E, L, N, V > _IntermodalEdge
std::map< const E *, std::vector< _IntermodalEdge * > > myDepartLookup
retrieve the depart edges for the given input edge E
_IntermodalEdge * getDepartConnector(const E *e, const int splitIndex=0) const
Returns the departing intermodal connector at the given split offset.
void addSchedule(const SUMOVehicleParameter &pars, const std::vector< SUMOVehicleParameter::Stop > *addStops=nullptr)
std::pair< _IntermodalEdge *, _IntermodalEdge * > EdgePair
const _IntermodalEdge * getDepartEdge(const E *e, const double pos) const
Returns the departing intermodal edge.
virtual void setID(const std::string &newID)
resets the id
const std::string & getID() const
Returns the id.
the pedestrian edge type that is given to the internal router (SUMOAbstractRouter)
A point in 2D or 3D with translation and scaling methods.
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimensions
the public transport edge type connecting the stop edges
void addSchedule(const std::string id, const SUMOTime begin, const int repetitionNumber, const SUMOTime period, const SUMOTime travelTime)
Definition of vehicle stop (position and duration)
Structure representing possible vehicle parameter.
SUMOTime repetitionOffset
The time offset between vehicle reinsertions.
std::string id
The vehicle's id.
std::vector< Stop > stops
List of the stops the vehicle will make, TraCI may add entries here.
std::string line
The vehicle's line (mainly for public transport)
the stop edge type representing bus and train stops