Пример #1
0
void
MSDevice_Vehroutes::generateOutput() const {
    OutputDevice& routeOut = OutputDevice::getDeviceByOption("vehroute-output");
    OutputDevice_String od(routeOut.isBinary(), 1);
    od.openTag(SUMO_TAG_VEHICLE).writeAttr(SUMO_ATTR_ID, myHolder.getID());
    if (myHolder.getVehicleType().getID() != DEFAULT_VTYPE_ID) {
        od.writeAttr(SUMO_ATTR_TYPE, myHolder.getVehicleType().getID());
    }
    od.writeAttr(SUMO_ATTR_DEPART, time2string(myHolder.getDeparture()));
    if (myHolder.hasArrived()) {
        od.writeAttr("arrival", time2string(MSNet::getInstance()->getCurrentTimeStep()));
    }
    if (myWithTaz) {
        od.writeAttr(SUMO_ATTR_FROM_TAZ, myHolder.getParameter().fromTaz).writeAttr(SUMO_ATTR_TO_TAZ, myHolder.getParameter().toTaz);
    }
    if (myReplacedRoutes.size() > 0) {
        od.openTag(SUMO_TAG_ROUTE_DISTRIBUTION);
        for (unsigned int i = 0; i < myReplacedRoutes.size(); ++i) {
            writeXMLRoute(od, i);
        }
    }
    writeXMLRoute(od);
    if (myReplacedRoutes.size() > 0) {
        od.closeTag();
    }
    od.closeTag();
    od.lf();
    if (mySorted) {
        myRouteInfos[myHolder.getDeparture()] += od.getString();
        myDepartureCounts[myHolder.getDeparture()]--;
        std::map<const SUMOTime, int>::iterator it = myDepartureCounts.begin();
        while (it != myDepartureCounts.end() && it->second == 0) {
            routeOut << myRouteInfos[it->first];
            myRouteInfos.erase(it->first);
            myDepartureCounts.erase(it);
            it = myDepartureCounts.begin();
        }
    } else {
        routeOut << od.getString();
    }
}
void
MSDevice_Vehroutes::generateOutput() const {
    OutputDevice& routeOut = OutputDevice::getDeviceByOption("vehroute-output");
    OutputDevice_String od(routeOut.isBinary(), 1);
    const SUMOTime departure = myIntendedDepart ? myHolder.getParameter().depart : myHolder.getDeparture();
    od.openTag(SUMO_TAG_VEHICLE).writeAttr(SUMO_ATTR_ID, myHolder.getID());
    if (myHolder.getVehicleType().getID() != DEFAULT_VTYPE_ID) {
        od.writeAttr(SUMO_ATTR_TYPE, myHolder.getVehicleType().getID());
    }
    od.writeAttr(SUMO_ATTR_DEPART, time2string(departure));
    if (myHolder.hasArrived()) {
        od.writeAttr("arrival", time2string(MSNet::getInstance()->getCurrentTimeStep()));
    }
    if (myWithTaz) {
        od.writeAttr(SUMO_ATTR_FROM_TAZ, myHolder.getParameter().fromTaz).writeAttr(SUMO_ATTR_TO_TAZ, myHolder.getParameter().toTaz);
    }
    if (myDUAStyle) {
        const RandomDistributor<const MSRoute*>* const routeDist = MSRoute::distDictionary("!" + myHolder.getID());
        if (routeDist != 0) {
            const std::vector<const MSRoute*>& routes = routeDist->getVals();
            unsigned index = 0;
            while (index < routes.size() && routes[index] != myCurrentRoute) {
                ++index;
            }
            od.openTag(SUMO_TAG_ROUTE_DISTRIBUTION).writeAttr(SUMO_ATTR_LAST, index);
            const std::vector<SUMOReal>& probs = routeDist->getProbs();
            for (unsigned int i = 0; i < routes.size(); ++i) {
                od.setPrecision();
                od.openTag(SUMO_TAG_ROUTE).writeAttr(SUMO_ATTR_COST, routes[i]->getCosts());
                od.setPrecision(8);
                od.writeAttr(SUMO_ATTR_PROB, probs[i]);
                od.setPrecision();
                od << " edges=\"";
                routes[i]->writeEdgeIDs(od, *routes[i]->begin());
                (od << "\"").closeTag();
            }
            od.closeTag();
        } else {
            writeXMLRoute(od);
        }
    } else {
        if (myReplacedRoutes.size() > 0) {
            od.openTag(SUMO_TAG_ROUTE_DISTRIBUTION);
            for (unsigned int i = 0; i < myReplacedRoutes.size(); ++i) {
                writeXMLRoute(od, i);
            }
        }
        writeXMLRoute(od);
        if (myReplacedRoutes.size() > 0) {
            od.closeTag();
        }
    }
    od.closeTag();
    od.lf();
    if (mySorted) {
        myRouteInfos[departure][myHolder.getID()] = od.getString();
        myDepartureCounts[departure]--;
        std::map<const SUMOTime, int>::iterator it = myDepartureCounts.begin();
        while (it != myDepartureCounts.end() && it->second == 0) {
            std::map<const std::string, std::string>& infos = myRouteInfos[it->first];
            for (std::map<const std::string, std::string>::const_iterator it2 = infos.begin(); it2 != infos.end(); ++it2) {
                routeOut << it2->second;
            }
            myRouteInfos.erase(it->first);
            myDepartureCounts.erase(it);
            it = myDepartureCounts.begin();
        }
    } else {
        routeOut << od.getString();
    }
}