bool RODFDetector::writeEmitterDefinition(const std::string& file, const std::map<size_t, RandomDistributor<size_t>* >& dists, const RODFDetectorFlows& flows, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset, bool includeUnusedRoutes, SUMOReal scale, bool insertionsOnly, SUMOReal defaultSpeed) const { OutputDevice& out = OutputDevice::getDevice(file); if (getType() != SOURCE_DETECTOR) { out.writeXMLHeader("calibrator"); } // routes if (myRoutes != 0 && myRoutes->get().size() != 0) { const std::vector<RODFRouteDesc>& routes = myRoutes->get(); out.openTag(SUMO_TAG_ROUTE_DISTRIBUTION).writeAttr(SUMO_ATTR_ID, myID); bool isEmptyDist = true; for (std::vector<RODFRouteDesc>::const_iterator i = routes.begin(); i != routes.end(); ++i) { if ((*i).overallProb > 0) { isEmptyDist = false; } } for (std::vector<RODFRouteDesc>::const_iterator i = routes.begin(); i != routes.end(); ++i) { if ((*i).overallProb > 0 || includeUnusedRoutes) { out.openTag(SUMO_TAG_ROUTE).writeAttr(SUMO_ATTR_REFID, (*i).routename).writeAttr(SUMO_ATTR_PROB, (*i).overallProb).closeTag(); } if (isEmptyDist) { out.openTag(SUMO_TAG_ROUTE).writeAttr(SUMO_ATTR_REFID, (*i).routename).writeAttr(SUMO_ATTR_PROB, SUMOReal(1)).closeTag(); } } out.closeTag(); // routeDistribution } else { WRITE_ERROR("Detector '" + getID() + "' has no routes!?"); return false; } // insertions if (insertionsOnly || flows.knows(myID)) { // get the flows for this detector const std::vector<FlowDef>& mflows = flows.getFlowDefs(myID); // go through the simulation seconds unsigned int index = 0; for (SUMOTime time = startTime; time < endTime; time += stepOffset, index++) { // get own (departure flow) assert(index < mflows.size()); const FlowDef& srcFD = mflows[index]; // !!! check stepOffset // get flows at end RandomDistributor<size_t>* destDist = dists.find(time) != dists.end() ? dists.find(time)->second : 0; // go through the cars size_t carNo = (size_t)((srcFD.qPKW + srcFD.qLKW) * scale); for (size_t car = 0; car < carNo; ++car) { // get the vehicle parameter SUMOReal v = -1; int destIndex = destDist != 0 && destDist->getOverallProb() > 0 ? (int) destDist->get() : -1; if (srcFD.isLKW >= 1) { srcFD.isLKW = srcFD.isLKW - (SUMOReal) 1.; v = srcFD.vLKW; } else { v = srcFD.vPKW; } // compute insertion speed if (v <= 0 || v > 250) { v = defaultSpeed; } else { v = (SUMOReal)(v / 3.6); } // compute the departure time SUMOTime ctime = (SUMOTime)(time + ((SUMOReal) stepOffset * (SUMOReal) car / (SUMOReal) carNo)); // write out.openTag(SUMO_TAG_VEHICLE); if (getType() == SOURCE_DETECTOR) { out.writeAttr(SUMO_ATTR_ID, "emitter_" + myID + "_" + toString(ctime)); } else { out.writeAttr(SUMO_ATTR_ID, "calibrator_" + myID + "_" + toString(ctime)); } out.writeAttr(SUMO_ATTR_DEPART, time2string(ctime)); if (v > defaultSpeed) { out.writeAttr(SUMO_ATTR_DEPARTSPEED, "max"); } else { out.writeAttr(SUMO_ATTR_DEPARTSPEED, v); } out.writeAttr(SUMO_ATTR_DEPARTPOS, myPosition).writeAttr(SUMO_ATTR_DEPARTLANE, TplConvert::_2int(myLaneID.substr(myLaneID.rfind("_") + 1).c_str())); if (destIndex >= 0) { out.writeAttr(SUMO_ATTR_ROUTE, myRoutes->get()[destIndex].routename); } else { out.writeAttr(SUMO_ATTR_ROUTE, myID); } out.closeTag(); srcFD.isLKW += srcFD.fLKW; } } } if (getType() != SOURCE_DETECTOR) { out.close(); } return true; }
void GUISUMOAbstractView::displayLegend() { // compute the scale bar length size_t length = 1; const std::string text("10000000000"); size_t noDigits = 1; size_t pixelSize = (size_t) m2p((SUMOReal) length); while (pixelSize <= 20) { length *= 10; noDigits++; if (noDigits > text.length()) { return; } pixelSize = (size_t) m2p((SUMOReal) length); } SUMOReal lineWidth = 1.0; glLineWidth((SUMOReal) lineWidth); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); // draw the scale bar glDisable(GL_TEXTURE_2D); glDisable(GL_ALPHA_TEST); glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); SUMOReal len = (SUMOReal) pixelSize / (SUMOReal)(getWidth() - 1) * (SUMOReal) 2.0; glColor3d(0, 0, 0); double o = double(15) / double(getHeight()); double o2 = o + o; double oo = double(5) / double(getHeight()); glBegin(GL_LINES); // vertical glVertex2d(-.98, -1. + o); glVertex2d(-.98 + len, -1. + o); // tick at begin glVertex2d(-.98, -1. + o); glVertex2d(-.98, -1. + o2); // tick at end glVertex2d(-.98 + len, -1. + o); glVertex2d(-.98 + len, -1. + o2); glEnd(); SUMOReal w = SUMOReal(35) / SUMOReal(getWidth()); SUMOReal h = SUMOReal(35) / SUMOReal(getHeight()); pfSetPosition(SUMOReal(-0.99), SUMOReal(1. - o2 - oo)); pfSetScaleXY(w, h); glRotated(180, 1, 0, 0); pfDrawString("0m"); glRotated(-180, 1, 0, 0); pfSetPosition(SUMOReal(-.99 + len), SUMOReal(1. - o2 - oo)); glRotated(180, 1, 0, 0); pfDrawString((text.substr(0, noDigits) + "m").c_str()); glRotated(-180, 1, 0, 0); // restore matrices glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); }
bool GeoConvHelper::x2cartesian(Position& from, bool includeInBoundary) { if (includeInBoundary) { myOrigBoundary.add(from); } // init projection parameter on first use #ifdef HAVE_PROJ if (myProjection == 0) { double x = from.x() * myGeoScale; switch (myProjectionMethod) { case DHDN_UTM: { int zone = (int)((x - 500000.) / 1000000.); if (zone < 1 || zone > 5) { WRITE_WARNING("Attempt to initialize DHDN_UTM-projection on invalid longitude " + toString(x)); return false; } myProjString = "+proj=tmerc +lat_0=0 +lon_0=" + toString(3 * zone) + " +k=1 +x_0=" + toString(zone * 1000000 + 500000) + " +y_0=0 +ellps=bessel +datum=potsdam +units=m +no_defs"; myInverseProjection = pj_init_plus(myProjString.c_str()); myGeoProjection = pj_init_plus("+proj=latlong +datum=WGS84"); //!!! check pj_errno x = ((x - 500000.) / 1000000.) * 3; // continues with UTM } case UTM: { int zone = (int)(x + 180) / 6 + 1; myProjString = "+proj=utm +zone=" + toString(zone) + " +ellps=WGS84 +datum=WGS84 +units=m +no_defs"; myProjection = pj_init_plus(myProjString.c_str()); //!!! check pj_errno } break; case DHDN: { int zone = (int)(x / 3); if (zone < 1 || zone > 5) { WRITE_WARNING("Attempt to initialize DHDN-projection on invalid longitude " + toString(x)); return false; } myProjString = "+proj=tmerc +lat_0=0 +lon_0=" + toString(3 * zone) + " +k=1 +x_0=" + toString(zone * 1000000 + 500000) + " +y_0=0 +ellps=bessel +datum=potsdam +units=m +no_defs"; myProjection = pj_init_plus(myProjString.c_str()); //!!! check pj_errno } break; default: break; } } if (myInverseProjection != 0) { double x = from.x(); double y = from.y(); if (pj_transform(myInverseProjection, myGeoProjection, 1, 1, &x, &y, NULL)) { WRITE_WARNING("Could not transform (" + toString(x) + "," + toString(y) + ")"); } from.set(SUMOReal(x * RAD_TO_DEG), SUMOReal(y * RAD_TO_DEG)); } #endif // perform conversion bool ok = x2cartesian_const(from); if (ok) { if (includeInBoundary) { myConvBoundary.add(from); } } return ok; }
void RORouteDef::addAlternative(SUMOAbstractRouter<ROEdge, ROVehicle>& router, const ROVehicle* const veh, RORoute* current, SUMOTime begin) { if (myTryRepair) { if (myNewRoute) { delete myAlternatives[0]; myAlternatives.pop_back(); myAlternatives.push_back(current); } const SUMOReal costs = router.recomputeCosts(current->getEdgeVector(), veh, begin); if (costs < 0) { throw ProcessError("Route '" + getID() + "' (vehicle '" + veh->getID() + "') is not valid."); } current->setCosts(costs); return; } // add the route when it's new if (myNewRoute) { myAlternatives.push_back(current); } // recompute the costs and (when a new route was added) scale the probabilities const SUMOReal scale = SUMOReal(myAlternatives.size() - 1) / SUMOReal(myAlternatives.size()); for (std::vector<RORoute*>::iterator i = myAlternatives.begin(); i != myAlternatives.end(); i++) { RORoute* alt = *i; // recompute the costs for all routes const SUMOReal newCosts = router.recomputeCosts(alt->getEdgeVector(), veh, begin); if (newCosts < 0.) { throw ProcessError("Route '" + current->getID() + "' (vehicle '" + veh->getID() + "') is not valid."); } assert(myAlternatives.size() != 0); if (myNewRoute) { if (*i == current) { // set initial probability and costs alt->setProbability((SUMOReal)(1.0 / (SUMOReal) myAlternatives.size())); alt->setCosts(newCosts); } else { // rescale probs for all others alt->setProbability(alt->getProbability() * scale); } } ROCostCalculator::getCalculator().setCosts(alt, newCosts, *i == myAlternatives[myLastUsed]); } assert(myAlternatives.size() != 0); ROCostCalculator::getCalculator().calculateProbabilities(veh, myAlternatives); if (!ROCostCalculator::getCalculator().keepRoutes()) { // remove with probability of 0 (not mentioned in Gawron) for (std::vector<RORoute*>::iterator i = myAlternatives.begin(); i != myAlternatives.end();) { if ((*i)->getProbability() == 0) { delete *i; i = myAlternatives.erase(i); } else { i++; } } } if (myAlternatives.size() > ROCostCalculator::getCalculator().getMaxRouteNumber()) { // only keep the routes with highest probability sort(myAlternatives.begin(), myAlternatives.end(), ComparatorProbability()); for (std::vector<RORoute*>::iterator i = myAlternatives.begin() + ROCostCalculator::getCalculator().getMaxRouteNumber(); i != myAlternatives.end(); i++) { delete *i; } myAlternatives.erase(myAlternatives.begin() + ROCostCalculator::getCalculator().getMaxRouteNumber(), myAlternatives.end()); // rescale probabilities SUMOReal newSum = 0; for (std::vector<RORoute*>::iterator i = myAlternatives.begin(); i != myAlternatives.end(); i++) { newSum += (*i)->getProbability(); } assert(newSum > 0); // @note newSum may be larger than 1 for numerical reasons for (std::vector<RORoute*>::iterator i = myAlternatives.begin(); i != myAlternatives.end(); i++) { (*i)->setProbability((*i)->getProbability() / newSum); } } // find the route to use SUMOReal chosen = RandHelper::rand(); int pos = 0; for (std::vector<RORoute*>::iterator i = myAlternatives.begin(); i != myAlternatives.end() - 1; i++, pos++) { chosen -= (*i)->getProbability(); if (chosen <= 0) { myLastUsed = pos; return; } } myLastUsed = pos; }
bool RODFDetector::writeEmitterDefinition(const std::string& file, const std::map<SUMOTime, RandomDistributor<int>* >& dists, const RODFDetectorFlows& flows, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset, bool includeUnusedRoutes, SUMOReal scale, bool insertionsOnly, SUMOReal defaultSpeed) const { OutputDevice& out = OutputDevice::getDevice(file); OptionsCont& oc = OptionsCont::getOptions(); if (getType() != SOURCE_DETECTOR) { out.writeXMLHeader("additional", "additional_file.xsd"); } // routes if (myRoutes != 0 && myRoutes->get().size() != 0) { const std::vector<RODFRouteDesc>& routes = myRoutes->get(); out.openTag(SUMO_TAG_ROUTE_DISTRIBUTION).writeAttr(SUMO_ATTR_ID, myID); bool isEmptyDist = true; for (std::vector<RODFRouteDesc>::const_iterator i = routes.begin(); i != routes.end(); ++i) { if ((*i).overallProb > 0) { isEmptyDist = false; } } for (std::vector<RODFRouteDesc>::const_iterator i = routes.begin(); i != routes.end(); ++i) { if ((*i).overallProb > 0 || includeUnusedRoutes) { out.openTag(SUMO_TAG_ROUTE).writeAttr(SUMO_ATTR_REFID, (*i).routename).writeAttr(SUMO_ATTR_PROB, (*i).overallProb).closeTag(); } if (isEmptyDist) { out.openTag(SUMO_TAG_ROUTE).writeAttr(SUMO_ATTR_REFID, (*i).routename).writeAttr(SUMO_ATTR_PROB, SUMOReal(1)).closeTag(); } } out.closeTag(); // routeDistribution } else { WRITE_ERROR("Detector '" + getID() + "' has no routes!?"); return false; } // insertions if (insertionsOnly || flows.knows(myID)) { // get the flows for this detector const std::vector<FlowDef>& mflows = flows.getFlowDefs(myID); // go through the simulation seconds int index = 0; for (SUMOTime time = startTime; time < endTime; time += stepOffset, index++) { // get own (departure flow) assert(index < (int)mflows.size()); const FlowDef& srcFD = mflows[index]; // !!! check stepOffset // get flows at end RandomDistributor<int>* destDist = dists.find(time) != dists.end() ? dists.find(time)->second : 0; // go through the cars int carNo = (int)((srcFD.qPKW + srcFD.qLKW) * scale); for (int car = 0; car < carNo; ++car) { // get the vehicle parameter SUMOReal v = -1; std::string vtype; int destIndex = destDist != 0 && destDist->getOverallProb() > 0 ? (int) destDist->get() : -1; if (srcFD.isLKW >= 1) { srcFD.isLKW = srcFD.isLKW - (SUMOReal) 1.; v = srcFD.vLKW; vtype = "LKW"; } else { v = srcFD.vPKW; vtype = "PKW"; } // compute insertion speed if (v <= 0 || v > 250) { v = defaultSpeed; } else { v = (SUMOReal)(v / 3.6); } // compute the departure time SUMOTime ctime = (SUMOTime)(time + ((SUMOReal) stepOffset * (SUMOReal) car / (SUMOReal) carNo)); // write out.openTag(SUMO_TAG_VEHICLE); if (getType() == SOURCE_DETECTOR) { out.writeAttr(SUMO_ATTR_ID, "emitter_" + myID + "_" + toString(ctime)); } else { out.writeAttr(SUMO_ATTR_ID, "calibrator_" + myID + "_" + toString(ctime)); } if (oc.getBool("vtype")) { out.writeAttr(SUMO_ATTR_TYPE, vtype); } out.writeAttr(SUMO_ATTR_DEPART, time2string(ctime)); if (oc.isSet("departlane")) { out.writeNonEmptyAttr(SUMO_ATTR_DEPARTLANE, oc.getString("departlane")); } else { out.writeAttr(SUMO_ATTR_DEPARTLANE, TplConvert::_2int(myLaneID.substr(myLaneID.rfind("_") + 1).c_str())); } if (oc.isSet("departpos")) { std::string posDesc = oc.getString("departpos"); if (posDesc.substr(0, 8) == "detector") { SUMOReal position = myPosition; if (posDesc.length() > 8) { if (posDesc[8] == '+') { position += TplConvert::_2SUMOReal(posDesc.substr(9).c_str()); } else if (posDesc[8] == '-') { position -= TplConvert::_2SUMOReal(posDesc.substr(9).c_str()); } else { throw NumberFormatException(); } } out.writeAttr(SUMO_ATTR_DEPARTPOS, position); } else { out.writeNonEmptyAttr(SUMO_ATTR_DEPARTPOS, posDesc); } } else { out.writeAttr(SUMO_ATTR_DEPARTPOS, myPosition); } if (oc.isSet("departspeed")) { out.writeNonEmptyAttr(SUMO_ATTR_DEPARTSPEED, oc.getString("departspeed")); } else { out.writeAttr(SUMO_ATTR_DEPARTSPEED, v); } if (oc.isSet("arrivallane")) { out.writeNonEmptyAttr(SUMO_ATTR_ARRIVALLANE, oc.getString("arrivallane")); } if (oc.isSet("arrivalpos")) { out.writeNonEmptyAttr(SUMO_ATTR_ARRIVALPOS, oc.getString("arrivalpos")); } if (oc.isSet("arrivalspeed")) { out.writeNonEmptyAttr(SUMO_ATTR_ARRIVALSPEED, oc.getString("arrivalspeed")); } if (destIndex >= 0) { out.writeAttr(SUMO_ATTR_ROUTE, myRoutes->get()[destIndex].routename); } else { out.writeAttr(SUMO_ATTR_ROUTE, myID); } out.closeTag(); srcFD.isLKW += srcFD.fLKW; } } } if (getType() != SOURCE_DETECTOR) { out.close(); } return true; }
SUMOReal MSCFModel_KraussOrig1::dawdle(SUMOReal speed) const { return MAX2(SUMOReal(0), speed - ACCEL2SPEED(myDawdle * myAccel * RandHelper::rand())); }
int GUIViewTraffic::doPaintGL(int mode, SUMOReal scale) { // init view settings glRenderMode(mode); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glDisable(GL_TEXTURE_2D); glDisable(GL_ALPHA_TEST); glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); GLdouble sxmin = myCX - myX1; GLdouble sxmax = myCX + myX1; GLdouble symin = myCY - myY1; GLdouble symax = myCY + myY1; // compute lane width ?? ACE ?? SUMOReal lw = m2p(3.0) * scale; // draw decals (if not in grabbing mode) if (!myUseToolTips) { drawDecals(); if (myVisualizationSettings->showGrid) { paintGLGrid(); } } glLineWidth(1); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); float minB[2]; float maxB[2]; minB[0] = sxmin; minB[1] = symin; maxB[0] = sxmax; maxB[1] = symax; myVisualizationSettings->needsGlID = myUseToolTips; myVisualizationSettings->scale = lw; glEnable(GL_POLYGON_OFFSET_FILL); glEnable(GL_POLYGON_OFFSET_LINE); int hits2 = myGrid->Search(minB, maxB, *myVisualizationSettings); // glTranslated(0, 0, -.01); for (std::vector<VehicleOps>::iterator i=myVehicleOps.begin(); i!=myVehicleOps.end(); ++i) { const VehicleOps &vo = *i; switch (vo.type) { case VO_SHOW_ROUTE: { if (vo.routeNo>=0) { drawRoute(vo, vo.routeNo, 0.25); } else { if (vo.vehicle->hasCORNIntValue(MSCORN::CORN_VEH_NUMBERROUTE)) { int noReroutePlus1 = vo.vehicle->getCORNIntValue(MSCORN::CORN_VEH_NUMBERROUTE) + 1; for (int i=noReroutePlus1-1; i>=0; i--) { SUMOReal darken = SUMOReal(0.4) / SUMOReal(noReroutePlus1) * SUMOReal(i); drawRoute(vo, i, darken); } } else { drawRoute(vo, 0, 0.25); } } } break; case VO_SHOW_BEST_LANES: { drawBestLanes(vo); break; } break; default: break; } } glTranslated(0, 0, .01); glPopMatrix(); /* // draw legends glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslated(1.-.2, 1.-.5, 0.); glScaled(.2, .5, 1.); GUIColoringSchemesMap<GUILaneWrapper> &sm = GUIViewTraffic::getLaneSchemesMap(); //!!! sm.getColorer(myVisualizationSettings->laneEdgeMode)->drawLegend(); */ return hits2; }
/* Test the method 'parseColor' with a longer String*/ TEST(RGBColor, test_parseColor_with_a_long_string) { RGBColor color = RGBColor::parseColor("1,2,3,5,432test"); EXPECT_FLOAT_EQ(SUMOReal(1), color.red()); EXPECT_FLOAT_EQ(SUMOReal(2), color.green()); EXPECT_FLOAT_EQ(SUMOReal(3), color.blue()); }
/* Test the method 'parseColor'*/ TEST(RGBColor, test_parseColor) { RGBColor color = RGBColor::parseColor("1,2,3"); EXPECT_FLOAT_EQ(SUMOReal(1), color.red()); EXPECT_FLOAT_EQ(SUMOReal(2), color.green()); EXPECT_FLOAT_EQ(SUMOReal(3), color.blue()); }