Skip to content

Commit

Permalink
extended duarouter output refs #3948
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Mar 28, 2018
1 parent c13e4d1 commit c99514d
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 9 deletions.
2 changes: 2 additions & 0 deletions data/xsd/routeTypes.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,8 @@
<xsd:attribute name="lines" type="xsd:string" use="required"/>
<xsd:attribute name="arrivalPos" type="xsd:float"/>
<xsd:attribute name="cost" type="xsd:float"/>
<xsd:attribute name="intended" type="xsd:string" use="optional"/>
<xsd:attribute name="depart" type="xsd:float" use="optional"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="walk">
Expand Down
8 changes: 7 additions & 1 deletion src/router/ROPerson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ ROPerson::Ride::saveAsXML(OutputDevice& os, const bool extended) const {
os.writeAttr(SUMO_ATTR_BUS_STOP, destStop);
}
os.writeAttr(SUMO_ATTR_LINES, lines);
if (intended != "") {
os.writeAttr(SUMO_ATTR_INTENDED, intended);
}
if (depart >= 0) {
os.writeAttr(SUMO_ATTR_DEPART, time2string(depart));
}
os.closeTag();
}

Expand Down Expand Up @@ -184,7 +190,7 @@ ROPerson::computeIntermodal(const RORouterProvider& provider, PersonTrip* const
veh->getRouteDefinition()->addLoadedAlternative(new RORoute(veh->getID() + "_RouteDef", it->edges));
carUsed = true;
} else {
trip->addTripItem(new Ride(0, 0, it->line, it->cost, it->destStop));
trip->addTripItem(new Ride(0, 0, it->line, it->cost, it->destStop, it->intended, TIME2STEPS(it->depart)));
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions src/router/ROPerson.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,13 @@ class ROPerson : public RORoutable {
class Ride : public TripItem {
public:
Ride(const ROEdge* const _from, const ROEdge* const _to,
const std::string& _lines, const double _cost, const std::string& _destStop = "")
: TripItem(_cost), from(_from), to(_to), lines(_lines), destStop(_destStop) {}
const std::string& _lines, const double _cost, const std::string& _destStop = "", const std::string& _intended = "", const SUMOTime _depart = -1) :
TripItem(_cost),
from(_from), to(_to),
lines(_lines),
destStop(_destStop),
intended(_intended),
depart(_depart) {}

const ROEdge* getOrigin() const {
return from;
Expand All @@ -173,6 +178,8 @@ class ROPerson : public RORoutable {
const ROEdge* const from;
const ROEdge* const to;
const std::string lines;
const std::string intended;
const SUMOTime depart;
const std::string destStop;

private:
Expand Down
4 changes: 4 additions & 0 deletions src/utils/vehicle/IntermodalEdge.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ class IntermodalEdge : public Named {
return 0.;
}

/// @brief set intended vehicle id and departure time of next public transport ride
virtual void setIntended(const IntermodalTrip<E, N, V>* const /* trip */, double /* time */, std::string& intended, double& depart) const {
}

static inline double getTravelTimeStatic(const IntermodalEdge* const edge, const IntermodalTrip<E, N, V>* const trip, double time) {
return edge == nullptr ? 0. : edge->getTravelTime(trip, time);
}
Expand Down
4 changes: 2 additions & 2 deletions src/utils/vehicle/IntermodalNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ class IntermodalNetwork {
if (lastStop != 0) {
_PTEdge* const newEdge = new _PTEdge(s->busstop, myNumericalID++, lastStop, currStop->getEdge(), pars.line);
addEdge(newEdge);
newEdge->addSchedule(lastTime, lastTime + pars.repetitionOffset * (pars.repetitionNumber - 1), pars.repetitionOffset, STEPS2TIME(s->until - lastTime));
newEdge->addSchedule(pars.id, lastTime, lastTime + pars.repetitionOffset * (pars.repetitionNumber - 1), pars.repetitionOffset, STEPS2TIME(s->until - lastTime));
lastStop->addSuccessor(newEdge);
newEdge->addSuccessor(currStop);
lineEdges.push_back(newEdge);
Expand All @@ -540,7 +540,7 @@ class IntermodalNetwork {
}
SUMOTime lastTime = validStops.front().until;
for (lineEdge = lineEdges.begin(), s = validStops.begin() + 1; lineEdge != lineEdges.end(); ++lineEdge, ++s) {
(*lineEdge)->addSchedule(lastTime, lastTime + pars.repetitionOffset * (pars.repetitionNumber - 1), pars.repetitionOffset, STEPS2TIME(s->until - lastTime));
(*lineEdge)->addSchedule(pars.id, lastTime, lastTime + pars.repetitionOffset * (pars.repetitionNumber - 1), pars.repetitionOffset, STEPS2TIME(s->until - lastTime));
lastTime = s->until;
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/utils/vehicle/IntermodalRouter.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class IntermodalRouter : public SUMOAbstractRouter<E, IntermodalTrip<E, N, V> >
TripItem(const std::string& _line = "") : line(_line), cost(0.) {}
std::string line;
std::string destStop;
std::string intended; // intended public transport vehicle id
double depart; // intended public transport departure
std::vector<const E*> edges;
double cost;
};
Expand Down Expand Up @@ -124,6 +126,7 @@ class IntermodalRouter : public SUMOAbstractRouter<E, IntermodalTrip<E, N, V> >
into.push_back(TripItem());
} else {
into.push_back(TripItem(lastLine));
iEdge->setIntended(&trip, time, into.back().intended, into.back().depart);
}
}
if (into.back().edges.empty() || into.back().edges.back() != iEdge->getEdge()) {
Expand Down
41 changes: 37 additions & 4 deletions src/utils/vehicle/PublicTransportEdge.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ template<class E, class L, class N, class V>
class PublicTransportEdge : public IntermodalEdge<E, L, N, V> {
private:
struct Schedule {
Schedule(const SUMOTime _begin, const SUMOTime _end, const SUMOTime _period, const double _travelTimeSec)
: begin(STEPS2TIME(_begin)), end(STEPS2TIME(_end)), period(STEPS2TIME(_period)), travelTimeSec(_travelTimeSec) {}
Schedule(const std::string& _id, const SUMOTime _begin, const SUMOTime _end, const SUMOTime _period, const double _travelTimeSec)
: id(_id), begin(STEPS2TIME(_begin)), end(STEPS2TIME(_end)), period(STEPS2TIME(_period)), travelTimeSec(_travelTimeSec) {}
// the id of the vehicle or flow from which this schedule is generated
const std::string id;
const double begin;
const double end;
// the repetition period for a flow or -1 for a vehicle
const double period;
const double travelTimeSec;
private:
Expand All @@ -65,11 +68,11 @@ class PublicTransportEdge : public IntermodalEdge<E, L, N, V> {
return myEntryStop;
}

void addSchedule(const SUMOTime begin, const SUMOTime end, const SUMOTime period, const double travelTimeSec) {
void addSchedule(const std::string id, const SUMOTime begin, const SUMOTime end, const SUMOTime period, const double travelTimeSec) {
//std::cout << " edge=" << myEntryStop->getID() << "->" << this->getID() << " beg=" << STEPS2TIME(begin) << " end=" << STEPS2TIME(end)
// << " period=" << STEPS2TIME(period)
// << " travelTime=" << travelTimeSec << "\n";
mySchedules.insert(std::make_pair(STEPS2TIME(begin), Schedule(begin, end, period, travelTimeSec)));
mySchedules.insert(std::make_pair(STEPS2TIME(begin), Schedule(id, begin, end, period, travelTimeSec)));
}

double getTravelTime(const IntermodalTrip<E, N, V>* const /* trip */, double time) const {
Expand Down Expand Up @@ -99,6 +102,36 @@ class PublicTransportEdge : public IntermodalEdge<E, L, N, V> {
return minArrivalSec - time;
}

void setIntended(const IntermodalTrip<E, N, V>* const /* trip */, double time, std::string& intended, double& depart) const {
/// @note: duplicates some code of getTravelTime()
double minArrivalSec = std::numeric_limits<double>::max();
double bestDepartTime = std::numeric_limits<double>::max();
for (typename std::multimap<double, Schedule>::const_iterator it = mySchedules.begin(); it != mySchedules.end(); ++it) {
const Schedule& s = it->second;
if (it->first > minArrivalSec) {
break;
}
if (time < s.end) {
int running;
if (s.period <= 0 || time < s.begin) {
// single vehicle or flow begin
running = 0;
} else {
// subsequent flow
running = (int)ceil((time - s.begin) / s.period);
}
const double nextDepart = s.begin + running * s.period;
if (nextDepart + s.travelTimeSec < minArrivalSec) {
minArrivalSec = nextDepart + s.travelTimeSec;
bestDepartTime = nextDepart;
// see naming scheme inMSInsertionControl::determineCandidates()
intended = s.period <= 0 ? s.id : s.id + "." + toString(running);
}
}
}
depart = bestDepartTime;
}

private:
std::multimap<double, Schedule> mySchedules;
const IntermodalEdge<E, L, N, V>* const myEntryStop;
Expand Down
1 change: 1 addition & 0 deletions src/utils/xml/SUMOXMLDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ StringBijection<int>::Entry SUMOXMLDefinitions::attrs[] = {
{ "chargingStation", SUMO_ATTR_CHARGING_STATION},
{ "line", SUMO_ATTR_LINE },
{ "lines", SUMO_ATTR_LINES },
{ "intended", SUMO_ATTR_INTENDED },
{ "value", SUMO_ATTR_VALUE },
{ "prohibitor", SUMO_ATTR_PROHIBITOR },
{ "prohibited", SUMO_ATTR_PROHIBITED },
Expand Down
1 change: 1 addition & 0 deletions src/utils/xml/SUMOXMLDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ enum SumoXMLAttr {
SUMO_ATTR_CHARGING_STATION,
SUMO_ATTR_LINE,
SUMO_ATTR_LINES,
SUMO_ATTR_INTENDED,
SUMO_ATTR_VALUE,
SUMO_ATTR_PROHIBITOR,
SUMO_ATTR_PROHIBITED,
Expand Down

0 comments on commit c99514d

Please sign in to comment.