Skip to content

Commit

Permalink
improving on removal #1922
Browse files Browse the repository at this point in the history
  • Loading branch information
behrisch committed Mar 15, 2024
1 parent 3ce3abd commit 0c8faac
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 11 deletions.
28 changes: 25 additions & 3 deletions src/microsim/devices/MSDevice_FCDReplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <microsim/MSEdge.h>
#include <microsim/MSLane.h>
#include <microsim/MSRoute.h>
#include <microsim/MSEventControl.h>
#include <microsim/MSInsertionControl.h>
#include <microsim/transportables/MSTransportableControl.h>
#include <microsim/transportables/MSStageWaiting.h>
Expand All @@ -39,6 +40,7 @@
// static member initializations
// ===========================================================================
MSDevice_FCDReplay::FCDHandler MSDevice_FCDReplay::myHandler;
MSDevice_FCDReplay::Removal* MSDevice_FCDReplay::myRemovalCommand = nullptr;


// ===========================================================================
Expand Down Expand Up @@ -97,7 +99,7 @@ MSDevice_FCDReplay::notifyMove(SUMOTrafficObject& veh,
double /*newPos*/,
double /*newSpeed*/) {
if (myTrajectory == nullptr || myTrajectory->empty()) {
// TODO remove vehicle
libsumo::Vehicle::remove(veh.getID());
return false;
}
MSVehicle* v = dynamic_cast<MSVehicle*>(&veh);
Expand All @@ -112,7 +114,11 @@ MSDevice_FCDReplay::notifyMove(SUMOTrafficObject& veh,
v->setPreviousSpeed(std::get<3>(p), std::numeric_limits<double>::min());
myTrajectory->erase(myTrajectory->begin());
if (myTrajectory->empty()) {
// TODO remove vehicle
if (myRemovalCommand == nullptr) {
myRemovalCommand = new Removal();
MSNet::getInstance()->getEndOfTimestepEvents()->addEvent(myRemovalCommand);
}
myRemovalCommand->schedule(v);
return false;
}
return true;
Expand Down Expand Up @@ -204,7 +210,7 @@ MSDevice_FCDReplay::FCDHandler::addTrafficObjects() {
MSNet::getInstance()->getInsertionControl().add(vehicle);
MSDevice_FCDReplay* device = static_cast<MSDevice_FCDReplay*>(vehicle->getDevice(typeid(MSDevice_FCDReplay)));
if (device == nullptr) { // Vehicle did not get a replay device
// TODO delete vehicle
MSNet::getInstance()->getVehicleControl().deleteVehicle(vehicle, true);
continue;
}
t.erase(t.begin());
Expand All @@ -214,4 +220,20 @@ MSDevice_FCDReplay::FCDHandler::addTrafficObjects() {
}


SUMOTime
MSDevice_FCDReplay::Removal::execute(SUMOTime /* currentTime */) {
for (MSVehicle* veh : myToRemove) {
libsumo::Vehicle::remove(veh->getID(), libsumo::REMOVE_ARRIVED);
}
myRemovalCommand = nullptr;
return 0;
}


void
MSDevice_FCDReplay::Removal::schedule(MSVehicle* v) {
myToRemove.push_back(v);
}


/****************************************************************************/
14 changes: 13 additions & 1 deletion src/microsim/devices/MSDevice_FCDReplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#pragma once
#include <config.h>

#include <utils/common/Command.h>
#include <utils/xml/SUMOSAXHandler.h>
#include "MSVehicleDevice.h"

Expand Down Expand Up @@ -102,15 +103,26 @@ class MSDevice_FCDReplay : public MSVehicleDevice {
*/
void myStartElement(int element, const SUMOSAXAttributes& attrs);
//@}

private:
SUMOTime myTime;
std::map<std::string, Trajectory> myTrajectories;
std::map<std::string, std::tuple<SUMOTime, std::string, bool, ConstMSEdgeVector > > myRoutes;
};

class Removal : public Command {
public:
SUMOTime execute(SUMOTime currentTime);
void schedule(MSVehicle* v);
private:
std::vector<MSVehicle*> myToRemove;
/// @brief Invalidated assignment operator.
Removal& operator=(const Removal&) = delete;
};

private:
static FCDHandler myHandler;
static Removal* myRemovalCommand;
Trajectory* myTrajectory = nullptr;

private:
Expand Down
17 changes: 11 additions & 6 deletions src/microsim/devices/MSTransportableDevice_FCDReplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,30 +77,35 @@ MSTransportableDevice_FCDReplay::~MSTransportableDevice_FCDReplay() {
SUMOTime
MSTransportableDevice_FCDReplay::MovePedestrians::execute(SUMOTime /* currentTime */) {
MSTransportableControl& c = MSNet::getInstance()->getPersonControl();
std::vector<MSTransportable*> toRemove;
for (MSTransportableControl::constVehIt i = c.loadedBegin(); i != c.loadedEnd(); ++i) {
MSTransportableDevice_FCDReplay* device = static_cast<MSTransportableDevice_FCDReplay*>(i->second->getDevice(typeid(MSTransportableDevice_FCDReplay)));
if (device != nullptr) {
device->move();
if (device != nullptr && device->move()) {
toRemove.push_back(&device->getHolder());
}
}
for (MSTransportable* t : toRemove) {
t->removeStage(0, false);
}
return DELTA_T;
}


void
bool
MSTransportableDevice_FCDReplay::move() {
MSPerson* person = dynamic_cast<MSPerson*>(&myHolder);
if (person == nullptr || !person->hasDeparted()) {
return;
return false;
}
if (myTrajectory == nullptr || myTrajectory->empty()) {
myHolder.removeStage(0, false);
return;
// removing person
return true;
}
const auto& p = myTrajectory->front();
libsumo::Person::moveToXY(person->getID(), std::get<1>(p), std::get<0>(p).x(), std::get<0>(p).y(), std::get<4>(p), 7);
// person->setPreviousSpeed(std::get<3>(p), std::numeric_limits<double>::min());
myTrajectory->erase(myTrajectory->begin());
return false;
}


Expand Down
2 changes: 1 addition & 1 deletion src/microsim/devices/MSTransportableDevice_FCDReplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class MSTransportableDevice_FCDReplay : public MSTransportableDevice {
myTrajectory = t;
}

void move();
bool move();

private:
/** @brief Constructor
Expand Down

0 comments on commit 0c8faac

Please sign in to comment.