#include <MSCalibrator.h>

Definition at line 59 of file MSCalibrator.h.
Public Member Functions | |
| bool | childCheckEmit (MSCalibratorChild *child) |
| size_t | getActiveChildIndex () const |
| Returns the index of the currently active child. | |
| const std::string & | getID () const throw () |
| Returns the id. | |
| MSCalibrator (const std::string &id, MSNet &net, MSLane *destLane, SUMOReal pos, const std::string &file) throw () | |
| Constructor. | |
| void | schedule (MSCalibratorChild *child, MSVehicle *v, SUMOReal speed) |
| Schedules a vehicle to emit. | |
| void | setActiveChild (MSCalibratorChild *child) |
| Sets the given child as the currently used one. | |
| virtual | ~MSCalibrator () throw () |
Static Public Member Functions | |
| static void | updateCalibrator (std::string name, int time, SUMOReal count) |
Data Fields | |
| NLDetectorBuilder | myDb |
| std::string | myDebugFilesBaseName |
| int | myDebugLevel |
| MSInductLoop * | myIL |
| SUMOTime | myInterval |
| SUMOReal | myNumVehicles |
| SUMOReal | myToCalibrate |
Protected Member Functions | |
| SUMOTime | execute (SUMOTime currentTime) throw (ProcessError) |
| TM. | |
Protected Attributes | |
| MSCalibratorChild * | myActiveChild |
| The currently active child. | |
| MSLane * | myDestLane |
| MSCalibratorChild * | myFileBasedCalibrator |
| The file-based child. | |
| std::string | myID |
| The name of the object. | |
| MSNet & | myNet |
| The network the calibrator is located in. | |
| SUMOReal | myPos |
| The position of the calibrator at the lane. | |
| std::map< MSCalibratorChild *, std::pair< MSVehicle *, SUMOReal > > | myToEmit |
| A map children->vehicles to emit. | |
Static Protected Attributes | |
| static std::map< std::string, MSCalibrator * > | calibratorMap |
Private Member Functions | |
| MSCalibrator (const MSCalibrator &) | |
| Invalidated copy constructor. | |
| MSCalibrator & | operator= (const MSCalibrator &) |
| Invalidated assignment operator. | |
Data Structures | |
| class | MSCalibrator_FileTriggeredChild |
| An CalibratorChild which uses information from a parsed file. More... | |
| class | MSCalibratorChild |
| Holder of information about vehicle routes and types. More... | |
| MSCalibrator::MSCalibrator | ( | const std::string & | id, | |
| MSNet & | net, | |||
| MSLane * | destLane, | |||
| SUMOReal | pos, | |||
| const std::string & | file | |||
| ) | throw () |
Constructor.
| [in] | id | The id of the calibrator |
| [in] | net | The net the calibrator belongs to |
| [in] | destLane | The lane the calibrator is placed on |
| [in] | pos | Position of the calibrator on the given lane |
| [in] | file | Name of the file to read the calibration definitions from |
Definition at line 402 of file MSCalibrator.cpp.
References MSEventControl::ADAPT_AFTER_EXECUTION, MSEventControl::addEvent(), calibratorMap, NLDetectorBuilder::createInductLoop(), execute(), MSNet::getEmissionEvents(), MSLane::getID(), MSNet::getInstance(), MSCalibrator::MSCalibrator_FileTriggeredChild::MSCalibrator_FileTriggeredChild(), myActiveChild, myDb, myDestLane, myFileBasedCalibrator, myIL, myInterval, myNumVehicles, myPos, and myToCalibrate.
00406 : MSTrigger(id), myNet(net), 00407 myDestLane(destLane), myPos((SUMOReal) pos), myDb(net), 00408 myDebugLevel(0), myDebugFilesBaseName("x:\\temp\\dbg_") { 00409 assert(myPos>=0); 00410 00411 myToCalibrate = 0; 00412 00413 //myInterval=atof(getenv("TM_INTERV")?getenv("TM_INTERV"):"1"); //1 00414 //myNumVehicles=atof(getenv("TM_NUMVEH")?getenv("TM_NUMVEH"):"0"); //14.0 00415 myInterval = 60; 00416 myNumVehicles= -1; 00417 00418 00419 00420 std::string ilId = "Calib_InductLoopOn_" + myDestLane->getID(); 00421 myIL = myDb.createInductLoop(ilId, myDestLane, myPos); 00422 00423 MSNet::getInstance()->getEmissionEvents().addEvent( 00424 new WrappingCommand<MSCalibrator>(this, &MSCalibrator::execute), 00425 //MSNet::getInstance()->getCurrentTimeStep() + 5, 00426 0, 00427 MSEventControl::ADAPT_AFTER_EXECUTION); 00428 00429 00430 //TODO clean up in destructor!!! 00431 MSCalibrator::calibratorMap[id]=this; 00432 00433 myActiveChild = 00434 new MSCalibrator_FileTriggeredChild(net, aXMLFilename, *this, net.getVehicleControl()); 00435 myFileBasedCalibrator = myActiveChild; 00436 }
| MSCalibrator::~MSCalibrator | ( | ) | throw () [virtual] |
Definition at line 439 of file MSCalibrator.cpp.
References myFileBasedCalibrator, and myToEmit.
00439 { 00440 { 00441 delete myFileBasedCalibrator; 00442 } 00443 { 00444 std::map<MSCalibratorChild*, std::pair<MSVehicle*, SUMOReal> >::iterator i; 00445 for (i=myToEmit.begin(); i!=myToEmit.end(); ++i) { 00446 delete(*i).second.first; 00447 } 00448 } 00449 }
| MSCalibrator::MSCalibrator | ( | const MSCalibrator & | ) | [private] |
Invalidated copy constructor.
| bool MSCalibrator::childCheckEmit | ( | MSCalibratorChild * | child | ) |
Called by a MSCalibratorChild (given as parameter) this method checks whether this child is the currently active one and whether a vehicle from this source can be emitted. Returns true if the child can continue with the next vehicle, false otherwise
Definition at line 453 of file MSCalibrator.cpp.
References MSVehicleControl::addVehicle(), MSEdge::emit(), MSNet::getCurrentTimeStep(), MSLane::getEdge(), MSVehicle::getID(), MSVehicle::getMaxSpeed(), MSLane::getMaxSpeed(), MSNet::getVehicleControl(), MSLane::isEmissionSuccess(), MSEdge::isVaporizing(), MIN2(), myActiveChild, myDestLane, myNet, myPos, myToEmit, MSVehicle::onDepart(), and SUMOReal.
Referenced by execute(), MSCalibrator::MSCalibrator_FileTriggeredChild::execute(), and MSCalibrator::MSCalibrator_FileTriggeredChild::processNextEntryReaderTriggered().
00453 { 00454 if (myToEmit.find(child)==myToEmit.end()) { 00455 // should not happen - a child is calling and should have a vehicle added 00456 throw 1; 00457 } 00458 if (child!=myActiveChild||myDestLane->getEdge().isVaporizing()) { 00459 // check whether this is due to vaporization 00460 if (myDestLane->getEdge().isVaporizing()) { 00461 myToEmit[child].first->setWasVaporized(true); 00462 } 00463 // remove the vehicle previously inserted by the child 00464 delete myToEmit[child].first; 00465 // erase the child information 00466 myToEmit.erase(myToEmit.find(child)); 00467 // inform child to process the next one (the current was not used) 00468 return true; 00469 } 00470 // get the vehicle and the speed the child has read/generated 00471 MSVehicle *veh = myToEmit[child].first; 00472 SUMOReal speed = myToEmit[child].second; 00473 // check whether the speed shall be patched 00474 //TM 00475 SUMOReal pos = myPos+1; 00476 if (speed<0) { 00477 speed = MIN2(myDestLane->getMaxSpeed(), veh->getMaxSpeed()); 00478 } 00479 // try to emit 00480 #ifdef HAVE_MESOSIM 00481 if (MSGlobals::gUseMesoSim) { 00482 if (myDestLane->getEdge().emit(*veh, myNet.getCurrentTimeStep())) { 00483 veh->onDepart(); 00484 // insert vehicle into the dictionary 00485 if (!myNet.getVehicleControl().addVehicle(veh->getID(), veh)) { 00486 // !!! 00487 throw 1; 00488 } 00489 // erase the child information 00490 myToEmit.erase(myToEmit.find(child)); 00491 return true; 00492 } 00493 } else { 00494 #endif 00495 if (myDestLane->isEmissionSuccess(veh, speed, pos, false)) { 00496 veh->onDepart(); 00497 // insert vehicle into the dictionary 00498 if (!myNet.getVehicleControl().addVehicle(veh->getID(), veh)) { 00499 // !!! 00500 throw 1; 00501 } 00502 // erase the child information 00503 myToEmit.erase(myToEmit.find(child)); 00504 return true; 00505 } 00506 #ifdef HAVE_MESOSIM 00507 } 00508 #endif 00509 return false; 00510 }
| SUMOTime MSCalibrator::execute | ( | SUMOTime | currentTime | ) | throw (ProcessError) [protected] |
TM.
Definition at line 81 of file MSCalibrator.cpp.
References childCheckEmit(), MSInductLoop::getCurrentSpeed(), MSVehicleType::getID(), MSNet::getInstance(), MSInductLoop::getNVehContributed(), MSNet::getVehicleControl(), MSLane::getVehicleNumber(), MSLane::getVehiclesSecure(), MSVehicle::getVehicleType(), myDestLane, myFileBasedCalibrator, myIL, myInterval, myNumVehicles, myToCalibrate, MSVehicle::onRemovalFromNet(), MSLane::removeVehicle(), MSVehicleControl::scheduleVehicleRemoval(), and SUMOReal.
Referenced by MSCalibrator().
00081 { 00082 00083 if (timestep == 0) { 00084 return 1; 00085 } 00086 00087 if (myNumVehicles == -1) { 00088 return 1; 00089 } 00090 00091 00092 00093 SUMOReal vehPerInterval = myNumVehicles / (myInterval); 00094 int num_replacements = 0; 00095 /* 00096 OutputDevice *dev = OutputDevice::getOutputDevice(myDebugFilesBaseName + "diff.csv"); 00097 OutputDevice *dev2 = OutputDevice::getOutputDevice(myDebugFilesBaseName + "replace.csv"); 00098 OutputDevice *dev3 = OutputDevice::getOutputDevice(myDebugFilesBaseName + "vehicle.xml"); 00099 */ 00100 00101 //positive diff=too many vehicles, negative diff=not enough vehicles 00102 unsigned veh_cnt = myIL->getNVehContributed(); 00103 SUMOReal diff = veh_cnt - vehPerInterval + myToCalibrate; 00104 SUMOReal meanSpeed = myIL->getCurrentSpeed(); 00105 00106 if (diff > 0) { 00107 00108 unsigned int vehNum = myDestLane->getVehicleNumber(); 00109 00110 //not enough vehicles to delete on the lane? 00111 if (vehNum < diff) { 00112 00113 myToCalibrate = diff - vehNum; 00114 00115 diff = (SUMOReal)vehNum; 00116 } else { 00117 myToCalibrate = diff - floor(diff); 00118 } 00119 00120 for (int i=1; i <= diff; i++) { 00121 00122 for (MSLane::VehCont::const_iterator it = myDestLane->getVehiclesSecure().begin(); 00123 it < myDestLane->getVehiclesSecure().end(); 00124 it++) { 00125 00126 MSVehicle * veh = (*it); 00127 00128 if (veh->getVehicleType().getID() == "BUS") { 00129 continue; 00130 } else { 00131 veh->onRemovalFromNet(false); 00132 myDestLane->removeVehicle(veh); 00133 MSNet::getInstance()->getVehicleControl().scheduleVehicleRemoval(veh); 00134 num_replacements++; 00135 break; 00136 } 00137 } 00138 // WRITE_WARNING("Removing Vehicle " + veh->getID() + " at Timestep: " + toString(timestep) + "\n"); 00139 } 00140 00141 //make sure enough cars were deleted, only happens if BUSSES were in the set 00142 myToCalibrate+diff-num_replacements; 00143 } else if (diff < 0) { 00144 00145 myToCalibrate = diff - ceil(diff); 00146 for (int i=-1; i >= diff; i--) { 00147 // WRITE_WARNING("Inserting Vehicle at Timestep: " + toString(timestep) + "\n"); 00148 00149 ((MSCalibrator_FileTriggeredChild*) myFileBasedCalibrator)->buildAndScheduleFlowVehicle(meanSpeed); 00150 childCheckEmit(myFileBasedCalibrator); 00151 num_replacements--; 00152 } 00153 } else if (diff == 0) { 00154 myToCalibrate = 0; 00155 } 00156 /* 00157 if (myDebugLevel > 0) { 00158 dev->getOStream() << timestep << "\t" << num_replacements << "\t" << diff << "\t" << myToCalibrate << "\t" << veh_cnt << "\t" << meanSpeed << endl; 00159 00160 dev2->getOStream() << num_replacements << endl; 00161 00162 myIL->writeXMLOutput(*dev3, timestep-1, timestep); 00163 } 00164 00165 // WRITE_WARNING("execute2(" + toString(timestep) + "): Count: " + toString(myIL->getNVehContributed(myInterval))); 00166 */ 00167 00168 return 1; 00169 }
| size_t MSCalibrator::getActiveChildIndex | ( | ) | const |
Returns the index of the currently active child.
Definition at line 521 of file MSCalibrator.cpp.
References myActiveChild, and myFileBasedCalibrator.
00521 { 00522 return 00523 myFileBasedCalibrator==myActiveChild ? 0 : 1; 00524 }
| const std::string& Named::getID | ( | ) | const throw () [inline, inherited] |
Returns the id.
Definition at line 59 of file Named.h.
References Named::myID.
Referenced by RORouteDef_Alternatives::addAlternative(), MSRouteProbe::addRoute(), MSEmitter::MSEmitter_FileTriggeredChild::buildAndScheduleFlowVehicle(), MSCalibrator::MSCalibrator_FileTriggeredChild::buildAndScheduleFlowVehicle(), RORouteDef_Complete::buildCurrentRoute(), ODDistrictHandler::closeDistrict(), NBTrafficLightDefinition::collectLinks(), NBTrafficLightDefinition::compute(), GUIPointOfInterest::drawGL(), MSInductLoop::enterDetectorByMove(), MSVTypeProbe::execute(), MSNet::getBusStopID(), GUITriggeredRerouter::getMicrosimID(), GUIPointOfInterest::getMicrosimID(), GUILaneSpeedTrigger::getMicrosimID(), GUIInductLoop::MyWrapper::getMicrosimID(), GUIEmitter::getMicrosimID(), GUIBusStop::getMicrosimID(), GUI_E2_ZS_Collector::MyWrapper::getMicrosimID(), traci::TraCIServer::handlePoiDomain(), RORDLoader_SUMOBase::myCharacters(), NBOwnTLDef::myCompute(), NBLoadedTLDef::myCompute(), MSTriggeredRerouter::myStartElement(), MSLaneSpeedTrigger::myStartElement(), MSEmitter::MSEmitter_FileTriggeredChild::myStartElement(), MSCalibrator::MSCalibrator_FileTriggeredChild::myStartElement(), NBLoadedTLDef::SignalGroup::patchTYellow(), TraCIServerAPI_Vehicle::processGet(), MSVehicle::replaceRoute(), MSVehicle::saveState(), NBOwnTLDef::setTLControllingInformation(), NBLoadedTLDef::setTLControllingInformation(), RORDLoader_SUMOBase::startRoute(), GUIEmitter::GUIEmitterChild_UserTriggeredChild::wrappedExecute(), NBTrafficLightLogic::writeXML(), MSRouteProbe::writeXMLOutput(), MSInductLoop::writeXMLOutput(), MSE2Collector::writeXMLOutput(), and MSVehicle::~MSVehicle().
00059 { 00060 return myID; 00061 }
| MSCalibrator& MSCalibrator::operator= | ( | const MSCalibrator & | ) | [private] |
Invalidated assignment operator.
| void MSCalibrator::schedule | ( | MSCalibratorChild * | child, | |
| MSVehicle * | v, | |||
| SUMOReal | speed | |||
| ) |
Schedules a vehicle to emit.
Definition at line 514 of file MSCalibrator.cpp.
References myToEmit.
Referenced by MSCalibrator::MSCalibrator_FileTriggeredChild::buildAndScheduleFlowVehicle(), and MSCalibrator::MSCalibrator_FileTriggeredChild::myStartElement().
00515 { 00516 myToEmit[child] = std::make_pair(v, speed); 00517 }
| void MSCalibrator::setActiveChild | ( | MSCalibratorChild * | child | ) |
Sets the given child as the currently used one.
Definition at line 528 of file MSCalibrator.cpp.
References myActiveChild.
00528 { 00529 myActiveChild = c; 00530 }
| void MSCalibrator::updateCalibrator | ( | std::string | name, | |
| int | time, | |||
| SUMOReal | count | |||
| ) | [static] |
Definition at line 535 of file MSCalibrator.cpp.
References myInterval, myNumVehicles, and WRITE_ERROR.
Referenced by traci::TraCIServer::commandUpdateCalibrator().
00535 { 00536 00537 std::map<std::string, MSCalibrator*>::iterator it = MSCalibrator::calibratorMap.find(name); 00538 00539 if (it==MSCalibrator::calibratorMap.end()) { 00540 WRITE_ERROR("WRONG UPDATE COMMAND, CALIBRATOR NOT FOUND: " + name); 00541 return; 00542 } 00543 00544 MSCalibrator * calibrator = (*it).second; 00545 00546 calibrator->myInterval = time; 00547 calibrator->myNumVehicles = count; 00548 00549 //DOME 00550 int i=0; 00551 00552 00553 }
std::map< std::string, MSCalibrator * > MSCalibrator::calibratorMap [static, protected] |
MSCalibratorChild* MSCalibrator::myActiveChild [protected] |
The currently active child.
Definition at line 302 of file MSCalibrator.h.
Referenced by childCheckEmit(), getActiveChildIndex(), MSCalibrator(), and setActiveChild().
| std::string MSCalibrator::myDebugFilesBaseName |
Definition at line 280 of file MSCalibrator.h.
Definition at line 279 of file MSCalibrator.h.
MSLane* MSCalibrator::myDestLane [protected] |
the lane the calibrator is placed on
Definition at line 289 of file MSCalibrator.h.
Referenced by childCheckEmit(), execute(), and MSCalibrator().
MSCalibratorChild* MSCalibrator::myFileBasedCalibrator [protected] |
The file-based child.
Definition at line 296 of file MSCalibrator.h.
Referenced by execute(), getActiveChildIndex(), MSCalibrator(), and ~MSCalibrator().
std::string Named::myID [protected, inherited] |
The name of the object.
Definition at line 66 of file Named.h.
Referenced by RORouteDef_OrigDest::buildCurrentRoute(), RORouteDef_Complete::buildCurrentRoute(), RORouteDef_Alternatives::buildCurrentRoute(), and Named::getID().
Definition at line 277 of file MSCalibrator.h.
Referenced by execute(), MSCalibrator(), and updateCalibrator().
MSNet& MSCalibrator::myNet [protected] |
The network the calibrator is located in.
Definition at line 286 of file MSCalibrator.h.
Referenced by childCheckEmit().
| SUMOReal MSCalibrator::myNumVehicles |
Definition at line 278 of file MSCalibrator.h.
Referenced by execute(), MSCalibrator(), and updateCalibrator().
SUMOReal MSCalibrator::myPos [protected] |
The position of the calibrator at the lane.
Definition at line 292 of file MSCalibrator.h.
Referenced by childCheckEmit(), and MSCalibrator().
| SUMOReal MSCalibrator::myToCalibrate |
std::map<MSCalibratorChild*, std::pair<MSVehicle*, SUMOReal> > MSCalibrator::myToEmit [protected] |
A map children->vehicles to emit.
Definition at line 299 of file MSCalibrator.h.
Referenced by childCheckEmit(), schedule(), and ~MSCalibrator().
1.5.6