void MSRouteProbe::writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime) { if (myCurrentRouteDistribution.second->getOverallProb() > 0) { dev.openTag("routeDistribution") << " id=\"" << getID() + "_" + time2string(startTime) << "\""; const std::vector<const MSRoute*>& routes = myCurrentRouteDistribution.second->getVals(); const std::vector<SUMOReal>& probs = myCurrentRouteDistribution.second->getProbs(); for (unsigned int j = 0; j < routes.size(); ++j) { const MSRoute* r = routes[j]; dev.openTag("route") << " id=\"" << r->getID() + "_" + time2string(startTime) << "\" edges=\""; for (MSRouteIterator i = r->begin(); i != r->end(); ++i) { if (i != r->begin()) { dev << " "; } dev << (*i)->getID(); } dev << "\" probability=\"" << probs[j] << "\""; dev.closeTag(); } dev.closeTag(); if (myLastRouteDistribution.second != 0) { MSRoute::checkDist(myLastRouteDistribution.first); } myLastRouteDistribution = myCurrentRouteDistribution; myCurrentRouteDistribution.first = getID() + "_" + toString(stopTime); myCurrentRouteDistribution.second = new RandomDistributor<const MSRoute*>(); MSRoute::dictionary(myCurrentRouteDistribution.first, myCurrentRouteDistribution.second, false); } }
void ROPerson::saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options) const { // write the person's vehicles for (std::vector<PlanItem*>::const_iterator it = myPlan.begin(); it != myPlan.end(); ++it) { (*it)->saveVehicles(os, typeos, asAlternatives, options); } if (typeos != 0 && myType != 0 && !myType->saved) { myType->write(*typeos); myType->saved = true; } if (myType != 0 && !myType->saved) { myType->write(os); myType->saved = asAlternatives; } // write the person myParameter.write(os, options, SUMO_TAG_PERSON); for (std::vector<PlanItem*>::const_iterator it = myPlan.begin(); it != myPlan.end(); ++it) { (*it)->saveAsXML(os); } for (std::map<std::string, std::string>::const_iterator j = myParameter.getMap().begin(); j != myParameter.getMap().end(); ++j) { os.openTag(SUMO_TAG_PARAM); os.writeAttr(SUMO_ATTR_KEY, (*j).first); os.writeAttr(SUMO_ATTR_VALUE, (*j).second); os.closeTag(); } os.closeTag(); }
// =========================================================================== // static method definitions // =========================================================================== OutputDevice& OutputDevice::getDevice(const std::string& name) { // check whether the device has already been aqcuired if (myOutputDevices.find(name) != myOutputDevices.end()) { return *myOutputDevices[name]; } // build the device OutputDevice* dev = 0; // check whether the device shall print to stdout if (name == "stdout") { dev = OutputDevice_COUT::getDevice(); } else if (name == "stderr") { dev = OutputDevice_CERR::getDevice(); } else if (FileHelpers::isSocket(name)) { try { int port = TplConvert::_2int(name.substr(name.find(":") + 1).c_str()); dev = new OutputDevice_Network(name.substr(0, name.find(":")), port); } catch (NumberFormatException&) { throw IOError("Given port number '" + name.substr(name.find(":") + 1) + "' is not numeric."); } catch (EmptyData&) { throw IOError("No port number given."); } } else { const size_t len = name.length(); dev = new OutputDevice_File(name, len > 4 && name.substr(len - 4) == ".sbx"); } dev->setPrecision(); dev->getOStream() << std::setiosflags(std::ios::fixed); myOutputDevices[name] = dev; return *dev; }
bool NWWriter_SUMO::writeInternalNodes(OutputDevice& into, const NBNode& n) { bool ret = false; const std::vector<NBEdge*>& incoming = n.getIncomingEdges(); for (std::vector<NBEdge*>::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 || !(*k).haveVia) { continue; } Position pos = (*k).shape[-1]; into.openTag(SUMO_TAG_JUNCTION).writeAttr(SUMO_ATTR_ID, (*k).viaID + "_0"); into.writeAttr(SUMO_ATTR_TYPE, NODETYPE_INTERNAL); NWFrame::writePositionLong(pos, into); std::string incLanes = (*k).id + "_0"; if ((*k).foeIncomingLanes.length() != 0) { incLanes += " " + (*k).foeIncomingLanes; } into.writeAttr(SUMO_ATTR_INCLANES, incLanes); into.writeAttr(SUMO_ATTR_INTLANES, (*k).foeInternalLanes); into.closeTag(); ret = true; } } return ret; }
void NWWriter_SUMO::writeRoundabout(OutputDevice& into, const std::vector<std::string>& edgeIDs, const NBEdgeCont& ec) { std::vector<std::string> validEdgeIDs; std::vector<std::string> invalidEdgeIDs; std::vector<std::string> nodeIDs; for (std::vector<std::string>::const_iterator i = edgeIDs.begin(); i != edgeIDs.end(); ++i) { const NBEdge* edge = ec.retrieve(*i); if (edge != 0) { nodeIDs.push_back(edge->getToNode()->getID()); validEdgeIDs.push_back(edge->getID()); } else { invalidEdgeIDs.push_back(*i); } } std::sort(nodeIDs.begin(), nodeIDs.end()); if (validEdgeIDs.size() > 0) { into.openTag(SUMO_TAG_ROUNDABOUT); into.writeAttr(SUMO_ATTR_NODES, joinToString(nodeIDs, " ")); into.writeAttr(SUMO_ATTR_EDGES, joinToString(validEdgeIDs, " ")); into.closeTag(); if (invalidEdgeIDs.size() > 0) { WRITE_WARNING("Writing incomplete roundabout. Edges: '" + joinToString(invalidEdgeIDs, " ") + "' no longer exist'"); } } }
void MSFullExport::writeTLS(OutputDevice& of, SUMOTime /* timestep */) { of.openTag("tls"); MSTLLogicControl& vc = MSNet::getInstance()->getTLSControl(); std::vector<std::string> ids = vc.getAllTLIds(); for (std::vector<std::string>::const_iterator id_it = ids.begin(); id_it != ids.end(); ++id_it) { MSTLLogicControl::TLSLogicVariants& vars = MSNet::getInstance()->getTLSControl().get(*id_it); const MSTrafficLightLogic::LaneVectorVector& lanes = vars.getActive()->getLaneVectors(); std::vector<std::string> laneIDs; for (MSTrafficLightLogic::LaneVectorVector::const_iterator i = lanes.begin(); i != lanes.end(); ++i) { const MSTrafficLightLogic::LaneVector& llanes = (*i); for (MSTrafficLightLogic::LaneVector::const_iterator j = llanes.begin(); j != llanes.end(); ++j) { laneIDs.push_back((*j)->getID()); } } std::string lane_output = ""; for (unsigned int i1 = 0; i1 < laneIDs.size(); ++i1) { lane_output += laneIDs[i1] + " "; } std::string state = vars.getActive()->getCurrentPhaseDef().getState(); of.openTag("trafficlight").writeAttr("id", *id_it).writeAttr("state", state).closeTag(); } of.closeTag(); }
void MSFullExport::writeEdge(OutputDevice& of) { of.openTag("edges") << ">\n"; MSEdgeControl& ec = MSNet::getInstance()->getEdgeControl(); const std::vector<MSEdge*>& edges = ec.getEdges(); for (std::vector<MSEdge*>::const_iterator e = edges.begin(); e != edges.end(); ++e) { MSEdge& edge = **e; of.openTag("edge") << " id=\"" << edge.getID() << "\" traveltime=\"" << edge.getCurrentTravelTime() << "\">\n"; const std::vector<MSLane*>& lanes = edge.getLanes(); for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) { writeLane(of, **lane); } of.closeTag(); } of.closeTag(); }
bool RODFRouteCont::save(std::vector<std::string>& saved, const std::string& prependix, OutputDevice& out) { bool haveSavedOneAtLeast = false; for (std::vector<RODFRouteDesc>::const_iterator j = myRoutes.begin(); j != myRoutes.end(); ++j) { const RODFRouteDesc& desc = (*j); if (find(saved.begin(), saved.end(), desc.routename) != saved.end()) { continue; } saved.push_back((*j).routename); assert(desc.edges2Pass.size() >= 1); out.openTag(SUMO_TAG_ROUTE).writeAttr(SUMO_ATTR_ID, prependix + desc.routename); out << " edges=\""; for (std::vector<ROEdge*>::const_iterator k = desc.edges2Pass.begin(); k != desc.edges2Pass.end(); k++) { if (k != desc.edges2Pass.begin()) { out << ' '; } out << (*k)->getID(); } out << '"'; out.closeTag(true); haveSavedOneAtLeast = true; } return haveSavedOneAtLeast; }
void MSContainer::tripInfoOutput(OutputDevice& os, MSTransportable* transportable) const { os.openTag("containerinfo").writeAttr("id", getID()).writeAttr("depart", time2string(getDesiredDepart())); for (MSTransportablePlan::const_iterator i = myPlan->begin(); i != myPlan->end(); ++i) { (*i)->tripInfoOutput(os, transportable); } os.closeTag(); }
void NWFrame::writePositionLong(const Position& pos, OutputDevice& dev) { dev.writeAttr(SUMO_ATTR_X, pos.x()); dev.writeAttr(SUMO_ATTR_Y, pos.y()); if (pos.z() != 0) { dev.writeAttr(SUMO_ATTR_Z, pos.z()); } }
void MSXMLRawOut::writeVehicle(OutputDevice& of, const MSBaseVehicle& veh) { if (veh.isOnRoad()) { of.openTag("vehicle") << " id=\"" << veh.getID() << "\" pos=\"" << veh.getPositionOnLane() << "\" speed=\"" << veh.getSpeed() << "\""; of.closeTag(); } }
void MEInductLoop::writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime) { mySegment->prepareDetectorForWriting(myMeanData); dev.openTag(SUMO_TAG_INTERVAL).writeAttr(SUMO_ATTR_BEGIN, time2string(startTime)).writeAttr(SUMO_ATTR_END, time2string(stopTime)); dev.writeAttr(SUMO_ATTR_ID, StringUtils::escapeXML(myID)).writeAttr("sampledSeconds", myMeanData.getSamples()); myMeanData.write(dev, stopTime - startTime, (SUMOReal)mySegment->getEdge().getLanes().size(), -1.0); myMeanData.reset(); }
void GNEDetectorEntry::writeAdditional(OutputDevice& device, const std::string &) { // Write parameters device.openTag(getTag()); device.writeAttr(SUMO_ATTR_LANE, myLane->getID()); device.writeAttr(SUMO_ATTR_POSITION, myPosition.x()); // Close tag device.closeTag(); }
void MSBaseVehicle::saveState(OutputDevice& out) { out.openTag(SUMO_TAG_VEHICLE).writeAttr(SUMO_ATTR_ID, myParameter->id); out.writeAttr(SUMO_ATTR_DEPART, time2string(myParameter->depart)); out.writeAttr(SUMO_ATTR_ROUTE, myRoute->getID()); out.writeAttr(SUMO_ATTR_TYPE, myType->getID()); // here starts the vehicle internal part (see loading) // @note: remember to close the vehicle tag when calling this in a subclass! }
// =========================================================================== // method definitions // =========================================================================== void MSQueueExport::write(OutputDevice& of, SUMOTime timestep) { of.openTag("data") << " timestep=\"" << time2string(timestep) << "\">\n"; writeEdge(of); of.closeTag(); }
void MSFullExport::writeLane(OutputDevice& of, const MSLane& lane) { of.openTag("lane").writeAttr("id", lane.getID()).writeAttr("CO", lane.getCOEmissions()).writeAttr("CO2", lane.getCO2Emissions()); of.writeAttr("NOx", lane.getNOxEmissions()).writeAttr("PMx", lane.getPMxEmissions()).writeAttr("HC", lane.getHCEmissions()); of.writeAttr("noise", lane.getHarmonoise_NoiseEmissions()).writeAttr("fuel", lane.getFuelConsumption()).writeAttr("maxspeed", lane.getSpeedLimit()); of.writeAttr("meanspeed", lane.getMeanSpeed() * 3.6).writeAttr("occupancy", lane.getNettoOccupancy()).writeAttr("vehicle_count", lane.getVehicleNumber()); of.closeTag(); }
void MSInductLoop::writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime) throw(IOError) { SUMOReal t(STEPS2TIME(stopTime-startTime)); unsigned nVehCrossed ; SUMOReal flow ; SUMOReal occupancy = 0; SUMOReal meanLength, meanSpeed; dev.openTag("interval"); dev <<" begin=\""<<time2string(startTime)<<"\" end=\""<< time2string(stopTime)<<"\" \n"; unsigned totVeh = 0; for(unsigned stripIndex=0;stripIndex<myStripCount;stripIndex++){ int no_vehicles = myVehicleDataCont[stripIndex].size(); nVehCrossed = (unsigned) no_vehicles; flow = ((SUMOReal) no_vehicles / (SUMOReal) t) * (SUMOReal) 3600.0; for (std::deque< VehicleData >::const_iterator i=myVehicleDataCont[stripIndex].begin(); i!=myVehicleDataCont[stripIndex].end(); ++i) { SUMOReal timeOnDetDuringInterval = (*i).leaveTimeM - MAX2(STEPS2TIME(startTime), (*i).entryTimeM); timeOnDetDuringInterval = MIN2(timeOnDetDuringInterval, t); occupancy += timeOnDetDuringInterval; } for (std::map< MSVehicle*, SUMOReal >::const_iterator i=myVehiclesOnDet[stripIndex].begin(); i!=myVehiclesOnDet[stripIndex].end(); ++i) { SUMOReal timeOnDetDuringInterval = STEPS2TIME(stopTime) - MAX2(STEPS2TIME(startTime), (*i).second); occupancy += timeOnDetDuringInterval; } occupancy = no_vehicles!=0 ? occupancy / t * (SUMOReal) 100.0 : 0; meanSpeed = no_vehicles!=0 ? accumulate(myVehicleDataCont[stripIndex].begin(), myVehicleDataCont[stripIndex].end(), (SUMOReal) 0.0, speedSum) / (SUMOReal) myVehicleDataCont[stripIndex].size() : -1; meanLength = no_vehicles!=0 ? accumulate(myVehicleDataCont[stripIndex].begin(), myVehicleDataCont[stripIndex].end(), (SUMOReal) 0.0, lengthSum) / (SUMOReal) myVehicleDataCont[stripIndex].size() : -1; if(no_vehicles >= 1){ dev <<"\tstripNum=\""<<stripIndex<<" \"vehicle_id=\""<< (myVehicleDataCont[stripIndex].begin())->idM <<"\" flow=\""<<flow<< "\" occupancy=\""<<occupancy<<"\" speed=\""<<meanSpeed<< "\" length=\""<<meanLength<< "\" nVehEntered=\""<<no_vehicles<<"\" \n"; totVeh += no_vehicles; } else { dev << "\tstripNum=\""<<stripIndex <<"\" flow=\""<<flow<< "\" occupancy=\""<<occupancy<<"\" speed=\""<<meanSpeed<< "\" length=\""<<meanLength<< "\" nVehEntered=\""<<no_vehicles<<"\" \n"; totVeh += no_vehicles; } } dev << "total_Vehicles=\" "<<totVeh + myDismissedVehicleNumber <<"\""; dev.closeTag(true); reset(); }
// =========================================================================== // method definitions // =========================================================================== void MSXMLRawOut::write(OutputDevice& of, const MSEdgeControl& ec, SUMOTime timestep) { of.openTag("timestep") << " time=\"" << time2string(timestep) << "\""; const std::vector<MSEdge*>& edges = ec.getEdges(); for (std::vector<MSEdge*>::const_iterator e = edges.begin(); e != edges.end(); ++e) { writeEdge(of, **e, timestep); } of.closeTag(); }
void MSInsertionControl::saveState(OutputDevice& out) { // save flow states for (const Flow& flow : myFlows) { out.openTag(SUMO_TAG_FLOWSTATE); out.writeAttr(SUMO_ATTR_ID, flow.pars->id); out.writeAttr(SUMO_ATTR_INDEX, flow.index); out.closeTag(); } }
void MESegment::saveState(OutputDevice& out) { out.openTag(SUMO_TAG_SEGMENT); for (size_t i = 0; i < myCarQues.size(); ++i) { out.openTag(SUMO_TAG_VIEWSETTINGS_VEHICLES).writeAttr(SUMO_ATTR_TIME, toString<SUMOTime>(myBlockTimes[i])); out.writeAttr(SUMO_ATTR_VALUE, myCarQues[i]); out.closeTag(); } out.closeTag(); }
void MSPerson::MSPersonStage_Walking::routeOutput(OutputDevice& os) const { os.openTag("walk").writeAttr(SUMO_ATTR_EDGES, myRoute); if (myWalkingTime > 0) { os.writeAttr(SUMO_ATTR_DURATION, time2string(myWalkingTime)); } else if (mySpeed > 0) { os.writeAttr(SUMO_ATTR_SPEED, mySpeed); } os.closeTag(); }
void ROPerson::Walk::saveAsXML(OutputDevice& os, const bool extended) const { os.openTag(SUMO_TAG_WALK); std::string comment = ""; if (extended && cost >= 0.) { os.writeAttr(SUMO_ATTR_COST, cost); } if (dur > 0) { os.writeAttr(SUMO_ATTR_DURATION, dur); } if (v > 0) { os.writeAttr(SUMO_ATTR_SPEED, v); } os.writeAttr(SUMO_ATTR_EDGES, edges); if (dep != 0.) { os.writeAttr(SUMO_ATTR_DEPARTPOS, dep); } if (arr != 0. && destStop == "") { os.writeAttr(SUMO_ATTR_ARRIVALPOS, arr); } if (destStop != "") { os.writeAttr(SUMO_ATTR_BUS_STOP, destStop); const std::string name = RONet::getInstance()->getStoppingPlaceName(destStop); if (name != "") { comment = " <!-- " + name + " -->"; } } os.closeTag(comment); }
void ROPerson::Ride::saveAsXML(OutputDevice& os, const bool extended) const { os.openTag(SUMO_TAG_RIDE); std::string comment = ""; if (extended && cost >= 0.) { os.writeAttr(SUMO_ATTR_COST, cost); } if (from != nullptr) { os.writeAttr(SUMO_ATTR_FROM, from->getID()); } if (to != nullptr) { os.writeAttr(SUMO_ATTR_TO, to->getID()); } if (destStop != "") { os.writeAttr(SUMO_ATTR_BUS_STOP, destStop); const std::string name = RONet::getInstance()->getStoppingPlaceName(destStop); if (name != "") { comment = " <!-- " + name + " -->"; } } os.writeAttr(SUMO_ATTR_LINES, lines); if (intended != "" && intended != lines) { os.writeAttr(SUMO_ATTR_INTENDED, intended); } if (depart >= 0) { os.writeAttr(SUMO_ATTR_DEPART, time2string(depart)); } os.closeTag(comment); }
void ODMatrix::writeFlows(const SUMOTime begin, const SUMOTime end, OutputDevice& dev, bool noVtype, const std::string& prefix, bool asProbability) { if (myContainer.size() == 0) { return; } int flowName = 0; sortByBeginTime(); // recheck begin time for (std::vector<ODCell*>::const_iterator i = myContainer.begin(); i != myContainer.end(); ++i) { const ODCell* const c = *i; if (c->end > begin && c->begin < end) { dev.openTag(SUMO_TAG_FLOW).writeAttr(SUMO_ATTR_ID, prefix + toString(flowName++)); dev.writeAttr(SUMO_ATTR_BEGIN, time2string(c->begin)); dev.writeAttr(SUMO_ATTR_END, time2string(c->end)); if (!asProbability) { dev.writeAttr(SUMO_ATTR_NUMBER, int(c->vehicleNumber)); } else { const double probability = float(c->vehicleNumber) / STEPS2TIME(c->end - c->begin); if (probability > 1) { WRITE_WARNING("Flow density of " + toString(probability) + " vehicles per second, cannot be represented with a simple probability. Falling back to even spacing."); dev.writeAttr(SUMO_ATTR_NUMBER, int(c->vehicleNumber)); } else { dev.setPrecision(6); dev.writeAttr(SUMO_ATTR_PROB, probability); dev.setPrecision(); } } writeDefaultAttrs(dev, noVtype, *i); dev.closeTag(); } } }
void MSPerson::MSPersonStage_Waiting::routeOutput(OutputDevice& os) const { os.openTag("stop").writeAttr(SUMO_ATTR_LANE, getDestination().getID()); if (myWaitingDuration >= 0) { os.writeAttr(SUMO_ATTR_DURATION, time2string(myWaitingDuration)); } if (myWaitingUntil >= 0) { os.writeAttr(SUMO_ATTR_UNTIL, time2string(myWaitingUntil)); } os.closeTag(); }
void MSDevice_Tripinfo::saveState(OutputDevice& out) const { out.openTag(SUMO_TAG_DEVICE); out.writeAttr(SUMO_ATTR_ID, getID()); std::vector<std::string> internals; internals.push_back(myDepartLane); internals.push_back(toString(myDepartPosLat)); internals.push_back(toString(myDepartSpeed)); out.writeAttr(SUMO_ATTR_STATE, toString(internals)); out.closeTag(); }
// =========================================================================== // method definitions // =========================================================================== void MSFullExport::write(OutputDevice& of, SUMOTime timestep) { of.openTag("data") << " timestep=\"" << time2string(timestep) << "\""; //Vehicles writeVehicles(of); //Edges writeEdge(of); //TrafficLights writeTLS(of, timestep); of.closeTag(); }
void MSVehicleTransfer::saveState(OutputDevice& out) const { for (VehicleInfVector::const_iterator it = myVehicles.begin(); it != myVehicles.end(); ++it) { out.openTag(SUMO_TAG_VEHICLETRANSFER); out.writeAttr(SUMO_ATTR_ID, it->myVeh->getID()); out.writeAttr(SUMO_ATTR_DEPART, it->myProceedTime); if (it->myParking) { out.writeAttr(SUMO_ATTR_PARKING, it->myVeh->getLane()->getID()); } out.closeTag(); } }
void MSContainer::routeOutput(OutputDevice& os) const { os.openTag(SUMO_TAG_CONTAINER).writeAttr(SUMO_ATTR_ID, getID()).writeAttr(SUMO_ATTR_DEPART, time2string(getDesiredDepart())); if (myStep == myPlan->end()) { os.writeAttr("arrival", time2string(MSNet::getInstance()->getCurrentTimeStep())); } for (MSTransportablePlan::const_iterator i = myPlan->begin(); i != myPlan->end(); ++i) { (*i)->routeOutput(os); } os.closeTag(); os.lf(); }
void MSInsertionControl::saveState(OutputDevice& out) { // save flow states for (const Flow& flow : myFlows) { out.openTag(SUMO_TAG_FLOWSTATE); out.writeAttr(SUMO_ATTR_ID, flow.pars->id); out.writeAttr(SUMO_ATTR_INDEX, flow.index); if (flow.pars->wasSet(VEHPARS_FORCE_REROUTE)) { out.writeAttr(SUMO_ATTR_REROUTE, true); } out.closeTag(); } }