Eclipse SUMO - Simulation of Urban MObility
Helper.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2017-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // C++ TraCI client API implementation
17 /****************************************************************************/
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
24 #include <utils/geom/GeomHelper.h>
26 #include <microsim/MSNet.h>
29 #include <microsim/MSEdgeControl.h>
31 #include <microsim/MSEdge.h>
32 #include <microsim/MSLane.h>
33 #include <microsim/MSVehicle.h>
36 #include <libsumo/TraCIDefs.h>
37 #include <libsumo/Edge.h>
38 #include <libsumo/InductionLoop.h>
39 #include <libsumo/Junction.h>
40 #include <libsumo/Lane.h>
41 #include <libsumo/LaneArea.h>
42 #include <libsumo/MultiEntryExit.h>
43 #include <libsumo/Person.h>
44 #include <libsumo/POI.h>
45 #include <libsumo/Polygon.h>
46 #include <libsumo/Route.h>
47 #include <libsumo/Simulation.h>
48 #include <libsumo/TrafficLight.h>
49 #include <libsumo/Vehicle.h>
50 #include <libsumo/VehicleType.h>
51 #include <libsumo/TraCIConstants.h>
52 #include "Helper.h"
53 
54 #define FAR_AWAY 1000.0
55 
56 //#define DEBUG_MOVEXY
57 //#define DEBUG_MOVEXY_ANGLE
58 //#define DEBUG_SURROUNDING
59 
60 
61 void
62 LaneStoringVisitor::add(const MSLane* const l) const {
63  switch (myDomain) {
65  const MSLane::VehCont& vehs = l->getVehiclesSecure();
66  for (MSLane::VehCont::const_iterator j = vehs.begin(); j != vehs.end(); ++j) {
67  if (myShape.distance2D((*j)->getPosition()) <= myRange) {
68  myIDs.insert((*j)->getID());
69  }
70  }
71  l->releaseVehicles();
72  }
73  break;
75  l->getVehiclesSecure();
76  std::vector<MSTransportable*> persons = l->getEdge().getSortedPersons(MSNet::getInstance()->getCurrentTimeStep(), true);
77  for (auto p : persons) {
78  if (myShape.distance2D(p->getPosition()) <= myRange) {
79  myIDs.insert(p->getID());
80  }
81  }
82  l->releaseVehicles();
83  }
84  break;
86  if (myShape.size() != 1 || l->getShape().distance2D(myShape[0]) <= myRange) {
87  myIDs.insert(l->getEdge().getID());
88  }
89  }
90  break;
92  if (myShape.size() != 1 || l->getShape().distance2D(myShape[0]) <= myRange) {
93  myIDs.insert(l->getID());
94  }
95  }
96  break;
97  default:
98  break;
99 
100  }
101 }
102 
103 namespace libsumo {
104 // ===========================================================================
105 // static member initializations
106 // ===========================================================================
107 std::vector<Subscription> Helper::mySubscriptions;
108 std::map<int, std::shared_ptr<VariableWrapper> > Helper::myWrapper;
109 Helper::VehicleStateListener Helper::myVehicleStateListener;
110 std::map<int, NamedRTree*> Helper::myObjects;
112 std::map<std::string, MSVehicle*> Helper::myRemoteControlledVehicles;
113 std::map<std::string, MSPerson*> Helper::myRemoteControlledPersons;
114 
115 
116 // ===========================================================================
117 // static member definitions
118 // ===========================================================================
119 void
120 Helper::subscribe(const int commandId, const std::string& id, const std::vector<int>& variables,
121  const double beginTime, const double endTime, const int contextDomain, const double range) {
122  if (variables.empty()) {
123  for (std::vector<libsumo::Subscription>::iterator j = mySubscriptions.begin(); j != mySubscriptions.end();) {
124  if (j->id == id && j->commandId == commandId && (contextDomain < 0 || j->contextDomain == contextDomain)) {
125  j = mySubscriptions.erase(j);
126  } else {
127  ++j;
128  }
129  }
130  }
131  std::vector<std::vector<unsigned char> > parameters;
132  const SUMOTime begin = beginTime == INVALID_DOUBLE_VALUE ? 0 : TIME2STEPS(beginTime);
133  const SUMOTime end = endTime == INVALID_DOUBLE_VALUE || endTime > STEPS2TIME(SUMOTime_MAX) ? SUMOTime_MAX : TIME2STEPS(endTime);
134  libsumo::Subscription s(commandId, id, variables, parameters, begin, end, contextDomain, range);
136  libsumo::Subscription* modifiedSubscription = nullptr;
137  if (needNewSubscription(s, mySubscriptions, modifiedSubscription)) {
138  mySubscriptions.push_back(s);
139  }
140 }
141 
142 
143 void
145  for (auto& wrapper : myWrapper) {
146  wrapper.second->clear();
147  }
148  for (const libsumo::Subscription& s : mySubscriptions) {
149  if (s.beginTime <= t) {
151  }
152  }
153 }
154 
155 
156 bool
157 Helper::needNewSubscription(libsumo::Subscription& s, std::vector<Subscription>& subscriptions, libsumo::Subscription*& modifiedSubscription) {
158  for (libsumo::Subscription& o : subscriptions) {
159  if (s.commandId == o.commandId && s.id == o.id &&
160  s.beginTime == o.beginTime && s.endTime == o.endTime &&
161  s.contextDomain == o.contextDomain && s.range == o.range) {
162  std::vector<std::vector<unsigned char> >::const_iterator k = s.parameters.begin();
163  for (const int v : s.variables) {
164  const int offset = (int)(std::find(o.variables.begin(), o.variables.end(), v) - o.variables.begin());
165  if (offset == (int)o.variables.size() || o.parameters[offset] != *k) {
166  o.variables.push_back(v);
167  o.parameters.push_back(*k);
168  }
169  ++k;
170  }
171  modifiedSubscription = &o;
172  return false;
173  }
174  }
175  return true;
176 }
177 
178 
179 void
181  mySubscriptions.clear();
182 }
183 
184 
185 void
187  const int getCommandId = s.contextDomain > 0 ? s.contextDomain : s.commandId - 0x30;
188  std::set<std::string> objIDs;
189  if (s.contextDomain > 0) {
190  if ((s.activeFilters & SUBS_FILTER_NO_RTREE) == 0) {
191  PositionVector shape;
192  findObjectShape(s.commandId, s.id, shape);
193  collectObjectsInRange(s.contextDomain, shape, s.range, objIDs);
194  }
195  applySubscriptionFilters(s, objIDs);
196  } else {
197  objIDs.insert(s.id);
198  }
199  if (myWrapper.empty()) {
214  }
215  auto wrapper = myWrapper.find(getCommandId);
216  if (wrapper == myWrapper.end()) {
217  throw TraCIException("Unsupported command specified");
218  }
219  std::shared_ptr<VariableWrapper> handler = wrapper->second;
220  VariableWrapper* container = handler.get();
221  if (s.contextDomain > 0) {
222  handler->setContext(s.id);
223  auto containerWrapper = myWrapper.find(s.commandId + 0x20);
224  if (containerWrapper == myWrapper.end()) {
225  throw TraCIException("Unsupported domain specified");
226  }
227  container = containerWrapper->second.get();
228  } else {
229  handler->setContext("");
230  }
231  for (const std::string& objID : objIDs) {
232  if (!s.variables.empty()) {
233  for (const int variable : s.variables) {
234  handler->handle(objID, variable, container);
235  }
236  } else {
237  if (s.contextDomain == 0 && getCommandId == libsumo::CMD_GET_VEHICLE_VARIABLE) {
238  // default for vehicles is edge id and lane position
239  handler->handle(objID, VAR_ROAD_ID, container);
240  handler->handle(objID, VAR_LANEPOSITION, container);
241  } else if (s.contextDomain > 0 || !handler->handle(objID, libsumo::LAST_STEP_VEHICLE_NUMBER, container)) {
242  // default for detectors is vehicle number, for all others (and contexts) id list
243  handler->handle(objID, libsumo::TRACI_ID_LIST, container);
244  }
245  }
246  }
247 }
248 
249 
250 void
251 Helper::fuseLaneCoverage(std::shared_ptr<LaneCoverageInfo> aggregatedLaneCoverage, const std::shared_ptr<LaneCoverageInfo> newLaneCoverage) {
252  for (auto& p : *newLaneCoverage) {
253  const MSLane* lane = p.first;
254  if (aggregatedLaneCoverage->find(lane) == aggregatedLaneCoverage->end()) {
255  // Lane has no coverage in aggregatedLaneCoverage, yet
256  (*aggregatedLaneCoverage)[lane] = (*newLaneCoverage)[lane];
257  } else {
258  // Lane is covered in aggregatedLaneCoverage as well
259  std::pair<double, double>& range1 = (*aggregatedLaneCoverage)[lane];
260  std::pair<double, double>& range2 = (*newLaneCoverage)[lane];
261  std::pair<double, double> hull = std::make_pair(MIN2(range1.first, range2.first), MAX2(range1.second, range2.second));
262  (*aggregatedLaneCoverage)[lane] = hull;
263  }
264  }
265 }
266 
267 
271  for (int i = 0; i < (int)positionVector.size(); ++i) {
272  tp.push_back(makeTraCIPosition(positionVector[i]));
273  }
274  return tp;
275 }
276 
277 
280  PositionVector pv;
281  for (const TraCIPosition& pos : vector) {
282  if (std::isnan(pos.x) || std::isnan(pos.y)) {
283  throw libsumo::TraCIException("NaN-Value in shape.");
284  }
285  pv.push_back(Position(pos.x, pos.y));
286  }
287  return pv;
288 }
289 
290 
293  TraCIColor tc;
294  tc.a = color.alpha();
295  tc.b = color.blue();
296  tc.g = color.green();
297  tc.r = color.red();
298  return tc;
299 }
300 
301 
302 RGBColor
304  return RGBColor((unsigned char)c.r, (unsigned char)c.g, (unsigned char)c.b, (unsigned char)c.a);
305 }
306 
307 
309 Helper::makeTraCIPosition(const Position& position, const bool includeZ) {
310  TraCIPosition p;
311  p.x = position.x();
312  p.y = position.y();
313  p.z = includeZ ? position.z() : INVALID_DOUBLE_VALUE;
314  return p;
315 }
316 
317 
318 Position
320  return Position(tpos.x, tpos.y, tpos.z);
321 }
322 
323 
324 MSEdge*
325 Helper::getEdge(const std::string& edgeID) {
326  MSEdge* edge = MSEdge::dictionary(edgeID);
327  if (edge == nullptr) {
328  throw TraCIException("Referenced edge '" + edgeID + "' is not known.");
329  }
330  return edge;
331 }
332 
333 
334 const MSLane*
335 Helper::getLaneChecking(const std::string& edgeID, int laneIndex, double pos) {
336  const MSEdge* edge = MSEdge::dictionary(edgeID);
337  if (edge == nullptr) {
338  throw TraCIException("Unknown edge " + edgeID);
339  }
340  if (laneIndex < 0 || laneIndex >= (int)edge->getLanes().size()) {
341  throw TraCIException("Invalid lane index for " + edgeID);
342  }
343  const MSLane* lane = edge->getLanes()[laneIndex];
344  if (pos < 0 || pos > lane->getLength()) {
345  throw TraCIException("Position on lane invalid");
346  }
347  return lane;
348 }
349 
350 
351 std::pair<MSLane*, double>
353  const PositionVector shape({ pos });
354  std::pair<MSLane*, double> result;
355  double range = 1000.;
356  const Boundary& netBounds = GeoConvHelper::getFinal().getConvBoundary();
357  const double maxRange = MAX2(1001., netBounds.getWidth() + netBounds.getHeight() + netBounds.distanceTo2D(pos));
358  while (range < maxRange) {
359  std::set<std::string> laneIds;
361  double minDistance = std::numeric_limits<double>::max();
362  for (const std::string& laneID : laneIds) {
363  MSLane* const lane = MSLane::dictionary(laneID);
364  if (lane->allowsVehicleClass(vClass)) {
365  // @todo this may be a place where 3D is required but 2D is used
366  const double newDistance = lane->getShape().distance2D(pos);
367  if (newDistance < minDistance) {
368  minDistance = newDistance;
369  result.first = lane;
370  }
371  }
372  }
373  if (minDistance < std::numeric_limits<double>::max()) {
374  result.second = result.first->interpolateGeometryPosToLanePos(result.first->getShape().nearest_offset_to_point2D(pos, false));
375  break;
376  }
377  range *= 2;
378  }
379  return result;
380 }
381 
382 
383 MSVehicle*
384 Helper::getVehicle(const std::string& id) {
386  if (sumoVehicle == nullptr) {
387  throw TraCIException("Vehicle '" + id + "' is not known.");
388  }
389  MSVehicle* v = dynamic_cast<MSVehicle*>(sumoVehicle);
390  if (v == nullptr) {
391  throw TraCIException("Vehicle '" + id + "' is not a micro-simulation vehicle.");
392  }
393  return v;
394 }
395 
396 
397 const MSVehicleType&
398 Helper::getVehicleType(const std::string& vehicleID) {
399  return getVehicle(vehicleID)->getVehicleType();
400 }
401 
402 
403 void
405  for (const auto i : myObjects) {
406  delete i.second;
407  }
408  myObjects.clear();
409  delete myLaneTree;
410  myLaneTree = nullptr;
411 }
412 
413 
414 void
416  if (MSNet::hasInstance()) {
418  }
419 }
420 
421 
422 const std::vector<std::string>&
425 }
426 
427 
428 void
431  i.second.clear();
432  }
433 }
434 
435 
436 void
437 Helper::findObjectShape(int domain, const std::string& id, PositionVector& shape) {
438  switch (domain) {
440  InductionLoop::storeShape(id, shape);
441  break;
443  Lane::storeShape(id, shape);
444  break;
446  Vehicle::storeShape(id, shape);
447  break;
449  Person::storeShape(id, shape);
450  break;
452  POI::storeShape(id, shape);
453  break;
455  Polygon::storeShape(id, shape);
456  break;
458  Junction::storeShape(id, shape);
459  break;
461  Edge::storeShape(id, shape);
462  break;
463  default:
464  break;
465  }
466 }
467 
468 
469 void
470 Helper::collectObjectsInRange(int domain, const PositionVector& shape, double range, std::set<std::string>& into) {
471  // build the look-up tree if not yet existing
472  if (myObjects.find(domain) == myObjects.end()) {
473  switch (domain) {
476  break;
487  break;
490  break;
493  break;
496  break;
497  default:
498  break;
499  }
500  }
501  const Boundary b = shape.getBoxBoundary().grow(range);
502  const float cmin[2] = {(float) b.xmin(), (float) b.ymin()};
503  const float cmax[2] = {(float) b.xmax(), (float) b.ymax()};
504  switch (domain) {
509  Named::StoringVisitor sv(into);
510  myObjects[domain]->Search(cmin, cmax, sv);
511  }
512  break;
517  LaneStoringVisitor sv(into, shape, range, domain);
518  myLaneTree->Search(cmin, cmax, sv);
519  }
520  break;
521  default:
522  break;
523  }
524 }
525 
526 
527 
528 void
529 Helper::applySubscriptionFilters(const Subscription& s, std::set<std::string>& objIDs) {
530 #ifdef DEBUG_SURROUNDING
531  MSVehicle* _veh = getVehicle(s.id);
532  std::cout << SIMTIME << " applySubscriptionFilters for vehicle '" << _veh->getID() << "' on lane '" << _veh->getLane()->getID() << "'"
533  << "\n on edge '" << _veh->getLane()->getEdge().getID() << "' (" << toString(_veh->getLane()->getEdge().getLanes()) << ")\n"
534  << "objIDs = " << toString(objIDs) << std::endl;
535 #endif
536 
537  if (s.activeFilters == 0) {
538  // No filters set
539  return;
540  }
541 
542  // Whether vehicles on opposite lanes shall be taken into account
543  const bool disregardOppositeDirection = (s.activeFilters & SUBS_FILTER_NOOPPOSITE) != 0;
544 
545  // Check filter specification consistency
546  // TODO: Warn only once
547  if (disregardOppositeDirection && (s.activeFilters & SUBS_FILTER_NO_RTREE) == 0) {
548  WRITE_WARNING("Ignoring no-opposite subscription filter for geographic range object collection. Consider using the 'lanes' filter.")
549  }
551  WRITE_WARNING("Ignoring field of vision subscription filter due to incompatibility with other filter(s).")
552  }
553 
554  // TODO: Treat case, where ego vehicle is currently on opposite lane
555 
556  std::set<const MSVehicle*> vehs;
557  if ((s.activeFilters & SUBS_FILTER_NO_RTREE) != 0) {
558  // Set defaults for upstream and downstream distances
559  double downstreamDist = s.range, upstreamDist = s.range;
561  // Specifies maximal downstream distance for vehicles in context subscription result
562  downstreamDist = s.filterDownstreamDist;
563  }
565  // Specifies maximal downstream distance for vehicles in context subscription result
566  upstreamDist = s.filterUpstreamDist;
567  }
568  MSVehicle* v = getVehicle(s.id);
569  if (!v->isOnRoad()) {
570  return;
571  }
572  MSLane* vehLane = v->getLane();
573  if (vehLane == nullptr) {
574  return;
575  }
576  MSEdge* vehEdge = &vehLane->getEdge();
577  std::vector<int> filterLanes;
578  if ((s.activeFilters & SUBS_FILTER_LANES) == 0) {
579  // No lane indices are specified (but downstream and/or upstream distance)
580  // -> use only vehicle's current lane as origin for the searches
581  filterLanes = {0};
582  // Lane indices must be specified when leader/follower information is requested.
583  assert((s.activeFilters & SUBS_FILTER_LEAD_FOLLOW) == 0);
584  } else {
585  filterLanes = s.filterLanes;
586  }
587 
588 #ifdef DEBUG_SURROUNDING
589  std::cout << "Filter lanes: " << toString(filterLanes) << std::endl;
590  std::cout << "Downstream distance: " << downstreamDist << std::endl;
591  std::cout << "Upstream distance: " << upstreamDist << std::endl;
592 #endif
593 
594  if ((s.activeFilters & SUBS_FILTER_MANEUVER) != 0) {
595  // Maneuver filters disables road net search for all surrounding vehicles
596  if ((s.activeFilters & SUBS_FILTER_LEAD_FOLLOW) != 0) {
597  // Return leader and follower on the specified lanes in context subscription result.
598  for (int offset : filterLanes) {
599  MSLane* lane = v->getLane()->getParallelLane(offset, false);
600  if (lane != nullptr) {
601  // this is a non-opposite lane
602  MSVehicle* leader = lane->getLeader(v, v->getPositionOnLane(), v->getBestLanesContinuation(lane), downstreamDist).first;
603  MSVehicle* follower = lane->getFollower(v, v->getPositionOnLane(), upstreamDist, false).first;
604  vehs.insert(vehs.end(), leader);
605  vehs.insert(vehs.end(), follower);
606 
607 #ifdef DEBUG_SURROUNDING
608  std::cout << "Lane at index " << offset << ": '" << lane->getID() << std::endl;
609  std::cout << "Leader: '" << (leader != nullptr ? leader->getID() : "NULL") << "'" << std::endl;
610  std::cout << "Follower: '" << (follower != nullptr ? follower->getID() : "NULL") << "'" << std::endl;
611 #endif
612 
613  } else if (!disregardOppositeDirection && offset > 0) { // TODO: offset<0 may indicate opposite query when vehicle is on opposite itself
614  // check whether ix points to an opposite lane
615  const MSEdge* opposite = vehEdge->getOppositeEdge();
616  if (opposite == nullptr) {
617 #ifdef DEBUG_SURROUNDING
618  std::cout << "No lane at index " << offset << std::endl;
619 #endif
620  // no opposite edge
621  continue;
622  }
623  // Index of opposite lane at relative offset
624  const int ix_opposite = (int)opposite->getLanes().size() - 1 - (vehLane->getIndex() + offset - (int)vehEdge->getLanes().size());
625  if (ix_opposite < 0) {
626 #ifdef DEBUG_SURROUNDING
627  std::cout << "No lane on opposite at index " << ix_opposite << std::endl;
628 #endif
629  // no opposite edge
630  continue;
631  }
632  lane = opposite->getLanes()[ix_opposite];
633  // Search vehs along opposite lanes (swap upstream and downstream distance)
634  // XXX transformations for curved geometries
635  double posOnOpposite = MAX2(0., opposite->getLength() - v->getPositionOnLane());
636  // Get leader on opposite
637  vehs.insert(vehs.end(), lane->getFollower(v, posOnOpposite, downstreamDist, true).first);
638  // Get follower (no search on consecutive lanes
639  vehs.insert(vehs.end(), lane->getLeader(v, posOnOpposite - v->getLength(), std::vector<MSLane*>()).first);
640  }
641  }
642  }
643 
645  // Get upcoming junctions and vialanes within downstream distance, where foe links exist or at least the link direction is not straight
646  MSLane* lane = v->getLane();
647  std::vector<const MSLink*> links = lane->getUpcomingLinks(v->getPositionOnLane(), downstreamDist, v->getBestLanesContinuation());
648 #ifdef DEBUG_SURROUNDING
649  std::cout << "Applying turn filter for vehicle '" << v->getID() << "'\n Gathering foes ..." << std::endl;
650 #endif
651  // Iterate through junctions and find approaching foes within upstreamDist.
652  for (auto& l : links) {
653 #ifdef DEBUG_SURROUNDING
654  std::cout << " On junction '" << l->getJunction()->getID() << "' (no. foe links = " << l->getFoeLinks().size() << "):" << std::endl;
655 #endif
656  for (auto& foeLane : l->getFoeLanes()) {
657  // Check vehicles approaching the entry link corresponding to this lane
658  const MSLink* foeLink = foeLane->getEntryLink();
659  for (auto& vi : foeLink->getApproaching()) {
660  if (vi.second.dist <= upstreamDist) {
661 #ifdef DEBUG_SURROUNDING
662  std::cout << " Approaching from foe-lane '" << vi.first->getID() << "'" << std::endl;
663 #endif
664  vehs.insert(vehs.end(), dynamic_cast<const MSVehicle*>(vi.first));
665  }
666  }
667  // add vehicles currently on the junction
668  for (const MSVehicle* foe : foeLane->getVehiclesSecure()) {
669  vehs.insert(vehs.end(), foe);
670  }
671  foeLane->releaseVehicles();
672  }
673  }
674  }
675 #ifdef DEBUG_SURROUNDING
676  std::cout << SIMTIME << " applySubscriptionFilters() for veh '" << v->getID() << "'. Found the following vehicles:\n";
677  for (auto veh : vehs) {
678  if (veh != nullptr) {
679  std::cout << " '" << veh->getID() << "' on lane '" << veh->getLane()->getID() << "'\n";
680  }
681  }
682 #endif
683  } else {
684  // No maneuver filters requested, but only lanes filter (directly, or indirectly by specifying downstream or upstream distance)
685  assert(filterLanes.size() > 0);
686  // This is to remember the lanes checked in the driving direction of the vehicle (their opposites can be added in a second pass)
687  auto checkedLanesInDrivingDir = std::make_shared<LaneCoverageInfo>();
688  for (int offset : filterLanes) {
689  MSLane* lane = vehLane->getParallelLane(offset, false);
690  if (lane != nullptr) {
691 #ifdef DEBUG_SURROUNDING
692  std::cout << "Checking for surrounding vehicles starting on lane '" << lane->getID() << "' at index " << offset << std::endl;
693 #endif
694  // Search vehs along this lane
695  // (Coverage info is collected per origin lane since lanes reached from neighboring lanes may have different distances
696  // and aborting at previously scanned when coming from a closer origin may prevent scanning of parts that should be included.)
697  std::shared_ptr<LaneCoverageInfo> checkedLanes = std::make_shared<LaneCoverageInfo>();
698  const std::set<MSVehicle*> new_vehs = lane->getSurroundingVehicles(v->getPositionOnLane(), downstreamDist, upstreamDist + v->getLength(), checkedLanes);
699  vehs.insert(new_vehs.begin(), new_vehs.end());
700  fuseLaneCoverage(checkedLanesInDrivingDir, checkedLanes);
701  } else if (!disregardOppositeDirection && offset > 0) {
702  // Check opposite edge, too
703  assert(vehLane->getIndex() + offset >= (int)vehEdge->getLanes().size()); // index points beyond this edge
704  const MSEdge* opposite = vehEdge->getOppositeEdge();
705  if (opposite == nullptr) {
706 #ifdef DEBUG_SURROUNDING
707  std::cout << "No opposite edge, thus no lane at index " << offset << std::endl;
708 #endif
709  // no opposite edge
710  continue;
711  }
712  // Index of opposite lane at relative offset
713  const int ix_opposite = (int)opposite->getLanes().size() - 1 - (vehLane->getIndex() + offset - (int)vehEdge->getLanes().size());
714  if (ix_opposite < 0) {
715 #ifdef DEBUG_SURROUNDING
716  std::cout << "No lane on opposite at index " << ix_opposite << std::endl;
717 #endif
718  // no opposite edge
719  continue;
720  }
721  lane = opposite->getLanes()[ix_opposite];
722  // Search vehs along opposite lanes (swap upstream and downstream distance)
723  const std::set<MSVehicle*> new_vehs = lane->getSurroundingVehicles(lane->getLength() - v->getPositionOnLane(), upstreamDist + v->getLength(), downstreamDist, std::make_shared<LaneCoverageInfo>());
724  vehs.insert(new_vehs.begin(), new_vehs.end());
725  }
726 #ifdef DEBUG_SURROUNDING
727  else {
728  std::cout << "No lane at index " << offset << std::endl;
729  }
730 #endif
731 
732  if (!disregardOppositeDirection) {
733  // If opposite should be checked, do this for each lane of the search tree in checkedLanesInDrivingDir
734  // (For instance, some opposite lanes of these would not be obtained if the ego lane does not have an opposite.)
735 
736  // Number of opposite lanes to be checked (assumes filterLanes.size()>0, see assertion above) determined as hypothetical offset
737  // overlap into opposing edge from the vehicle's current lane.
738  // TODO: offset<0 may indicate opposite query when vehicle is on opposite itself (-> use min_element(filterLanes...) instead, etc)
739  const int nOpp = MAX2(0, (*std::max_element(filterLanes.begin(), filterLanes.end())) - ((int)vehEdge->getLanes().size() - 1 - vehLane->getIndex()));
740  // Collect vehicles from opposite lanes
741  if (nOpp > 0) {
742  for (auto& laneCov : *checkedLanesInDrivingDir) {
743  const MSLane* const l = laneCov.first;
744  if (l == nullptr || l->getEdge().getOppositeEdge() == nullptr) {
745  continue;
746  }
747  const MSEdge* opposite = l->getEdge().getOppositeEdge();
748  const std::pair<double, double>& range = laneCov.second;
749  auto leftMostOppositeLaneIt = opposite->getLanes().rbegin();
750  for (auto oppositeLaneIt = leftMostOppositeLaneIt;
751  oppositeLaneIt != opposite->getLanes().rend(); ++oppositeLaneIt) {
752  if ((int)(oppositeLaneIt - leftMostOppositeLaneIt) == nOpp) {
753  break;
754  }
755  // Add vehicles from corresponding range on opposite direction
756  const MSLane* oppositeLane = *oppositeLaneIt;
757  auto new_vehs = oppositeLane->getVehiclesInRange(l->getLength() - range.second, l->getLength() - range.first);
758  vehs.insert(new_vehs.begin(), new_vehs.end());
759  }
760  }
761  }
762  }
763 #ifdef DEBUG_SURROUNDING
764  std::cout << SIMTIME << " applySubscriptionFilters() for veh '" << v->getID() << "'. Found the following vehicles:\n";
765  for (auto veh : vehs) {
766  if (veh != nullptr) {
767  std::cout << " '" << veh->getID() << "' on lane '" << veh->getLane()->getID() << "'\n";
768  }
769  }
770 #endif
771  }
772 
773  // filter vehicles in vehs by class and/or type if requested
775  // Only return vehicles of the given vClass in context subscription result
776  auto i = vehs.begin();
777  while (i != vehs.end()) {
778  if (((*i)->getVehicleType().getVehicleClass() & s.filterVClasses) == 0) {
779  i = vehs.erase(i);
780  } else {
781  ++i;
782  }
783  }
784  }
786  // Only return vehicles of the given vType in context subscription result
787  auto i = vehs.begin();
788  while (i != vehs.end()) {
789  if (s.filterVTypes.find((*i)->getVehicleType().getID()) == s.filterVTypes.end()) {
790  i = vehs.erase(i);
791  } else {
792  ++i;
793  }
794  }
795  }
796  }
797  // Write vehs IDs in objIDs
798  for (const MSVehicle* veh : vehs) {
799  if (veh != nullptr) {
800  objIDs.insert(objIDs.end(), veh->getID());
801  }
802  }
803  } else { // apply rTree-based filters
805  // Only return vehicles of the given vClass in context subscription result
806  auto i = objIDs.begin();
807  while (i != objIDs.end()) {
808  MSVehicle* veh = getVehicle(*i);
809  if ((veh->getVehicleType().getVehicleClass() & s.filterVClasses) == 0) {
810  i = objIDs.erase(i);
811  } else {
812  ++i;
813  }
814  }
815  }
817  // Only return vehicles of the given vType in context subscription result
818  auto i = objIDs.begin();
819  while (i != objIDs.end()) {
820  MSVehicle* veh = getVehicle(*i);
821  if (s.filterVTypes.find(veh->getVehicleType().getID()) == s.filterVTypes.end()) {
822  i = objIDs.erase(i);
823  } else {
824  ++i;
825  }
826  }
827  }
829  // Only return vehicles within field of vision in context subscription result
831  }
832  }
833 }
834 
835 void
836 Helper::applySubscriptionFilterFieldOfVision(const Subscription& s, std::set<std::string>& objIDs) {
838  WRITE_WARNINGF("Field of vision opening angle ('%') should be within interval (0, 360), ignoring filter...", s.filterFieldOfVisionOpeningAngle);
839  return;
840  }
841 
842  MSVehicle* egoVehicle = getVehicle(s.id);
843  Position egoPosition = egoVehicle->getPosition();
844  double openingAngle = DEG2RAD(s.filterFieldOfVisionOpeningAngle);
845 
846 #ifdef DEBUG_SURROUNDING
847  std::cout << "FOVFILTER: ego direction = " << toString(RAD2DEG(egoVehicle->getAngle())) << " (deg)" << std::endl;
848 #endif
849 
850  auto i = objIDs.begin();
851  while (i != objIDs.end()) {
852  if (s.id.compare(*i) == 0) { // skip if this is the ego vehicle
853  ++i;
854  continue;
855  }
856  MSVehicle* veh = getVehicle(*i);
857  double angleEgoToVeh = egoPosition.angleTo2D(veh->getPosition());
858  double alpha = GeomHelper::angleDiff(egoVehicle->getAngle(), angleEgoToVeh);
859 
860 #ifdef DEBUG_SURROUNDING
861  std::cout << "FOVFILTER: veh '" << *i << "' dist = " << toString(egoPosition.distanceTo2D(veh->getPosition())) << std::endl;
862  std::cout << "FOVFILTER: veh '" << *i << "' alpha = " << toString(RAD2DEG(alpha)) << " (deg)" << std::endl;
863 #endif
864 
865  if (abs(alpha) > openingAngle * 0.5) {
866  i = objIDs.erase(i);
867  } else {
868  ++i;
869  }
870  }
871 }
872 
873 void
874 Helper::setRemoteControlled(MSVehicle* v, Position xyPos, MSLane* l, double pos, double posLat, double angle,
875  int edgeOffset, ConstMSEdgeVector route, SUMOTime t) {
877  v->getInfluencer().setRemoteControlled(xyPos, l, pos, posLat, angle, edgeOffset, route, t);
878 }
879 
880 void
881 Helper::setRemoteControlled(MSPerson* p, Position xyPos, MSLane* l, double pos, double posLat, double angle,
882  int edgeOffset, ConstMSEdgeVector route, SUMOTime t) {
884  p->getInfluencer().setRemoteControlled(xyPos, l, pos, posLat, angle, edgeOffset, route, t);
885 }
886 
887 
888 void
890  for (auto& controlled : myRemoteControlledVehicles) {
891  if (MSNet::getInstance()->getVehicleControl().getVehicle(controlled.first) != nullptr) {
892  controlled.second->getInfluencer().postProcessRemoteControl(controlled.second);
893  } else {
894  WRITE_WARNING("Vehicle '" + controlled.first + "' was removed though being controlled by TraCI");
895  }
896  }
898  for (auto& controlled : myRemoteControlledPersons) {
899  if (MSNet::getInstance()->getPersonControl().get(controlled.first) != nullptr) {
900  controlled.second->getInfluencer().postProcessRemoteControl(controlled.second);
901  } else {
902  WRITE_WARNING("Person '" + controlled.first + "' was removed though being controlled by TraCI");
903  }
904  }
906 }
907 
908 
909 bool
910 Helper::moveToXYMap(const Position& pos, double maxRouteDistance, bool mayLeaveNetwork, const std::string& origID, const double angle,
911  double speed, const ConstMSEdgeVector& currentRoute, const int routePosition, MSLane* currentLane, double currentLanePos, bool onRoad,
912  SUMOVehicleClass vClass,
913  double& bestDistance, MSLane** lane, double& lanePos, int& routeOffset, ConstMSEdgeVector& edges) {
914  // collect edges around the vehicle/person
915  const MSEdge* const currentRouteEdge = currentRoute[routePosition];
916  std::set<std::string> into;
917  PositionVector shape;
918  shape.push_back(pos);
919  collectObjectsInRange(libsumo::CMD_GET_EDGE_VARIABLE, shape, maxRouteDistance, into);
920  double maxDist = 0;
921  std::map<MSLane*, LaneUtility> lane2utility;
922  // compute utility for all candidate edges
923  for (std::set<std::string>::const_iterator j = into.begin(); j != into.end(); ++j) {
924  const MSEdge* const e = MSEdge::dictionary(*j);
925  const MSEdge* prevEdge = nullptr;
926  const MSEdge* nextEdge = nullptr;
927  bool onRoute = false;
928  // the next if/the clause sets "onRoute", "prevEdge", and "nextEdge", depending on
929  // whether the currently seen edge is an internal one or a normal one
930  if (!e->isInternal()) {
931 #ifdef DEBUG_MOVEXY_ANGLE
932  std::cout << "Ego on normal" << std::endl;
933 #endif
934  // a normal edge
935  //
936  // check whether the currently seen edge is in the vehicle's route
937  // - either the one it's on or one of the next edges
938  ConstMSEdgeVector::const_iterator searchStart = currentRoute.begin() + routePosition;
939  if (onRoad && currentLane->getEdge().isInternal()) {
940  ++searchStart;
941  }
942  ConstMSEdgeVector::const_iterator edgePos = std::find(searchStart, currentRoute.end(), e);
943  onRoute = edgePos != currentRoute.end(); // no? -> onRoute is false
944  if (edgePos == currentRoute.end() - 1 && currentRouteEdge == e) {
945  // onRoute is false as well if the vehicle is beyond the edge
946  onRoute &= currentRouteEdge->getLength() > currentLanePos + SPEED2DIST(speed);
947  }
948  // save prior and next edges
949  prevEdge = e;
950  nextEdge = !onRoute || edgePos == currentRoute.end() - 1 ? nullptr : *(edgePos + 1);
951 #ifdef DEBUG_MOVEXY_ANGLE
952  std::cout << "normal:" << e->getID() << " prev:" << prevEdge->getID() << " next:";
953  if (nextEdge != 0) {
954  std::cout << nextEdge->getID();
955  }
956  std::cout << std::endl;
957 #endif
958  } else {
959 #ifdef DEBUG_MOVEXY_ANGLE
960  std::cout << "Ego on internal" << std::endl;
961 #endif
962  // an internal edge
963  // get the previous edge
964  prevEdge = e;
965  while (prevEdge != nullptr && prevEdge->isInternal()) {
966  MSLane* l = prevEdge->getLanes()[0];
967  l = l->getLogicalPredecessorLane();
968  prevEdge = l == nullptr ? nullptr : &l->getEdge();
969  }
970  // check whether the previous edge is on the route (was on the route)
971  ConstMSEdgeVector::const_iterator prevEdgePos = std::find(currentRoute.begin() + routePosition, currentRoute.end(), prevEdge);
972  nextEdge = e;
973  while (nextEdge != nullptr && nextEdge->isInternal()) {
974  nextEdge = nextEdge->getSuccessors()[0]; // should be only one for an internal edge
975  }
976  if (prevEdgePos != currentRoute.end() && (prevEdgePos + 1) != currentRoute.end()) {
977  onRoute = *(prevEdgePos + 1) == nextEdge;
978  }
979 #ifdef DEBUG_MOVEXY_ANGLE
980  std::cout << "internal:" << e->getID() << " prev:" << prevEdge->getID() << " next:" << nextEdge->getID() << std::endl;
981 #endif
982  }
983 
984 
985  // weight the lanes...
986  const bool perpendicular = false;
987  for (MSLane* const l : e->getLanes()) {
988  if (!l->allowsVehicleClass(vClass)) {
989  continue;
990  }
991  double langle = 180.;
992  double dist = FAR_AWAY;
993  double perpendicularDist = FAR_AWAY;
994  // add some slack to avoid issues from tiny gaps between consecutive lanes
995  const double slack = POSITION_EPS;
996  PositionVector laneShape = l->getShape();
997  laneShape.extrapolate2D(slack);
998  double off = laneShape.nearest_offset_to_point2D(pos, true);
999  if (off != GeomHelper::INVALID_OFFSET) {
1000  perpendicularDist = laneShape.distance2D(pos, true);
1001  }
1002  off = l->getShape().nearest_offset_to_point2D(pos, perpendicular);
1003  if (off != GeomHelper::INVALID_OFFSET) {
1004  dist = l->getShape().distance2D(pos, perpendicular);
1005  langle = GeomHelper::naviDegree(l->getShape().rotationAtOffset(off));
1006  }
1007  bool sameEdge = onRoad && e == &currentLane->getEdge() && currentRouteEdge->getLength() > currentLanePos + SPEED2DIST(speed);
1008  /*
1009  const MSEdge* rNextEdge = nextEdge;
1010  while(rNextEdge==0&&lane->getEdge().getPurpose()==MSEdge::EDGEFUNCTION_INTERNAL) {
1011  MSLane* next = lane->getLinkCont()[0]->getLane();
1012  rNextEdge = next == 0 ? 0 : &next->getEdge();
1013  }
1014  */
1015  double dist2 = dist;
1016  if (mayLeaveNetwork && fabs(dist - perpendicularDist) > slack) {
1017  // ambiguous mapping. Don't trust this
1018  dist2 = FAR_AWAY;
1019  }
1020  const double angleDiff = (angle == INVALID_DOUBLE_VALUE ? 0 : GeomHelper::getMinAngleDiff(angle, langle));
1021 #ifdef DEBUG_MOVEXY_ANGLE
1022  std::cout << std::setprecision(gPrecision)
1023  << " candLane=" << l->getID() << " lAngle=" << langle << " lLength=" << l->getLength()
1024  << " angleDiff=" << angleDiff
1025  << " off=" << off
1026  << " pDist=" << perpendicularDist
1027  << " dist=" << dist
1028  << " dist2=" << dist2
1029  << "\n";
1030  std::cout << l->getID() << " param=" << l->getParameter(SUMO_PARAM_ORIGID, lane->getID()) << " origID='" << origID << "\n";
1031 #endif
1032  lane2utility.emplace(l, LaneUtility(
1033  dist2, perpendicularDist, off, angleDiff,
1034  l->getParameter(SUMO_PARAM_ORIGID, l->getID()) == origID,
1035  onRoute, sameEdge, prevEdge, nextEdge));
1036  // update scaling value
1037  maxDist = MAX2(maxDist, MIN2(dist, SUMO_const_laneWidth));
1038 
1039  }
1040  }
1041 
1042  // get the best lane given the previously computed values
1043  double bestValue = 0;
1044  MSLane* bestLane = nullptr;
1045  for (const auto& it : lane2utility) {
1046  MSLane* const l = it.first;
1047  const LaneUtility& u = it.second;
1048  double distN = u.dist > 999 ? -10 : 1. - (u.dist / maxDist);
1049  double angleDiffN = 1. - (u.angleDiff / 180.);
1050  double idN = u.ID ? 1 : 0;
1051  double onRouteN = u.onRoute ? 1 : 0;
1052  double sameEdgeN = u.sameEdge ? MIN2(currentRouteEdge->getLength() / speed, (double)1.) : 0;
1053  double value = (distN * .5 // distance is more important than angle because the vehicle might be driving in the opposite direction
1054  + angleDiffN * 0.35 /*.5 */
1055  + idN * 1
1056  + onRouteN * 0.1
1057  + sameEdgeN * 0.1);
1058 #ifdef DEBUG_MOVEXY
1059  std::cout << " x; l:" << l->getID() << " d:" << u.dist << " dN:" << distN << " aD:" << angleDiffN <<
1060  " ID:" << idN << " oRN:" << onRouteN << " sEN:" << sameEdgeN << " value:" << value << std::endl;
1061 #endif
1062  if (value > bestValue || bestLane == nullptr) {
1063  bestValue = value;
1064  if (u.dist == FAR_AWAY) {
1065  bestLane = nullptr;
1066  } else {
1067  bestLane = l;
1068  }
1069  }
1070  }
1071  // no best lane found, return
1072  if (bestLane == nullptr) {
1073  return false;
1074  }
1075  const LaneUtility& u = lane2utility.find(bestLane)->second;
1076  bestDistance = u.dist;
1077  *lane = bestLane;
1078  lanePos = bestLane->getShape().nearest_offset_to_point25D(pos, false);
1079  const MSEdge* prevEdge = u.prevEdge;
1080  if (u.onRoute) {
1081  ConstMSEdgeVector::const_iterator prevEdgePos = std::find(currentRoute.begin(), currentRoute.end(), prevEdge);
1082  routeOffset = (int)std::distance(currentRoute.begin(), prevEdgePos);
1083  //std::cout << SIMTIME << "moveToXYMap vehicle=" << veh.getID() << " currLane=" << veh.getLane()->getID() << " routeOffset=" << routeOffset << " edges=" << toString(ev) << " bestLane=" << bestLane->getID() << " prevEdge=" << prevEdge->getID() << "\n";
1084  } else {
1085  edges.push_back(u.prevEdge);
1086  /*
1087  if(bestLane->getEdge().getPurpose()!=MSEdge::EDGEFUNCTION_INTERNAL) {
1088  edges.push_back(&bestLane->getEdge());
1089  }
1090  */
1091  if (u.nextEdge != nullptr) {
1092  edges.push_back(u.nextEdge);
1093  }
1094  routeOffset = 0;
1095 #ifdef DEBUG_MOVEXY_ANGLE
1096  std::cout << SIMTIME << " internal2: lane=" << bestLane->getID() << " prev=" << Named::getIDSecure(u.prevEdge) << " next=" << Named::getIDSecure(u.nextEdge) << "\n";
1097 #endif
1098  }
1099  return true;
1100 }
1101 
1102 
1103 bool
1104 Helper::findCloserLane(const MSEdge* edge, const Position& pos, SUMOVehicleClass vClass, double& bestDistance, MSLane** lane) {
1105  if (edge == nullptr) {
1106  return false;
1107  }
1108  const std::vector<MSLane*>& lanes = edge->getLanes();
1109  bool newBest = false;
1110  for (std::vector<MSLane*>::const_iterator k = lanes.begin(); k != lanes.end() && bestDistance > POSITION_EPS; ++k) {
1111  MSLane* candidateLane = *k;
1112  if (!candidateLane->allowsVehicleClass(vClass)) {
1113  continue;
1114  }
1115  const double dist = candidateLane->getShape().distance2D(pos); // get distance
1116 #ifdef DEBUG_MOVEXY
1117  std::cout << " b at lane " << candidateLane->getID() << " dist:" << dist << " best:" << bestDistance << std::endl;
1118 #endif
1119  if (dist < bestDistance) {
1120  // is the new distance the best one? keep then...
1121  bestDistance = dist;
1122  *lane = candidateLane;
1123  newBest = true;
1124  }
1125  }
1126  return newBest;
1127 }
1128 
1129 
1130 bool
1131 Helper::moveToXYMap_matchingRoutePosition(const Position& pos, const std::string& origID,
1132  const ConstMSEdgeVector& currentRoute, int routeIndex,
1133  SUMOVehicleClass vClass,
1134  double& bestDistance, MSLane** lane, double& lanePos, int& routeOffset) {
1135  //std::cout << "moveToXYMap_matchingRoutePosition pos=" << pos << "\n";
1136  routeOffset = 0;
1137  // routes may be looped which makes routeOffset ambiguous. We first try to
1138  // find the closest upcoming edge on the route and then look for closer passed edges
1139 
1140  // look forward along the route
1141  const MSEdge* prev = nullptr;
1142  for (int i = routeIndex; i < (int)currentRoute.size(); ++i) {
1143  const MSEdge* cand = currentRoute[i];
1144  while (prev != nullptr) {
1145  // check internal edge(s)
1146  const MSEdge* internalCand = prev->getInternalFollowingEdge(cand);
1147  findCloserLane(internalCand, pos, vClass, bestDistance, lane);
1148  prev = internalCand;
1149  }
1150  if (findCloserLane(cand, pos, vClass, bestDistance, lane)) {
1151  routeOffset = i;
1152  }
1153  prev = cand;
1154  }
1155  // look backward along the route
1156  const MSEdge* next = currentRoute[routeIndex];
1157  for (int i = routeIndex; i >= 0; --i) {
1158  const MSEdge* cand = currentRoute[i];
1159  //std::cout << " next=" << next->getID() << " cand=" << cand->getID() << " i=" << i << " routeIndex=" << routeIndex << "\n";
1160  prev = cand;
1161  while (prev != nullptr) {
1162  // check internal edge(s)
1163  const MSEdge* internalCand = prev->getInternalFollowingEdge(next);
1164  if (findCloserLane(internalCand, pos, vClass, bestDistance, lane)) {
1165  routeOffset = i;
1166  }
1167  prev = internalCand;
1168  }
1169  if (findCloserLane(cand, pos, vClass, bestDistance, lane)) {
1170  routeOffset = i;
1171  }
1172  next = cand;
1173  }
1174 
1175  assert(lane != 0);
1176  // quit if no solution was found, reporting a failure
1177  if (lane == nullptr) {
1178 #ifdef DEBUG_MOVEXY
1179  std::cout << " b failed - no best route lane" << std::endl;
1180 #endif
1181  return false;
1182  }
1183 
1184 
1185  // position may be inaccurate; let's checkt the given index, too
1186  // @note: this is enabled for non-internal lanes only, as otherwise the position information may ambiguous
1187  if (!(*lane)->getEdge().isInternal()) {
1188  const std::vector<MSLane*>& lanes = (*lane)->getEdge().getLanes();
1189  for (std::vector<MSLane*>::const_iterator i = lanes.begin(); i != lanes.end(); ++i) {
1190  if ((*i)->getParameter(SUMO_PARAM_ORIGID, (*i)->getID()) == origID) {
1191  *lane = *i;
1192  break;
1193  }
1194  }
1195  }
1196  // check position, stuff, we should have the best lane along the route
1197  lanePos = MAX2(0., MIN2(double((*lane)->getLength() - POSITION_EPS),
1198  (*lane)->interpolateGeometryPosToLanePos(
1199  (*lane)->getShape().nearest_offset_to_point25D(pos, false))));
1200  //std::cout << SIMTIME << " moveToXYMap_matchingRoutePosition vehicle=" << veh.getID() << " currLane=" << veh.getLane()->getID() << " routeOffset=" << routeOffset << " edges=" << toString(edges) << " lane=" << (*lane)->getID() << "\n";
1201 #ifdef DEBUG_MOVEXY
1202  std::cout << " b ok lane " << (*lane)->getID() << " lanePos:" << lanePos << std::endl;
1203 #endif
1204  return true;
1205 }
1206 
1207 
1209  : VariableWrapper(handler), myResults(into), myContextResults(context), myActiveResults(&into) {
1210 
1211 }
1212 
1213 
1214 void
1215 Helper::SubscriptionWrapper::setContext(const std::string& refID) {
1216  myActiveResults = refID == "" ? &myResults : &myContextResults[refID];
1217 }
1218 
1219 
1220 void
1222  myActiveResults = &myResults;
1223  myResults.clear();
1224  myContextResults.clear();
1225 }
1226 
1227 
1228 bool
1229 Helper::SubscriptionWrapper::wrapDouble(const std::string& objID, const int variable, const double value) {
1230  (*myActiveResults)[objID][variable] = std::make_shared<TraCIDouble>(value);
1231  return true;
1232 }
1233 
1234 
1235 bool
1236 Helper::SubscriptionWrapper::wrapInt(const std::string& objID, const int variable, const int value) {
1237  (*myActiveResults)[objID][variable] = std::make_shared<TraCIInt>(value);
1238  return true;
1239 }
1240 
1241 
1242 bool
1243 Helper::SubscriptionWrapper::wrapString(const std::string& objID, const int variable, const std::string& value) {
1244  (*myActiveResults)[objID][variable] = std::make_shared<TraCIString>(value);
1245  return true;
1246 }
1247 
1248 
1249 bool
1250 Helper::SubscriptionWrapper::wrapStringList(const std::string& objID, const int variable, const std::vector<std::string>& value) {
1251  auto sl = std::make_shared<TraCIStringList>();
1252  sl->value = value;
1253  (*myActiveResults)[objID][variable] = sl;
1254  return true;
1255 }
1256 
1257 
1258 bool
1259 Helper::SubscriptionWrapper::wrapPosition(const std::string& objID, const int variable, const TraCIPosition& value) {
1260  (*myActiveResults)[objID][variable] = std::make_shared<TraCIPosition>(value);
1261  return true;
1262 }
1263 
1264 
1265 bool
1266 Helper::SubscriptionWrapper::wrapColor(const std::string& objID, const int variable, const TraCIColor& value) {
1267  (*myActiveResults)[objID][variable] = std::make_shared<TraCIColor>(value);
1268  return true;
1269 }
1270 
1271 
1272 bool
1273 Helper::SubscriptionWrapper::wrapRoadPosition(const std::string& objID, const int variable, const TraCIRoadPosition& value) {
1274  (*myActiveResults)[objID][variable] = std::make_shared<TraCIRoadPosition>(value);
1275  return true;
1276 }
1277 
1278 
1279 void
1280 Helper::VehicleStateListener::vehicleStateChanged(const SUMOVehicle* const vehicle, MSNet::VehicleState to, const std::string& /*info*/) {
1281  myVehicleStateChanges[to].push_back(vehicle->getID());
1282 }
1283 
1284 
1285 }
1286 
1287 
1288 /****************************************************************************/
RGBColor::alpha
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition: RGBColor.h:82
PositionVector::nearest_offset_to_point25D
double nearest_offset_to_point25D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D projected onto the 3D geometry
Definition: PositionVector.cpp:853
MSLane::releaseVehicles
virtual void releaseVehicles() const
Allows to use the container for microsimulation again.
Definition: MSLane.h:457
MultiEntryExit.h
libsumo::Helper::getEdge
static MSEdge * getEdge(const std::string &edgeID)
Definition: Helper.cpp:325
MSVehicleType
The car-following model and parameter.
Definition: MSVehicleType.h:65
libsumo::CMD_GET_TL_VARIABLE
TRACI_CONST int CMD_GET_TL_VARIABLE
Definition: TraCIConstants.h:119
libsumo::Helper::handleSubscriptions
static void handleSubscriptions(const SUMOTime t)
Definition: Helper.cpp:144
libsumo::Helper::makePosition
static Position makePosition(const TraCIPosition &position)
Definition: Helper.cpp:319
libsumo::Helper::myObjects
static std::map< int, NamedRTree * > myObjects
A storage of objects.
Definition: Helper.h:245
SUMOVehicleClass
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
Definition: SUMOVehicleClass.h:133
libsumo::Subscription::activeFilters
int activeFilters
Active filters for the subscription (bitset,.
Definition: Subscription.h:117
MSLane::getVehiclesSecure
virtual const VehCont & getVehiclesSecure() const
Returns the vehicles container; locks it for microsimulation.
Definition: MSLane.h:427
SPEED2DIST
#define SPEED2DIST(x)
Definition: SUMOTime.h:46
libsumo::CMD_GET_POLYGON_VARIABLE
TRACI_CONST int CMD_GET_POLYGON_VARIABLE
Definition: TraCIConstants.h:209
MSLane::dictionary
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
Definition: MSLane.cpp:1866
MSVehicleType::getID
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:93
LANE_RTREE_QUAL
#define LANE_RTREE_QUAL
Definition: Helper.h:79
MSEdge::getSuccessors
const MSEdgeVector & getSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Returns the following edges, restricted by vClass.
Definition: MSEdge.cpp:959
MIN2
T MIN2(T a, T b)
Definition: StdDefs.h:73
libsumo::Helper::VehicleStateListener::vehicleStateChanged
void vehicleStateChanged(const SUMOVehicle *const vehicle, MSNet::VehicleState to, const std::string &info="")
Called if a vehicle changes its state.
Definition: Helper.cpp:1280
TraCIPositionVector
A list of positions.
libsumo::Subscription::filterUpstreamDist
double filterUpstreamDist
Upstream distance specified by the upstream distance filter.
Definition: Subscription.h:123
WRITE_WARNING
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:275
GeoConvHelper::getConvBoundary
const Boundary & getConvBoundary() const
Returns the converted boundary.
Definition: GeoConvHelper.cpp:489
MSNet.h
libsumo::Polygon::getTree
static NamedRTree * getTree()
Returns a tree filled with polygon instances.
Definition: Polygon.cpp:247
libsumo::Helper::myLaneTree
static LANE_RTREE_QUAL * myLaneTree
A storage of lanes.
Definition: Helper.h:248
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
libsumo::Helper::getVehicle
static MSVehicle * getVehicle(const std::string &id)
Definition: Helper.cpp:384
libsumo::INVALID_DOUBLE_VALUE
TRACI_CONST double INVALID_DOUBLE_VALUE
Definition: TraCIConstants.h:362
Junction.h
GeomHelper::angleDiff
static double angleDiff(const double angle1, const double angle2)
Returns the difference of the second angle to the first angle in radiants.
Definition: GeomHelper.cpp:180
libsumo::Helper::makeTraCIColor
static TraCIColor makeTraCIColor(const RGBColor &color)
Definition: Helper.cpp:292
MSEdge::getSortedPersons
std::vector< MSTransportable * > getSortedPersons(SUMOTime timestep, bool includeRiding=false) const
Returns this edge's persons sorted by pos.
Definition: MSEdge.cpp:907
MSVehicle::isOnRoad
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition: MSVehicle.h:582
libsumo::Helper::LaneUtility::dist
double dist
Definition: Helper.h:184
Boundary::ymin
double ymin() const
Returns minimum y-coordinate.
Definition: Boundary.cpp:130
libsumo::VAR_ROAD_ID
TRACI_CONST int VAR_ROAD_ID
Definition: TraCIConstants.h:675
MSEdge::getOppositeEdge
const MSEdge * getOppositeEdge() const
Returns the opposite direction edge if on exists else a nullptr.
Definition: MSEdge.cpp:1038
libsumo::TraCIPosition
A 3D-position.
Definition: TraCIDefs.h:109
Boundary::distanceTo2D
double distanceTo2D(const Position &p) const
returns the euclidean distance in the x-y-plane
Definition: Boundary.cpp:222
libsumo::Helper::cleanup
static void cleanup()
Definition: Helper.cpp:404
libsumo::Helper::SubscriptionWrapper::SubscriptionWrapper
SubscriptionWrapper(VariableWrapper::SubscriptionHandler handler, SubscriptionResults &into, ContextSubscriptionResults &context)
Definition: Helper.cpp:1208
libsumo::Subscription::filterDownstreamDist
double filterDownstreamDist
Downstream distance specified by the downstream distance filter.
Definition: Subscription.h:121
libsumo::Helper::SubscriptionWrapper::setContext
void setContext(const std::string &refID)
Definition: Helper.cpp:1215
libsumo::TraCIPosition::x
double x
Definition: TraCIDefs.h:115
libsumo::VariableWrapper
Definition: Subscription.h:132
Position::z
double z() const
Returns the z-position.
Definition: Position.h:66
LaneArea.h
libsumo::SUBS_FILTER_VCLASS
@ SUBS_FILTER_VCLASS
Definition: Subscription.h:50
Named::StoringVisitor
Allows to store the object; used as context while traveling the rtree in TraCI.
Definition: Named.h:92
GeomHelper::getMinAngleDiff
static double getMinAngleDiff(double angle1, double angle2)
Returns the minimum distance (clockwise/counter-clockwise) between both angles.
Definition: GeomHelper.cpp:174
SUMOTrafficObject::getID
virtual const std::string & getID() const =0
Get the vehicle's ID.
LaneStoringVisitor::myShape
const PositionVector & myShape
Definition: Helper.h:67
libsumo::Helper::makePositionVector
static PositionVector makePositionVector(const TraCIPositionVector &vector)
Definition: Helper.cpp:279
libsumo::CMD_GET_PERSON_VARIABLE
TRACI_CONST int CMD_GET_PERSON_VARIABLE
Definition: TraCIConstants.h:297
libsumo::TraCIColor::a
int a
Definition: TraCIDefs.h:143
MSPerson
Definition: MSPerson.h:63
libsumo::Helper::makeRGBColor
static RGBColor makeRGBColor(const TraCIColor &color)
Definition: Helper.cpp:303
libsumo::TraCIColor::g
int g
Definition: TraCIDefs.h:143
MSBaseVehicle::getLength
double getLength() const
Returns the vehicle's length.
Definition: MSBaseVehicle.h:410
libsumo::Route::makeWrapper
static LIBSUMO_SUBSCRIPTION_API std::shared_ptr< VariableWrapper > makeWrapper()
Definition: Route.cpp:117
libsumo::Helper::myRemoteControlledVehicles
static std::map< std::string, MSVehicle * > myRemoteControlledVehicles
Definition: Helper.h:250
libsumo::Vehicle::makeWrapper
static std::shared_ptr< VariableWrapper > makeWrapper()
Definition: Vehicle.cpp:1736
libsumo::Subscription::filterLanes
std::vector< int > filterLanes
lanes specified by the lanes filter
Definition: Subscription.h:119
libsumo::CMD_GET_LANEAREA_VARIABLE
TRACI_CONST int CMD_GET_LANEAREA_VARIABLE
Definition: TraCIConstants.h:284
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
libsumo::Helper::SubscriptionWrapper::wrapRoadPosition
bool wrapRoadPosition(const std::string &objID, const int variable, const TraCIRoadPosition &value)
Definition: Helper.cpp:1273
libsumo::Lane::storeShape
static LIBSUMO_SUBSCRIPTION_API void storeShape(const std::string &id, PositionVector &shape)
Saves the shape of the requested object in the given container.
Definition: Lane.cpp:368
SUMOVehicle
Representation of a vehicle.
Definition: SUMOVehicle.h:60
MSLane::VehCont
std::vector< MSVehicle * > VehCont
Container for vehicles.
Definition: MSLane.h:92
libsumo::Subscription::id
std::string id
The id of the object that is subscribed.
Definition: Subscription.h:102
libsumo::Helper::moveToXYMap
static bool moveToXYMap(const Position &pos, double maxRouteDistance, bool mayLeaveNetwork, const std::string &origID, const double angle, double speed, const ConstMSEdgeVector &currentRoute, const int routePosition, MSLane *currentLane, double currentLanePos, bool onRoad, SUMOVehicleClass vClass, double &bestDistance, MSLane **lane, double &lanePos, int &routeOffset, ConstMSEdgeVector &edges)
Definition: Helper.cpp:910
GeomHelper::naviDegree
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:193
GeoConvHelper.h
ConstMSEdgeVector
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:75
Boundary::xmax
double xmax() const
Returns maximum x-coordinate.
Definition: Boundary.cpp:124
libsumo::Edge::storeShape
static LIBSUMO_SUBSCRIPTION_API void storeShape(const std::string &id, PositionVector &shape)
Saves the shape of the requested object in the given container.
Definition: Edge.cpp:348
Boundary::getHeight
double getHeight() const
Returns the height of the boundary (y-axis)
Definition: Boundary.cpp:160
libsumo::Helper::subscribe
static void subscribe(const int commandId, const std::string &id, const std::vector< int > &variables, const double beginTime, const double endTime, const int contextDomain=0, const double range=0.)
Definition: Helper.cpp:120
libsumo::ContextSubscriptionResults
std::map< std::string, SubscriptionResults > ContextSubscriptionResults
Definition: TraCIDefs.h:204
libsumo::Helper::needNewSubscription
static bool needNewSubscription(libsumo::Subscription &s, std::vector< Subscription > &subscriptions, libsumo::Subscription *&modifiedSubscription)
Definition: Helper.cpp:157
SUMO_const_laneWidth
const double SUMO_const_laneWidth
Definition: StdDefs.h:49
libsumo::CMD_SUBSCRIBE_PERSON_CONTEXT
TRACI_CONST int CMD_SUBSCRIBE_PERSON_CONTEXT
Definition: TraCIConstants.h:293
RAD2DEG
#define RAD2DEG(x)
Definition: GeomHelper.h:38
libsumo::Subscription::endTime
SUMOTime endTime
The end time of the subscription.
Definition: Subscription.h:110
MSPerson::Influencer::setRemoteControlled
void setRemoteControlled(Position xyPos, MSLane *l, double pos, double posLat, double angle, int edgeOffset, const ConstMSEdgeVector &route, SUMOTime t)
Definition: MSPerson.cpp:776
WRITE_WARNINGF
#define WRITE_WARNINGF(...)
Definition: MsgHandler.h:276
RGBColor::red
unsigned char red() const
Returns the red-amount of the color.
Definition: RGBColor.h:61
libsumo::Helper::applySubscriptionFilters
static void applySubscriptionFilters(const Subscription &s, std::set< std::string > &objIDs)
Filter the given ID-Set (which was obtained from an R-Tree search) according to the filters set by th...
Definition: Helper.cpp:529
MSEdge.h
VehicleType.h
libsumo::Helper::makeTraCIPosition
static TraCIPosition makeTraCIPosition(const Position &position, const bool includeZ=false)
Definition: Helper.cpp:309
libsumo::Junction::storeShape
static void storeShape(const std::string &id, PositionVector &shape)
Saves the shape of the requested object in the given container.
Definition: Junction.cpp:100
libsumo::TraCIColor
A color.
Definition: TraCIDefs.h:135
libsumo::CMD_SUBSCRIBE_POI_CONTEXT
TRACI_CONST int CMD_SUBSCRIBE_POI_CONTEXT
Definition: TraCIConstants.h:190
MSInsertionControl.h
libsumo::CMD_GET_LANE_VARIABLE
TRACI_CONST int CMD_GET_LANE_VARIABLE
Definition: TraCIConstants.h:134
libsumo::SUBS_FILTER_MANEUVER
@ SUBS_FILTER_MANEUVER
Definition: Subscription.h:59
PositionVector
A list of positions.
Definition: PositionVector.h:45
Vehicle.h
libsumo::Helper::SubscriptionWrapper::wrapString
bool wrapString(const std::string &objID, const int variable, const std::string &value)
Definition: Helper.cpp:1243
LaneStoringVisitor::myIDs
std::set< std::string > & myIDs
The container.
Definition: Helper.h:66
libsumo::CMD_SUBSCRIBE_VEHICLE_CONTEXT
TRACI_CONST int CMD_SUBSCRIBE_VEHICLE_CONTEXT
Definition: TraCIConstants.h:145
MSEdge::getLength
double getLength() const
return the length of the edge
Definition: MSEdge.h:589
libsumo::TraCIColor::b
int b
Definition: TraCIDefs.h:143
libsumo::Helper::SubscriptionWrapper::clear
void clear()
Definition: Helper.cpp:1221
MSLane::getUpcomingLinks
std::vector< const MSLink * > getUpcomingLinks(double pos, double range, const std::vector< MSLane * > &contLanes) const
Returns all upcoming junctions within given range along the given (non-internal) continuation lanes m...
Definition: MSLane.cpp:3470
PositionVector::getBoxBoundary
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
Definition: PositionVector.cpp:390
libsumo::CMD_GET_VEHICLE_VARIABLE
TRACI_CONST int CMD_GET_VEHICLE_VARIABLE
Definition: TraCIConstants.h:149
libsumo::CMD_GET_VEHICLETYPE_VARIABLE
TRACI_CONST int CMD_GET_VEHICLETYPE_VARIABLE
Definition: TraCIConstants.h:164
libsumo::POI::getTree
static LIBSUMO_SUBSCRIPTION_API NamedRTree * getTree()
Returns a tree filled with PoI instances.
Definition: POI.cpp:250
libsumo::Subscription::variables
std::vector< int > variables
The subscribed variables.
Definition: Subscription.h:104
LaneStoringVisitor
Definition: Helper.h:52
libsumo::SUBS_FILTER_NOOPPOSITE
@ SUBS_FILTER_NOOPPOSITE
Definition: Subscription.h:40
libsumo::POI::makeWrapper
static std::shared_ptr< VariableWrapper > makeWrapper()
Definition: POI.cpp:269
MSVehicle.h
libsumo::Helper::getLaneChecking
static const MSLane * getLaneChecking(const std::string &edgeID, int laneIndex, double pos)
Definition: Helper.cpp:335
libsumo::VehicleType::makeWrapper
static LIBSUMO_SUBSCRIPTION_API std::shared_ptr< VariableWrapper > makeWrapper()
Definition: VehicleType.cpp:359
libsumo
Definition: Edge.cpp:29
FAR_AWAY
#define FAR_AWAY
Definition: Helper.cpp:54
MAX2
T MAX2(T a, T b)
Definition: StdDefs.h:79
libsumo::Subscription::parameters
std::vector< std::vector< unsigned char > > parameters
The parameters for the subscribed variables.
Definition: Subscription.h:106
MSEdge::isInternal
bool isInternal() const
return whether this edge is an internal edge
Definition: MSEdge.h:235
MSVehicle::getPosition
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
Definition: MSVehicle.cpp:1269
Person.h
libsumo::CMD_SUBSCRIBE_POLYGON_CONTEXT
TRACI_CONST int CMD_SUBSCRIBE_POLYGON_CONTEXT
Definition: TraCIConstants.h:205
libsumo::Subscription::commandId
int commandId
commandIdArg The command id of the subscription
Definition: Subscription.h:100
PositionVector::nearest_offset_to_point2D
double nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
Definition: PositionVector.cpp:817
RGBColor
Definition: RGBColor.h:39
libsumo::SUBS_FILTER_TURN
@ SUBS_FILTER_TURN
Definition: Subscription.h:48
libsumo::Person::storeShape
LIBSUMO_VEHICLE_TYPE_SETTER static LIBSUMO_SUBSCRIPTION_API void storeShape(const std::string &id, PositionVector &shape)
Saves the shape of the requested object in the given container.
Definition: Person.cpp:975
MSPerson::getInfluencer
Influencer & getInfluencer()
Returns the velocity/lane influencer.
Definition: MSPerson.cpp:751
Simulation.h
SIMTIME
#define SIMTIME
Definition: SUMOTime.h:63
MSVehicleControl::getVehicle
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
Definition: MSVehicleControl.cpp:240
MSLane::interpolateGeometryPosToLanePos
double interpolateGeometryPosToLanePos(double geometryPos) const
Definition: MSLane.h:510
MSVehicle::getPositionOnLane
double getPositionOnLane() const
Get the vehicle's position along the lane.
Definition: MSVehicle.h:392
libsumo::CMD_GET_POI_VARIABLE
TRACI_CONST int CMD_GET_POI_VARIABLE
Definition: TraCIConstants.h:194
TraCIConstants.h
libsumo::SUBS_FILTER_UPSTREAM_DIST
@ SUBS_FILTER_UPSTREAM_DIST
Definition: Subscription.h:44
Boundary::xmin
double xmin() const
Returns minimum x-coordinate.
Definition: Boundary.cpp:118
libsumo::Subscription
Representation of a subscription.
Definition: Subscription.h:67
libsumo::Subscription::filterFieldOfVisionOpeningAngle
double filterFieldOfVisionOpeningAngle
Opening angle (in deg) specified by the field of vision filter.
Definition: Subscription.h:129
GeoConvHelper::getFinal
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
Definition: GeoConvHelper.h:105
libsumo::Helper::SubscriptionWrapper::wrapInt
bool wrapInt(const std::string &objID, const int variable, const int value)
Definition: Helper.cpp:1236
libsumo::Helper::fuseLaneCoverage
static void fuseLaneCoverage(std::shared_ptr< LaneCoverageInfo > aggregatedLaneCoverage, const std::shared_ptr< LaneCoverageInfo > newLaneCoverage)
Adds lane coverage information from newLaneCoverage into aggregatedLaneCoverage.
Definition: Helper.cpp:251
MSTransportableControl.h
libsumo::LaneArea::makeWrapper
static LIBSUMO_SUBSCRIPTION_API std::shared_ptr< VariableWrapper > makeWrapper()
Definition: LaneArea.cpp:134
TIME2STEPS
#define TIME2STEPS(x)
Definition: SUMOTime.h:58
MSNet::VehicleState
VehicleState
Definition of a vehicle state.
Definition: MSNet.h:535
libsumo::Helper::LaneUtility::sameEdge
bool sameEdge
Definition: Helper.h:190
GeomHelper::INVALID_OFFSET
static const double INVALID_OFFSET
a value to signify offsets outside the range of [0, Line.length()]
Definition: GeomHelper.h:51
MSLane::getLeader
std::pair< MSVehicle *const, double > getLeader(const MSVehicle *veh, const double vehPos, const std::vector< MSLane * > &bestLaneConts, double dist=-1, bool checkTmpVehicles=false) const
Returns the immediate leader of veh and the distance to veh starting on this lane.
Definition: MSLane.cpp:2279
libsumo::Subscription::filterVClasses
int filterVClasses
vClasses specified by the vClasses filter,
Definition: Subscription.h:127
MSEdge::dictionary
static bool dictionary(const std::string &id, MSEdge *edge)
Inserts edge into the static dictionary Returns true if the key id isn't already in the dictionary....
Definition: MSEdge.cpp:765
SUMO_PARAM_ORIGID
const std::string SUMO_PARAM_ORIGID
STEPS2TIME
#define STEPS2TIME(x)
Definition: SUMOTime.h:56
MSLane::getVehiclesInRange
std::set< MSVehicle * > getVehiclesInRange(const double a, const double b) const
Returns all vehicles on the lane overlapping with the interval [a,b].
Definition: MSLane.cpp:3439
libsumo::Junction::makeWrapper
static std::shared_ptr< VariableWrapper > makeWrapper()
Definition: Junction.cpp:106
Boundary
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:41
MSLane::getLength
double getLength() const
Returns the lane's length.
Definition: MSLane.h:540
libsumo::Polygon::storeShape
static void storeShape(const std::string &id, PositionVector &shape)
Saves the shape of the requested object in the given container.
Definition: Polygon.cpp:261
libsumo::TraCIPosition::z
double z
Definition: TraCIDefs.h:115
libsumo::Lane::makeWrapper
static std::shared_ptr< VariableWrapper > makeWrapper()
Definition: Lane.cpp:374
Boundary::getWidth
double getWidth() const
Returns the width of the boudary (x-axis)
Definition: Boundary.cpp:154
MSNet::addVehicleStateListener
void addVehicleStateListener(VehicleStateListener *listener)
Adds a vehicle states listener.
Definition: MSNet.cpp:877
libsumo::Helper::moveToXYMap_matchingRoutePosition
static bool moveToXYMap_matchingRoutePosition(const Position &pos, const std::string &origID, const ConstMSEdgeVector &currentRoute, int routeIndex, SUMOVehicleClass vClass, double &bestDistance, MSLane **lane, double &lanePos, int &routeOffset)
Definition: Helper.cpp:1131
MSVehicle::getAngle
double getAngle() const
Returns the vehicle's direction in radians.
Definition: MSVehicle.h:680
Helper.h
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
Position::x
double x() const
Returns the x-position.
Definition: Position.h:56
libsumo::CMD_GET_SIM_VARIABLE
TRACI_CONST int CMD_GET_SIM_VARIABLE
Definition: TraCIConstants.h:254
InductionLoop.h
libsumo::Helper::makeTraCIPositionVector
static TraCIPositionVector makeTraCIPositionVector(const PositionVector &positionVector)
helper functions
Definition: Helper.cpp:269
libsumo::TRACI_ID_LIST
TRACI_CONST int TRACI_ID_LIST
Definition: TraCIConstants.h:498
libsumo::VariableWrapper::SubscriptionHandler
bool(* SubscriptionHandler)(const std::string &objID, const int variable, VariableWrapper *wrapper)
Definition of a method to be called for serving an associated commandID.
Definition: Subscription.h:135
libsumo::Helper::LaneUtility::nextEdge
const MSEdge * nextEdge
Definition: Helper.h:192
libsumo::TraCIColor::r
int r
Definition: TraCIDefs.h:143
MSEdge
A road/street connecting two junctions.
Definition: MSEdge.h:78
Route.h
libsumo::Subscription::beginTime
SUMOTime beginTime
The begin time of the subscription.
Definition: Subscription.h:108
libsumo::Simulation::makeWrapper
static std::shared_ptr< VariableWrapper > makeWrapper()
Definition: Simulation.cpp:689
MSLane::getSurroundingVehicles
std::set< MSVehicle * > getSurroundingVehicles(double startPos, double downstreamDist, double upstreamDist, std::shared_ptr< LaneCoverageInfo > checkedLanes) const
Returns all vehicles closer than downstreamDist along the along the road network starting on the give...
Definition: MSLane.cpp:3387
TrafficLight.h
libsumo::CMD_SUBSCRIBE_JUNCTION_CONTEXT
TRACI_CONST int CMD_SUBSCRIBE_JUNCTION_CONTEXT
Definition: TraCIConstants.h:220
MSBaseVehicle::getVehicleType
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
Definition: MSBaseVehicle.h:123
MSEdge::getInternalFollowingEdge
const MSEdge * getInternalFollowingEdge(const MSEdge *followerAfterInternal) const
Definition: MSEdge.cpp:669
RGBColor::green
unsigned char green() const
Returns the green-amount of the color.
Definition: RGBColor.h:68
libsumo::Helper::SubscriptionWrapper::wrapPosition
bool wrapPosition(const std::string &objID, const int variable, const TraCIPosition &value)
Definition: Helper.cpp:1259
libsumo::Helper::LaneUtility
Definition: Helper.h:176
libsumo::SUBS_FILTER_LANES
@ SUBS_FILTER_LANES
Definition: Subscription.h:38
MSLane::visit
void visit(const LaneStoringVisitor &cont) const
Callback for visiting the lane when traversing an RTree.
Definition: MSLane.h:1191
libsumo::InductionLoop::getTree
static LIBSUMO_SUBSCRIPTION_API NamedRTree * getTree()
Returns a tree filled with inductive loop instances.
Definition: InductionLoop.cpp:139
libsumo::TraCIException
Definition: TraCIDefs.h:89
MSLane::allowsVehicleClass
bool allowsVehicleClass(SUMOVehicleClass vclass) const
Definition: MSLane.h:805
libsumo::TrafficLight::makeWrapper
static LIBSUMO_SUBSCRIPTION_API std::shared_ptr< VariableWrapper > makeWrapper()
Definition: TrafficLight.cpp:323
libsumo::SUBS_FILTER_NO_RTREE
@ SUBS_FILTER_NO_RTREE
Definition: Subscription.h:57
DEG2RAD
#define DEG2RAD(x)
Definition: GeomHelper.h:37
MSLane::getLogicalPredecessorLane
MSLane * getLogicalPredecessorLane() const
get the most likely precedecessor lane (sorted using by_connections_to_sorter). The result is cached ...
Definition: MSLane.cpp:2543
MSPerson.h
libsumo::Helper::postProcessRemoteControl
static void postProcessRemoteControl()
Definition: Helper.cpp:889
MSVehicle::getLane
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:560
PositionVector::distance2D
double distance2D(const Position &p, bool perpendicular=false) const
closest 2D-distance to point p (or -1 if perpendicular is true and the point is beyond this vector)
Definition: PositionVector.cpp:1259
libsumo::MultiEntryExit::makeWrapper
static LIBSUMO_SUBSCRIPTION_API std::shared_ptr< VariableWrapper > makeWrapper()
Definition: MultiEntryExit.cpp:97
libsumo::Helper::VehicleStateListener::myVehicleStateChanges
std::map< MSNet::VehicleState, std::vector< std::string > > myVehicleStateChanges
Changes in the states of simulated vehicles.
Definition: Helper.h:232
libsumo::Person::makeWrapper
static std::shared_ptr< VariableWrapper > makeWrapper()
Definition: Person.cpp:981
libsumo::Helper::LaneUtility::angleDiff
double angleDiff
Definition: Helper.h:187
Position::angleTo2D
double angleTo2D(const Position &other) const
returns the angle in the plane of the vector pointing from here to the other position
Definition: Position.h:253
MSLane::getEdge
MSEdge & getEdge() const
Returns the lane's edge.
Definition: MSLane.h:669
Position::distanceTo2D
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:243
Polygon.h
MSEdgeControl.h
libsumo::Junction::getTree
static LIBSUMO_SUBSCRIPTION_API NamedRTree * getTree()
Returns a tree filled with junction instances.
Definition: Junction.cpp:87
MSVehicle::getInfluencer
Influencer & getInfluencer()
Returns the velocity/lane influencer.
Definition: MSVehicle.cpp:5900
libsumo::Helper::applySubscriptionFilterFieldOfVision
static void applySubscriptionFilterFieldOfVision(const Subscription &s, std::set< std::string > &objIDs)
Definition: Helper.cpp:836
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
libsumo::Helper::collectObjectsInRange
static void collectObjectsInRange(int domain, const PositionVector &shape, double range, std::set< std::string > &into)
Definition: Helper.cpp:470
MSLane::getShape
const PositionVector & getShape() const
Returns this lane's shape.
Definition: MSLane.h:477
LaneStoringVisitor::myDomain
const int myDomain
Definition: Helper.h:69
MSVehicle::Influencer::setRemoteControlled
void setRemoteControlled(Position xyPos, MSLane *l, double pos, double posLat, double angle, int edgeOffset, const ConstMSEdgeVector &route, SUMOTime t)
Definition: MSVehicle.cpp:778
libsumo::Helper::clearSubscriptions
static void clearSubscriptions()
Definition: Helper.cpp:180
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
Position::y
double y() const
Returns the y-position.
Definition: Position.h:61
libsumo::Edge::makeWrapper
static std::shared_ptr< VariableWrapper > makeWrapper()
Definition: Edge.cpp:359
libsumo::CMD_GET_MULTIENTRYEXIT_VARIABLE
TRACI_CONST int CMD_GET_MULTIENTRYEXIT_VARIABLE
Definition: TraCIConstants.h:106
RGBColor::blue
unsigned char blue() const
Returns the blue-amount of the color.
Definition: RGBColor.h:75
LaneStoringVisitor::myRange
const double myRange
Definition: Helper.h:68
libsumo::CMD_SUBSCRIBE_INDUCTIONLOOP_CONTEXT
TRACI_CONST int CMD_SUBSCRIBE_INDUCTIONLOOP_CONTEXT
Definition: TraCIConstants.h:89
libsumo::Helper::myVehicleStateListener
static VehicleStateListener myVehicleStateListener
Changes in the states of simulated vehicles.
Definition: Helper.h:242
libsumo::Subscription::range
double range
The range of the context.
Definition: Subscription.h:114
libsumo::Vehicle::storeShape
static void storeShape(const std::string &id, PositionVector &shape)
Saves the shape of the requested object in the given container.
Definition: Vehicle.cpp:1730
libsumo::Helper::setRemoteControlled
static void setRemoteControlled(MSVehicle *v, Position xyPos, MSLane *l, double pos, double posLat, double angle, int edgeOffset, ConstMSEdgeVector route, SUMOTime t)
Definition: Helper.cpp:874
libsumo::CMD_GET_INDUCTIONLOOP_VARIABLE
TRACI_CONST int CMD_GET_INDUCTIONLOOP_VARIABLE
Definition: TraCIConstants.h:93
libsumo::Helper::myRemoteControlledPersons
static std::map< std::string, MSPerson * > myRemoteControlledPersons
Definition: Helper.h:251
libsumo::Helper::LaneUtility::prevEdge
const MSEdge * prevEdge
Definition: Helper.h:191
libsumo::POI::storeShape
static void storeShape(const std::string &id, PositionVector &shape)
Saves the shape of the requested object in the given container.
Definition: POI.cpp:263
MSTransportable.h
POI.h
libsumo::Helper::handleSingleSubscription
static void handleSingleSubscription(const Subscription &s)
Definition: Helper.cpp:186
libsumo::CMD_SUBSCRIBE_LANE_CONTEXT
TRACI_CONST int CMD_SUBSCRIBE_LANE_CONTEXT
Definition: TraCIConstants.h:130
libsumo::VAR_LANEPOSITION
TRACI_CONST int VAR_LANEPOSITION
Definition: TraCIConstants.h:699
libsumo::Helper::SubscriptionWrapper::wrapDouble
bool wrapDouble(const std::string &objID, const int variable, const double value)
Definition: Helper.cpp:1229
libsumo::SUBS_FILTER_DOWNSTREAM_DIST
@ SUBS_FILTER_DOWNSTREAM_DIST
Definition: Subscription.h:42
libsumo::Helper::findObjectShape
static void findObjectShape(int domain, const std::string &id, PositionVector &shape)
Definition: Helper.cpp:437
MSTransportable::getID
const std::string & getID() const
returns the id of the transportable
Definition: MSTransportable.cpp:699
MSVehicle::getBestLanesContinuation
const std::vector< MSLane * > & getBestLanesContinuation() const
Returns the best sequence of lanes to continue the route starting at myLane.
Definition: MSVehicle.cpp:5058
MSLane::fill
static void fill(RTREE &into)
Fills the given RTree with lane instances.
Definition: MSLane.cpp:1906
MSBaseVehicle::getID
const std::string & getID() const
Returns the name of the vehicle.
Definition: MSBaseVehicle.cpp:138
MSLane::getParallelLane
MSLane * getParallelLane(int offset, bool includeOpposite=true) const
Returns the lane with the given offset parallel to this one or 0 if it does not exist.
Definition: MSLane.cpp:2198
libsumo::CMD_SUBSCRIBE_EDGE_CONTEXT
TRACI_CONST int CMD_SUBSCRIBE_EDGE_CONTEXT
Definition: TraCIConstants.h:235
Lane.h
Edge.h
MSEdge::getLanes
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:167
libsumo::Helper::SubscriptionWrapper::wrapColor
bool wrapColor(const std::string &objID, const int variable, const TraCIColor &value)
Definition: Helper.cpp:1266
libsumo::Helper::LaneUtility::onRoute
bool onRoute
Definition: Helper.h:189
libsumo::SUBS_FILTER_FIELD_OF_VISION
@ SUBS_FILTER_FIELD_OF_VISION
Definition: Subscription.h:55
libsumo::VariableWrapper::setContext
virtual void setContext(const std::string &)
Definition: Subscription.h:138
MSNet::hasInstance
static bool hasInstance()
Returns whether the network was already constructed.
Definition: MSNet.h:143
libsumo::TraCIRoadPosition
An edgeId, position and laneIndex.
Definition: TraCIDefs.h:121
libsumo::Subscription::contextDomain
int contextDomain
The domain ID of the context.
Definition: Subscription.h:112
config.h
libsumo::Helper::LaneUtility::ID
bool ID
Definition: Helper.h:188
Named::getIDSecure
static std::string getIDSecure(const T *obj, const std::string &fallBack="NULL")
get an identifier for Named-like object which may be Null
Definition: Named.h:69
GeomHelper.h
gPrecision
int gPrecision
the precision for floating point outputs
Definition: StdDefs.cpp:26
Boundary::grow
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:300
libsumo::LAST_STEP_VEHICLE_NUMBER
TRACI_CONST int LAST_STEP_VEHICLE_NUMBER
Definition: TraCIConstants.h:513
libsumo::Polygon::makeWrapper
static std::shared_ptr< VariableWrapper > makeWrapper()
Definition: Polygon.cpp:267
SUMOTime_MAX
#define SUMOTime_MAX
Definition: SUMOTime.h:35
libsumo::Helper::getVehicleStateChanges
static const std::vector< std::string > & getVehicleStateChanges(const MSNet::VehicleState state)
Definition: Helper.cpp:423
MSLane.h
libsumo::SUBS_FILTER_LEAD_FOLLOW
@ SUBS_FILTER_LEAD_FOLLOW
Definition: Subscription.h:46
libsumo::Helper::findCloserLane
static bool findCloserLane(const MSEdge *edge, const Position &pos, SUMOVehicleClass vClass, double &bestDistance, MSLane **lane)
Definition: Helper.cpp:1104
libsumo::Helper::mySubscriptions
static std::vector< Subscription > mySubscriptions
The list of known, still valid subscriptions.
Definition: Helper.h:236
MSVehicleType::getVehicleClass
SUMOVehicleClass getVehicleClass() const
Get this vehicle type's vehicle class.
Definition: MSVehicleType.h:184
libsumo::SUBS_FILTER_VTYPE
@ SUBS_FILTER_VTYPE
Definition: Subscription.h:52
libsumo::Helper::SubscriptionWrapper::wrapStringList
bool wrapStringList(const std::string &objID, const int variable, const std::vector< std::string > &value)
Definition: Helper.cpp:1250
libsumo::InductionLoop::makeWrapper
static std::shared_ptr< VariableWrapper > makeWrapper()
Definition: InductionLoop.cpp:160
libsumo::InductionLoop::storeShape
static void storeShape(const std::string &id, PositionVector &shape)
Saves the shape of the requested object in the given container.
Definition: InductionLoop.cpp:153
libsumo::Helper::getVehicleType
static const MSVehicleType & getVehicleType(const std::string &vehicleID)
Definition: Helper.cpp:398
MSVehicleControl.h
TraCIDefs.h
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:76
POSITION_EPS
#define POSITION_EPS
Definition: config.h:172
libsumo::CMD_GET_EDGE_VARIABLE
TRACI_CONST int CMD_GET_EDGE_VARIABLE
Definition: TraCIConstants.h:239
libsumo::Helper::myWrapper
static std::map< int, std::shared_ptr< VariableWrapper > > myWrapper
Map of commandIds -> their executors; applicable if the executor applies to the method footprint.
Definition: Helper.h:239
MSLane::getIndex
int getIndex() const
Returns the lane's index.
Definition: MSLane.h:563
libsumo::Helper::registerVehicleStateListener
static void registerVehicleStateListener()
Definition: Helper.cpp:415
libsumo::Helper::convertCartesianToRoadMap
static std::pair< MSLane *, double > convertCartesianToRoadMap(const Position &pos, const SUMOVehicleClass vClass)
Definition: Helper.cpp:352
MSNet::getVehicleControl
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:336
PositionVector::extrapolate2D
void extrapolate2D(const double val, const bool onlyFirst=false)
extrapolate position vector in two dimensions (Z is ignored)
Definition: PositionVector.cpp:1064
LaneStoringVisitor::add
void add(const MSLane *const l) const
Adds the given object to the container.
Definition: Helper.cpp:62
libsumo::SubscriptionResults
std::map< std::string, TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition: TraCIDefs.h:203
libsumo::Helper::clearVehicleStates
static void clearVehicleStates()
Definition: Helper.cpp:429
Boundary::ymax
double ymax() const
Returns maximum y-coordinate.
Definition: Boundary.cpp:136
libsumo::Subscription::filterVTypes
std::set< std::string > filterVTypes
vTypes specified by the vTypes filter
Definition: Subscription.h:125
libsumo::CMD_GET_JUNCTION_VARIABLE
TRACI_CONST int CMD_GET_JUNCTION_VARIABLE
Definition: TraCIConstants.h:224
libsumo::CMD_GET_ROUTE_VARIABLE
TRACI_CONST int CMD_GET_ROUTE_VARIABLE
Definition: TraCIConstants.h:179
libsumo::TraCIPosition::y
double y
Definition: TraCIDefs.h:115
MSVehicle
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79
MSLane::getFollower
std::pair< MSVehicle *const, double > getFollower(const MSVehicle *ego, double egoPos, double dist, bool ignoreMinorLinks) const
Find follower vehicle for the given ego vehicle (which may be on the opposite direction lane)
Definition: MSLane.cpp:3539