Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4 : // This program and the accompanying materials are made available under the
5 : // terms of the Eclipse Public License 2.0 which is available at
6 : // https://www.eclipse.org/legal/epl-2.0/
7 : // This Source Code may also be made available under the following Secondary
8 : // Licenses when the conditions for such availability set forth in the Eclipse
9 : // Public License 2.0 are satisfied: GNU General Public License, version 2
10 : // or later which is available at
11 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 : /****************************************************************************/
14 : /// @file MSPerson.cpp
15 : /// @author Daniel Krajzewicz
16 : /// @author Jakob Erdmann
17 : /// @author Michael Behrisch
18 : /// @author Laura Bieker
19 : /// @date Mon, 9 Jul 2001
20 : ///
21 : // The class for modelling person-movements
22 : /****************************************************************************/
23 : #include <config.h>
24 :
25 : #include <string>
26 : #include <vector>
27 : #include <utils/iodevices/OutputDevice.h>
28 : #include <utils/options/OptionsCont.h>
29 : #include <utils/common/ToString.h>
30 : #include <utils/common/StringUtils.h>
31 : #include <utils/geom/GeomHelper.h>
32 : #include <utils/router/IntermodalNetwork.h>
33 : #include <microsim/MSNet.h>
34 : #include <microsim/MSEdge.h>
35 : #include <microsim/MSLane.h>
36 : #include <microsim/transportables/MSTransportableControl.h>
37 : #include <microsim/MSInsertionControl.h>
38 : #include <microsim/MSEventControl.h>
39 : #include <microsim/MSVehicle.h>
40 : #include <microsim/MSVehicleControl.h>
41 : #include <microsim/MSStoppingPlace.h>
42 : #include <microsim/MSRouteHandler.h>
43 : #include <microsim/devices/MSDevice_Tripinfo.h>
44 : #include <microsim/devices/MSDevice_Taxi.h>
45 : #include <microsim/trigger/MSTriggeredRerouter.h>
46 : #include "MSPModel_Striping.h"
47 : #include "MSStageTrip.h"
48 : #include "MSStageWalking.h"
49 : #include "MSPerson.h"
50 :
51 :
52 : // ===========================================================================
53 : // method definitions
54 : // ===========================================================================
55 : /* -------------------------------------------------------------------------
56 : * MSPerson::MSPersonStage_Access - methods
57 : * ----------------------------------------------------------------------- */
58 4120 : MSPerson::MSPersonStage_Access::MSPersonStage_Access(const MSEdge* destination, MSStoppingPlace* toStop,
59 : const double arrivalPos, const double arrivalPosLat, const double dist, const bool isExit,
60 4120 : const Position& startPos, const Position& endPos) :
61 : MSStage(MSStageType::ACCESS, destination, toStop, arrivalPos, arrivalPosLat),
62 8240 : myDist(dist), myAmExit(isExit) {
63 4120 : myPath.push_back(startPos);
64 4120 : myPath.push_back(endPos);
65 4120 : }
66 :
67 :
68 8240 : MSPerson::MSPersonStage_Access::~MSPersonStage_Access() {}
69 :
70 : MSStage*
71 0 : MSPerson::MSPersonStage_Access::clone() const {
72 0 : return new MSPersonStage_Access(myDestination, myDestinationStop, myArrivalPos, myArrivalPosLat, myDist, myAmExit, myPath.front(), myPath.back());
73 : }
74 :
75 : void
76 4120 : MSPerson::MSPersonStage_Access::proceed(MSNet* net, MSTransportable* person, SUMOTime now, MSStage* /* previous */) {
77 4120 : myDeparted = now;
78 4120 : myEstimatedArrival = now + TIME2STEPS(myDist / person->getMaxSpeed());
79 : // TODO myEstimatedArrival is not a multiple of DELTA_T here. This might give a problem because the destination position will not be reached precisely
80 4120 : net->getBeginOfTimestepEvents()->addEvent(new ProceedCmd(person, &myDestinationStop->getLane().getEdge()), myEstimatedArrival);
81 4120 : net->getPersonControl().startedAccess();
82 4120 : myDestinationStop->getLane().getEdge().addTransportable(person);
83 4120 : }
84 :
85 :
86 : std::string
87 0 : MSPerson::MSPersonStage_Access::getStageDescription(const bool /* isPerson */) const {
88 0 : return "access";
89 : }
90 :
91 :
92 : std::string
93 0 : MSPerson::MSPersonStage_Access::getStageSummary(const bool /* isPerson */) const {
94 0 : return (myAmExit ? "access from stop '" : "access to stop '") + getDestinationStop()->getID() + "'";
95 : }
96 :
97 :
98 : Position
99 19676 : MSPerson::MSPersonStage_Access::getPosition(SUMOTime now) const {
100 19676 : return myPath.positionAtOffset(myPath.length() * (double)(now - myDeparted) / (double)(myEstimatedArrival - myDeparted));
101 : }
102 :
103 :
104 : double
105 19676 : MSPerson::MSPersonStage_Access::getAngle(SUMOTime /* now */) const {
106 19676 : return myPath.angleAt2D(0);
107 : }
108 :
109 :
110 : double
111 18942 : MSPerson::MSPersonStage_Access::getSpeed() const {
112 18942 : return myDist / STEPS2TIME(MAX2((SUMOTime)1, myEstimatedArrival - myDeparted));
113 : }
114 :
115 : void
116 2864 : MSPerson::MSPersonStage_Access::tripInfoOutput(OutputDevice& os, const MSTransportable* const) const {
117 5728 : os.openTag("access");
118 2864 : os.writeAttr("stop", getDestinationStop()->getID());
119 5728 : os.writeAttr("depart", time2string(myDeparted));
120 5728 : os.writeAttr("arrival", myArrived >= 0 ? time2string(myArrived) : "-1");
121 5728 : os.writeAttr("duration", myArrived > 0 ? time2string(getDuration()) : "-1");
122 2864 : os.writeAttr("routeLength", myDist);
123 2864 : os.closeTag();
124 2864 : }
125 :
126 :
127 : SUMOTime
128 4088 : MSPerson::MSPersonStage_Access::ProceedCmd::execute(SUMOTime currentTime) {
129 4088 : MSNet::getInstance()->getPersonControl().endedAccess();
130 4088 : myStopEdge->removeTransportable(myPerson);
131 4088 : if (!myPerson->proceed(MSNet::getInstance(), currentTime)) {
132 49 : MSNet::getInstance()->getPersonControl().erase(myPerson);
133 : }
134 4088 : return 0;
135 : }
136 :
137 :
138 : /* -------------------------------------------------------------------------
139 : * MSPerson - methods
140 : * ----------------------------------------------------------------------- */
141 305903 : MSPerson::MSPerson(const SUMOVehicleParameter* pars, MSVehicleType* vtype, MSTransportable::MSTransportablePlan* plan, const double speedFactor) :
142 : MSTransportable(pars, vtype, plan, true),
143 305903 : myInfluencer(nullptr),
144 305903 : myChosenSpeedFactor(pars->speedFactor < 0 ? speedFactor : pars->speedFactor)
145 305903 : { }
146 :
147 :
148 584150 : MSPerson::~MSPerson() {
149 305857 : delete myInfluencer;
150 584150 : }
151 :
152 :
153 : bool
154 467006 : MSPerson::checkAccess(const MSStage* const prior, const bool waitAtStop) {
155 : MSStoppingPlace* prevStop = prior->getDestinationStop();
156 467006 : if (!waitAtStop && prior->getStageType() == MSStageType::TRIP) {
157 174766 : prevStop = prior->getOriginStop();
158 : }
159 467006 : if (prevStop != nullptr) {
160 57873 : const MSEdge* const accessEdge = waitAtStop ? prior->getDestination() : (*myStep)->getFromEdge();
161 57873 : const MSStoppingPlace::Access* const access = prevStop->getAccess(accessEdge);
162 57873 : if (access != nullptr) {
163 4120 : const MSLane* const lane = accessEdge->getLanes()[0];
164 4120 : MSStage* newStage = nullptr;
165 4120 : if (waitAtStop) {
166 2018 : const MSEdge* const stopEdge = &prevStop->getLane().getEdge();
167 2018 : const double arrivalAtBs = (prevStop->getBeginLanePosition() + prevStop->getEndLanePosition()) / 2;
168 2018 : newStage = new MSPersonStage_Access(stopEdge, prevStop, arrivalAtBs, 0.0, access->length, false,
169 2018 : lane->geometryPositionAtOffset(access->endPos),
170 4036 : prevStop->getLane().geometryPositionAtOffset(arrivalAtBs));
171 : } else {
172 3754 : const bool useDoors = access->exit == MSStoppingPlace::AccessExit::DOORS ||
173 7058 : (OptionsCont::getOptions().getString("pedestrian.model") != "jupedsim" && access->exit == MSStoppingPlace::AccessExit::CARRIAGE);
174 2102 : if (access->exit == MSStoppingPlace::AccessExit::CARRIAGE) {
175 0 : const double startPos = prior->getStageType() == MSStageType::TRIP ? prior->getEdgePos(0) : prior->getArrivalPos();
176 0 : const double startPosLat = prior->getStageType() == MSStageType::TRIP ? prior->getEdgePosLat(0) : prior->getArrivalPosLat();
177 : // The start and end attributes of the access stage are equal in this case, but we need to compute the arrival position relatively
178 : // to the current lane and not the lane of the previous stage.
179 0 : const Position start = prevStop->getLane().geometryPositionAtOffset(startPos, startPosLat);
180 0 : const Position end = lane->getShape().transformToVectorCoordinates(start);
181 0 : newStage = new MSPersonStage_Access(accessEdge, prevStop, end.x(), -end.y(), access->length, true, start, start);
182 : } else {
183 2102 : const double startPos = prior->getStageType() == MSStageType::TRIP ? prior->getEdgePos(0) : prior->getArrivalPos();
184 2102 : const Position& trainExit = prevStop->getLane().geometryPositionAtOffset(startPos);
185 2102 : const double arrivalPos = useDoors ? lane->getShape().nearest_offset_to_point2D(trainExit) : access->endPos;
186 : Position platformEntry = lane->geometryPositionAtOffset(arrivalPos);
187 2102 : if (useDoors) {
188 : // find the closer side of the platform to enter
189 900 : const double halfWidth = lane->getWidth() / 2. - MAX2(getVehicleType().getLength(), getVehicleType().getWidth()) / 2. - POSITION_EPS;
190 450 : platformEntry = lane->geometryPositionAtOffset(arrivalPos, halfWidth);
191 450 : const Position& plat2 = lane->geometryPositionAtOffset(arrivalPos, -halfWidth);
192 450 : if (trainExit.distanceSquaredTo2D(plat2) < trainExit.distanceSquaredTo2D(platformEntry)) {
193 356 : platformEntry = plat2;
194 : }
195 : }
196 2102 : newStage = new MSPersonStage_Access(accessEdge, prevStop, arrivalPos, 0.0, access->length, true,
197 2102 : trainExit, platformEntry);
198 : }
199 : }
200 4120 : newStage->setTrip(prior->getTrip());
201 4120 : myStep = myPlan->insert(myStep, newStage);
202 : return true;
203 : }
204 : }
205 : return false;
206 : }
207 :
208 :
209 : double
210 0 : MSPerson::getImpatience() const {
211 0 : return MAX2(0., MIN2(1., getVehicleType().getImpatience()
212 0 : + STEPS2TIME((*myStep)->getWaitingTime(SIMSTEP)) / MSPModel_Striping::MAX_WAIT_TOLERANCE));
213 : }
214 :
215 : const std::string&
216 2625 : MSPerson::getNextEdge() const {
217 : // if (getCurrentStageType() == WALKING) {
218 : // MSStageWalking* walkingStage = dynamic_cast<MSStageWalking*>(*myStep);
219 : // assert(walkingStage != 0);
220 : // const MSEdge* nextEdge = walkingStage->getPedestrianState()->getNextEdge(*walkingStage);
221 : // if (nextEdge != 0) {
222 : // return nextEdge->getID();
223 : // }
224 : // }
225 : // return StringUtils::emptyString;
226 2625 : const MSEdge* nextEdge = getNextEdgePtr();
227 2625 : if (nextEdge != nullptr) {
228 2623 : return nextEdge->getID();
229 : }
230 : return StringUtils::emptyString;
231 : }
232 :
233 :
234 : const MSEdge*
235 163102 : MSPerson::getNextEdgePtr() const {
236 163102 : if (getCurrentStageType() == MSStageType::WALKING) {
237 163102 : MSStageWalking* walkingStage = dynamic_cast<MSStageWalking*>(*myStep);
238 : assert(walkingStage != nullptr);
239 163102 : return walkingStage->getPState()->getNextEdge(*walkingStage);
240 : }
241 : return nullptr;
242 : }
243 :
244 :
245 :
246 : void
247 1507 : MSPerson::replaceWalk(const ConstMSEdgeVector& newEdges, double departPos, int firstIndex, int nextIndex) {
248 : assert(nextIndex > firstIndex);
249 : //std::cout << SIMTIME << " reroute person " << getID()
250 : // << " newEdges=" << toString(newEdges)
251 : // << " firstIndex=" << firstIndex
252 : // << " nextIndex=" << nextIndex
253 : // << " departPos=" << getEdgePos()
254 : // << " arrivalPos=" << getNextStage(nextIndex - 1)->getArrivalPos()
255 : // << "\n";
256 1507 : MSStage* const toBeReplaced = getNextStage(nextIndex - 1);
257 : MSStageWalking* newStage = new MSStageWalking(getID(), newEdges,
258 : toBeReplaced->getDestinationStop(), -1,
259 : -1,
260 : departPos,
261 1507 : toBeReplaced->getArrivalPos(),
262 1507 : MSPModel::UNSPECIFIED_POS_LAT);
263 1507 : appendStage(newStage, nextIndex);
264 : // remove stages in reverse order so that proceed will only be called at the last removal
265 3019 : for (int i = nextIndex - 1; i >= firstIndex; i--) {
266 : //std::cout << " removeStage=" << i << "\n";
267 1512 : removeStage(i);
268 : }
269 1507 : }
270 :
271 :
272 : MSPerson::Influencer&
273 43222 : MSPerson::getInfluencer() {
274 43222 : if (myInfluencer == nullptr) {
275 106 : myInfluencer = new Influencer();
276 : }
277 43222 : return *myInfluencer;
278 : }
279 :
280 :
281 : const MSPerson::Influencer*
282 0 : MSPerson::getInfluencer() const {
283 0 : return myInfluencer;
284 : }
285 :
286 :
287 :
288 : /* -------------------------------------------------------------------------
289 : * methods of MSPerson::Influencer
290 : * ----------------------------------------------------------------------- */
291 106 : MSPerson::Influencer::Influencer() {}
292 :
293 :
294 106 : MSPerson::Influencer::~Influencer() {}
295 :
296 :
297 : void
298 10316 : MSPerson::Influencer::setRemoteControlled(Position xyPos, MSLane* l, double pos, double posLat, double angle, int edgeOffset, const ConstMSEdgeVector& route, SUMOTime t) {
299 10316 : myRemoteXYPos = xyPos;
300 10316 : myRemoteLane = l;
301 10316 : myRemotePos = pos;
302 10316 : myRemotePosLat = posLat;
303 10316 : myRemoteAngle = angle;
304 10316 : myRemoteEdgeOffset = edgeOffset;
305 10316 : myRemoteRoute = route;
306 10316 : myLastRemoteAccess = t;
307 10316 : }
308 :
309 :
310 : bool
311 22590 : MSPerson::Influencer::isRemoteControlled() const {
312 22590 : return myLastRemoteAccess == MSNet::getInstance()->getCurrentTimeStep();
313 : }
314 :
315 :
316 : bool
317 0 : MSPerson::Influencer::isRemoteAffected(SUMOTime t) const {
318 0 : return myLastRemoteAccess >= t - TIME2STEPS(10);
319 : }
320 :
321 :
322 : void
323 10316 : MSPerson::Influencer::postProcessRemoteControl(MSPerson* p) {
324 : /*
325 : std::cout << SIMTIME << " moveToXY person=" << p->getID()
326 : << " xyPos=" << myRemoteXYPos
327 : << " lane=" << Named::getIDSecure(myRemoteLane)
328 : << " pos=" << myRemotePos
329 : << " posLat=" << myRemotePosLat
330 : << " angle=" << myRemoteAngle
331 : << " eOf=" << myRemoteEdgeOffset
332 : << " route=" << toString(myRemoteRoute)
333 : << " aTime=" << time2string(myLastRemoteAccess)
334 : << "\n";
335 : */
336 10316 : switch (p->getStageType(0)) {
337 : case MSStageType::WALKING: {
338 10276 : MSStageWalking* s = dynamic_cast<MSStageWalking*>(p->getCurrentStage());
339 : assert(s != nullptr);
340 10276 : s->getPState()->moveToXY(p, myRemoteXYPos, myRemoteLane, myRemotePos, myRemotePosLat,
341 10276 : myRemoteAngle, myRemoteEdgeOffset, myRemoteRoute,
342 : MSNet::getInstance()->getCurrentTimeStep());
343 : }
344 10276 : break;
345 : default:
346 : break;
347 : }
348 10316 : }
349 :
350 :
351 : /****************************************************************************/
|