bool AGWorkAndSchool::carsToTrips() { // check if the starting edge allows cars if (!myHousehold->getPosition().getStreet().allows(SVC_PASSENGER)) { return false; } std::list<AGAdult>::const_iterator itDriA; std::list<AGCar>::const_iterator itCar = myHousehold->getCars().begin(); for (itDriA = personsDrivingCars.begin(); itDriA != personsDrivingCars.end(); ++itDriA) { //check if the number of cars is lower than the number of drivers if (itCar == myHousehold->getCars().end()) { return false; } // check if the destination edge allows cars if (!itDriA->getWorkPosition().getPosition().getStreet().allows(SVC_PASSENGER)) { return false; } AGTrip trip(myHousehold->getPosition(), itDriA->getWorkPosition().getPosition(), *itCar, depHour(myHousehold->getPosition(), itDriA->getWorkPosition().getPosition(), itDriA->getWorkPosition().getOpening())); ++itCar; tempTrip.push_back(trip); } std::list<AGAdult>::iterator itAccA; for (itAccA = adultNeedingCarAccompaniment.begin(); itAccA != adultNeedingCarAccompaniment.end(); ++itAccA) { AGTrip trip(myHousehold->getPosition(), itAccA->getWorkPosition().getPosition(), depHour(myHousehold->getPosition(), itAccA->getWorkPosition().getPosition(), itAccA->getWorkPosition().getOpening())); tempAccTrip.push_back(trip); } std::list<AGChild>::iterator itAccC; for (itAccC = childrenNeedingCarAccompaniment.begin(); itAccC != childrenNeedingCarAccompaniment.end(); ++itAccC) { AGTrip trip(myHousehold->getPosition(), itAccC->getSchoolLocation(), depHour(myHousehold->getPosition(), itAccC->getSchoolLocation(), itAccC->getSchoolOpening())); tempAccTrip.push_back(trip); } checkAndBuildTripConsistancy(); if (isThereUnusedCar() && ! checkDriversScheduleMatching()) { makePossibleDriversDrive(); } generateListTrips(); return true; }
//! Insert a value to unassembled vector void insert( const IndexType i, const IndexType j, const ValueType value ) { // combine index pair IndexPair_ ip( i, j ); // combine triples Triple_ trip( ip, value ); // insert it to buffer in any case matrixCooVec_.push_back( trip ); sorted_ = false; // resort if number of new unsorted entries excess a critical value if ( (matrixCooVec_.size() - sortedSize_) > ALLOWED_MEM_OVERHEAD ) { this -> finishAssembly(); } return; }
void AGWorkAndSchool::generateListTrips() { int arrTime; std::list<AGTrip>::iterator itAccT; std::list<AGTrip>::iterator itDriT; std::list<AGAdult>::iterator itA; bool alreadyDone; /** * 1 / 3 : Accompaniment */ for (itAccT = tempAccTrip.begin(); itAccT != tempAccTrip.end(); ++itAccT) { alreadyDone = false; for (itDriT = tempTrip.begin(); itDriT != tempTrip.end(); ++itDriT) { if (!alreadyDone) { if (itAccT->getArrTime(this->timePerKm) < itDriT->getArrTime(this->timePerKm) && !alreadyDone) { //Add the accompaniment trip to the driver's trip OR new trip if (itAccT->getRideBackArrTime(this->timePerKm) < itDriT->getTime()) { //there is enough time to accompany people and go back home before going to work itAccT->setVehicleName(itDriT->getVehicleName()); itAccT->addLayOver(itAccT->getArr());//final destination is the last accompaniment stop: not the destination of the course itAccT->setArr(myHousehold->getPosition());//final destination of the whole trip: home myPartialActivityTrips.push_back(*itAccT); alreadyDone = true; } else { //the driver drives people to their working place or school and goes directly to work after that arrTime = itDriT->getArrTime(this->timePerKm); itDriT->addLayOver(*itAccT); itDriT->setDepTime(itDriT->estimateDepTime(arrTime, this->timePerKm)); //tempAccTrip.erase(itAccT); //--itAccT; //because of erasure alreadyDone = true; } } } } for (itA = notNeedingDrivers.begin(); itA != notNeedingDrivers.end(); ++itA) { if (!itA->isWorking() && !alreadyDone) { std::string nameC = getUnusedCar(); if (nameC.size() != 0) { itAccT->setVehicleName(getUnusedCar()); itAccT->addLayOver(itAccT->getArr()); itAccT->setArr(myHousehold->getPosition()); myPartialActivityTrips.push_back(*itAccT); alreadyDone = true; } } else if (itAccT->getRideBackArrTime(this->timePerKm) < itA->getWorkPosition().getOpening() && !alreadyDone) { std::string nameC = getUnusedCar(); if (nameC.size() != 0) { itAccT->setVehicleName(getUnusedCar()); itAccT->addLayOver(itAccT->getArr()); itAccT->setArr(myHousehold->getPosition()); myPartialActivityTrips.push_back(*itAccT); alreadyDone = true; } } } } /** * 2/3 : drivers way */ for (itDriT = tempTrip.begin(); itDriT != tempTrip.end(); ++itDriT) { myPartialActivityTrips.push_back(*itDriT); } /** * 3/3: way return */ for (itA = personsDrivingCars.begin(); itA != personsDrivingCars.end(); ++itA) { for (itDriT = tempTrip.begin(); itDriT != tempTrip.end(); ++itDriT) { if (itA->getWorkPosition().getPosition() == itDriT->getArr()) { AGTrip trip(itA->getWorkPosition().getPosition(), myHousehold->getPosition(), itDriT->getVehicleName(), itA->getWorkPosition().getClosing()); myPartialActivityTrips.push_back(trip); tempTrip.erase(itDriT); break; } } } }