void Person::appendWalkingStage(const std::string& personID, const std::vector<std::string>& edgeIDs, double arrivalPos, double duration, double speed, const std::string& stopID) { MSTransportable* p = getPerson(personID); ConstMSEdgeVector edges; try { MSEdge::parseEdgesList(edgeIDs, edges, "<unknown>"); } catch (ProcessError& e) { throw TraCIException(e.what()); } if (edges.empty()) { throw TraCIException("Empty edge list for walking stage of person '" + personID + "'."); } if (fabs(arrivalPos) > edges.back()->getLength()) { throw TraCIException("Invalid arrivalPos for walking stage of person '" + personID + "'."); } if (arrivalPos < 0) { arrivalPos += edges.back()->getLength(); } if (speed < 0) { speed = p->getVehicleType().getMaxSpeed(); } MSStoppingPlace* bs = nullptr; if (stopID != "") { bs = MSNet::getInstance()->getStoppingPlace(stopID, SUMO_TAG_BUS_STOP); if (bs == nullptr) { throw TraCIException("Invalid stopping place id '" + stopID + "' for person: '" + personID + "'"); } } p->appendStage(new MSPerson::MSPersonStage_Walking(p->getID(), edges, bs, TIME2STEPS(duration), speed, p->getArrivalPos(), arrivalPos, 0)); }
bool MSDevice_Container::notifyMove(SUMOVehicle& veh, SUMOReal /*oldPos*/, SUMOReal /*newPos*/, SUMOReal /*newSpeed*/) { if (myStopped) { // if veh is not anymore at the stop if (!veh.isStopped()) { for (std::vector<MSTransportable*>::iterator i = myContainers.begin(); i != myContainers.end(); ++i) { (*i)->setDeparted(MSNet::getInstance()->getCurrentTimeStep()); } myStopped = false; } } else { if (veh.isStopped()) { for (std::vector<MSTransportable*>::iterator i = myContainers.begin(); i != myContainers.end();) { MSTransportable* container = *i; if (&(container->getDestination()) == veh.getEdge()) { if (!container->proceed(MSNet::getInstance(), MSNet::getInstance()->getCurrentTimeStep())) { MSNet::getInstance()->getContainerControl().erase(container); } i = myContainers.erase(i); } else { ++i; } } myStopped = true; } } return true; }
bool MSDevice_Person::notifyMove(SUMOVehicle& veh, SUMOReal /*oldPos*/, SUMOReal /*newPos*/, SUMOReal /*newSpeed*/) { if (myStopped) { if (!veh.isStopped()) { for (std::vector<MSTransportable*>::iterator i = myPersons.begin(); i != myPersons.end(); ++i) { (*i)->setDeparted(MSNet::getInstance()->getCurrentTimeStep()); } myStopped = false; } } else { if (veh.isStopped()) { for (std::vector<MSTransportable*>::iterator i = myPersons.begin(); i != myPersons.end();) { MSTransportable* person = *i; if (&(person->getDestination()) == veh.getEdge()) { if (!person->proceed(MSNet::getInstance(), MSNet::getInstance()->getCurrentTimeStep())) { MSNet::getInstance()->getPersonControl().erase(person); } i = myPersons.erase(i); } else { ++i; } } myStopped = true; } } return true; }
void Person::removeStage(const std::string& personID, int nextStageIndex) { MSTransportable* p = getPerson(personID); if (nextStageIndex >= p->getNumRemainingStages()) { throw TraCIException("The stage index must be lower than the number of remaining stages."); } if (nextStageIndex < 0) { throw TraCIException("The stage index may not be negative."); } p->removeStage(nextStageIndex); }
int Person::getStage(const std::string& personID, int nextStageIndex) { MSTransportable* p = getPerson(personID); if (nextStageIndex >= p->getNumRemainingStages()) { throw TraCIException("The stage index must be lower than the number of remaining stages."); } if (nextStageIndex < (p->getNumRemainingStages() - p->getNumStages())) { throw TraCIException("The negative stage index must refer to a valid previous stage."); } return p->getStageType(nextStageIndex); }
void Person::appendWaitingStage(const std::string& personID, double duration, const std::string& description, const std::string& stopID) { MSTransportable* p = getPerson(personID); if (duration < 0) { throw TraCIException("Duration for person: '" + personID + "' must not be negative"); } MSStoppingPlace* bs = nullptr; if (stopID != "") { bs = MSNet::getInstance()->getStoppingPlace(stopID, SUMO_TAG_BUS_STOP); if (bs == nullptr) { throw TraCIException("Invalid stopping place id '" + stopID + "' for person: '" + personID + "'"); } } p->appendStage(new MSTransportable::Stage_Waiting(p->getArrivalEdge(), nullptr, TIME2STEPS(duration), 0, p->getArrivalPos(), description, false)); }
std::vector<std::string> Person::getEdges(const std::string& personID, int nextStageIndex) { MSTransportable* p = getPerson(personID); if (nextStageIndex >= p->getNumRemainingStages()) { throw TraCIException("The stage index must be lower than the number of remaining stages."); } if (nextStageIndex < (p->getNumRemainingStages() - p->getNumStages())) { throw TraCIException("The negative stage index must refer to a valid previous stage."); } std::vector<std::string> edgeIDs; for (auto& e : p->getEdges(nextStageIndex)) { if (e != nullptr) { edgeIDs.push_back(e->getID()); } } return edgeIDs; }
bool MSDevice_Container::notifyLeave(SUMOVehicle& veh, SUMOReal /*lastPos*/, MSMoveReminder::Notification reason) { if (reason >= MSMoveReminder::NOTIFICATION_ARRIVED) { for (std::vector<MSTransportable*>::iterator i = myContainers.begin(); i != myContainers.end(); ++i) { MSTransportable* container = *i; if (&(container->getDestination()) != veh.getEdge()) { WRITE_WARNING("Teleporting container '" + container->getID() + "' from vehicle destination edge '" + veh.getEdge()->getID() + "' to intended destination edge '" + container->getDestination().getID() + "'"); } if (!container->proceed(MSNet::getInstance(), MSNet::getInstance()->getCurrentTimeStep())) { MSNet::getInstance()->getContainerControl().erase(container); }; } } return true; }
void Person::appendDrivingStage(const std::string& personID, const std::string& toEdge, const std::string& lines, const std::string& stopID) { MSTransportable* p = getPerson(personID); const MSEdge* edge = MSEdge::dictionary(toEdge); if (!edge) { throw TraCIException("Invalid edge '" + toEdge + "' for person: '" + personID + "'"); } if (lines.size() == 0) { return throw TraCIException("Empty lines parameter for person: '" + personID + "'"); } MSStoppingPlace* bs = nullptr; if (stopID != "") { bs = MSNet::getInstance()->getStoppingPlace(stopID, SUMO_TAG_BUS_STOP); if (bs == nullptr) { throw TraCIException("Invalid stopping place id '" + stopID + "' for person: '" + personID + "'"); } } p->appendStage(new MSPerson::MSPersonStage_Driving(edge, bs, -NUMERICAL_EPS, StringTokenizer(lines).getVector())); }
void Person::setParameter(const std::string& personID, const std::string& key, const std::string& value) { MSTransportable* p = getPerson(personID); ((SUMOVehicleParameter&)p->getParameter()).setParameter(key, value); }
void MSPerson::MSPersonStage_Waiting::endEventOutput(const MSTransportable& p, SUMOTime t, OutputDevice& os) const { os.openTag("event").writeAttr("time", time2string(t)).writeAttr("type", "actend " + myActType).writeAttr("agent", p.getID()) .writeAttr("link", getEdge()->getID()).closeTag(); }
void MSPerson::MSPersonStage_Driving::beginEventOutput(const MSTransportable& p, SUMOTime t, OutputDevice& os) const { os.openTag("event").writeAttr("time", time2string(t)).writeAttr("type", "arrival").writeAttr("agent", p.getID()).writeAttr("link", getEdge()->getID()).closeTag(); }
void MSPerson::MSPersonStage_Walking::endEventOutput(const MSTransportable& p, SUMOTime t, OutputDevice& os) const { os.openTag("event").writeAttr("time", time2string(t)).writeAttr("type", "arrival") .writeAttr("agent", p.getID()).writeAttr("link", myRoute.back()->getID()).closeTag(); }
void MSContainer::MSContainerStage_Tranship::endEventOutput(const MSTransportable& c, SUMOTime t, OutputDevice& os) const { os.openTag("event").writeAttr("time", time2string(t)).writeAttr("type", "arrival") .writeAttr("agent", c.getID()).writeAttr("link", myRoute.back()->getID()).closeTag(); }