bool MSMeanData_Net::MSLaneMeanDataValues::notifyLeave(SUMOVehicle& veh, SUMOReal /*lastPos*/, MSMoveReminder::Notification reason) { if (vehicleApplies(veh) && (getLane() == 0 || getLane() == static_cast<MSVehicle&>(veh).getLane())) { #ifdef HAVE_INTERNAL if (MSGlobals::gUseMesoSim) { myLastVehicleUpdateValues.erase(&veh); } #endif if (reason == MSMoveReminder::NOTIFICATION_ARRIVED) { ++nVehArrived; } else if (reason == MSMoveReminder::NOTIFICATION_LANE_CHANGE) { ++nVehLaneChangeFrom; } else if (myParent == 0 || reason != MSMoveReminder::NOTIFICATION_SEGMENT) { ++nVehLeft; if (reason == MSMoveReminder::NOTIFICATION_VAPORIZED) { ++nVehVaporized; } } } #ifdef HAVE_INTERNAL if (MSGlobals::gUseMesoSim) { return false; } #endif return reason == MSMoveReminder::NOTIFICATION_JUNCTION; }
void GUILaneWrapper::drawArrows() const { unsigned int noLinks = getLinkNumber(); if (noLinks == 0) { return; } // draw all links const Position& end = getShape().back(); const Position& f = getShape()[-2]; SUMOReal rot = (SUMOReal) atan2((end.x() - f.x()), (f.y() - end.y())) * (SUMOReal) 180.0 / (SUMOReal) PI; glPushMatrix(); glPushName(0); glColor3d(1, 1, 1); glTranslated(end.x(), end.y(), 0); glRotated(rot, 0, 0, 1); for (unsigned int i = 0; i < noLinks; ++i) { LinkDirection dir = getLane().getLinkCont()[i]->getDirection(); LinkState state = getLane().getLinkCont()[i]->getState(); if (state == LINKSTATE_TL_OFF_NOSIGNAL || dir == LINKDIR_NODIR) { continue; } switch (dir) { case LINKDIR_STRAIGHT: GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05); GLHelper::drawTriangleAtEnd(Line(Position(0, 4), Position(0, 1)), (SUMOReal) 1, (SUMOReal) .25); break; case LINKDIR_TURN: GLHelper::drawBoxLine(Position(0, 4), 0, 1.5, .05); GLHelper::drawBoxLine(Position(0, 2.5), 90, .5, .05); GLHelper::drawBoxLine(Position(0.5, 2.5), 180, 1, .05); GLHelper::drawTriangleAtEnd(Line(Position(0.5, 2.5), Position(0.5, 4)), (SUMOReal) 1, (SUMOReal) .25); break; case LINKDIR_LEFT: GLHelper::drawBoxLine(Position(0, 4), 0, 1.5, .05); GLHelper::drawBoxLine(Position(0, 2.5), 90, 1, .05); GLHelper::drawTriangleAtEnd(Line(Position(0, 2.5), Position(1.5, 2.5)), (SUMOReal) 1, (SUMOReal) .25); break; case LINKDIR_RIGHT: GLHelper::drawBoxLine(Position(0, 4), 0, 1.5, .05); GLHelper::drawBoxLine(Position(0, 2.5), -90, 1, .05); GLHelper::drawTriangleAtEnd(Line(Position(0, 2.5), Position(-1.5, 2.5)), (SUMOReal) 1, (SUMOReal) .25); break; case LINKDIR_PARTLEFT: GLHelper::drawBoxLine(Position(0, 4), 0, 1.5, .05); GLHelper::drawBoxLine(Position(0, 2.5), 45, .7, .05); GLHelper::drawTriangleAtEnd(Line(Position(0, 2.5), Position(1.2, 1.3)), (SUMOReal) 1, (SUMOReal) .25); break; case LINKDIR_PARTRIGHT: GLHelper::drawBoxLine(Position(0, 4), 0, 1.5, .05); GLHelper::drawBoxLine(Position(0, 2.5), -45, .7, .05); GLHelper::drawTriangleAtEnd(Line(Position(0, 2.5), Position(-1.2, 1.3)), (SUMOReal) 1, (SUMOReal) .25); break; default: break; } } glPopMatrix(); glPopName(); }
bool MSMeanData_Amitran::MSLaneMeanDataValues::notifyEnter(SUMOVehicle& veh, MSMoveReminder::Notification reason) { if (vehicleApplies(veh)) { if (getLane() == 0 || getLane() == static_cast<MSVehicle&>(veh).getLane()) { if (reason == MSMoveReminder::NOTIFICATION_DEPARTED || reason == MSMoveReminder::NOTIFICATION_JUNCTION) { ++amount; typedAmount[&veh.getVehicleType()]++; } } return true; } return false; }
void GUILaneWrapper::drawLane2LaneConnections() const { unsigned int noLinks = getLinkNumber(); for (unsigned int i = 0; i < noLinks; ++i) { LinkState state = getLane().getLinkCont()[i]->getState(); const MSLane* connected = getLane().getLinkCont()[i]->getLane(); if (connected == 0) { continue; } switch (state) { case LINKSTATE_TL_GREEN_MAJOR: case LINKSTATE_TL_GREEN_MINOR: glColor3d(0, 1, 0); break; case LINKSTATE_TL_RED: glColor3d(1, 0, 0); break; case LINKSTATE_TL_YELLOW_MAJOR: case LINKSTATE_TL_YELLOW_MINOR: glColor3d(1, 1, 0); break; case LINKSTATE_TL_OFF_BLINKING: glColor3d(1, 1, 0); break; case LINKSTATE_TL_OFF_NOSIGNAL: glColor3d(0, 1, 1); break; case LINKSTATE_MAJOR: glColor3d(1, 1, 1); break; case LINKSTATE_MINOR: glColor3d(.2, .2, .2); break; case LINKSTATE_EQUAL: glColor3d(.5, .5, .5); break; case LINKSTATE_DEADEND: glColor3d(0, 0, 0); break; } glBegin(GL_LINES); const Position& p1 = getShape()[-1]; const Position& p2 = connected->getShape()[0]; glVertex2f(p1.x(), p1.y()); glVertex2f(p2.x(), p2.y()); glEnd(); GLHelper::drawTriangleAtEnd(Line(p1, p2), (SUMOReal) .4, (SUMOReal) .2); } }
// find the nearest agent in front of the car and return its distance and speed std::pair<double, double> TrajectoryGenerator::findClosestCarInLane() { int car_lane = getLane(car.d()); double distance = map.max_s; double speed = car.max_speed; for (auto&& agent : agents) { if (getLane(agent.d) == car_lane) { double agent_to_car = subtract_s(agent.s, car.s()); //compute agent.s - car.s if (agent_to_car >= 0 && agent_to_car < distance) { distance = agent_to_car; speed = agent.speed; } } } return { distance, speed }; }
void GUILaneWrapper::drawTLSLinkNo(const GUINet& net) const { unsigned int noLinks = getLinkNumber(); if (noLinks == 0) { return; } // draw all links SUMOReal w = myLane.getWidth() / (SUMOReal) noLinks; SUMOReal x1 = (SUMOReal)(myLane.getWidth() / 2.); glPushMatrix(); const PositionVector& g = getShape(); const Position& end = g.back(); const Position& f = g[-2]; const Position& s = end; SUMOReal rot = (SUMOReal) atan2((s.x() - f.x()), (f.y() - s.y())) * (SUMOReal) 180.0 / (SUMOReal) PI; glTranslated(end.x(), end.y(), 0); glRotated(rot, 0, 0, 1); for (int i = noLinks; --i >= 0;) { SUMOReal x2 = x1 - (SUMOReal)(w / 2.); int linkNo = net.getLinkTLIndex(getLane().getLinkCont()[i]); if (linkNo < 0) { continue; } GLHelper::drawText(toString(linkNo), Position(x2, 0), 0, .6, RGBColor(128, 128, 255, 255), 180); x1 -= w; } glPopMatrix(); }
// find the nearest agent in front of or behind the car in 'lane' and return its distance and speed std::pair<double, double> TrajectoryGenerator::findNextCarInLane(int lane, bool in_front) { int car_lane = getLane(car.d()); double distance = map.max_s; double speed = car.max_speed; double coef = in_front ? 1. : -1; for (auto&& agent : agents) { if (getLane(agent.d) == lane) { double agent_to_car = coef*subtract_s(agent.s, car.s()); //compute agent.s - car.s if (agent_to_car >= 0 && agent_to_car < distance) { distance = agent_to_car; speed = agent.speed; } } } return { distance, speed }; }
bool MSMeanData_Net::MSLaneMeanDataValues::notifyEnter(SUMOVehicle& veh, MSMoveReminder::Notification reason) { if (vehicleApplies(veh)) { if (getLane() == 0 || getLane() == static_cast<MSVehicle&>(veh).getLane()) { if (reason == MSMoveReminder::NOTIFICATION_DEPARTED) { ++nVehDeparted; } else if (reason == MSMoveReminder::NOTIFICATION_LANE_CHANGE) { ++nVehLaneChangeTo; } else if (myParent == 0 || reason != MSMoveReminder::NOTIFICATION_SEGMENT) { ++nVehEntered; } } return true; } return false; }
BcmPortGroup::BcmPortGroup(BcmSwitch* hw, BcmPort* controllingPort, std::vector<BcmPort*> allPorts) : hw_(hw), controllingPort_(controllingPort), allPorts_(std::move(allPorts)) { if (allPorts_.size() != 4) { throw FbossError("Port groups must have exactly four members"); } for (int i = 0; i < allPorts_.size(); ++i) { if (getLane(allPorts_[i]) != i) { throw FbossError("Ports passed in are not ordered by lane"); } } // get the number of active lanes auto activeLanes = retrieveActiveLanes(); switch (activeLanes) { case 1: laneMode_ = LaneMode::QUAD; break; case 2: laneMode_ = LaneMode::DUAL; break; case 4: laneMode_ = LaneMode::SINGLE; break; default: throw FbossError("Unexpected number of lanes retrieved for bcm port ", controllingPort_->getBcmPortId()); } }
void NLTriggerBuilder::parseAndBuildCalibrator(MSNet& net, const SUMOSAXAttributes& attrs, const std::string& base) { bool ok = true; // get the id, throw if not given or empty... std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok); if (!ok) { throw ProcessError(); } // get the file name to read further definitions from MSLane* lane = getLane(attrs, "calibrator", id); const SUMOReal pos = getPosition(attrs, lane, "calibrator", id); const SUMOTime freq = attrs.getOptSUMOTimeReporting(SUMO_ATTR_FREQUENCY, id.c_str(), ok, DELTA_T); // !!! no error handling std::string file = getFileName(attrs, base, true); std::string outfile = attrs.getOpt<std::string>(SUMO_ATTR_OUTPUT, 0, ok, ""); if (MSGlobals::gUseMesoSim) { #ifdef HAVE_INTERNAL METriggeredCalibrator* trigger = buildMECalibrator(net, id, &lane->getEdge(), pos, file, outfile, freq); if (file == "") { trigger->registerParent(SUMO_TAG_CALIBRATOR, myHandler); } #endif } else { MSCalibrator* trigger = buildCalibrator(net, id, &lane->getEdge(), pos, file, outfile, freq); if (file == "") { trigger->registerParent(SUMO_TAG_CALIBRATOR, myHandler); } } }
std::pair<std::vector<double>, std::vector<double>> TrajectoryGenerator::generateTrajectory(int target_lane, double target_velocity, int pts_to_copy) { int path_pts_num = 100; // 50 points for 1 second of driving double target_v = target_velocity; //meters per second std::vector<double> next_x_vals; next_x_vals.reserve(path_pts_num); std::vector<double> next_y_vals; next_y_vals.reserve(path_pts_num); if (prev_path_x.size() == 0) { pts_to_copy = 1; next_x_vals.push_back(car.x()); next_y_vals.push_back(car.y()); } else { std::copy(prev_path_x.begin(), prev_path_x.begin() + pts_to_copy, std::back_inserter(next_x_vals)); std::copy(prev_path_y.begin(), prev_path_y.begin() + pts_to_copy, std::back_inserter(next_y_vals)); } tk::spline path = getPath(target_lane, pts_to_copy); double last_x = next_x_vals.back(); double last_y = next_y_vals.back(); std::tie(last_x, last_y) = car.from_map(last_x, last_y); double speed = car.speed(); int num_prev = next_x_vals.size(); if (num_prev > 1) { speed = distance(next_x_vals[num_prev - 1], next_y_vals[num_prev - 1], next_x_vals[num_prev - 2], next_y_vals[num_prev - 2]) / dt; } double x_diff = 1.; double x_target = last_x + x_diff; double y_target = path(x_target); double len = distance(last_x, last_y, x_target, y_target); double l = 0; double acc_coef = getLane(car.d()) == target_lane ? 0.8 : 0.1; double vel_step = car.max_acc*acc_coef*dt; auto same_lane = [target_d = lanes[target_lane]](double d) { return d > target_d - 0.5 && d < target_d + 0.5; }; for (int i = pts_to_copy; i < path_pts_num; ++i) { if (speed < target_v - vel_step) speed += vel_step; if (speed > target_v + vel_step) speed -= vel_step; if (speed > target_v - vel_step && speed < target_v + vel_step) speed = target_v; double dl = speed * dt; l += dl; double x = last_x + l / len * x_diff; if (l / len > 1.0) { last_x = x; last_y = path(last_x); x_target = last_x + x_diff; y_target = path(x_target); len = distance(last_x, last_y, x_target, y_target); l = 0; } next_x_vals.push_back(0); next_y_vals.push_back(0); std::tie(next_x_vals[i], next_y_vals[i]) = car.to_map(x, path(x)); } return { next_x_vals, next_y_vals }; }
bool BlockManager::isMatching(Pix* pix) { Block* b = getLane(pix->getTag()); if (b->isMatch(pix->getZColor())) { return true; } return false; }
SUMOReal GUILaneWrapper::getColorValue(size_t activeScheme) const { switch (activeScheme) { case 1: return (gSelected.isSelected(getType(), getGlID()) || gSelected.isSelected(GLO_EDGE, dynamic_cast<GUIEdge*>(&(getLane().getEdge()))->getGlID())); case 2: { if (getLane().allowsVehicleClass(SVC_PASSENGER)) { return 0; } else { return 1; } } case 3: return getLane().getSpeedLimit(); case 4: return getLane().getOccupancy(); case 5: return firstWaitingTime(); case 6: return getEdgeLaneNumber(); case 7: return getNormedHBEFA_CO2Emissions(); case 8: return getNormedHBEFA_COEmissions(); case 9: return getNormedHBEFA_PMxEmissions(); case 10: return getNormedHBEFA_NOxEmissions(); case 11: return getNormedHBEFA_HCEmissions(); case 12: return getNormedHBEFA_FuelConsumption(); case 13: return getLane().getHarmonoise_NoiseEmissions(); case 14: { return getStoredEdgeTravelTime(); } case 15: { MSEdgeWeightsStorage& ews = MSNet::getInstance()->getWeightsStorage(); MSEdge& e = getLane().getEdge(); if (!ews.knowsTravelTime(&e)) { return -1; } else { SUMOReal value(0); ews.retrieveExistingTravelTime(&e, 0, 0, value); return 100 * getLane().getLength() / value / getLane().getSpeedLimit(); } } } return 0; }
bool MSMeanData_Net::MSLaneMeanDataValues::notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane) { #ifdef DEBUG_NOTIFY_ENTER std::cout << "\n" << SIMTIME << " MSMeanData_Net::MSLaneMeanDataValues: veh '" << veh.getID() << "' enters lane '" << enteredLane->getID() << "'" << std::endl; #else UNUSED_PARAMETER(enteredLane); #endif if (myParent == nullptr || myParent->vehicleApplies(veh)) { if (getLane() == nullptr || !veh.isVehicle() || getLane() == static_cast<MSVehicle&>(veh).getLane()) { if (reason == MSMoveReminder::NOTIFICATION_DEPARTED) { ++nVehDeparted; } else if (reason == MSMoveReminder::NOTIFICATION_LANE_CHANGE) { ++nVehLaneChangeTo; } else if (myParent == nullptr || reason != MSMoveReminder::NOTIFICATION_SEGMENT) { ++nVehEntered; } } return true; } return false; }
SUMOReal GUILaneWrapper::getStoredEdgeTravelTime() const { MSEdgeWeightsStorage& ews = MSNet::getInstance()->getWeightsStorage(); MSEdge& e = getLane().getEdge(); if (!ews.knowsTravelTime(&e)) { return -1; } else { SUMOReal value(0); ews.retrieveExistingTravelTime(&e, 0, STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep()), value); return value; } }
// @param front_distance meters, distance to agents in front of the car // @param back_distance meters, distance to agents behind the car std::array<double, 3> TrajectoryGenerator::getLaneSpeeds(double front_distance, double back_distance) { std::array<double, 3> lane_speed{ car.max_speed, car.max_speed, car.max_speed }; for (auto&& agent : agents) { double agent_to_car = subtract_s(agent.s, car.s()); //compute agent.s - car.s if ((agent_to_car >= 0 && agent_to_car < front_distance) || (agent_to_car < 0 && -agent_to_car < back_distance)) { int agent_lane = getLane(agent.d); if (agent.speed < lane_speed[agent_lane]) { lane_speed[agent_lane] = agent.speed; } } } return lane_speed; }
bool MSMeanData_Net::MSLaneMeanDataValues::notifyLeave(SUMOTrafficObject& veh, double /*lastPos*/, MSMoveReminder::Notification reason, const MSLane* /* enteredLane */) { if ((myParent == nullptr || myParent->vehicleApplies(veh)) && ( getLane() == nullptr || !veh.isVehicle() || getLane() == static_cast<MSVehicle&>(veh).getLane())) { if (MSGlobals::gUseMesoSim) { removeFromVehicleUpdateValues(veh); } if (reason == MSMoveReminder::NOTIFICATION_ARRIVED) { ++nVehArrived; } else if (reason == MSMoveReminder::NOTIFICATION_LANE_CHANGE) { ++nVehLaneChangeFrom; } else if (myParent == nullptr || reason != MSMoveReminder::NOTIFICATION_SEGMENT) { ++nVehLeft; if (reason == MSMoveReminder::NOTIFICATION_VAPORIZED) { ++nVehVaporized; } } } if (MSGlobals::gUseMesoSim) { return false; } return reason == MSMoveReminder::NOTIFICATION_JUNCTION; }
glm::vec3 CharacterController::calculateRoadTarget(const glm::vec3 &target, const glm::vec3 &start, const glm::vec3 &end) { // @todo set the real value static constexpr float roadWidth = 5.f; static const glm::vec3 up = glm::vec3(0.f, 0.f, 1.f); const glm::vec3 dir = glm::normalize(start - end); // Calculate the strafe vector glm::vec3 strafe = glm::cross(up, dir); const glm::vec3 laneOffset = strafe * (roadWidth / 2 + roadWidth * static_cast<float>(getLane() - 1)); return target + laneOffset; }
void NLTriggerBuilder::parseAndBuildBusStop(MSNet& net, const SUMOSAXAttributes& attrs) { bool ok = true; // get the id, throw if not given or empty... std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok); if (!ok) { throw ProcessError(); } // get the lane MSLane* lane = getLane(attrs, "busStop", id); // get the positions SUMOReal frompos = attrs.getOpt<SUMOReal>(SUMO_ATTR_STARTPOS, id.c_str(), ok, 0); SUMOReal topos = attrs.getOpt<SUMOReal>(SUMO_ATTR_ENDPOS, id.c_str(), ok, lane->getLength()); const bool friendlyPos = attrs.getOpt<bool>(SUMO_ATTR_FRIENDLY_POS, id.c_str(), ok, false); if (!ok || !myHandler->checkStopPos(frompos, topos, lane->getLength(), POSITION_EPS, friendlyPos)) { throw InvalidArgument("Invalid position for bus stop '" + id + "'."); } // get the lines std::vector<std::string> lines; SUMOSAXAttributes::parseStringVector(attrs.getOpt<std::string>(SUMO_ATTR_LINES, id.c_str(), ok, "", false), lines); // build the bus stop buildBusStop(net, id, lines, lane, frompos, topos); }
void GUILaneWrapper::drawLinkRules(const GUINet& net) const { unsigned int noLinks = getLinkNumber(); const PositionVector& g = getShape(); const Position& end = g.back(); const Position& f = g[-2]; const Position& s = end; SUMOReal rot = (SUMOReal) atan2((s.x() - f.x()), (f.y() - s.y())) * (SUMOReal) 180.0 / (SUMOReal) PI; if (noLinks == 0) { glPushName(getGlID()); // draw a grey bar if no links are on the street glColor3d(0.5, 0.5, 0.5); glPushMatrix(); glTranslated(end.x(), end.y(), 0); glRotated(rot, 0, 0, 1); glBegin(GL_QUADS); glVertex2d(-myHalfLaneWidth, 0.0); glVertex2d(-myHalfLaneWidth, 0.5); glVertex2d(myHalfLaneWidth, 0.5); glVertex2d(myHalfLaneWidth, 0.0); glEnd(); glPopMatrix(); glPopName(); return; } // draw all links SUMOReal w = myLane.getWidth() / (SUMOReal) noLinks; SUMOReal x1 = 0; glPushMatrix(); glTranslated(end.x(), end.y(), 0); glRotated(rot, 0, 0, 1); for (unsigned int i = 0; i < noLinks; ++i) { SUMOReal x2 = x1 + w; MSLink* link = getLane().getLinkCont()[i]; // select glID switch (link->getState()) { case LINKSTATE_TL_GREEN_MAJOR: case LINKSTATE_TL_GREEN_MINOR: case LINKSTATE_TL_RED: case LINKSTATE_TL_YELLOW_MAJOR: case LINKSTATE_TL_YELLOW_MINOR: case LINKSTATE_TL_OFF_BLINKING: glPushName(net.getLinkTLID(link)); break; case LINKSTATE_MAJOR: case LINKSTATE_MINOR: case LINKSTATE_EQUAL: case LINKSTATE_TL_OFF_NOSIGNAL: default: glPushName(getGlID()); break; } // select color switch (link->getState()) { case LINKSTATE_TL_GREEN_MAJOR: case LINKSTATE_TL_GREEN_MINOR: glColor3d(0, 1, 0); break; case LINKSTATE_TL_RED: glColor3d(1, 0, 0); break; case LINKSTATE_TL_YELLOW_MAJOR: case LINKSTATE_TL_YELLOW_MINOR: glColor3d(1, 1, 0); break; case LINKSTATE_TL_OFF_BLINKING: glColor3d(.7, .7, 0); break; case LINKSTATE_TL_OFF_NOSIGNAL: glColor3d(0, 1, 1); break; case LINKSTATE_MAJOR: glColor3d(1, 1, 1); break; case LINKSTATE_MINOR: glColor3d(.2, .2, .2); break; case LINKSTATE_EQUAL: glColor3d(.5, .5, .5); break; case LINKSTATE_DEADEND: glColor3d(0, 0, 0); break; } glBegin(GL_QUADS); glVertex2d(x1 - myHalfLaneWidth, 0.0); glVertex2d(x1 - myHalfLaneWidth, 0.5); glVertex2d(x2 - myHalfLaneWidth, 0.5); glVertex2d(x2 - myHalfLaneWidth, 0.0); glEnd(); glPopName(); x1 = x2; x2 += w; } glPopMatrix(); }
void MSE2Collector::detectorUpdate(const SUMOTime /* step */) { JamInfo* currentJam = 0; std::map<SUMOVehicle*, SUMOTime> haltingVehicles; std::map<SUMOVehicle*, SUMOTime> intervalHaltingVehicles; std::vector<JamInfo*> jams; SUMOReal lengthSum = 0; myCurrentMeanSpeed = 0; myCurrentMeanLength = 0; myCurrentStartedHalts = 0; myCurrentHaltingsNumber = 0; // go through the (sorted) list of vehicles positioned on the detector // sum up values and prepare the list of jams myKnownVehicles.sort(by_vehicle_position_sorter(getLane())); for (std::list<SUMOVehicle*>::const_iterator i = myKnownVehicles.begin(); i != myKnownVehicles.end(); ++i) { MSVehicle* veh = static_cast<MSVehicle*>(*i); SUMOReal length = veh->getVehicleType().getLength(); if (veh->getLane() == getLane()) { if (veh->getPositionOnLane() - veh->getVehicleType().getLength() < myStartPos) { // vehicle entered detector partially length -= (veh->getVehicleType().getLength() - (veh->getPositionOnLane() - myStartPos)); } if (veh->getPositionOnLane() > myEndPos && veh->getPositionOnLane() - veh->getVehicleType().getLength() <= myEndPos) { // vehicle left detector partially length -= (veh->getPositionOnLane() - myEndPos); } } else { // ok, the vehicle is only partially still on the detector, has already moved to the // next lane; still, we do not know how far away it is assert(veh == myLane->getPartialOccupator()); length = myEndPos - myLane->getPartialOccupatorEnd(); } assert(length >= 0); mySpeedSum += veh->getSpeed(); myCurrentMeanSpeed += veh->getSpeed(); lengthSum += length; myCurrentMeanLength += length; // jam-checking begins bool isInJam = false; // first, check whether the vehicle is slow enough to be states as halting if (veh->getSpeed() < myJamHaltingSpeedThreshold) { myCurrentHaltingsNumber++; // we have to track the time it was halting; // so let's look up whether it was halting before and compute the overall halting time bool wasHalting = myHaltingVehicleDurations.find(veh) != myHaltingVehicleDurations.end(); if (wasHalting) { haltingVehicles[veh] = myHaltingVehicleDurations[veh] + DELTA_T; intervalHaltingVehicles[veh] = myIntervalHaltingVehicleDurations[veh] + DELTA_T; } else { haltingVehicles[veh] = DELTA_T; intervalHaltingVehicles[veh] = DELTA_T; myCurrentStartedHalts++; myStartedHalts++; } // we now check whether the halting time is large enough if (haltingVehicles[veh] > myJamHaltingTimeThreshold) { // yep --> the vehicle is a part of a jam isInJam = true; } } else { // is not standing anymore; keep duration information std::map<SUMOVehicle*, SUMOTime>::iterator v = myHaltingVehicleDurations.find(veh); if (v != myHaltingVehicleDurations.end()) { myPastStandingDurations.push_back((*v).second); myHaltingVehicleDurations.erase(v); } v = myIntervalHaltingVehicleDurations.find(veh); if (v != myIntervalHaltingVehicleDurations.end()) { myPastIntervalStandingDurations.push_back((*v).second); myIntervalHaltingVehicleDurations.erase(v); } } // jam-building if (isInJam) { // the vehicle is in a jam; // it may be a new one or already an existing one if (currentJam == 0) { // the vehicle is the first vehicle in a jam currentJam = new JamInfo; currentJam->firstStandingVehicle = i; } else { // ok, we have a jam already. But - maybe it is too far away // ... honestly, I can hardly find a reason for doing this, // but jams were defined this way in an earlier version... if (veh->getPositionOnLane() - (*currentJam->lastStandingVehicle)->getPositionOnLane() > myJamDistanceThreshold) { // yep, yep, yep - it's a new one... // close the frist, build a new jams.push_back(currentJam); currentJam = new JamInfo; currentJam->firstStandingVehicle = i; } } currentJam->lastStandingVehicle = i; } else { // the vehicle is not part of a jam... // maybe we have to close an already computed jam if (currentJam != 0) { jams.push_back(currentJam); currentJam = 0; } } } if (currentJam != 0) { jams.push_back(currentJam); currentJam = 0; } myCurrentMaxJamLengthInMeters = 0; myCurrentMaxJamLengthInVehicles = 0; myCurrentJamLengthInMeters = 0; myCurrentJamLengthInVehicles = 0; // process jam information for (std::vector<JamInfo*>::iterator i = jams.begin(); i != jams.end(); ++i) { // compute current jam's values SUMOReal jamLengthInMeters = (*(*i)->firstStandingVehicle)->getPositionOnLane() - (*(*i)->lastStandingVehicle)->getPositionOnLane() + (*(*i)->lastStandingVehicle)->getVehicleType().getLengthWithGap(); const MSVehicle* const occ = myLane->getPartialOccupator(); if (occ && occ == *(*i)->firstStandingVehicle && occ != *(*i)->lastStandingVehicle) { jamLengthInMeters = myLane->getPartialOccupatorEnd() + occ->getVehicleType().getLengthWithGap() - (*(*i)->lastStandingVehicle)->getPositionOnLane() + (*(*i)->lastStandingVehicle)->getVehicleType().getLengthWithGap(); } unsigned jamLengthInVehicles = (unsigned) distance((*i)->firstStandingVehicle, (*i)->lastStandingVehicle) + 1; // apply them to the statistics myCurrentMaxJamLengthInMeters = MAX2(myCurrentMaxJamLengthInMeters, jamLengthInMeters); myCurrentMaxJamLengthInVehicles = MAX2(myCurrentMaxJamLengthInVehicles, jamLengthInVehicles); myJamLengthInMetersSum += jamLengthInMeters; myJamLengthInVehiclesSum += jamLengthInVehicles; myCurrentJamLengthInMeters += jamLengthInMeters; myCurrentJamLengthInVehicles += jamLengthInVehicles; } myCurrentJamNo = (unsigned) jams.size(); unsigned noVehicles = (unsigned) myKnownVehicles.size(); myVehicleSamples += noVehicles; myTimeSamples += 1; // compute occupancy values SUMOReal currentOccupancy = lengthSum / (myEndPos - myStartPos) * (SUMOReal) 100.; myCurrentOccupancy = currentOccupancy; myOccupancySum += currentOccupancy; myMaxOccupancy = MAX2(myMaxOccupancy, currentOccupancy); // compute jam values myMeanMaxJamInVehicles += myCurrentMaxJamLengthInVehicles; myMeanMaxJamInMeters += myCurrentMaxJamLengthInMeters; myMaxJamInVehicles = MAX2(myMaxJamInVehicles, myCurrentMaxJamLengthInVehicles); myMaxJamInMeters = MAX2(myMaxJamInMeters, myCurrentMaxJamLengthInMeters); // save information about halting vehicles myHaltingVehicleDurations = haltingVehicles; myIntervalHaltingVehicleDurations = intervalHaltingVehicles; // compute information about vehicle numbers myMeanVehicleNumber += (unsigned) myKnownVehicles.size(); myMaxVehicleNumber = MAX2((unsigned) myKnownVehicles.size(), myMaxVehicleNumber); // norm current values myCurrentMeanSpeed = noVehicles != 0 ? myCurrentMeanSpeed / (SUMOReal) noVehicles : -1; myCurrentMeanLength = noVehicles != 0 ? myCurrentMeanLength / (SUMOReal) noVehicles : -1; // clean up for (std::vector<JamInfo*>::iterator i = jams.begin(); i != jams.end(); ++i) { delete *i; } jams.clear(); }
void GUILaneWrapper::drawGL(const GUIVisualizationSettings &s) const throw() { // set lane color #ifdef HAVE_MESOSIM if (!MSGlobals::gUseMesoSim) #endif s.laneColorer.setGlColor(*this); // (optional) set id if (s.needsGlID) { glPushName(getGlID()); } // draw lane // check whether it is not too small if (s.scale<1.) { GLHelper::drawLine(myShape); // (optional) clear id if (s.needsGlID) { glPopName(); } } else { if (getLane().getEdge().getPurpose()!=MSEdge::EDGEFUNCTION_INTERNAL) { glTranslated(0, 0, .005); GLHelper::drawBoxLines(myShape, myShapeRotations, myShapeLengths, SUMO_const_halfLaneWidth); glTranslated(0, 0, -.005); } else { GLHelper::drawBoxLines(myShape, myShapeRotations, myShapeLengths, SUMO_const_quarterLaneWidth); } // (optional) clear id if (s.needsGlID) { glPopName(); } // draw ROWs (not for inner lanes) if (getLane().getEdge().getPurpose()!=MSEdge::EDGEFUNCTION_INTERNAL) {// !!! getPurpose() glTranslated(0, 0, -.02); GUINet *net = (GUINet*) MSNet::getInstance(); ROWdrawAction_drawLinkRules(*net, *this, s.needsGlID); if (s.showLinkDecals) { ROWdrawAction_drawArrows(*this, s.needsGlID); } if (s.showLane2Lane) { // this should be independent to the geometry: // draw from end of first to the begin of second ROWdrawAction_drawLane2LaneConnections(*this); } glTranslated(0, 0, .02); if (s.drawLinkJunctionIndex) { glTranslated(0, 0, -.03); ROWdrawAction_drawLinkNo(*this); glTranslated(0, 0, .03); } if (s.drawLinkTLIndex) { glTranslated(0, 0, -.03); ROWdrawAction_drawTLSLinkNo(*net, *this); glTranslated(0, 0, .03); } } } // draw vehicles if (s.scale>s.minVehicleSize) { // retrieve vehicles from lane; disallow simulation const MSLane::VehCont &vehicles = myLane.getVehiclesSecure(); for (MSLane::VehCont::const_iterator v=vehicles.begin(); v!=vehicles.end(); ++v) { static_cast<const GUIVehicle*const>(*v)->drawGL(s); } // allow lane simulation myLane.releaseVehicles(); } glPopMatrix(); }
void GNEDetectorE2::moveGeometry(const Position& offset) { // Calculate new position using old position Position newPosition = myMove.originalViewPosition; newPosition.add(offset); // filtern position using snap to active grid newPosition = myViewNet->snapToActiveGrid(newPosition); double offsetLane = getLaneParents().front()->getGeometry().shape.nearest_offset_to_point2D(newPosition, false) - getLaneParents().front()->getGeometry().shape.nearest_offset_to_point2D(myMove.originalViewPosition, false); // move geometry depending of number of lanes if (getLaneParents().size() == 1) { // calculate new position over lane double newPositionOverLane = parse<double>(myMove.firstOriginalLanePosition) + offsetLane; // obtain lane length double laneLenght = getLaneParents().front()->getParentEdge().getNBEdge()->getFinalLength() * getLane()->getLengthGeometryFactor(); if (newPositionOverLane < 0) { myPositionOverLane = 0; } else if (newPositionOverLane + myLength > laneLenght) { myPositionOverLane = laneLenght - myLength; } else { myPositionOverLane = newPositionOverLane; } } else { // calculate new start and end positions double newStartPosition = parse<double>(myMove.firstOriginalLanePosition) + offsetLane; double newEndPosition = parse<double>(myMove.secondOriginalPosition) + offsetLane; // change start and end position of E2 detector ONLY if both extremes aren't overpassed if ((newStartPosition >= 0) && (newStartPosition <= getLaneParents().front()->getLaneShapeLength()) && (newEndPosition >= 0) && (newEndPosition <= getLaneParents().back()->getLaneShapeLength())) { myPositionOverLane = newStartPosition; myEndPositionOverLane = newEndPosition; } } // Update geometry updateGeometry(); }
void GUILaneWrapper::drawGL(const GUIVisualizationSettings& s) const { glPushMatrix(); const bool isInternal = getLane().getEdge().getPurpose() == MSEdge::EDGEFUNCTION_INTERNAL; bool mustDrawMarkings = false; const bool drawDetails = s.scale * s.laneWidthExaggeration > 5; if (isInternal) { // draw internal lanes on top of junctions glTranslated(0, 0, GLO_JUNCTION + 0.1); } else { glTranslated(0, 0, getType()); } // set lane color if (!MSGlobals::gUseMesoSim) { setColor(s); glPushName(getGlID()); // do not register for clicks in MESOSIM } // draw lane // check whether it is not too small if (s.scale * s.laneWidthExaggeration < 1.) { GLHelper::drawLine(myShape); if (!MSGlobals::gUseMesoSim) { glPopName(); } glPopMatrix(); } else if (isRailway(getLane().getPermissions())) { // draw as railway const SUMOReal halfRailWidth = 0.725; GLHelper::drawBoxLines(myShape, myShapeRotations, myShapeLengths, halfRailWidth * s.laneWidthExaggeration); glColor3d(1, 1, 1); glTranslated(0, 0, .1); GLHelper::drawBoxLines(myShape, myShapeRotations, myShapeLengths, (halfRailWidth - 0.2) * s.laneWidthExaggeration); drawCrossties(s); if (!MSGlobals::gUseMesoSim) { glPopName(); } glPopMatrix(); } else { const SUMOReal laneWidth = isInternal ? myQuarterLaneWidth : myHalfLaneWidth; mustDrawMarkings = !isInternal; GLHelper::drawBoxLines(myShape, myShapeRotations, myShapeLengths, laneWidth * s.laneWidthExaggeration); if (!MSGlobals::gUseMesoSim) { glPopName(); } glPopMatrix(); // draw ROWs (not for inner lanes) if (!isInternal && drawDetails) { glPushMatrix(); glTranslated(0, 0, GLO_JUNCTION); // must draw on top of junction shape GUINet* net = (GUINet*) MSNet::getInstance(); glTranslated(0, 0, .2); drawLinkRules(*net); if (s.showLinkDecals) { drawArrows(); } if (s.showLane2Lane) { // this should be independent to the geometry: // draw from end of first to the begin of second drawLane2LaneConnections(); } glTranslated(0, 0, .1); if (s.drawLinkJunctionIndex) { drawLinkNo(); } if (s.drawLinkTLIndex) { drawTLSLinkNo(*net); } glPopMatrix(); } } if (mustDrawMarkings && drawDetails) { // needs matrix reset drawMarkings(s); } // draw vehicles if (s.scale > s.minVehicleSize) { // retrieve vehicles from lane; disallow simulation const MSLane::VehCont& vehicles = myLane.getVehiclesSecure(); for (MSLane::VehCont::const_iterator v = vehicles.begin(); v != vehicles.end(); ++v) { static_cast<const GUIVehicle* const>(*v)->drawGL(s); } // allow lane simulation myLane.releaseVehicles(); } }
double GUIVehicle::getColorValue(int activeScheme) const { switch (activeScheme) { case 8: return getSpeed(); case 9: // color by action step if (isActionStep(SIMSTEP)) { // Upcoming simstep is actionstep (t was already increased before drawing) return 1.; } else if (isActive()) { // Completed simstep was actionstep return 2.; } else { // not active return 0.; } case 10: return getWaitingSeconds(); case 11: return getAccumulatedWaitingSeconds(); case 12: return getLastLaneChangeOffset(); case 13: return getLane()->getVehicleMaxSpeed(this); case 14: return getCO2Emissions(); case 15: return getCOEmissions(); case 16: return getPMxEmissions(); case 17: return getNOxEmissions(); case 18: return getHCEmissions(); case 19: return getFuelConsumption(); case 20: return getHarmonoise_NoiseEmissions(); case 21: if (getNumberReroutes() == 0) { return -1; } return getNumberReroutes(); case 22: return gSelected.isSelected(GLO_VEHICLE, getGlID()); case 23: return getLaneChangeModel().isOpposite() ? -100 : getBestLaneOffset(); case 24: return getAcceleration(); case 25: return getTimeGapOnLane(); case 26: return STEPS2TIME(getDepartDelay()); case 27: return getElectricityConsumption(); case 28: return getTimeLossSeconds(); case 29: return getLaneChangeModel().getSpeedLat(); } return 0; }