int main(int argc, char** argv) { OptionsCont& oc = OptionsCont::getOptions(); // give some application descriptions oc.setApplicationDescription("Road network generator for the microscopic road traffic simulation SUMO."); oc.setApplicationName("netgen", "SUMO netgen Version " + (std::string)VERSION_STRING); int ret = 0; try { // initialise the application system (messaging, xml, options) XMLSubSys::init(false); fillOptions(); OptionsIO::getOptions(true, argc, argv); if (oc.processMetaOptions(argc < 2)) { SystemFrame::close(); return 0; } MsgHandler::initOutputOptions(); if (!checkOptions()) { throw ProcessError(); } RandHelper::initRandGlobal(); NBNetBuilder nb; nb.applyOptions(oc); // build the netgen-network description NGNet* net = buildNetwork(nb); // ... and we have to do this... oc.resetWritable(); // transfer to the netbuilding structures net->toNB(); delete net; // report generated structures WRITE_MESSAGE(" Generation done;"); WRITE_MESSAGE(" " + toString<int>(nb.getNodeCont().size()) + " nodes generated."); WRITE_MESSAGE(" " + toString<int>(nb.getEdgeCont().size()) + " edges generated."); nb.compute(oc); NWFrame::writeNetwork(oc, nb); } catch (ProcessError& e) { if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) { WRITE_ERROR(e.what()); } MsgHandler::getErrorInstance()->inform("Quitting (on error).", false); ret = 1; #ifndef _DEBUG } catch (...) { MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false); ret = 1; #endif } OutputDevice::closeAll(); SystemFrame::close(); if (ret == 0) { std::cout << "Success." << std::endl; } return ret; }
void NBTrafficLightLogicCont::computeLogics(NBEdgeCont &ec, OptionsCont &oc) throw() { unsigned int no = 0; for (DefinitionContType::iterator i=myDefinitions.begin(); i!=myDefinitions.end(); i++) { std::string id = (*i).first; if (myComputed.find(id)!=myComputed.end()) { WRITE_WARNING("Traffic light '" + id + "' was already built."); continue; } // build program NBTrafficLightDefinition *def = (*i).second; NBTrafficLightLogic *built = def->compute(ec, oc); if (built==0) { WRITE_WARNING("Could not build traffic lights '" + id + "'"); continue; } // compute offset SUMOTime T = built->getDuration(); if (find(myHalfOffsetTLS.begin(), myHalfOffsetTLS.end(), id)!=myHalfOffsetTLS.end()) { built->setOffset((SUMOTime)(T/2.)); } if (find(myQuarterOffsetTLS.begin(), myQuarterOffsetTLS.end(), id)!=myQuarterOffsetTLS.end()) { built->setOffset((SUMOTime)(T/4.)); } // and insert the result after computation myComputed[(*i).first] = built; no++; } WRITE_MESSAGE(toString<int>(no) + " traffic light(s) computed."); }
void NIImporter_SUMO::addConnection(const SUMOSAXAttributes& attrs) { bool ok = true; std::string fromID = attrs.getStringReporting(SUMO_ATTR_FROM, 0, ok); if (myEdges.count(fromID) == 0) { WRITE_ERROR("Unknown edge '" + fromID + "' given in connection."); return; } EdgeAttrs* from = myEdges[fromID]; Connection conn; conn.toEdgeID = attrs.getStringReporting(SUMO_ATTR_TO, 0, ok); unsigned int fromLaneIdx = attrs.getIntReporting(SUMO_ATTR_FROM_LANE, 0, ok); conn.toLaneIdx = attrs.getIntReporting(SUMO_ATTR_TO_LANE, 0, ok); conn.tlID = attrs.getOptStringReporting(SUMO_ATTR_TLID, 0, ok, ""); conn.mayDefinitelyPass = attrs.getOptBoolReporting(SUMO_ATTR_PASS, 0, ok, false); const size_t suffixSize = NBRampsComputer::ADDED_ON_RAMP_EDGE.size(); if (!conn.mayDefinitelyPass && conn.toEdgeID.size() > suffixSize && conn.toEdgeID.substr(conn.toEdgeID.size() - suffixSize) == NBRampsComputer::ADDED_ON_RAMP_EDGE) { WRITE_MESSAGE("Infering connection attribute pass=\"1\" from to-edge id '" + conn.toEdgeID + "'"); conn.mayDefinitelyPass = true; } if (conn.tlID != "") { conn.tlLinkNo = attrs.getIntReporting(SUMO_ATTR_TLLINKINDEX, 0, ok); } if (from->lanes.size() <= (size_t) fromLaneIdx) { WRITE_ERROR("Invalid lane index '" + toString(fromLaneIdx) + "' for connection from '" + fromID + "'."); return; } from->lanes[fromLaneIdx]->connections.push_back(conn); }
void MSNet::closeSimulation(SUMOTime start) { if (myLogExecutionTime) { long duration = SysUtils::getCurrentMillis() - mySimBeginMillis; std::ostringstream msg; msg << "Performance: " << "\n" << " Duration: " << duration << " ms" << "\n"; if (duration != 0) { msg << " Real time factor: " << (STEPS2TIME(myStep - start) * 1000. / (SUMOReal)duration) << "\n"; msg.setf(std::ios::fixed , std::ios::floatfield); // use decimal format msg.setf(std::ios::showpoint); // print decimal point msg << " UPS: " << ((SUMOReal) myVehiclesMoved * 1000. / (SUMOReal) duration) << "\n"; } const std::string scaleNotice = ((myVehicleControl->getLoadedVehicleNo() != myVehicleControl->getDepartedVehicleNo()) ? " (Loaded: " + toString(myVehicleControl->getLoadedVehicleNo()) + ")" : ""); msg << "Vehicles: " << "\n" << " Emitted: " << myVehicleControl->getDepartedVehicleNo() << scaleNotice << "\n" << " Running: " << myVehicleControl->getRunningVehicleNo() << "\n" << " Waiting: " << myInserter->getWaitingVehicleNo() << "\n"; WRITE_MESSAGE(msg.str()); } myDetectorControl->close(myStep); #ifndef NO_TRACI traci::TraCIServer::close(); #endif }
void ROLoader::openRoutes(RONet& net) { // build loader // load relevant elements from additinal file bool ok = openTypedRoutes("additional-files", net); // load sumo-routes when wished ok &= openTypedRoutes("route-files", net); // load the XML-trip definitions when wished ok &= openTypedRoutes("trip-files", net); // load the sumo-alternative file when wished ok &= openTypedRoutes("alternative-files", net); // load the amount definitions if wished ok &= openTypedRoutes("flow-files", net); // check if (ok) { myLoaders.loadNext(string2time(myOptions.getString("begin"))); if (!MsgHandler::getErrorInstance()->wasInformed() && !net.furtherStored()) { throw ProcessError("No route input specified or all routes were invalid."); } // skip routes prior to the begin time if (!myOptions.getBool("unsorted-input")) { WRITE_MESSAGE("Skipped until: " + time2string(myLoaders.getFirstLoadTime())); } } }
int MSNet::simulate(SUMOTime start, SUMOTime stop) { // the simulation loop std::string quitMessage = ""; myStep = start; do { if (myLogStepNumber) { preSimStepOutput(); } simulationStep(); if (myLogStepNumber) { postSimStepOutput(); } MSNet::SimulationState state = simulationState(stop); #ifndef NO_TRACI if (state!=SIMSTATE_RUNNING) { if (OptionsCont::getOptions().getInt("remote-port")!=0&&!traci::TraCIServer::wasClosed()) { state = SIMSTATE_RUNNING; } } #endif if (state!=SIMSTATE_RUNNING) { quitMessage = "Simulation End: " + getStateMessage(state); } } while (quitMessage==""); WRITE_MESSAGE(quitMessage); // exit simulation loop closeSimulation(start); return 0; }
void MSSOTLE2Sensors::buildCountSensorForLane(MSLane* lane, NLDetectorBuilder& nb) { SUMOReal sensorPos; SUMOReal lensorLength; MSE2Collector* newSensor = NULL; //Check not to have more than a sensor for lane if (m_sensorMap.find(lane->getID()) == m_sensorMap.end()) { //Check and set zero if the lane is not long enough for the specified sensor start sensorPos = COUNT_SENSOR_START <= lane->getLength() ? COUNT_SENSOR_START : 0; //Original: SUMOReal sensorLength = INPUT_COUNT_SENSOR_LENGTH; //Check and trim if the lane is not long enough for the specified sensor length lensorLength = sensorLength <= (lane->getLength() - sensorPos) ? sensorLength : (lane->getLength() - sensorPos); //TODO check this lengths DBG( std::ostringstream phero_str; phero_str << " lane " << lane->getID() << " sensorPos= " << sensorPos << " ,SENSOR_START " << SENSOR_START << "; lane->getLength = " << lane->getLength() << " ,lensorLength= " << lensorLength << " ,SENSOR_LENGTH= " << INPUT_SENSOR_LENGTH; WRITE_MESSAGE( "MSSOTLE2Sensors::buildSensorForLane::" + phero_str.str()); )
// =========================================================================== // method definitions // =========================================================================== TraCIServer::TraCIServer(const SUMOTime begin, const int port) : mySocket(0), myTargetTime(begin), myDoingSimStep(false), myAmEmbedded(port == 0), myLaneTree(0) { myVehicleStateChanges[MSNet::VEHICLE_STATE_BUILT] = std::vector<std::string>(); myVehicleStateChanges[MSNet::VEHICLE_STATE_DEPARTED] = std::vector<std::string>(); myVehicleStateChanges[MSNet::VEHICLE_STATE_STARTING_TELEPORT] = std::vector<std::string>(); myVehicleStateChanges[MSNet::VEHICLE_STATE_ENDING_TELEPORT] = std::vector<std::string>(); myVehicleStateChanges[MSNet::VEHICLE_STATE_ARRIVED] = std::vector<std::string>(); myVehicleStateChanges[MSNet::VEHICLE_STATE_NEWROUTE] = std::vector<std::string>(); myVehicleStateChanges[MSNet::VEHICLE_STATE_STARTING_PARKING] = std::vector<std::string>(); myVehicleStateChanges[MSNet::VEHICLE_STATE_ENDING_PARKING] = std::vector<std::string>(); myVehicleStateChanges[MSNet::VEHICLE_STATE_STARTING_STOP] = std::vector<std::string>(); myVehicleStateChanges[MSNet::VEHICLE_STATE_ENDING_STOP] = std::vector<std::string>(); MSNet::getInstance()->addVehicleStateListener(this); myExecutors[CMD_GET_INDUCTIONLOOP_VARIABLE] = &TraCIServerAPI_InductionLoop::processGet; myExecutors[CMD_GET_AREAL_DETECTOR_VARIABLE] = &TraCIServerAPI_ArealDetector::processGet; myExecutors[CMD_GET_MULTI_ENTRY_EXIT_DETECTOR_VARIABLE] = &TraCIServerAPI_MeMeDetector::processGet; myExecutors[CMD_GET_TL_VARIABLE] = &TraCIServerAPI_TLS::processGet; myExecutors[CMD_SET_TL_VARIABLE] = &TraCIServerAPI_TLS::processSet; myExecutors[CMD_GET_LANE_VARIABLE] = &TraCIServerAPI_Lane::processGet; myExecutors[CMD_SET_LANE_VARIABLE] = &TraCIServerAPI_Lane::processSet; myExecutors[CMD_GET_VEHICLE_VARIABLE] = &TraCIServerAPI_Vehicle::processGet; myExecutors[CMD_SET_VEHICLE_VARIABLE] = &TraCIServerAPI_Vehicle::processSet; myExecutors[CMD_GET_VEHICLETYPE_VARIABLE] = &TraCIServerAPI_VehicleType::processGet; myExecutors[CMD_SET_VEHICLETYPE_VARIABLE] = &TraCIServerAPI_VehicleType::processSet; myExecutors[CMD_GET_ROUTE_VARIABLE] = &TraCIServerAPI_Route::processGet; myExecutors[CMD_SET_ROUTE_VARIABLE] = &TraCIServerAPI_Route::processSet; myExecutors[CMD_GET_POI_VARIABLE] = &TraCIServerAPI_POI::processGet; myExecutors[CMD_SET_POI_VARIABLE] = &TraCIServerAPI_POI::processSet; myExecutors[CMD_GET_POLYGON_VARIABLE] = &TraCIServerAPI_Polygon::processGet; myExecutors[CMD_SET_POLYGON_VARIABLE] = &TraCIServerAPI_Polygon::processSet; myExecutors[CMD_GET_JUNCTION_VARIABLE] = &TraCIServerAPI_Junction::processGet; myExecutors[CMD_GET_EDGE_VARIABLE] = &TraCIServerAPI_Edge::processGet; myExecutors[CMD_SET_EDGE_VARIABLE] = &TraCIServerAPI_Edge::processSet; myExecutors[CMD_GET_SIM_VARIABLE] = &TraCIServerAPI_Simulation::processGet; myExecutors[CMD_SET_SIM_VARIABLE] = &TraCIServerAPI_Simulation::processSet; myDoCloseConnection = false; // display warning if internal lanes are not used if (!MSGlobals::gUsingInternalLanes) { WRITE_WARNING("Starting TraCI without using internal lanes!"); MsgHandler::getWarningInstance()->inform("Vehicles will jump over junctions.", false); MsgHandler::getWarningInstance()->inform("Use without option --no-internal-links to avoid unexpected behavior", false); } if (!myAmEmbedded) { try { WRITE_MESSAGE("***Starting server on port " + toString(port) + " ***"); mySocket = new tcpip::Socket(port); mySocket->accept(); // When got here, a client has connected } catch (tcpip::SocketException& e) { throw ProcessError(e.what()); } } }
void NIImporter_OpenStreetMap::NodesHandler::myStartElement(int element, const SUMOSAXAttributes& attrs) { ++myHierarchyLevel; if (element == SUMO_TAG_NODE) { bool ok = true; if (myHierarchyLevel != 2) { WRITE_ERROR("Node element on wrong XML hierarchy level (id='" + toString(attrs.getIntReporting(SUMO_ATTR_ID, 0, ok)) + "', level='" + toString(myHierarchyLevel) + "')."); return; } int id = attrs.getIntReporting(SUMO_ATTR_ID, 0, ok); std::string action = attrs.hasAttribute("action") ? attrs.getStringSecure("action", "") : ""; if (action == "delete") { return; } if (!ok) { return; } myLastNodeID = -1; if (myToFill.find(id) == myToFill.end()) { myLastNodeID = id; // assume we are loading multiple files... // ... so we won't report duplicate nodes bool ok = true; double tlat, tlon; std::istringstream lon(attrs.getStringReporting(SUMO_ATTR_LON, toString(id).c_str(), ok)); if (!ok) { return; } lon >> tlon; if (lon.fail()) { WRITE_ERROR("Node's '" + toString(id) + "' lon information is not numeric."); return; } std::istringstream lat(attrs.getStringReporting(SUMO_ATTR_LAT, toString(id).c_str(), ok)); if (!ok) { return; } lat >> tlat; if (lat.fail()) { WRITE_ERROR("Node's '" + toString(id) + "' lat information is not numeric."); return; } NIOSMNode* toAdd = new NIOSMNode(); toAdd->id = id; toAdd->tlsControlled = false; toAdd->lat = tlat; toAdd->lon = tlon; myIsInValidNodeTag = true; std::set<NIOSMNode*, CompareNodes>::iterator similarNode = myUniqueNodes.find(toAdd); if (similarNode == myUniqueNodes.end()) { myUniqueNodes.insert(toAdd); } else { delete toAdd; toAdd = *similarNode; WRITE_MESSAGE("Found duplicate nodes. Substituting " + toString(id) + " with " + toString(toAdd->id)); } myToFill[id] = toAdd; }
void NILoader::load(OptionsCont& oc) { // load types first NIXMLTypesHandler* handler = new NIXMLTypesHandler(myNetBuilder.getTypeCont()); loadXMLType(handler, oc.getStringVector("type-files"), "types"); // try to load height data so it is ready for use by other importers #ifdef HAVE_INTERNAL HeightMapper::loadIfSet(oc); #endif // try to load using different methods NIImporter_SUMO::loadNetwork(oc, myNetBuilder); NIImporter_RobocupRescue::loadNetwork(oc, myNetBuilder); NIImporter_OpenStreetMap::loadNetwork(oc, myNetBuilder); NIImporter_VISUM::loadNetwork(oc, myNetBuilder); NIImporter_ArcView::loadNetwork(oc, myNetBuilder); NIImporter_Vissim::loadNetwork(oc, myNetBuilder); NIImporter_DlrNavteq::loadNetwork(oc, myNetBuilder); NIImporter_OpenDrive::loadNetwork(oc, myNetBuilder); NIImporter_MATSim::loadNetwork(oc, myNetBuilder); NIImporter_ITSUMO::loadNetwork(oc, myNetBuilder); if (oc.getBool("tls.discard-loaded") || oc.getBool("tls.discard-simple")) { myNetBuilder.getNodeCont().discardTrafficLights(myNetBuilder.getTLLogicCont(), oc.getBool("tls.discard-simple"), oc.getBool("tls.guess-signals")); size_t removed = myNetBuilder.getTLLogicCont().getNumExtracted(); if (removed > 0) { WRITE_MESSAGE(" Removed " + toString(removed) + " traffic lights before loading plain-XML"); } } loadXML(oc); // check the loaded structures if (myNetBuilder.getNodeCont().size() == 0) { throw ProcessError("No nodes loaded."); } if (myNetBuilder.getEdgeCont().size() == 0) { throw ProcessError("No edges loaded."); } // report loaded structures WRITE_MESSAGE(" Import done:"); if (myNetBuilder.getDistrictCont().size() > 0) { WRITE_MESSAGE(" " + toString(myNetBuilder.getDistrictCont().size()) + " districts loaded."); } WRITE_MESSAGE(" " + toString(myNetBuilder.getNodeCont().size()) + " nodes loaded."); if (myNetBuilder.getTypeCont().size() > 0) { WRITE_MESSAGE(" " + toString(myNetBuilder.getTypeCont().size()) + " types loaded."); } WRITE_MESSAGE(" " + toString(myNetBuilder.getEdgeCont().size()) + " edges loaded."); if (myNetBuilder.getEdgeCont().getNoEdgeSplits() > 0) { WRITE_MESSAGE("The split of edges was performed " + toString(myNetBuilder.getEdgeCont().getNoEdgeSplits()) + " times."); } if (GeoConvHelper::getProcessing().usingGeoProjection()) { WRITE_MESSAGE("Proj projection parameters used: '" + GeoConvHelper::getProcessing().getProjString() + "'."); } }
int MSNet::simulate(SUMOTime start, SUMOTime stop) { // report the begin when wished WRITE_MESSAGE("Simulation started with time: " + time2string(start)); // the simulation loop MSNet::SimulationState state = SIMSTATE_RUNNING; myStep = start; // preload the routes especially for TraCI loadRoutes(); #ifndef NO_TRACI #ifdef HAVE_PYTHON if (OptionsCont::getOptions().isSet("python-script")) { traci::TraCIServer::runEmbedded(OptionsCont::getOptions().getString("python-script")); closeSimulation(start); WRITE_MESSAGE("Simulation ended at time: " + time2string(getCurrentTimeStep())); WRITE_MESSAGE("Reason: Script ended"); return 0; } #endif #endif while (state == SIMSTATE_RUNNING) { if (myLogStepNumber) { preSimStepOutput(); } simulationStep(); if (myLogStepNumber) { postSimStepOutput(); } state = simulationState(stop); #ifndef NO_TRACI if (state != SIMSTATE_RUNNING) { if (OptionsCont::getOptions().getInt("remote-port") != 0 && !traci::TraCIServer::wasClosed()) { state = SIMSTATE_RUNNING; } } #endif } // report the end when wished WRITE_MESSAGE("Simulation ended at time: " + time2string(getCurrentTimeStep())); WRITE_MESSAGE("Reason: " + getStateMessage(state)); // exit simulation loop closeSimulation(start); return 0; }
bool ShapeHandler::loadFiles(const std::vector<std::string>& files, ShapeHandler& sh) { for (std::vector<std::string>::const_iterator fileIt = files.begin(); fileIt != files.end(); ++fileIt) { if (!XMLSubSys::runParser(sh, *fileIt, false)) { WRITE_MESSAGE("Loading of shapes from " + *fileIt + " failed."); return false; } } return true; }
SUMOTime RONet::saveAndRemoveRoutesUntil(OptionsCont& options, SUMOAbstractRouter<ROEdge, ROVehicle>& router, SUMOTime time) { checkFlows(time); SUMOTime lastTime = -1; // write all vehicles (and additional structures) while (myVehicles.size() != 0 || myPersons.size() != 0) { // get the next vehicle and person const ROVehicle* const veh = myVehicles.getTopVehicle(); const SUMOTime vehicleTime = veh == 0 ? SUMOTime_MAX : veh->getDepartureTime(); PersonMap::iterator person = myPersons.begin(); const SUMOTime personTime = person == myPersons.end() ? SUMOTime_MAX : person->first; // check whether it shall not yet be computed if (vehicleTime > time && personTime > time) { lastTime = MIN2(vehicleTime, personTime); break; } if (vehicleTime < personTime) { // check whether to print the output if (lastTime != vehicleTime && lastTime != -1) { // report writing progress if (options.getInt("stats-period") >= 0 && ((int) vehicleTime % options.getInt("stats-period")) == 0) { WRITE_MESSAGE("Read: " + toString(myReadRouteNo) + ", Discarded: " + toString(myDiscardedRouteNo) + ", Written: " + toString(myWrittenRouteNo)); } } lastTime = vehicleTime; // ok, compute the route (try it) if (computeRoute(options, router, veh)) { // write the route veh->saveAllAsXML(*myRoutesOutput, myRouteAlternativesOutput, myTypesOutput, options.getBool("exit-times")); myWrittenRouteNo++; } else { myDiscardedRouteNo++; } // delete routes and the vehicle if (veh->getRouteDefinition()->getID()[0] == '!') { if (!myRoutes.erase(veh->getRouteDefinition()->getID())) { delete veh->getRouteDefinition(); } } myVehicles.erase(veh->getID()); } else { myRoutesOutput->writePreformattedTag(person->second); if (myRouteAlternativesOutput != 0) { myRouteAlternativesOutput->writePreformattedTag(person->second); } myPersons.erase(person); } } return lastTime; }
bool PushButtonLogic::pushButtonLogic(SUMOTime elapsed, bool pushButtonPressed, const MSPhaseDefinition* stage) { //pushbutton logic if (pushButtonPressed && elapsed >= (stage->duration * m_pushButtonScaleFactor)) { //If the stage duration has been passed // DBG( std::ostringstream oss; oss << m_prefix << "::pushButtonLogic pushButtonPressed elapsed " << elapsed << " stage duration " << (stage->duration * m_pushButtonScaleFactor); WRITE_MESSAGE(oss.str()); // ); return true; } return false; }
void RODFNet::computeTypes(RODFDetectorCon& detcont, bool sourcesStrict) const { PROGRESS_BEGIN_MESSAGE("Computing detector types"); const std::vector< RODFDetector*>& dets = detcont.getDetectors(); // build needed information. first buildDetectorEdgeDependencies(detcont); // compute detector types then for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) { if (isSource(**i, detcont, sourcesStrict)) { (*i)->setType(SOURCE_DETECTOR); mySourceNumber++; } if (isDestination(**i, detcont)) { (*i)->setType(SINK_DETECTOR); mySinkNumber++; } if ((*i)->getType() == TYPE_NOT_DEFINED) { (*i)->setType(BETWEEN_DETECTOR); myInBetweenNumber++; } } // recheck sources for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) { if ((*i)->getType() == SOURCE_DETECTOR && isFalseSource(**i, detcont)) { (*i)->setType(DISCARDED_DETECTOR); myInvalidNumber++; mySourceNumber--; } } // print results PROGRESS_DONE_MESSAGE(); WRITE_MESSAGE("Computed detector types:"); WRITE_MESSAGE(" " + toString(mySourceNumber) + " source detectors"); WRITE_MESSAGE(" " + toString(mySinkNumber) + " sink detectors"); WRITE_MESSAGE(" " + toString(myInBetweenNumber) + " in-between detectors"); WRITE_MESSAGE(" " + toString(myInvalidNumber) + " invalid detectors"); }
void NBNodeCont::printBuiltNodesStatistics() const { int numUnregulatedJunctions = 0; int numDeadEndJunctions = 0; int numPriorityJunctions = 0; int numRightBeforeLeftJunctions = 0; for (NodeCont::const_iterator i = myNodes.begin(); i != myNodes.end(); i++) { switch ((*i).second->getType()) { case NODETYPE_NOJUNCTION: ++numUnregulatedJunctions; break; case NODETYPE_DEAD_END: ++numDeadEndJunctions; break; case NODETYPE_PRIORITY_JUNCTION: case NODETYPE_TRAFFIC_LIGHT: ++numPriorityJunctions; break; case NODETYPE_RIGHT_BEFORE_LEFT: ++numRightBeforeLeftJunctions; break; case NODETYPE_DISTRICT: ++numRightBeforeLeftJunctions; break; case NODETYPE_UNKNOWN: break; default: break; } } WRITE_MESSAGE(" Node type statistics:"); WRITE_MESSAGE(" Unregulated junctions : " + toString(numUnregulatedJunctions)); if (numDeadEndJunctions > 0) { WRITE_MESSAGE(" Dead-end junctions : " + toString(numDeadEndJunctions)); } WRITE_MESSAGE(" Priority junctions : " + toString(numPriorityJunctions)); WRITE_MESSAGE(" Right-before-left junctions : " + toString(numRightBeforeLeftJunctions)); }
void SigmoidLogic::init(std::string prefix, const Parameterised* parameterised) { m_prefix = prefix; m_useSigmoid = parameterised->getParameter("PLATOON_USE_SIGMOID", "0") != "0"; m_k = TplConvert::_2SUMOReal(parameterised->getParameter("PLATOON_SIGMOID_K_VALUE", "1").c_str()); // DBG( WRITE_MESSAGE(m_prefix + "::SigmoidLogic::init use " + parameterised->getParameter("PLATOON_USE_SIGMOID", "0") + " k " + parameterised->getParameter("PLATOON_SIGMOID_K_VALUE", "1")); // for (int elapsed = 10; elapsed < 51; ++elapsed) // { // SUMOReal sigmoidValue = 1.0 / (1.0 + exp(-m_k * (elapsed - 31))); // std::ostringstream oss; // oss << "elapsed " << elapsed << " value " << sigmoidValue; // WRITE_MESSAGE(oss.str()) // } // ) }
void RODFNet::reportEmptyDetectors(RODFDetectorCon& detectors, RODFDetectorFlows& flows) { const std::vector<RODFDetector*>& dets = detectors.getDetectors(); for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) { bool remove = true; // check whether there is at least one entry with a flow larger than zero if (flows.knows((*i)->getID())) { remove = false; } if (remove) { WRITE_MESSAGE("Detector '" + (*i)->getID() + "' has no flow."); } } }
bool NLBuilder::load(const std::string& mmlWhat, const bool isNet) { if (!myOptions.isUsableFileList(mmlWhat)) { return false; } std::vector<std::string> files = myOptions.getStringVector(mmlWhat); for (std::vector<std::string>::const_iterator fileIt = files.begin(); fileIt != files.end(); ++fileIt) { PROGRESS_BEGIN_MESSAGE("Loading " + mmlWhat + " from '" + *fileIt + "'"); long before = SysUtils::getCurrentMillis(); if (!XMLSubSys::runParser(myXMLHandler, *fileIt, isNet)) { WRITE_MESSAGE("Loading of " + mmlWhat + " failed."); return false; } PROGRESS_TIME_MESSAGE(before); } return true; }
void NIImporter_DlrNavteq::TimeRestrictionsHandler::printSummary() { if (myConstructionEntries > 0) { char buff[1024]; std::ostringstream msg; strftime(buff, 1024, "%Y-%m-%d", localtime(&myCS_min)); msg << "Parsed " << myConstructionEntries << " construction entries between " << buff; strftime(buff, 1024, "%Y-%m-%d", localtime(&myCS_max)); msg << " and " << buff << ".\n"; strftime(buff, 1024, "%Y-%m-%d", localtime(&myConstructionTime)); msg << "Removed " << myRemovedEdges << " edges not yet constructed at " << buff << ".\n"; msg << " not yet started: " << myNotStarted << "\n"; msg << " under construction: " << myUnderConstruction << "\n"; msg << " finished: " << myFinished << "\n"; WRITE_MESSAGE(msg.str()); } }
void NIXMLTrafficLightsHandler::myEndElement(int element) { switch (element) { case SUMO_TAG_TLLOGIC: if (!myCurrentTL) { WRITE_ERROR("Unmatched closing tag for tl-logic."); } else { if (!myTLLCont.insert(myCurrentTL)) { WRITE_MESSAGE("Updating program '" + myCurrentTL->getProgramID() + "' for traffic light '" + myCurrentTL->getID() + "'"); } myCurrentTL = 0; } break; default: break; } }
void RODFNet::removeEmptyDetectors(RODFDetectorCon& detectors, RODFDetectorFlows& flows) { const std::vector<RODFDetector*>& dets = detectors.getDetectors(); for (std::vector<RODFDetector*>::const_iterator i = dets.begin(); i != dets.end();) { bool remove = true; // check whether there is at least one entry with a flow larger than zero if (flows.knows((*i)->getID())) { remove = false; } if (remove) { WRITE_MESSAGE("Removed detector '" + (*i)->getID() + "' because no flows for him exist."); flows.removeFlow((*i)->getID()); detectors.removeDetector((*i)->getID()); i = dets.begin(); } else { i++; } } }
void GNENet::computeEverything(GNEApplicationWindow* window, bool force) { if (!myNeedRecompute) { if (force) { window->setStatusBarText("Forced computing junctions ..."); } else { return; } } else { window->setStatusBarText("Computing junctions ..."); } // compute OptionsCont& oc = OptionsCont::getOptions(); computeAndUpdate(oc); WRITE_MESSAGE("\nFinished computing junctions."); window->getApp()->endWaitCursor(); window->setStatusBarText("Finished computing junctions."); update(); }
bool ROLoader::loadWeights(RONet& net, const std::string& optionName, const std::string& measure, bool useLanes) { // check whether the file exists if (!myOptions.isUsableFileList(optionName)) { return false; } // build and prepare the weights handler std::vector<SAXWeightsHandler::ToRetrieveDefinition*> retrieverDefs; // travel time, first (always used) EdgeFloatTimeLineRetriever_EdgeTravelTime ttRetriever(net); retrieverDefs.push_back(new SAXWeightsHandler::ToRetrieveDefinition("traveltime", !useLanes, ttRetriever)); // the measure to use, then EdgeFloatTimeLineRetriever_EdgeWeight eRetriever(net); if (measure != "traveltime") { std::string umeasure = measure; if (measure == "CO" || measure == "CO2" || measure == "HC" || measure == "PMx" || measure == "NOx" || measure == "fuel") { umeasure = measure + "_perVeh"; } retrieverDefs.push_back(new SAXWeightsHandler::ToRetrieveDefinition(umeasure, !useLanes, eRetriever)); } // set up handler SAXWeightsHandler handler(retrieverDefs, ""); // go through files std::vector<std::string> files = myOptions.getStringVector(optionName); for (std::vector<std::string>::const_iterator fileIt = files.begin(); fileIt != files.end(); ++fileIt) { PROGRESS_BEGIN_MESSAGE("Loading precomputed net weights from '" + *fileIt + "'"); if (XMLSubSys::runParser(handler, *fileIt)) { PROGRESS_DONE_MESSAGE(); } else { WRITE_MESSAGE("failed."); return false; } } // build edge-internal time lines const std::map<std::string, ROEdge*>& edges = net.getEdgeMap(); for (std::map<std::string, ROEdge*>::const_iterator i = edges.begin(); i != edges.end(); ++i) { (*i).second->buildTimeLines(measure); } return true; }
void ROLoader::processRoutes(SUMOTime start, SUMOTime end, RONet& net, SUMOAbstractRouter<ROEdge, ROVehicle>& router) { SUMOTime absNo = end - start; // skip routes that begin before the simulation's begin // loop till the end bool endReached = false; bool errorOccured = false; const SUMOTime firstStep = myLoaders.getFirstLoadTime(); SUMOTime lastStep = firstStep; for (SUMOTime time = firstStep; time < end && !errorOccured && !endReached; time += DELTA_T) { writeStats(time, start, absNo); myLoaders.loadNext(time); net.saveAndRemoveRoutesUntil(myOptions, router, time); endReached = !net.furtherStored(); lastStep = time; errorOccured = MsgHandler::getErrorInstance()->wasInformed() && !myOptions.getBool("ignore-errors"); } if (myLogSteps) { WRITE_MESSAGE("Routes found between time steps " + time2string(firstStep) + " and " + time2string(lastStep) + "."); } }
/* ------------------------------------------------------------------------- * main * ----------------------------------------------------------------------- */ void single(const std::string& of, const std::string& className, SUMOEmissionClass c, SUMOReal vMin, SUMOReal vMax, SUMOReal vStep, SUMOReal aMin, SUMOReal aMax, SUMOReal aStep, SUMOReal sMin, SUMOReal sMax, SUMOReal sStep, bool verbose) { if (verbose) { WRITE_MESSAGE("Writing map of '" + className + "' into '" + of + "'."); } std::ofstream o(of.c_str()); for (SUMOReal v = vMin; v <= vMax; v += vStep) { for (SUMOReal a = aMin; a <= aMax; a += aStep) { for (SUMOReal s = sMin; s <= sMax; s += sStep) { const PollutantsInterface::Emissions result = PollutantsInterface::computeAll(c, v, a, s); o << v << ";" << a << ";" << s << ";" << "CO" << ";" << result.CO << std::endl; o << v << ";" << a << ";" << s << ";" << "CO2" << ";" << result.CO2 << std::endl; o << v << ";" << a << ";" << s << ";" << "HC" << ";" << result.HC << std::endl; o << v << ";" << a << ";" << s << ";" << "PMx" << ";" << result.PMx << std::endl; o << v << ";" << a << ";" << s << ";" << "NOx" << ";" << result.NOx << std::endl; o << v << ";" << a << ";" << s << ";" << "fuel" << ";" << result.fuel << std::endl; } } } }
void RORouteDef::repairCurrentRoute(SUMOAbstractRouter<ROEdge, ROVehicle>& router, SUMOTime begin, const ROVehicle& veh) const { const std::vector<const ROEdge*>& oldEdges = myAlternatives[0]->getEdgeVector(); if (oldEdges.size() == 0) { MsgHandler* m = OptionsCont::getOptions().getBool("ignore-errors") ? MsgHandler::getWarningInstance() : MsgHandler::getErrorInstance(); m->inform("Could not repair empty route of vehicle '" + veh.getID() + "'."); return; } std::vector<const ROEdge*> newEdges; if (oldEdges.size() == 1) { /// should happen with jtrrouter only router.compute(oldEdges.front(), oldEdges.front(), &veh, begin, newEdges); } else { newEdges.push_back(*(oldEdges.begin())); for (std::vector<const ROEdge*>::const_iterator i = oldEdges.begin() + 1; i != oldEdges.end(); ++i) { if ((*(i - 1))->isConnectedTo(*i)) { newEdges.push_back(*i); } else { std::vector<const ROEdge*> edges; router.compute(*(i - 1), *i, &veh, begin, edges); if (edges.size() == 0) { return; } std::copy(edges.begin() + 1, edges.end(), back_inserter(newEdges)); } } } if (myAlternatives[0]->getEdgeVector() != newEdges) { WRITE_MESSAGE("Repaired route of vehicle '" + veh.getID() + "'."); myNewRoute = true; RGBColor* col = myAlternatives[0]->getColor() != 0 ? new RGBColor(*myAlternatives[0]->getColor()) : 0; myPrecomputed = new RORoute(myID, 0, 1, newEdges, col); } else { myPrecomputed = myAlternatives[0]; } }
void MSNet::closeSimulation(SUMOTime start) { if (myLogExecutionTime) { long duration = SysUtils::getCurrentMillis() - mySimBeginMillis; std::ostringstream msg; msg << "Performance: " << "\n" << " Duration: " << duration << " ms" << "\n"; if (duration != 0) { msg << " Real time factor: " << (STEPS2TIME(myStep - start) * 1000. / (SUMOReal)duration) << "\n"; msg.setf(std::ios::fixed , std::ios::floatfield); // use decimal format msg.setf(std::ios::showpoint); // print decimal point msg << " UPS: " << ((SUMOReal)myVehiclesMoved / ((SUMOReal)duration / 1000)) << "\n"; } // prepare optional statistics const std::string discardNotice = ((myVehicleControl->getLoadedVehicleNo() != myVehicleControl->getDepartedVehicleNo()) ? " (Loaded: " + toString(myVehicleControl->getLoadedVehicleNo()) + ")" : ""); const std::string collisionNotice = ( myVehicleControl->getCollisionCount() > 0 ? " (Collisions: " + toString(myVehicleControl->getCollisionCount()) + ")" : ""); const std::string teleportNotice = ( myVehicleControl->getTeleportCount() > 0 ? "Teleports: " + toString(myVehicleControl->getTeleportCount()) + collisionNotice + "\n" : ""); // print statistics msg << "Vehicles: " << "\n" << " Emitted: " << myVehicleControl->getDepartedVehicleNo() << discardNotice << "\n" << " Running: " << myVehicleControl->getRunningVehicleNo() << "\n" << " Waiting: " << myInserter->getWaitingVehicleNo() << "\n" << teleportNotice; WRITE_MESSAGE(msg.str()); } myDetectorControl->close(myStep); if (OptionsCont::getOptions().getBool("vehroute-output.write-unfinished")) { MSDevice_Vehroutes::generateOutputForUnfinished(); } #ifndef NO_TRACI traci::TraCIServer::close(); #endif }
FXImage* GUISUMOAbstractView::checkGDALImage(Decal& d) { #ifdef HAVE_GDAL GDALAllRegister(); GDALDataset* poDataset = (GDALDataset*)GDALOpen(d.filename.c_str(), GA_ReadOnly); if (poDataset == 0) { return 0; } const int xSize = poDataset->GetRasterXSize(); const int ySize = poDataset->GetRasterYSize(); // checking for geodata in the picture and try to adapt position and scale if (d.width <= 0.) { double adfGeoTransform[6]; if (poDataset->GetGeoTransform(adfGeoTransform) == CE_None) { Position topLeft(adfGeoTransform[0], adfGeoTransform[3]); const double horizontalSize = xSize * adfGeoTransform[1]; const double verticalSize = ySize * adfGeoTransform[5]; Position bottomRight(topLeft.x() + horizontalSize, topLeft.y() + verticalSize); if (GeoConvHelper::getProcessing().x2cartesian(topLeft) && GeoConvHelper::getProcessing().x2cartesian(bottomRight)) { d.width = bottomRight.x() - topLeft.x(); d.height = topLeft.y() - bottomRight.y(); d.centerX = (topLeft.x() + bottomRight.x()) / 2; d.centerY = (topLeft.y() + bottomRight.y()) / 2; //WRITE_MESSAGE("proj: " + toString(poDataset->GetProjectionRef()) + " dim: " + toString(d.width) + "," + toString(d.height) + " center: " + toString(d.centerX) + "," + toString(d.centerY)); } else { WRITE_WARNING("Could not convert coordinates in " + d.filename + "."); } } } #endif if (d.width <= 0.) { d.width = getGridWidth(); d.height = getGridHeight(); } // trying to read the picture #ifdef HAVE_GDAL const int picSize = xSize * ySize; FXColor* result; if (!FXMALLOC(&result, FXColor, picSize)) { WRITE_WARNING("Could not allocate memory for " + d.filename + "."); return 0; } for (int j = 0; j < picSize; j++) { result[j] = FXRGB(0, 0, 0); } bool valid = true; for (int i = 1; i <= poDataset->GetRasterCount(); i++) { GDALRasterBand* poBand = poDataset->GetRasterBand(i); int shift = -1; if (poBand->GetColorInterpretation() == GCI_RedBand) { shift = 0; } else if (poBand->GetColorInterpretation() == GCI_GreenBand) { shift = 1; } else if (poBand->GetColorInterpretation() == GCI_BlueBand) { shift = 2; } else if (poBand->GetColorInterpretation() == GCI_AlphaBand) { shift = 3; } else { WRITE_MESSAGE("Unknown color band in " + d.filename + ", maybe fox can parse it."); valid = false; break; } assert(xSize == poBand->GetXSize() && ySize == poBand->GetYSize()); if (poBand->RasterIO(GF_Read, 0, 0, xSize, ySize, ((unsigned char*)result) + shift, xSize, ySize, GDT_Byte, 4, 4 * xSize) == CE_Failure) { valid = false; break; } } GDALClose(poDataset); if (valid) { return new FXImage(getApp(), result, IMAGE_OWNED | IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP, xSize, ySize); } FXFREE(&result); #endif return 0; }
void GUIRunThread::begin() { // report the begin when wished WRITE_MESSAGE("Simulation started with time: " + time2string(mySimStartTime)); myOk = true; }