19 #include <grpc++/grpc++.h> 25 #include "hybridsim.grpc.pb.h" 30 using grpc::ClientContext;
35 const std::string address = oc.
getString(
"pedestrian.remote.address");
36 myHybridsimStub = hybridsim::HybridSimulation::NewStub(grpc::CreateChannel(
37 address, grpc::InsecureChannelCredentials()));
59 double offset = departureOffsetAlongLane == 0 ? 0.4 : -0.4;
60 departureOffsetAlongLane += offset;
63 hybridsim::Coordinate* departureCoordinate = req.mutable_enterlocation();
64 departureCoordinate->set_x(departurePos.
x());
65 departureCoordinate->set_y(departurePos.
y());
70 hybridsim::Coordinate* arrivalCoordinate = req.mutable_leavelocation();
71 arrivalCoordinate->set_x(arrivalPos.
x());
72 arrivalCoordinate->set_y(arrivalPos.
y());
76 for (ConstMSEdgeVector::const_iterator it = stage->
getRoute().begin(); it != stage->
getRoute().end(); it++) {
81 const MSEdge* nxt = *(it + 1);
92 throw ProcessError(
"Cannot map edge : " + edge->
getID() +
" to remote simulation");
96 int frId = dir ==
FORWARD ? std::get<0>(transitions) : std::get<1>(transitions);
97 int toId = dir ==
FORWARD ? std::get<1>(transitions) : std::get<0>(transitions);
98 hybridsim::Destination* destFr = req.add_dests();
100 hybridsim::Destination* destTo = req.add_dests();
101 destTo->set_id(toId);
105 hybridsim::Boolean rpl;
106 ClientContext context;
109 throw ProcessError(
"Person: " + person->
getID() +
" could not be transferred to remote simulation");
113 throw ProcessError(
"Remote simulation declined to accept person: " + person->
getID() +
".");
121 hybridsim::Empty req;
122 hybridsim::Empty rpl;
123 ClientContext context1;
134 hybridsim::LeftClosedRightOpenTimeInterval interval;
135 interval.set_fromtimeincluding(time /
DELTA_T);
140 hybridsim::Empty rpl;
141 ClientContext context1;
142 Status st =
myHybridsimStub->simulatedTimeInerval(&context1, interval, &rpl);
148 hybridsim::Empty req2;
149 hybridsim::Trajectories trajectories;
150 ClientContext context2;
151 Status st2 =
myHybridsimStub->receiveTrajectories(&context2, req2, &trajectories);
153 throw ProcessError(
"Could not receive trajectories from remote simulation");
155 for (hybridsim::Trajectory trajectory : trajectories.trajectories()) {
158 pState->
setPosition(trajectory.x(), trajectory.y());
159 pState->
setPhi(trajectory.phi());
164 if (nextTargetEdge == nextStageEdge) {
166 std::cout <<
"next edge" << std::endl;
176 hybridsim::Empty req3;
177 hybridsim::Agents agents;
178 ClientContext context3;
179 Status st3 =
myHybridsimStub->queryRetrievableAgents(&context3, req3, &agents);
181 throw ProcessError(
"Could not query retrievable agents");
184 for (hybridsim::Agent agent : agents.agents()) {
194 hybridsim::Empty rpl2;
195 ClientContext context4;
196 Status st4 =
myHybridsimStub->confirmRetrievedAgents(&context4, agents, &rpl2);
198 throw ProcessError(
"Could not confirm retrieved agents");
221 hybridsim::Scenario req;
225 if (e->isInternal()) {
228 if (e->isWalkingArea()) {
232 for (
MSLane* l : e->getLanes()) {
240 hybridsim::Edge* edge = req.add_edges();
245 edge->set_type(hybridsim::Edge_Type_OBSTACLE);
247 edge = req.add_edges();
252 edge->set_type(hybridsim::Edge_Type_OBSTACLE);
254 edge = req.add_edges();
259 edge->set_type(hybridsim::Edge_Type_OBSTACLE);
261 edge = req.add_edges();
266 edge->set_type(hybridsim::Edge_Type_OBSTACLE);
269 hybridsim::Empty rpl;
270 ClientContext context;
273 throw ProcessError(
"Remote side could not initialize scenario!");
281 if (shape.size() < 2) {
291 hybridsim::Edge* edge = scenario.add_edges();
292 edge->mutable_c0()->set_x(frst.
x());
293 edge->mutable_c0()->set_y(frst.
y());
294 edge->mutable_c1()->set_x(scnd.
x());
295 edge->mutable_c1()->set_y(scnd.
y());
296 edge->set_type(hybridsim::Edge_Type_OBSTACLE);
303 if (centerLine.size() < 2) {
314 hybridsim::Edge_Type edgeType;
316 edgeType = hybridsim::Edge_Type_TRANSITION_HOLDOVER;
318 edgeType = hybridsim::Edge_Type_TRANSITION_INTERNAL;
320 edgeType = hybridsim::Edge_Type_TRANSITION;
324 Position frst = *centerLine.begin();
325 Position scnd = *(centerLine.begin() + 1);
327 Position thrd = *(centerLine.end() - 1);
328 Position frth = *(centerLine.end() - 2);
339 hybridsim::Edge_Type type,
int id) {
341 double dx = scnd.
x() - frst.
x();
342 double dy = scnd.
y() - frst.
y();
343 double length = sqrt(dx * dx + dy * dy);
346 double x0 = frst.
x() - dy * width / 2.;
347 double y0 = frst.
y() + dx * width / 2.;
348 double x1 = frst.
x() + dy * width / 2.;
349 double y1 = frst.
y() - dx * width / 2.;
350 hybridsim::Edge* edge = scenario.add_edges();
351 edge->mutable_c0()->set_x(x0);
352 edge->mutable_c0()->set_y(y0);
353 edge->mutable_c1()->set_x(x1);
354 edge->mutable_c1()->set_y(y1);
355 edge->set_type(type);
360 PositionVector::const_iterator it = shape.begin();
365 for (; it != shape.end(); it++) {
366 hybridsim::Edge* edge = scenario.add_edges();
367 edge->mutable_c0()->set_x(frst.
x());
368 edge->mutable_c0()->set_y(frst.
y());
369 edge->mutable_c1()->set_x((*it).x());
370 edge->mutable_c1()->set_y((*it).y());
371 edge->set_type(hybridsim::Edge_Type_OBSTACLE);
383 : myPerson(person), myPhi(0), myPosition(0, 0), myStage(stage) {
PState(MSPerson *person, MSPerson::MSPersonStage_Walking *stage)
double ymin() const
Returns minimum y-coordinate.
virtual void cleanupHelper()
double xmax() const
Returns maximum x-coordinate.
MSEdge & getEdge() const
Returns the lane's edge.
MSLane * getFirstPedestrianLane(const MSEdge *const &edge)
double y() const
Returns the y-position.
void makeStartOrEndTransition(Position position, Position scnd, double width, hybridsim::Scenario &scenario, hybridsim::Edge_Type type, int i)
double getDepartPos() const
MSPModel_Remote(const OptionsCont &oc, MSNet *net)
double x() const
Returns the x-position.
MSPerson::MSPersonStage_Walking * getStage()
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
const PositionVector & getShape() const
Returns this lane's shape.
const std::string & getID() const
Returns the id.
const MSEdge * getNextEdge(const MSPerson::MSPersonStage_Walking &stage) const override
return the list of internal edges if the pedestrian is on an intersection
std::map< int, const MSEdge * > transitionsEdgesMapping
void handlePedestrianLane(MSLane *pLane, hybridsim::Scenario &scenario)
void set(double x, double y)
set positions x and y
const MSJunction * getToJunction() const
SUMOTime execute(SUMOTime time)
double getWidth() const
Returns the lane's width.
The simulated network and simulation perfomer.
A road/street connecting two junctions.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
std::map< int, PState * > remoteIdPStateMapping
A point in 2D or 3D with translation and scaling methods.
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
SUMOTime getWaitingTime(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const override
return the time the person spent standing
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
double xmin() const
Returns minimum x-coordinate.
const std::string & getID() const
returns the id of the transportable
void remove(PedestrianState *state) override
remove the specified person from the pedestrian simulation
bool hasInternalLinks() const
return whether the network contains internal links
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
void handleShape(const PositionVector &shape, hybridsim::Scenario &scenario)
double getArrivalPos() const
bool isCrossing() const
return whether this edge is a pedestrian crossing
void setPosition(double x, double y)
const ConstMSEdgeVector & getRoute() const
void move2side(double amount)
move position vector to side using certain ammount
PedestrianState * add(MSPerson *person, MSPerson::MSPersonStage_Walking *stage, SUMOTime now) override
register the given person as a pedestrian
abstract base class for managing callbacks to retrieve various state information from the model ...
double getSpeed(const MSPerson::MSPersonStage_Walking &stage) const override
return the current speed of the person
Container for pedestrian state and individual position update function.
bool usingInternalLanes()
whether movements on intersections are modelled
const MSJunction * getFromJunction() const
Position getPosition(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const override
return the network coordinate of the person
bool moveToNextEdge(MSPerson *person, SUMOTime currentTime, MSEdge *nextInternal=nullptr)
move forward and return whether the person arrived
A storage for options typed value containers)
std::unique_ptr< hybridsim::HybridSimulation::Stub > myHybridsimStub
const MSEdgeVector & getEdges() const
Returns loaded edges.
std::map< const MSEdge *, std::tuple< int, int > > edgesTransitionsMapping
static const int BACKWARD
bool isWalkingArea() const
return whether this edge is walking area
MSPerson::MSPersonStage_Walking * myStage
MSEdgeControl & getEdgeControl()
Returns the edge control.
const MSEdge * getNextRouteEdge() const
double getAngle(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const override
return the direction in which the person faces in degrees
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
double ymax() const
Returns maximum y-coordinate.
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
Representation of a lane in the micro simulation.
void cleanupHelper() override
double getEdgePos(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const override
return the offset from the start of the current edge measured in its natural direction ...
void handleWalkingArea(MSEdge *msEdge, hybridsim::Scenario &scenario)
StageType getCurrentStageType() const
the current stage type of the transportable