void MSDevice_Vehroutes::writeXMLRoute(OutputDevice& os, int index) const { // check if a previous route shall be written os.openTag(SUMO_TAG_ROUTE); if (index >= 0) { assert((int) myReplacedRoutes.size() > index); // write edge on which the vehicle was when the route was valid os << " replacedOnEdge=\""; if (myReplacedRoutes[index].edge) { os << myReplacedRoutes[index].edge->getID(); } // write the time at which the route was replaced os << "\" replacedAtTime=\"" << time2string(myReplacedRoutes[index].time) << "\" probability=\"0\" edges=\""; // get the route int i = index; while (i > 0 && myReplacedRoutes[i - 1].edge) { i--; } const MSEdge* lastEdge = 0; for (; i < index; ++i) { myReplacedRoutes[i].route->writeEdgeIDs(os, lastEdge, myReplacedRoutes[i].edge); lastEdge = myReplacedRoutes[i].edge; } myReplacedRoutes[index].route->writeEdgeIDs(os, lastEdge); } else { os << " edges=\""; const MSEdge* lastEdge = 0; int numWritten = 0; if (myHolder.getNumberReroutes() > 0) { assert(myReplacedRoutes.size() <= myHolder.getNumberReroutes()); unsigned int i = static_cast<unsigned int>(myReplacedRoutes.size()); while (i > 0 && myReplacedRoutes[i - 1].edge) { i--; } for (; i < myReplacedRoutes.size(); ++i) { numWritten += myReplacedRoutes[i].route->writeEdgeIDs(os, lastEdge, myReplacedRoutes[i].edge); lastEdge = myReplacedRoutes[i].edge; } } const MSEdge* upTo = 0; if (mySaveExits) { int remainingWithExitTime = (int)myExits.size() - numWritten; assert(remainingWithExitTime >= 0); assert(remainingWithExitTime <= (int)myCurrentRoute->size()); if (remainingWithExitTime < (int)myCurrentRoute->size()) { upTo = *(myCurrentRoute->begin() + remainingWithExitTime); } } myCurrentRoute->writeEdgeIDs(os, lastEdge, upTo); if (mySaveExits) { os << "\" exitTimes=\""; for (std::vector<SUMOTime>::const_iterator it = myExits.begin(); it != myExits.end(); ++it) { if (it != myExits.begin()) { os << " "; } os << time2string(*it); } } } (os << "\"").closeTag(); }
void MSContainer::MSContainerStage_Tranship::endEventOutput(const MSTransportable& c, SUMOTime t, OutputDevice& os) const { os.openTag("event").writeAttr("time", time2string(t)).writeAttr("type", "arrival") .writeAttr("agent", c.getID()).writeAttr("link", myRoute.back()->getID()).closeTag(); }
void MSContainer::MSContainerStage_Driving::tripInfoOutput(OutputDevice& os) const { os.openTag("transport").writeAttr("depart", time2string(myDeparted)).writeAttr("arrival", time2string(myArrived)).closeTag(); }
void MSContainer::MSContainerStage_Tranship::tripInfoOutput(OutputDevice& os) const { os.openTag("tranship").writeAttr("arrival", time2string(myArrived)).closeTag(); }
void MSContainer::MSContainerStage_Tranship::routeOutput(OutputDevice& os) const { os.openTag("tranship").writeAttr(SUMO_ATTR_EDGES, myRoute); os.writeAttr(SUMO_ATTR_SPEED, mySpeed); os.closeTag(); }
void NWWriter_SUMO::writeJunction(OutputDevice& into, const NBNode& n, const bool checkLaneFoes) { // write the attributes into.openTag(SUMO_TAG_JUNCTION).writeAttr(SUMO_ATTR_ID, n.getID()); into.writeAttr(SUMO_ATTR_TYPE, n.getType()); NWFrame::writePositionLong(n.getPosition(), into); // write the incoming lanes std::string incLanes; const std::vector<NBEdge*>& incoming = n.getIncomingEdges(); for (std::vector<NBEdge*>::const_iterator i = incoming.begin(); i != incoming.end(); ++i) { unsigned int noLanes = (*i)->getNumLanes(); for (unsigned int j = 0; j < noLanes; j++) { incLanes += (*i)->getLaneID(j); if (i != incoming.end() - 1 || j < noLanes - 1) { incLanes += ' '; } } } const std::vector<NBNode::Crossing>& crossings = n.getCrossings(); for (std::vector<NBNode::Crossing>::const_iterator it = crossings.begin(); it != crossings.end(); it++) { incLanes += ' ' + (*it).prevWalkingArea + "_0"; } into.writeAttr(SUMO_ATTR_INCLANES, incLanes); // write the internal lanes std::string intLanes; if (!OptionsCont::getOptions().getBool("no-internal-links")) { unsigned int l = 0; for (EdgeVector::const_iterator i = incoming.begin(); i != incoming.end(); i++) { const std::vector<NBEdge::Connection>& elv = (*i)->getConnections(); for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) { if ((*k).toEdge == 0) { continue; } if (l != 0) { intLanes += ' '; } if (!(*k).haveVia) { intLanes += (*k).getInternalLaneID(); } else { intLanes += (*k).viaID + "_0"; } l++; } } } if (n.getType() != NODETYPE_DEAD_END && n.getType() != NODETYPE_NOJUNCTION) { for (std::vector<NBNode::Crossing>::const_iterator it = crossings.begin(); it != crossings.end(); it++) { intLanes += ' ' + (*it).id + "_0"; } } into.writeAttr(SUMO_ATTR_INTLANES, intLanes); // close writing into.writeAttr(SUMO_ATTR_SHAPE, n.getShape()); // write optional radius if (n.getRadius() != NBNode::UNSPECIFIED_RADIUS) { into.writeAttr(SUMO_ATTR_RADIUS, n.getRadius()); } // specify whether a custom shape was used if (n.hasCustomShape()) { into.writeAttr(SUMO_ATTR_CUSTOMSHAPE, true); } if (n.getType() == NODETYPE_DEAD_END) { into.closeTag(); } else { // write right-of-way logics n.writeLogic(into, checkLaneFoes); into.closeTag(); } }
void MSContainer::MSContainerStage_Driving::routeOutput(OutputDevice& os) const { os.openTag("transport").writeAttr(SUMO_ATTR_FROM, getFromEdge()->getID()).writeAttr(SUMO_ATTR_TO, getDestination().getID()); os.writeAttr(SUMO_ATTR_LINES, myLines).closeTag(); }
bool NWWriter_SUMO::writeInternalEdges(OutputDevice& into, const NBNode& n, bool origNames) { bool ret = false; const EdgeVector& incoming = n.getIncomingEdges(); for (EdgeVector::const_iterator i = incoming.begin(); i != incoming.end(); i++) { const std::vector<NBEdge::Connection>& elv = (*i)->getConnections(); if (elv.size() > 0) { bool haveVia = false; NBEdge* toEdge = 0; std::string internalEdgeID = ""; // first pass: compute average lengths of non-via edges std::map<NBEdge*, SUMOReal> lengthSum; std::map<NBEdge*, int> numLanes; for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) { lengthSum[(*k).toEdge] += MAX2((*k).shape.length(), POSITION_EPS); numLanes[(*k).toEdge] += 1; } // second pass: write non-via edges for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) { if ((*k).toEdge == 0) { assert(false); // should never happen. tell me when it does continue; } if (toEdge != (*k).toEdge) { internalEdgeID = (*k).id; if (toEdge != 0) { // close the previous edge into.closeTag(); } toEdge = (*k).toEdge; into.openTag(SUMO_TAG_EDGE); into.writeAttr(SUMO_ATTR_ID, internalEdgeID); into.writeAttr(SUMO_ATTR_FUNCTION, EDGEFUNC_INTERNAL); // open a new edge } // to avoid changing to an internal lane which has a successor // with the wrong permissions we need to inherit them from the successor const NBEdge::Lane& successor = (*k).toEdge->getLanes()[(*k).toLane]; const SUMOReal length = lengthSum[toEdge] / numLanes[toEdge]; // @note the actual length should be used once sumo supports lanes of // varying length within the same edge //const SUMOReal length = MAX2((*k).shape.length(), POSITION_EPS); writeLane(into, internalEdgeID, (*k).getInternalLaneID(), (*k).vmax, successor.permissions, successor.preferred, NBEdge::UNSPECIFIED_OFFSET, successor.width, (*k).shape, (*k).origID, length, (*k).internalLaneIndex, origNames, &n); haveVia = haveVia || (*k).haveVia; } ret = true; into.closeTag(); // close the last edge // third pass: write via edges if (haveVia) { for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) { if (!(*k).haveVia) { continue; } if ((*k).toEdge == 0) { assert(false); // should never happen. tell me when it does continue; } const NBEdge::Lane& successor = (*k).toEdge->getLanes()[(*k).toLane]; into.openTag(SUMO_TAG_EDGE); into.writeAttr(SUMO_ATTR_ID, (*k).viaID); into.writeAttr(SUMO_ATTR_FUNCTION, EDGEFUNC_INTERNAL); writeLane(into, (*k).viaID, (*k).viaID + "_0", (*k).viaVmax, SVCAll, SVCAll, NBEdge::UNSPECIFIED_OFFSET, successor.width, (*k).viaShape, (*k).origID, MAX2((*k).viaShape.length(), POSITION_EPS), // microsim needs positive length 0, origNames, &n); into.closeTag(); } } } } // write pedestrian crossings const std::vector<NBNode::Crossing>& crossings = n.getCrossings(); for (std::vector<NBNode::Crossing>::const_iterator it = crossings.begin(); it != crossings.end(); it++) { into.openTag(SUMO_TAG_EDGE); into.writeAttr(SUMO_ATTR_ID, (*it).id); into.writeAttr(SUMO_ATTR_FUNCTION, EDGEFUNC_CROSSING); into.writeAttr(SUMO_ATTR_CROSSING_EDGES, (*it).edges); writeLane(into, (*it).id, (*it).id + "_0", 1, SVC_PEDESTRIAN, 0, NBEdge::UNSPECIFIED_OFFSET, (*it).width, (*it).shape, "", (*it).shape.length(), 0, false, &n); into.closeTag(); } // write pedestrian walking areas const std::vector<NBNode::WalkingArea>& WalkingAreas = n.getWalkingAreas(); for (std::vector<NBNode::WalkingArea>::const_iterator it = WalkingAreas.begin(); it != WalkingAreas.end(); it++) { const NBNode::WalkingArea& wa = *it; into.openTag(SUMO_TAG_EDGE); into.writeAttr(SUMO_ATTR_ID, wa.id); into.writeAttr(SUMO_ATTR_FUNCTION, EDGEFUNC_WALKINGAREA); writeLane(into, wa.id, wa.id + "_0", 1, SVC_PEDESTRIAN, 0, NBEdge::UNSPECIFIED_OFFSET, wa.width, wa.shape, "", wa.length, 0, false, &n); into.closeTag(); } return ret; }
SUMOReal NWWriter_OpenDrive::writeGeomPP3( OutputDevice& device, OutputDevice& elevationDevice, PositionVector init, SUMOReal length, SUMOReal offset) { assert(init.size() == 3 || init.size() == 4); // avoid division by 0 length = MAX2(POSITION_EPS, length); const Position p = init.front(); const SUMOReal hdg = init.angleAt2D(0); // backup elevation values const PositionVector initZ = init; // translate to u,v coordinates init.add(-p.x(), -p.y(), -p.z()); init.rotate2D(-hdg); // parametric coefficients SUMOReal aU, bU, cU, dU; SUMOReal aV, bV, cV, dV; SUMOReal aZ, bZ, cZ, dZ; // unfactor the Bernstein polynomials of degree 2 (or 3) and collect the coefficients if (init.size() == 3) { //f(x, a, b ,c) = a + (2*b - 2*a)*x + (a - 2*b + c)*x*x aU = init[0].x(); bU = 2 * init[1].x() - 2 * init[0].x(); cU = init[0].x() - 2 * init[1].x() + init[2].x(); dU = 0; aV = init[0].y(); bV = 2 * init[1].y() - 2 * init[0].y(); cV = init[0].y() - 2 * init[1].y() + init[2].y(); dV = 0; // elevation is not parameteric on [0:1] but on [0:length] aZ = initZ[0].z(); bZ = (2 * initZ[1].z() - 2 * initZ[0].z()) / length; cZ = (initZ[0].z() - 2 * initZ[1].z() + initZ[2].z()) / (length * length); dZ = 0; } else { // f(x, a, b, c, d) = a + (x*((3*b) - (3*a))) + ((x*x)*((3*a) + (3*c) - (6*b))) + ((x*x*x)*((3*b) - (3*c) - a + d)) aU = init[0].x(); bU = 3 * init[1].x() - 3 * init[0].x(); cU = 3 * init[0].x() - 6 * init[1].x() + 3 * init[2].x(); dU = -init[0].x() + 3 * init[1].x() - 3 * init[2].x() + init[3].x(); aV = init[0].y(); bV = 3 * init[1].y() - 3 * init[0].y(); cV = 3 * init[0].y() - 6 * init[1].y() + 3 * init[2].y(); dV = -init[0].y() + 3 * init[1].y() - 3 * init[2].y() + init[3].y(); // elevation is not parameteric on [0:1] but on [0:length] aZ = initZ[0].z(); bZ = (3 * initZ[1].z() - 3 * initZ[0].z()) / length; cZ = (3 * initZ[0].z() - 6 * initZ[1].z() + 3 * initZ[2].z()) / (length * length); dZ = (-initZ[0].z() + 3 * initZ[1].z() - 3 * initZ[2].z() + initZ[3].z()) / (length * length * length); } device.openTag("geometry"); device.writeAttr("s", offset); device.writeAttr("x", p.x()); device.writeAttr("y", p.y()); device.writeAttr("hdg", hdg); device.writeAttr("length", length); device.openTag("paramPoly3"); device.writeAttr("aU", aU); device.writeAttr("bU", bU); device.writeAttr("cU", cU); device.writeAttr("dU", dU); device.writeAttr("aV", aV); device.writeAttr("bV", bV); device.writeAttr("cV", cV); device.writeAttr("dV", dV); device.closeTag(); device.closeTag(); // write elevation elevationDevice.openTag("elevation"); elevationDevice.writeAttr("s", offset); elevationDevice.writeAttr("a", aZ); elevationDevice.writeAttr("b", bZ); elevationDevice.writeAttr("c", cZ); elevationDevice.writeAttr("d", dZ); elevationDevice.closeTag(); return offset + length; }
void MSXMLRawOut::writeEdge(OutputDevice& of, const MSEdge& edge, SUMOTime timestep) { //en bool dump = !MSGlobals::gOmitEmptyEdgesOnDump; if (!dump) { #ifdef HAVE_INTERNAL if (MSGlobals::gUseMesoSim) { MESegment* seg = MSGlobals::gMesoNet->getSegmentForEdge(edge); while (seg != 0) { if (seg->getCarNumber() != 0) { dump = true; break; } seg = seg->getNextSegment(); } } else { #endif const std::vector<MSLane*>& lanes = edge.getLanes(); for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) { if (((**lane).getVehicleNumber() != 0)) { dump = true; break; } } #ifdef HAVE_INTERNAL } #endif } //en const std::vector<MSPerson*>& persons = edge.getSortedPersons(timestep); if (dump || persons.size() > 0) { of.openTag("edge") << " id=\"" << edge.getID() << "\""; if (dump) { #ifdef HAVE_INTERNAL if (MSGlobals::gUseMesoSim) { MESegment* seg = MSGlobals::gMesoNet->getSegmentForEdge(edge); while (seg != 0) { seg->writeVehicles(of); seg = seg->getNextSegment(); } } else { #endif const std::vector<MSLane*>& lanes = edge.getLanes(); for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) { writeLane(of, **lane); } #ifdef HAVE_INTERNAL } #endif } // write persons for (std::vector<MSPerson*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) { of.openTag(SUMO_TAG_PERSON); of.writeAttr(SUMO_ATTR_ID, (*it_p)->getID()); of.writeAttr(SUMO_ATTR_POSITION, (*it_p)->getEdgePos()); of.writeAttr(SUMO_ATTR_ANGLE, (*it_p)->getAngle()); of.writeAttr("stage", (*it_p)->getCurrentStageDescription()); of.closeTag(); } of.closeTag(); } }
void SUMOVTypeParameter::write(OutputDevice& dev) const { if (onlyReferenced) { return; } dev.openTag(SUMO_TAG_VTYPE); dev.writeAttr(SUMO_ATTR_ID, id); if (wasSet(VTYPEPARS_LENGTH_SET)) { dev.writeAttr(SUMO_ATTR_LENGTH, length); } if (wasSet(VTYPEPARS_MINGAP_SET)) { dev.writeAttr(SUMO_ATTR_MINGAP, minGap); } if (wasSet(VTYPEPARS_MAXSPEED_SET)) { dev.writeAttr(SUMO_ATTR_MAXSPEED, maxSpeed); } if (wasSet(VTYPEPARS_PROBABILITY_SET)) { dev.writeAttr(SUMO_ATTR_PROB, defaultProbability); } if (wasSet(VTYPEPARS_SPEEDFACTOR_SET)) { dev.writeAttr(SUMO_ATTR_SPEEDFACTOR, speedFactor); } if (wasSet(VTYPEPARS_SPEEDDEVIATION_SET)) { dev.writeAttr(SUMO_ATTR_SPEEDDEV, speedDev); } if (wasSet(VTYPEPARS_VEHICLECLASS_SET)) { dev.writeAttr(SUMO_ATTR_VCLASS, toString(vehicleClass)); } if (wasSet(VTYPEPARS_EMISSIONCLASS_SET)) { dev.writeAttr(SUMO_ATTR_EMISSIONCLASS, PollutantsInterface::getName(emissionClass)); } if (wasSet(VTYPEPARS_IMPATIENCE_SET)) { if (impatience == -std::numeric_limits<SUMOReal>::max()) { dev.writeAttr(SUMO_ATTR_IMPATIENCE, "off"); } else { dev.writeAttr(SUMO_ATTR_IMPATIENCE, impatience); } } if (wasSet(VTYPEPARS_SHAPE_SET)) { dev.writeAttr(SUMO_ATTR_GUISHAPE, getVehicleShapeName(shape)); } if (wasSet(VTYPEPARS_WIDTH_SET)) { dev.writeAttr(SUMO_ATTR_WIDTH, width); } if (wasSet(VTYPEPARS_HEIGHT_SET)) { dev.writeAttr(SUMO_ATTR_HEIGHT, height); } if (wasSet(VTYPEPARS_COLOR_SET)) { dev.writeAttr(SUMO_ATTR_COLOR, color); } if (wasSet(VTYPEPARS_OSGFILE_SET)) { dev.writeAttr(SUMO_ATTR_OSGFILE, osgFile); } if (wasSet(VTYPEPARS_IMGFILE_SET)) { dev.writeAttr(SUMO_ATTR_IMGFILE, imgFile); } if (wasSet(VTYPEPARS_LANE_CHANGE_MODEL_SET)) { dev.writeAttr(SUMO_ATTR_LANE_CHANGE_MODEL, lcModel); } if (cfParameter.size() != 0) { dev.openTag(cfModel); std::vector<SumoXMLAttr> attrs; for (CFParams::const_iterator i = cfParameter.begin(); i != cfParameter.end(); ++i) { attrs.push_back(i->first); } std::sort(attrs.begin(), attrs.end()); for (std::vector<SumoXMLAttr>::const_iterator i = attrs.begin(); i != attrs.end(); ++i) { dev.writeAttr(*i, cfParameter.find(*i)->second); } dev.closeTag(); dev.closeTag(); } else { dev.closeTag(); } }
void ODMatrix::write(SUMOTime begin, const SUMOTime end, OutputDevice& dev, const bool uniform, const bool differSourceSink, const bool noVtype, const std::string& prefix, const bool stepLog, bool pedestrians, bool persontrips) { if (myContainer.size() == 0) { return; } std::map<std::pair<std::string, std::string>, double> fractionLeft; int vehName = 0; sortByBeginTime(); // recheck begin time begin = MAX2(begin, myContainer.front()->begin); std::vector<ODCell*>::iterator next = myContainer.begin(); std::vector<ODVehicle> vehicles; SUMOTime lastOut = -DELTA_T; // go through the time steps for (SUMOTime t = begin; t < end;) { if (stepLog && t - lastOut >= DELTA_T) { std::cout << "Parsing time " + time2string(t) << '\r'; lastOut = t; } // recheck whether a new cell got valid bool changed = false; while (next != myContainer.end() && (*next)->begin <= t && (*next)->end > t) { std::pair<std::string, std::string> odID = std::make_pair((*next)->origin, (*next)->destination); // check whether the current cell must be extended by the last fraction if (fractionLeft.find(odID) != fractionLeft.end()) { (*next)->vehicleNumber += fractionLeft[odID]; fractionLeft[odID] = 0; } // get the new departures (into tmp) const int oldSize = (int)vehicles.size(); const double fraction = computeDeparts(*next, vehName, vehicles, uniform, differSourceSink, prefix); if (oldSize != (int)vehicles.size()) { changed = true; } if (fraction != 0) { fractionLeft[odID] = fraction; } ++next; } if (changed) { sort(vehicles.begin(), vehicles.end(), descending_departure_comperator()); } for (std::vector<ODVehicle>::reverse_iterator i = vehicles.rbegin(); i != vehicles.rend() && (*i).depart == t; ++i) { if (t >= begin) { myNumWritten++; if (pedestrians) { dev.openTag(SUMO_TAG_PERSON).writeAttr(SUMO_ATTR_ID, (*i).id).writeAttr(SUMO_ATTR_DEPART, time2string(t)); dev.writeAttr(SUMO_ATTR_DEPARTPOS, "random"); dev.openTag(SUMO_TAG_WALK); dev.writeAttr(SUMO_ATTR_FROM, (*i).from).writeAttr(SUMO_ATTR_TO, (*i).to); dev.writeAttr(SUMO_ATTR_ARRIVALPOS, "random"); dev.closeTag(); dev.closeTag(); } else if (persontrips) { dev.openTag(SUMO_TAG_PERSON).writeAttr(SUMO_ATTR_ID, (*i).id).writeAttr(SUMO_ATTR_DEPART, time2string(t)); dev.writeAttr(SUMO_ATTR_DEPARTPOS, "random"); dev.openTag(SUMO_TAG_PERSONTRIP); dev.writeAttr(SUMO_ATTR_FROM, (*i).from).writeAttr(SUMO_ATTR_TO, (*i).to); dev.writeAttr(SUMO_ATTR_ARRIVALPOS, "random"); dev.closeTag(); dev.closeTag(); } else { dev.openTag(SUMO_TAG_TRIP).writeAttr(SUMO_ATTR_ID, (*i).id).writeAttr(SUMO_ATTR_DEPART, time2string(t)); dev.writeAttr(SUMO_ATTR_FROM, (*i).from).writeAttr(SUMO_ATTR_TO, (*i).to); writeDefaultAttrs(dev, noVtype, i->cell); dev.closeTag(); } } } while (vehicles.size() != 0 && vehicles.back().depart == t) { vehicles.pop_back(); } if (!vehicles.empty()) { t = vehicles.back().depart; } if (next != myContainer.end() && (t > (*next)->begin || vehicles.empty())) { t = (*next)->begin; } if (next == myContainer.end() && vehicles.empty()) { break; } } }