55 #ifdef CHECK_MEMORY_LEAKS
57 #endif // CHECK_MEMORY_LEAKS
63 using namespace traci;
106 std::vector<std::string> ids;
109 if ((*i).second->isOnRoad()) {
110 ids.push_back((*i).first);
122 if (sumoVehicle == 0) {
160 tempMsg.
writeInt((
int)std::distance(lanes.begin(), std::find(lanes.begin(), lanes.end(), v->
getLane())));
220 if (inputStorage.
readInt() != 2) {
252 if (inputStorage.
readInt() != 2) {
302 unsigned int cnt = 0;
304 const std::vector<MSVehicle::LaneQ>& bestLanes = onRoad ? v->
getBestLanes() : std::vector<MSVehicle::LaneQ>();
305 tempContent.
writeInt((
int) bestLanes.size());
307 for (std::vector<MSVehicle::LaneQ>::const_iterator i = bestLanes.begin(); i != bestLanes.end(); ++i) {
324 std::vector<std::string> bestContIDs;
326 bestContIDs.push_back((*j)->getID());
337 if (!commandDistanceRequest(server, inputStorage, tempMsg, v)) {
355 std::string warning =
"";
377 const bool shouldExist = variable !=
ADD;
379 if (sumoVehicle == 0) {
385 if (v == 0 && shouldExist) {
393 if (inputStorage.
readInt() != 4) {
423 const std::vector<MSLane*>& allLanes = road->
getLanes();
424 if ((laneIndex < 0) || laneIndex >= (
int)(allLanes.size())) {
428 if (!v->
addTraciStop(allLanes[laneIndex], pos, 0, waitTime)) {
437 if (inputStorage.
readInt() != 2) {
450 if ((laneIndex < 0) || (laneIndex >= (
int)(v->
getEdge()->
getLanes().size()))) {
454 std::vector<std::pair<SUMOTime, unsigned int> > laneTimeLine;
455 laneTimeLine.push_back(std::make_pair(
MSNet::getInstance()->getCurrentTimeStep(), laneIndex));
456 laneTimeLine.push_back(std::make_pair(
MSNet::getInstance()->getCurrentTimeStep() + stickyTime, laneIndex));
467 if (inputStorage.
readInt() != 2) {
484 std::vector<std::pair<SUMOTime, SUMOReal> > speedTimeLine;
486 speedTimeLine.push_back(std::make_pair(
MSNet::getInstance()->getCurrentTimeStep() + duration, newSpeed));
525 std::vector<std::string> edgeIDs;
529 std::vector<const MSEdge*> edges;
540 int parameterCount = inputStorage.
readInt();
541 if (parameterCount == 4) {
567 }
else if (parameterCount == 2) {
587 }
else if (parameterCount == 1) {
610 int parameterCount = inputStorage.
readInt();
611 if (parameterCount == 4) {
637 }
else if (parameterCount == 2) {
657 }
else if (parameterCount == 1) {
680 if (inputStorage.
readInt() != 0) {
690 if (inputStorage.
readInt() != 0) {
709 if (inputStorage.
readInt() != 2) {
728 if (!v->
willPass(&destinationEdge)) {
733 while (v->
getEdge() != &destinationEdge) {
749 std::vector<std::pair<SUMOTime, SUMOReal> > speedTimeLine;
751 speedTimeLine.push_back(std::make_pair(
MSNet::getInstance()->getCurrentTimeStep(), speed));
752 speedTimeLine.push_back(std::make_pair(
SUMOTime_MAX, speed));
783 if (inputStorage.
readInt() != 6) {
787 vehicleParams.
id = id;
810 if (vehicleParams.
depart < 0) {
811 const int proc =
static_cast<int>(-vehicleParams.
depart);
824 const int proc =
static_cast<int>(-vehicleParams.
departPos);
839 const int proc =
static_cast<int>(-vehicleParams.
departSpeed);
853 const int proc =
static_cast<int>(-vehicleParams.
departLane);
863 *params = vehicleParams;
911 if (inputStorage.
readInt() != 4) {
937 std::string origID = edgeID +
" " +
toString(laneNum);
939 edgeID =
'-' + edgeID;
947 if(report) std::cout << std::endl <<
"begin vehicle " << v->
getID() <<
" vehPos:" << vehPos <<
" lane:" << v->
getLane()->
getID() << std::endl;
948 if(report) std::cout <<
" want pos:" << pos <<
" edge:" << edgeID <<
" laneNum:" << laneNum << std::endl;
951 MSLane *laneA, *laneB, *laneC;
952 laneA = laneB = laneC = 0;
953 SUMOReal lanePosA, lanePosB, lanePosC;
954 SUMOReal bestDistanceA, bestDistanceB, bestDistanceC;
955 bestDistanceA = bestDistanceB = bestDistanceC = 1000.;
956 int routeOffsetA, routeOffsetB, routeOffsetC;
957 routeOffsetA = routeOffsetB = routeOffsetC = 0;
959 bool aFound = vtdMap_matchingEdgeLane(pos, origID, *v, server.
vtdDebug(), bestDistanceA, &laneA, lanePosA, routeOffsetA, edgesA);
961 bool bFound = vtdMap_matchingRoutePosition(pos, origID, *v, server.
vtdDebug(), bestDistanceB, &laneB, lanePosB, routeOffsetB, edgesB);
963 bool cFound = vtdMap_matchingNearest(pos, origID, *v, server, server.
vtdDebug(), bestDistanceC, &laneC, lanePosC, routeOffsetC, edgesC);
966 if(cFound && (bestDistanceA>maxRouteDistance&&bestDistanceC>maxRouteDistance)) {
1001 const std::map<std::string, std::vector<MSLane*> > &vtdMap = getOrBuildVTDMap();
1002 if(vtdMap.find(origID)==vtdMap.end()) {
1003 if(report) std::cout <<
" a failed - lane not in map" << std::endl;
1006 const std::vector<MSLane*> &lanes = vtdMap.find(origID)->second;
1007 for(std::vector<MSLane*>::const_iterator i=lanes.begin(); i!=lanes.end()&&bestDistance>
POSITION_EPS; ++i) {
1010 if(report) std::cout <<
" a at lane " << l->
getID() <<
" dist:" << dist <<
" best:" << bestDistance << std::endl;
1011 if (dist < bestDistance) {
1012 bestDistance = dist;
1022 if(report) std::cout <<
" a failed - no incoming lane" << std::endl;
1026 MSEdgeVector::const_iterator p = std::find(tedges.begin() + v.
getRoutePosition(), tedges.end(), &pni->
getEdge());
1027 if(p!=tedges.end()) {
1028 lanePos =
MAX2(
SUMOReal(0),
MIN2((*lane)->getLength()-
POSITION_EPS, (*lane)->getShape().nearest_position_on_line_to_point2D(pos,
false)));
1030 if(report) std::cout <<
" a ok lane:" << (*lane)->getID() <<
" lanePos:" << lanePos <<
" routeOffset:" << routeOffset << std::endl;
1033 if(report) std::cout <<
" a failed - route position beyond route length" << std::endl;
1042 int lastBestRouteEdge = 0;
1043 int lastRouteEdge = 0;
1044 MSLane *bestRouteLane = 0;
1046 for(std::vector<MSLane*>::const_iterator i=bestLaneConts.begin(); i!=bestLaneConts.end()&&bestDistance>
POSITION_EPS; ++i) {
1047 MSEdge &e = (*i)->getEdge();
1051 const std::vector<MSLane*>& lanes = e.
getLanes();
1052 for (std::vector<MSLane*>::const_iterator k = lanes.begin(); k != lanes.end()&&bestDistance>
POSITION_EPS; ++k) {
1055 if(report) std::cout <<
" b at lane " << cl->
getID() <<
" dist:" << dist <<
" best:" << bestDistance << std::endl;
1056 if (dist < bestDistance) {
1057 bestDistance = dist;
1059 lastBestRouteEdge = lastRouteEdge;
1063 bestRouteLane = *lane;
1068 if(bestRouteLane==0) {
1069 if(report) std::cout <<
" b failed - no best route lane" << std::endl;
1073 routeOffset = lastBestRouteEdge;
1074 if(report) std::cout <<
" b ok lane " << bestRouteLane->
getID() <<
" lanePos:" << lanePos <<
" best:" << lastBestRouteEdge << std::endl;
1085 MSLane* nameMatchingLane = 0;
1086 SUMOReal minDistNameMatchingLane = 1 << (11);
1087 for (; minDistLane == 0 && r < 10 && nameMatchingLane == 0; ++r) {
1088 std::set<std::string> into;
1092 for (std::set<std::string>::const_iterator j = into.begin(); j != into.end(); ++j) {
1094 const std::vector<MSLane*>& lanes = e->
getLanes();
1095 for (std::vector<MSLane*>::const_iterator k = lanes.begin(); k != lanes.end(); ++k) {
1100 if (dist < minDistNameMatchingLane) {
1101 minDistNameMatchingLane = dist;
1102 nameMatchingLane = lane;
1106 if (dist < minDist) {
1113 *lane = nameMatchingLane != 0 ? nameMatchingLane : minDistLane;
1115 if(report) std::cout <<
" c failed - no matching lane" << std::endl;
1121 if(report) std::cout <<
" c ok, on same lane" << std::endl;
1124 MSEdge& destinationEdge = (*lane)->getEdge();
1125 MSEdge* routePos = &destinationEdge;
1127 routePos = &routePos->
getLanes()[0]->getLogicalPredecessorLane()->getEdge();
1133 unsigned int rindex = 0;
1135 while (!found && ((
int)(c - r) >= 0 || c + r < l)) {
1136 if ((
int)(c - r) >= 0 && route[c - r] == routePos) {
1140 if (c + r < l && route[c + r] == routePos) {
1149 if(report) std::cout <<
" c ok, on a different edge of same route" << std::endl;
1153 MSLane* firstLane = *lane;
1155 edges.push_back(&destinationEdge);
1158 edges.push_back(&firstLane->
getEdge());
1161 if (lc.size() != 0 && lc[0]->getLane() != 0) {
1162 edges.push_back(&lc[0]->getLane()->getEdge());
1164 if(report) std::cout <<
" c ok, on a different route" << std::endl;
1175 if (inputStorage.
readInt() != 2) {
1180 std::pair<const MSLane*, SUMOReal> roadPos;
1187 std::string roadID = inputStorage.
readString();
1190 pos = roadPos.first->getShape().positionAtLengthPosition(roadPos.second);
1197 const double p1x = inputStorage.
readDouble();
1198 const double p1y = inputStorage.
readDouble();
1217 v->
getEdge(), &roadPos.first->getEdge());
1248 std::string newID = oType.
getID().find(
'@') == std::string::npos ? oType.
getID() +
"@" + veh->
getID() : oType.
getID();
1250 static_cast<MSVehicle*
>(veh)->replaceVehicleType(type);
1257 const std::map<std::string, std::vector<MSLane*> > &
1259 if(gVTDMap.size()==0) {
1261 for(std::vector<MSEdge*>::const_iterator i=edges.begin(); i!=edges.end(); ++i) {
1262 const std::vector<MSLane*> &lanes = (*i)->getLanes();
1263 for(std::vector<MSLane*>::const_iterator j=lanes.begin(); j!=lanes.end(); ++j) {
1264 if ((*j)->knowsParameter(
"origId")) {
1265 std::string origID = (*j)->getParameter(
"origId",
"");
1266 if(gVTDMap.find(origID)==gVTDMap.end()) {
1267 gVTDMap[origID] = std::vector<MSLane*>();
1269 gVTDMap[origID].push_back(*j);
1273 if(gVTDMap.size()==0) {
1274 gVTDMap[
"unknown"] = std::vector<MSLane*>();