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)); }
void PhoneBook::addEntry() { pair<Person, string> nameEntry; // Stores a name book entry pair<string, Person> numberEntry; // Stores a number book entry string number; Person person = getPerson(); cout << "Enter the phone number for " << person.getName() << ": "; getline(cin, number); // Add an entry to namebook nameEntry = make_pair(person, number); multimap<Person,string>::iterator nameIter = namebook.lower_bound(person); if(nameIter == namebook.end()) // Is there a previous entry for person? namebook.insert(nameEntry); // No, so just insert the pair else namebook.insert(nameIter, nameEntry); // Yes, so insert the pair after this point // Add an entry to numberbook numberEntry = make_pair(number, person); multimap<string,Person>::iterator numberIter = numberbook.lower_bound(number); if(numberIter == numberbook.end()) // Is there a previous entry for number? numberbook.insert(numberEntry); // No, so just insert the pair else numberbook.insert(numberIter, numberEntry); // Yes, so insert the pair after this point cout << "Entry successful." << endl; }
void Person::setType(const std::string& personID, const std::string& typeID) { MSVehicleType* vehicleType = MSNet::getInstance()->getVehicleControl().getVType(typeID); if (vehicleType == nullptr) { throw TraCIException("The vehicle type '" + typeID + "' is not known."); } getPerson(personID)->replaceVehicleType(vehicleType); }
void BikeDisplay::setPerson(unsigned int site, unsigned int personID) { PersonItem *person = getPerson(personID); QPointF curPos = m_sitePos[site]; float angle = rand(); person->setPos(curPos.x() + 40*cos(angle),curPos.y() + 40*sin(angle)); person->show(); }
std::string Person::getVehicle(const std::string& personID) { const SUMOVehicle* veh = getPerson(personID)->getVehicle(); if (veh == nullptr) { return ""; } else { return veh->getID(); } }
TraCIColor Person::getColor(const std::string& personID) { const RGBColor& col = getPerson(personID)->getParameter().color; TraCIColor tcol; tcol.r = col.red(); tcol.g = col.green(); tcol.b = col.blue(); tcol.a = col.alpha(); return tcol; }
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::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 main() { struct Person p1; p1 = getPerson(); // 반환된 구조체 변수의 내용이 p1로 모두 복사됨 // getPerson에서 저장한 값이 출력됨 printf("이름: %s\n", p1.name); // 홍길동 printf("나이: %d\n", p1.age); // 30 printf("주소: %s\n", p1.address); // 서울시 용산구 한남동 return 0; }
// Retrieves all the numbers for a given person void PhoneBook::getNumber() { Person person = getPerson(); multimap<Person, string>::iterator iter = namebook.lower_bound(person); if(iter == namebook.end()) cout << "No entry found for " << person.getName() << endl; else { cout << "The following numbers are listed for " << person.getName() << ":" << endl; for( ; iter != namebook.upper_bound(person) ; iter++) cout << iter->second << endl; } }
void Person::rerouteTraveltime(const std::string& personID) { MSPerson* p = getPerson(personID); if (p->getNumRemainingStages() == 0) { throw TraCIException("Person '" + personID + "' has no remaining stages."); } const MSEdge* from = p->getEdge(); double departPos = p->getEdgePos(); // reroute to the start of the next-non-walking stage int firstIndex; if (p->getCurrentStageType() == MSTransportable::MOVING_WITHOUT_VEHICLE) { firstIndex = 0; } else if (p->getCurrentStageType() == MSTransportable::WAITING) { if (p->getNumRemainingStages() < 2 || p->getStageType(1) != MSTransportable::MOVING_WITHOUT_VEHICLE) { throw TraCIException("Person '" + personID + "' cannot reroute after the current stop."); } firstIndex = 1; } else { throw TraCIException("Person '" + personID + "' cannot reroute in stage type '" + toString(p->getCurrentStageType()) + "'."); } int nextIndex = firstIndex + 1; for (; nextIndex < p->getNumRemainingStages(); nextIndex++) { if (p->getStageType(nextIndex) != MSTransportable::MOVING_WITHOUT_VEHICLE) { break; } } MSTransportable::Stage* destStage = p->getNextStage(nextIndex - 1); const MSEdge* to = destStage->getEdges().back(); double arrivalPos = destStage->getArrivalPos(); double speed = p->getVehicleType().getMaxSpeed(); ConstMSEdgeVector newEdges; MSNet::getInstance()->getPedestrianRouter().compute(from, to, departPos, arrivalPos, speed, 0, nullptr, newEdges); if (newEdges.empty()) { throw TraCIException("Could not find new route for person '" + personID + "'."); } ConstMSEdgeVector oldEdges = p->getEdges(firstIndex); assert(!oldEdges.empty()); if (oldEdges.front()->getFunction() != EDGEFUNC_NORMAL) { oldEdges.erase(oldEdges.begin()); } //std::cout << " remainingStages=" << p->getNumRemainingStages() << " oldEdges=" << toString(oldEdges) << " newEdges=" << toString(newEdges) << " firstIndex=" << firstIndex << " nextIndex=" << nextIndex << "\n"; if (newEdges == oldEdges && (firstIndex + 1 == nextIndex)) { return; } if (newEdges.front() != from) { // @note: maybe this should be done automatically by the router newEdges.insert(newEdges.begin(), from); } p->reroute(newEdges, departPos, firstIndex, nextIndex); }
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; }
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())); }
// Allows the deletion of a number for a given person // Note that the erase() function increments the iterator you pass as the // argument so it is important to exit the loop after calling erase() to // avoid the possibility of attempting to increment the iterator when it // is already pointing to one beyond the end of the container. void PhoneBook::deleteNameEntry() { Person person = getPerson(); multimap<Person, string>::iterator nameIter = namebook.lower_bound(person); multimap<string, Person>::iterator numberIter; string number; char answer; if(nameIter == namebook.end()) cout << "No entry found in name book for " << person.getName() << endl; else for( ; nameIter != namebook.upper_bound(person) ; nameIter++) { cout << "Do you want to erase " << nameIter->second << " for " << person.getName() << "? (y or n): "; cin >> answer; if(tolower(answer) == 'y') { // Find the corresponding entry in the numberbook before erasing namebook entry number = nameIter->second; numberIter = numberbook.lower_bound(number); if(numberIter == numberbook.end()) cout << "No entry found in number book for " << number << endl; else { for( ; numberIter != numberbook.upper_bound(number) ; numberIter++) if(numberIter->second.getName().compare(person.getName()) == 0) { numberbook.erase(numberIter); cout << "Deleted number entry" << endl; break; } namebook.erase(nameIter); cout << person.getName() << " erased." << endl; break; // Exit the loop } } else continue; } }
void BikeDisplay::travel(unsigned int personId,unsigned int site1, unsigned int site2,unsigned int ms) { static QMutex mutex; mutex.lock(); QParallelAnimationGroup *group=new QParallelAnimationGroup(this); { BikeItem *bike=getFreeBike(); bike->show(); QPropertyAnimation *animation=new QPropertyAnimation(bike, "pos"); animation->setDuration(ms-10); animation->setStartValue(m_sitePos[site1]- QPointF(BIKEWIDTH/2,BIKEWIDTH/2)); animation->setEndValue(m_sitePos[site2]- QPointF(BIKEWIDTH/2,BIKEWIDTH/2)); group->addAnimation(animation); } { PersonItem *person=getPerson(personId); person->show(); QPropertyAnimation *animation=new QPropertyAnimation(person, "pos"); animation->setDuration(ms-10); animation->setStartValue(m_sitePos[site1]- QPointF(BIKEWIDTH/2,BIKEWIDTH*1.2)); animation->setEndValue(m_sitePos[site2]- QPointF(BIKEWIDTH/2,BIKEWIDTH*1.2)); group->addAnimation(animation); } group->start(); QObject::connect(group, SIGNAL(finished()), this, SLOT(finishedAnimation())); mutex.unlock(); }
void Person::moveTo(const std::string& personID, const std::string& edgeID, double /* position */) { MSPerson* p = getPerson(personID); MSEdge* e = MSEdge::dictionary(edgeID); if (e == nullptr) { throw TraCIException("Unknown edge '" + edgeID + "'."); } /* switch (p->getStageType(0)) { case MSTransportable::MOVING_WITHOUT_VEHICLE: { MSPerson::MSPersonStage_Walking* s = dynamic_cast<MSPerson::MSPersonStage_Walking*>(p->getCurrentStage()); assert(s != 0); const std::string error = s->moveTo(p, Simulation::getCurrentTime()); if (error != "") { throw TraCIException("Command moveTo failed for person '" + personID + "' (" + error + ")."); } break; } default: */ throw TraCIException("Command moveTo is not supported for person '" + personID + "' while " + p->getCurrentStageDescription() + "."); //} }
double Person::getSpeed(const std::string& personID) { return getPerson(personID)->getSpeed(); }
void Person::storeShape(const std::string& id, PositionVector& shape) { shape.push_back(getPerson(id)->getPosition()); }
void Person::setColor(const std::string& personID, const TraCIColor& c) { const SUMOVehicleParameter& p = getPerson(personID)->getParameter(); p.color.set((unsigned char)c.r, (unsigned char)c.g, (unsigned char)c.b, (unsigned char)c.a); p.parametersSet |= VEHPARS_COLOR_SET; }
void Person::setActionStepLength(const std::string& personID, double actionStepLength, bool resetActionOffset) { getPerson(personID)->getSingularType().setActionStepLength(SUMOVehicleParserHelper::processActionStepLength(actionStepLength), resetActionOffset); }
void Person::setSpeedFactor(const std::string& personID, double factor) { getPerson(personID)->getSingularType().setSpeedFactor(factor); }
void Person::setLateralAlignment(const std::string& personID, const std::string& latAlignment) { getPerson(personID)->getSingularType().setPreferredLateralAlignment(SUMOXMLDefinitions::LateralAlignments.get(latAlignment)); }
void Person::setMaxSpeedLat(const std::string& personID, double speed) { getPerson(personID)->getSingularType().setMaxSpeedLat(speed); }
void Person::setMinGapLat(const std::string& personID, double minGapLat) { getPerson(personID)->getSingularType().setMinGapLat(minGapLat); }
void Person::setTau(const std::string& personID, double tau) { getPerson(personID)->getSingularType().setTau(tau); }
void Person::setImperfection(const std::string& personID, double imperfection) { getPerson(personID)->getSingularType().setImperfection(imperfection); }
void Person::setApparentDecel(const std::string& personID, double decel) { getPerson(personID)->getSingularType().setApparentDecel(decel); }
void Person::setEmergencyDecel(const std::string& personID, double decel) { getPerson(personID)->getSingularType().setEmergencyDecel(decel); }
void Person::setAccel(const std::string& personID, double accel) { getPerson(personID)->getSingularType().setAccel(accel); }