20 #ifndef IntermodalRouter_h 21 #define IntermodalRouter_h 57 template<
class E,
class L,
class N,
class V,
class INTERNALROUTER = DijkstraRouterTT<IntermodalEdge<E, L, N, V>, IntermodalTrip<E, N, V>, prohibited_withPermissions<IntermodalEdge<E, L, N, V>, IntermodalTrip<E, N, V> > > >
94 assert(stopEdge != 0);
100 const L* lane = getSidewalk<E, L>(stopEdge);
104 const int splitIndex =
splitEdge(pair.first, fwdSplit, pos, stopConn);
107 if (splitIndex >= 0) {
108 _IntermodalEdge* carSplit = 0;
117 _IntermodalEdge*
const depConn =
new _IntermodalEdge(stopEdge->
getID() +
"_depart_connector" +
toString(pos), myNumericalID++, stopEdge,
"!connector");
128 _IntermodalEdge*
const arrConn =
new _IntermodalEdge(stopEdge->getID() +
"_arrival_connector" +
toString(pos), myNumericalID++, stopEdge,
"!connector");
141 std::vector<SUMOVehicleParameter::Stop> validStops;
144 for (std::vector<SUMOVehicleParameter::Stop>::const_iterator s = addStops->begin(); s != addStops->end(); ++s) {
149 if (stop.
until >= lastUntil) {
150 validStops.push_back(stop);
151 lastUntil = stop.
until;
158 for (std::vector<SUMOVehicleParameter::Stop>::const_iterator s = pars.
stops.begin(); s != pars.
stops.end(); ++s) {
161 validStops.push_back(*s);
162 lastUntil = s->until;
165 if (validStops.size() < 2) {
166 WRITE_WARNING(
"Ignoring public transport line '" + pars.
line +
"' with less than two usable stops.");
170 typename std::vector<_PTEdge*>& lineEdges =
myPTLines[pars.
line];
171 if (lineEdges.empty()) {
172 _IntermodalEdge* lastStop = 0;
174 for (std::vector<SUMOVehicleParameter::Stop>::const_iterator s = validStops.begin(); s != validStops.end(); ++s) {
182 lineEdges.push_back(newEdge);
188 if (validStops.size() != lineEdges.size() + 1) {
189 WRITE_WARNING(
"Number of stops for public transport line '" + pars.
line +
"' does not match earlier definitions, ignoring schedule.");
192 if (lineEdges.front()->getEntryStop() !=
myStopConnections[validStops.front().busstop]) {
193 WRITE_WARNING(
"Different stop for '" + pars.
line +
"' compared to earlier definitions, ignoring schedule.");
196 typename std::vector<_PTEdge*>::const_iterator lineEdge = lineEdges.begin();
197 typename std::vector<SUMOVehicleParameter::Stop>::const_iterator s = validStops.begin() + 1;
198 for (; s != validStops.end(); ++s, ++lineEdge) {
200 WRITE_WARNING(
"Different stop for '" + pars.
line +
"' compared to earlier definitions, ignoring schedule.");
204 SUMOTime lastTime = validStops.front().until;
205 for (lineEdge = lineEdges.begin(), s = validStops.begin() + 1; lineEdge != lineEdges.end(); ++lineEdge, ++s) {
216 std::vector<TripItem>& into) {
218 _IntermodalTrip trip(from, to, departPos, arrivalPos, speed, msTime, 0, vehicle, modeSet);
219 std::vector<const _IntermodalEdge*> intoPed;
222 &trip, msTime, intoPed);
224 std::string lastLine =
"";
225 for (
int i = 0; i < (int)intoPed.size(); ++i) {
226 if (intoPed[i]->includeInRoute(
false)) {
227 if (intoPed[i]->getLine() ==
"!stop") {
228 into.back().destStop = intoPed[i]->getID();
230 if (intoPed[i]->getLine() != lastLine) {
231 lastLine = intoPed[i]->getLine();
232 if (lastLine ==
"!car") {
233 into.push_back(
TripItem(vehicle->getID()));
234 }
else if (lastLine ==
"!ped") {
240 if (into.back().edges.empty() || into.back().edges.back() != intoPed[i]->getEdge()) {
241 into.back().edges.push_back(intoPed[i]->getEdge());
247 #ifdef IntermodalRouter_DEBUG_ROUTES 249 for (
int i = 0; i < intoPed.size(); ++i) {
252 std::cout <<
TIME2STEPS(msTime) <<
" trip from " << from->getID() <<
" to " << to->getID()
253 <<
" departPos=" << departPos
254 <<
" arrivalPos=" << arrivalPos
265 bool compute(
const E*,
const E*,
const _IntermodalTrip*
const,
275 std::vector<_IntermodalEdge*> toProhibitPE;
276 for (
typename std::vector<E*>::const_iterator it = toProhibit.begin(); it != toProhibit.end(); ++it) {
287 myInternalRouter(
new INTERNALROUTER(net->getAllEdges(), true, &_IntermodalEdge::getTravelTimeStatic)),
291 _IntermodalEdge*
const fwdConn, _IntermodalEdge*
const backConn = 0) {
293 std::vector<_IntermodalEdge*>& splitList =
myAccessSplits[toSplit];
294 if (splitList.empty()) {
295 splitList.push_back(toSplit);
297 typename std::vector<_IntermodalEdge*>::iterator splitIt = splitList.begin();
299 while (splitIt != splitList.end() && relPos > (*splitIt)->getLength() +
POSITION_EPS) {
300 relPos -= (*splitIt)->getLength();
304 assert(splitIt != splitList.end());
305 _IntermodalEdge*
const beforeSplit = *splitIt;
306 if (fabs(relPos - beforeSplit->getLength()) <
POSITION_EPS && splitIt + 1 != splitList.end()) {
309 afterSplit = *(splitIt + 1);
313 beforeSplit->clearSuccessors();
314 beforeSplit->addSuccessor(afterSplit);
315 afterSplit->
setLength(beforeSplit->getLength() - relPos);
316 beforeSplit->setLength(relPos);
317 splitList.insert(splitIt + 1, afterSplit);
322 beforeSplit->addSuccessor(access);
332 beforeSplit->addSuccessor(backward);
339 for (
typename std::vector<E*>::const_iterator i = edges.begin(); i != edges.end(); ++i) {
340 const E*
const edge = *i;
341 if (!edge->isInternal()) {
346 for (
typename std::vector<E*>::const_iterator i = edges.begin(); i != edges.end(); ++i) {
347 const E*
const edge = *i;
348 if (!edge->isInternal()) {
352 const std::vector<E*>& successors = edge->getSuccessors();
353 for (
typename std::vector<E*>::const_iterator it = successors.begin(); it != successors.end(); ++it) {
374 typename std::map<const E*, _IntermodalEdge*>::const_iterator it =
myCarLookup.find(e);
376 throw ProcessError(
"Car edge '" + e->getID() +
"' not found in pedestrian network.");
392 std::map<std::string, std::vector<_PTEdge*> >
myPTLines;
413 template<
class E,
class L,
class N,
class V>
419 : myVehRouter(vehRouter), myPedRouter(pedRouter), myInterRouter(interRouter) {}
422 : myVehRouter(original.getVehicleRouter().
clone()),
424 myInterRouter(static_cast<
IntermodalRouter<E, L, N, V>*>(original.myInterRouter == 0 ? 0 : original.getIntermodalRouter().
clone())) {}
435 return *myInterRouter;
441 delete myInterRouter;
SUMOReal getLength() const
bool compute(const E *from, const E *to, SUMOReal departPos, SUMOReal arrivalPos, SUMOReal speed, const V *const vehicle, const SVCPermissions modeSet, SUMOTime msTime, std::vector< TripItem > &into)
Builds the route between the given edges using the minimum effort at the given time The definition of...
IntermodalRouter & operator=(const IntermodalRouter &s)
Invalidated assignment operator.
std::map< const E *, _IntermodalEdge * > myCarLookup
retrieve the car edge for the given input edge E
void addSchedule(const SUMOTime begin, const SUMOTime end, const SUMOTime period, const SUMOReal travelTimeSec)
int repetitionNumber
The number of times the vehicle shall be repeatedly inserted.
const std::vector< _IntermodalEdge * > & getAllEdges()
RouterProvider(const RouterProvider &original)
virtual ~RouterProvider()
SUMOAbstractRouter< E, V > *const myVehRouter
void addEdge(_IntermodalEdge *edge)
void(* CreateNetCallback)(IntermodalRouter< E, L, N, V, INTERNALROUTER > &)
_IntermodalEdge * getDepartEdge(const E *e, const SUMOReal pos=-1.)
Returns the departing Intermodal edge.
AccessEdge< E, L, N, V > _AccessEdge
void addSuccessor(IntermodalEdge *s)
_IntermodalNetwork * myIntermodalNet
std::string time2string(SUMOTime t)
std::map< _IntermodalEdge *, std::vector< _IntermodalEdge * > > myAccessSplits
retrieve the splitted edges for the given "original"
the car edge type that is given to the internal router (SUMOAbstractRouter)
std::map< std::string, std::vector< _PTEdge * > > myPTLines
retrieve the public transport edges for the given line
SUMOTime until
The time at which the vehicle may continue its journey.
void addAccess(const std::string &stopId, const E *stopEdge, const SUMOReal pos)
bool compute(const E *, const E *, const _IntermodalTrip *const, SUMOTime, std::vector< const E * > &)
Builds the route between the given edges using the minimum effort at the given time The definition of...
TripItem(const std::string &_line="")
#define WRITE_WARNING(msg)
SUMOTime repetitionOffset
The time offset between vehicle reinsertions.
void removeSuccessor(const IntermodalEdge *const edge)
_IntermodalEdge * getArrivalEdge(const E *e, const SUMOReal pos=-1.)
Returns the arriving Intermodal edge.
PedestrianRouterDijkstra< E, L, N, V > & getPedestrianRouter() const
std::vector< Stop > stops
List of the stops the vehicle will make, TraCI may add entries here.
std::string busstop
(Optional) bus stop if one is assigned to the stop
PublicTransportEdge< E, L, N, V > _PTEdge
const std::string & getID() const
Returns the id.
CreateNetCallback myCallback
void addSchedule(const SUMOVehicleParameter &pars, const std::vector< SUMOVehicleParameter::Stop > *addStops=0)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
int splitEdge(_IntermodalEdge *const toSplit, _IntermodalEdge *afterSplit, const SUMOReal pos, _IntermodalEdge *const fwdConn, _IntermodalEdge *const backConn=0)
IntermodalRouter(_IntermodalNetwork *net)
void prohibit(const std::vector< E * > &toProhibit)
IntermodalTrip< E, N, V > _IntermodalTrip
SUMOAbstractRouter< E, _IntermodalTrip > * clone()
SUMOTime depart
The vehicle's departure time.
the "vehicle" type that is given to the internal router (SUMOAbstractRouter)
IntermodalRouter(CreateNetCallback callback)
Constructor.
SUMOAbstractRouter< E, V > & getVehicleRouter() const
std::vector< const E * > edges
_IntermodalEdge * getCarEdge(const E *e)
Returns the associated car edge.
const E * getEdge() const
PedestrianRouterDijkstra< E, L, N, V > *const myPedRouter
the pedestrian network storing edges, connections and the mappings to the "real" edges ...
std::string line
The vehicle's line (mainly for public transport)
the base edge type that is given to the internal router (SUMOAbstractRouter)
INTERNALROUTER * myInternalRouter
std::map< std::string, _IntermodalEdge * > myStopConnections
retrieve the connecting edges for the given "bus" stop
IntermodalNetwork< E, L, N, V > _IntermodalNetwork
Structure representing possible vehicle parameter.
IntermodalEdge< E, L, N, V > _IntermodalEdge
virtual ~IntermodalRouter()
Destructor.
Definition of vehicle stop (position and duration)
the public transport edge type connecting the stop edges
const EdgePair & getBothDirections(const E *e)
Returns the pair of forward and backward edge.
IntermodalRouter< E, L, N, V > *const myInterRouter
IntermodalRouter< E, L, N, V > & getIntermodalRouter() const
static SUMOReal getTravelTimeStatic(const IntermodalEdge *const edge, const IntermodalTrip< E, N, V > *const trip, SUMOReal time)
void setLength(const SUMOReal length)
the pedestrian edge type that is given to the internal router (SUMOAbstractRouter) ...
SUMOReal recomputeCosts(const std::vector< const E * > &, const _IntermodalTrip *const, SUMOTime) const
void setSuccessors(const std::vector< IntermodalEdge * > &edges)
void addCarEdges(const std::vector< E * > &edges)
RouterProvider(SUMOAbstractRouter< E, V > *vehRouter, PedestrianRouterDijkstra< E, L, N, V > *pedRouter, IntermodalRouter< E, L, N, V > *interRouter)
void addConnectors(_IntermodalEdge *const depConn, _IntermodalEdge *const arrConn, const int splitIndex)
the stop edge type representing bus and train stops
vehicles ignoring classes
the access edge connecting different modes that is given to the internal router (SUMOAbstractRouter) ...
std::string id
The vehicle's id.