#include <MSTLLogicControl.h>

Definition at line 583 of file MSTLLogicControl.h.
Public Member Functions | |
| void | adaptLogic (SUMOTime step, SUMOReal position) |
| void | cutLogic (SUMOTime step, unsigned int pos, size_t deltaToCut) |
| unsigned int | getDiffToStartOfPhase (MSSimpleTrafficLightLogic *givenLogic, unsigned int pos) |
| Returns the difference between an given position and the start of the phase. | |
| bool | isPosAtGSP (SUMOTime step, MSSimpleTrafficLightLogic *testLogic) |
| void | stretchLogic (SUMOTime step, unsigned int startPos, size_t deltaToStretch) |
| void | switchToPos (SUMOTime simStep, MSSimpleTrafficLightLogic *givenLogic, unsigned int toPos) |
| bool | trySwitch (SUMOTime step) |
| Determines whether a switch is possible. | |
| WAUTSwitchProcedure_Stretch (MSTLLogicControl &control, WAUT &waut, MSTrafficLightLogic *from, MSTrafficLightLogic *to, bool synchron) | |
| Constructor. | |
| ~WAUTSwitchProcedure_Stretch () | |
| Destructor. | |
Protected Member Functions | |
| SUMOReal | getGSPValue (MSTrafficLightLogic *from) const |
| Returns the GSP-value which should be within the tls program definition. | |
| StretchBereichDef | getStretchBereichDef (MSTrafficLightLogic *from, int index) const |
| Returns the numbered Stretch-Bereich for the given program. | |
| int | getStretchBereicheNo (MSTrafficLightLogic *from) const |
| Returns the number of given Stretch-Bereiche(?) for the given program. | |
Protected Attributes | |
| MSTLLogicControl & | myControl |
| The control the logic belongs to. | |
| MSTrafficLightLogic * | myFrom |
| The current program of the tls to switch. | |
| bool | mySwitchSynchron |
| Information whether to switch synchron (?). | |
| MSTrafficLightLogic * | myTo |
| The program to switch the tls to. | |
| WAUT & | myWAUT |
| The WAUT responsible for switching. | |
Private Member Functions | |
| WAUTSwitchProcedure_Stretch & | operator= (const WAUTSwitchProcedure_Stretch &) |
| Invalidated assignment operator. | |
| WAUTSwitchProcedure_Stretch (const WAUTSwitchProcedure_Stretch &) | |
| Invalidated copy constructor. | |
Data Structures | |
| struct | StretchBereichDef |
| A definition of a stretch - Bereich. More... | |
| MSTLLogicControl::WAUTSwitchProcedure_Stretch::WAUTSwitchProcedure_Stretch | ( | MSTLLogicControl & | control, | |
| WAUT & | waut, | |||
| MSTrafficLightLogic * | from, | |||
| MSTrafficLightLogic * | to, | |||
| bool | synchron | |||
| ) |
Constructor.
Definition at line 360 of file MSTLLogicControl.cpp.
00363 : MSTLLogicControl::WAUTSwitchProcedure(control, waut, from, to, synchron) {}
| MSTLLogicControl::WAUTSwitchProcedure_Stretch::~WAUTSwitchProcedure_Stretch | ( | ) |
| MSTLLogicControl::WAUTSwitchProcedure_Stretch::WAUTSwitchProcedure_Stretch | ( | const WAUTSwitchProcedure_Stretch & | ) | [private] |
Invalidated copy constructor.
| void MSTLLogicControl::WAUTSwitchProcedure_Stretch::adaptLogic | ( | SUMOTime | step, | |
| SUMOReal | position | |||
| ) |
Definition at line 389 of file MSTLLogicControl.cpp.
References MSTLLogicControl::WAUTSwitchProcedure_Stretch::StretchBereichDef::begin, cutLogic(), MSTLLogicControl::WAUTSwitchProcedure_Stretch::StretchBereichDef::end, MSTrafficLightLogic::getDefaultCycleTime(), MSTrafficLightLogic::getParameterValue(), MSSimpleTrafficLightLogic::getPhaseIndexAtTime(), getStretchBereichDef(), getStretchBereicheNo(), MSTLLogicControl::WAUTSwitchProcedure::myTo, and stretchLogic().
Referenced by trySwitch().
00389 { 00390 MSSimpleTrafficLightLogic *LogicTo = (MSSimpleTrafficLightLogic*) myTo; 00391 size_t cycleTime = LogicTo->getDefaultCycleTime(); 00392 // the position, in which the logic has to be switched 00393 unsigned int startPos = (unsigned int) position; 00394 // this is the position, where the Logic have to be after synchronisation 00395 size_t posAfterSyn = LogicTo->getPhaseIndexAtTime(step); 00396 00397 // switch the toLogic to the startPosition 00398 // fehlt!!!! 00399 // erfolgt in cutLogic und/oder stretchLogic! 00400 00401 00402 // calculate the difference, that has to be equalized 00403 size_t deltaToCut = 0; 00404 if (posAfterSyn < startPos) { 00405 deltaToCut = posAfterSyn + cycleTime - startPos; 00406 } else deltaToCut = posAfterSyn - startPos; 00407 // test, wheter cutting of the Signalplan is possible 00408 size_t deltaPossible = 0; 00409 int noBereiche = getStretchBereicheNo(myTo); 00410 for (int i=0; i<noBereiche; i++) { 00411 StretchBereichDef def = getStretchBereichDef(myTo, i+1); 00412 assert(def.end >= def.begin) ; 00413 deltaPossible = deltaPossible + (size_t)(def.end - def.begin); 00414 } 00415 int stretchUmlaufAnz = (int) TplConvert<char>::_2SUMOReal(LogicTo->getParameterValue("StretchUmlaufAnz").c_str()); 00416 deltaPossible = stretchUmlaufAnz * deltaPossible; 00417 if ((deltaPossible > deltaToCut)&&(deltaToCut < (cycleTime / 2))) { 00418 cutLogic(step, startPos, deltaToCut); 00419 } else { 00420 size_t deltaToStretch = cycleTime - deltaToCut; 00421 if (deltaToStretch == cycleTime) { 00422 deltaToStretch = 0; 00423 } 00424 stretchLogic(step, startPos, deltaToStretch); 00425 } 00426 00427 }
| void MSTLLogicControl::WAUTSwitchProcedure_Stretch::cutLogic | ( | SUMOTime | step, | |
| unsigned int | pos, | |||
| size_t | deltaToCut | |||
| ) |
Definition at line 431 of file MSTLLogicControl.cpp.
References MSTrafficLightLogic::addOverridingDuration(), MSTLLogicControl::WAUTSwitchProcedure_Stretch::StretchBereichDef::begin, MSTrafficLightLogic::changeStepAndDuration(), MSPhaseDefinition::duration, MSTLLogicControl::WAUTSwitchProcedure_Stretch::StretchBereichDef::end, MSTLLogicControl::WAUTSwitchProcedure::getDiffToStartOfPhase(), MSSimpleTrafficLightLogic::getIndexFromOffset(), MSSimpleTrafficLightLogic::getOffsetFromIndex(), MSSimpleTrafficLightLogic::getPhase(), MSSimpleTrafficLightLogic::getPhases(), getStretchBereichDef(), getStretchBereicheNo(), MSTLLogicControl::WAUTSwitchProcedure::myControl, and MSTLLogicControl::WAUTSwitchProcedure::myTo.
Referenced by adaptLogic().
00431 { 00432 MSSimpleTrafficLightLogic *LogicTo = (MSSimpleTrafficLightLogic*) myTo; 00433 unsigned int startPos = pos; 00434 unsigned int actStep = LogicTo->getIndexFromOffset(startPos); 00435 size_t allCutTime = deltaToCut; 00436 // switches to startPos and cuts this phase, if there is a "Bereich" 00437 int noBereiche = getStretchBereicheNo(myTo); 00438 size_t toCut = 0; 00439 for (int i=0; i<noBereiche; i++) { 00440 StretchBereichDef def = getStretchBereichDef(myTo, i+1); 00441 unsigned int begin = (unsigned int) def.begin; 00442 unsigned int end = (unsigned int) def.end; 00443 size_t stepOfBegin = LogicTo->getIndexFromOffset(begin); 00444 if (stepOfBegin == actStep) { 00445 if (begin < startPos) { 00446 toCut = end - startPos; 00447 } else { 00448 toCut = end - begin; 00449 } 00450 if (allCutTime < toCut) { 00451 toCut = allCutTime; 00452 } 00453 allCutTime = allCutTime - toCut; 00454 } 00455 } 00456 unsigned int remainingDur = LogicTo->getPhase(actStep).duration - getDiffToStartOfPhase(LogicTo, startPos); 00457 unsigned int newDur = remainingDur - toCut; 00458 myTo->changeStepAndDuration(myControl,step,actStep,newDur); 00459 00460 // changes the duration of all other phases 00461 int currStep = actStep + 1; 00462 if (currStep == (int) LogicTo->getPhases().size()) { 00463 currStep = 0; 00464 } 00465 while (allCutTime > 0) { 00466 for (int i=currStep; i<(int) LogicTo->getPhases().size(); i++) { 00467 size_t beginOfPhase = LogicTo->getOffsetFromIndex(i); 00468 unsigned int durOfPhase = LogicTo->getPhase(i).duration; 00469 size_t endOfPhase = beginOfPhase + durOfPhase; 00470 for (int i=0; i<noBereiche; i++) { 00471 StretchBereichDef def = getStretchBereichDef(myTo, i+1); 00472 size_t begin = (size_t) def.begin; 00473 size_t end = (size_t) def.end; 00474 if ((beginOfPhase <= begin) && (endOfPhase >= end)) { 00475 size_t maxCutOfPhase = end - begin; 00476 if (allCutTime< maxCutOfPhase) { 00477 maxCutOfPhase = allCutTime; 00478 } 00479 allCutTime = allCutTime - maxCutOfPhase; 00480 durOfPhase = durOfPhase - maxCutOfPhase; 00481 } 00482 } 00483 LogicTo->addOverridingDuration(durOfPhase); 00484 } 00485 currStep = 0; 00486 } 00487 }
| unsigned int MSTLLogicControl::WAUTSwitchProcedure::getDiffToStartOfPhase | ( | MSSimpleTrafficLightLogic * | givenLogic, | |
| unsigned int | pos | |||
| ) | [inherited] |
Returns the difference between an given position and the start of the phase.
Definition at line 253 of file MSTLLogicControl.cpp.
References MSPhaseDefinition::duration, MSSimpleTrafficLightLogic::getIndexFromOffset(), MSSimpleTrafficLightLogic::getOffsetFromIndex(), and MSSimpleTrafficLightLogic::getPhase().
Referenced by MSTLLogicControl::WAUTSwitchProcedure_GSP::adaptLogic(), cutLogic(), stretchLogic(), and MSTLLogicControl::WAUTSwitchProcedure::switchToPos().
00253 { 00254 MSSimpleTrafficLightLogic *myLogic = givenLogic; 00255 unsigned int myPos = pos; 00256 unsigned int stepOfMyPos = myLogic->getIndexFromOffset(myPos); 00257 unsigned int startOfPhase = myLogic->getOffsetFromIndex(stepOfMyPos); 00258 MSPhaseDefinition myPhase = myLogic->getPhase(stepOfMyPos); 00259 unsigned int durOfPhase = (unsigned int)myPhase.duration; 00260 00261 assert(myPos >= startOfPhase); 00262 unsigned int diff = myPos - startOfPhase; 00263 assert(diff <= durOfPhase); 00264 return diff; 00265 }
| SUMOReal MSTLLogicControl::WAUTSwitchProcedure::getGSPValue | ( | MSTrafficLightLogic * | from | ) | const [protected, inherited] |
Returns the GSP-value which should be within the tls program definition.
Definition at line 223 of file MSTLLogicControl.cpp.
References TplConvert< E >::_2SUMOReal(), and MSTrafficLightLogic::getParameterValue().
Referenced by MSTLLogicControl::WAUTSwitchProcedure_GSP::adaptLogic(), MSTLLogicControl::WAUTSwitchProcedure::isPosAtGSP(), trySwitch(), and MSTLLogicControl::WAUTSwitchProcedure_GSP::trySwitch().
00223 { 00224 std::string val = from->getParameterValue("GSP"); 00225 if (val.length()==0) { 00226 return -1; 00227 } 00228 return TplConvert<char>::_2SUMOReal(val.c_str()); 00229 }
| MSTLLogicControl::WAUTSwitchProcedure_Stretch::StretchBereichDef MSTLLogicControl::WAUTSwitchProcedure_Stretch::getStretchBereichDef | ( | MSTrafficLightLogic * | from, | |
| int | index | |||
| ) | const [protected] |
Returns the numbered Stretch-Bereich for the given program.
The first bereich has normally the number "1", not "0"!
Definition at line 566 of file MSTLLogicControl.cpp.
References TplConvert< E >::_2SUMOReal(), MSTLLogicControl::WAUTSwitchProcedure_Stretch::StretchBereichDef::begin, MSTLLogicControl::WAUTSwitchProcedure_Stretch::StretchBereichDef::end, MSTLLogicControl::WAUTSwitchProcedure_Stretch::StretchBereichDef::fac, MSTrafficLightLogic::getParameterValue(), and toString().
Referenced by adaptLogic(), cutLogic(), and stretchLogic().
00566 { 00567 StretchBereichDef def; 00568 def.begin = TplConvert<char>::_2SUMOReal(from->getParameterValue("B" + toString(index) + ".begin").c_str()); 00569 def.end = TplConvert<char>::_2SUMOReal(from->getParameterValue("B" + toString(index) + ".end").c_str()); 00570 def.fac = TplConvert<char>::_2SUMOReal(from->getParameterValue("B" + toString(index) + ".factor").c_str()); 00571 return def; 00572 }
| int MSTLLogicControl::WAUTSwitchProcedure_Stretch::getStretchBereicheNo | ( | MSTrafficLightLogic * | from | ) | const [protected] |
Returns the number of given Stretch-Bereiche(?) for the given program.
Definition at line 556 of file MSTLLogicControl.cpp.
References MSTrafficLightLogic::getParameterValue(), and toString().
Referenced by adaptLogic(), cutLogic(), and stretchLogic().
00556 { 00557 int no = 0; 00558 while (from->getParameterValue("B" + toString(no+1) + ".begin")!="") { 00559 no++; 00560 } 00561 return no; 00562 }
| bool MSTLLogicControl::WAUTSwitchProcedure::isPosAtGSP | ( | SUMOTime | step, | |
| MSSimpleTrafficLightLogic * | testLogic | |||
| ) | [inherited] |
get the position of the given signalprogramm at the actual simulationsecond
compare the position of the given programm with the GSP (GSP = "GuenstigerSchaltPunkt")
Definition at line 233 of file MSTLLogicControl.cpp.
References MSTrafficLightLogic::getDefaultCycleTime(), MSTLLogicControl::WAUTSwitchProcedure::getGSPValue(), and SUMOReal.
Referenced by trySwitch(), and MSTLLogicControl::WAUTSwitchProcedure_GSP::trySwitch().
00233 { 00234 MSSimpleTrafficLightLogic *givenLogic = (MSSimpleTrafficLightLogic*) testLogic; 00235 size_t CycleTime = givenLogic->getDefaultCycleTime(); 00236 SUMOReal gspFrom = getGSPValue(givenLogic); 00238 size_t posFrom = givenLogic -> getPhaseIndexAtTime(step); 00239 00240 if (gspFrom == CycleTime) { 00241 gspFrom = 0; 00242 } 00244 if (gspFrom == posFrom) { 00245 return true; 00246 } else { 00247 return false; 00248 } 00249 }
| WAUTSwitchProcedure_Stretch& MSTLLogicControl::WAUTSwitchProcedure_Stretch::operator= | ( | const WAUTSwitchProcedure_Stretch & | ) | [private] |
Invalidated assignment operator.
| void MSTLLogicControl::WAUTSwitchProcedure_Stretch::stretchLogic | ( | SUMOTime | step, | |
| unsigned int | startPos, | |||
| size_t | deltaToStretch | |||
| ) |
Definition at line 490 of file MSTLLogicControl.cpp.
References MSTrafficLightLogic::addOverridingDuration(), MSTrafficLightLogic::changeStepAndDuration(), MSPhaseDefinition::duration, MSTLLogicControl::WAUTSwitchProcedure_Stretch::StretchBereichDef::end, MSTLLogicControl::WAUTSwitchProcedure_Stretch::StretchBereichDef::fac, MSTLLogicControl::WAUTSwitchProcedure::getDiffToStartOfPhase(), MSSimpleTrafficLightLogic::getIndexFromOffset(), MSSimpleTrafficLightLogic::getOffsetFromIndex(), MSTrafficLightLogic::getParameterValue(), MSSimpleTrafficLightLogic::getPhase(), MSSimpleTrafficLightLogic::getPhases(), getStretchBereichDef(), getStretchBereicheNo(), MSTLLogicControl::WAUTSwitchProcedure::myControl, MSTLLogicControl::WAUTSwitchProcedure::myTo, and SUMOReal.
Referenced by adaptLogic().
00490 { 00491 MSSimpleTrafficLightLogic *LogicTo = (MSSimpleTrafficLightLogic*) myTo; 00492 unsigned int currPos = startPos; 00493 unsigned int currStep = LogicTo->getIndexFromOffset(currPos); 00494 unsigned int durOfPhase = LogicTo->getPhase(currStep).duration; 00495 size_t allStretchTime = deltaToStretch; 00496 size_t remainingStretchTime = allStretchTime; 00497 int StretchTimeOfPhase = 0; 00498 size_t stretchUmlaufAnz = (size_t) TplConvert<char>::_2SUMOReal(LogicTo->getParameterValue("StretchUmlaufAnz").c_str()); 00499 SUMOReal facSum = 0; 00500 int noBereiche = getStretchBereicheNo(myTo); 00501 int x; 00502 for (x=0; x<noBereiche; x++) { 00503 StretchBereichDef def = getStretchBereichDef(myTo, x+1); 00504 facSum += def.fac; 00505 } 00506 facSum *= stretchUmlaufAnz; 00507 00508 00509 //switch to startPos and stretch this phase, if there is a end of "bereich" between startpos and end of phase 00510 size_t diffToStart = getDiffToStartOfPhase(LogicTo, currPos); 00511 for (x=0; x<noBereiche; x++) { 00512 StretchBereichDef def = getStretchBereichDef(myTo, x+1); 00513 size_t end = (size_t) def.end; 00514 size_t endOfPhase = (size_t)(currPos + durOfPhase - diffToStart); 00515 if (end <= endOfPhase && end >= currPos) { 00516 SUMOReal fac = def.fac; 00517 SUMOReal actualfac = fac / facSum; 00518 facSum = facSum - fac; 00519 StretchTimeOfPhase = (int)((float)remainingStretchTime * actualfac + 0.5); 00520 remainingStretchTime = allStretchTime - StretchTimeOfPhase; 00521 } 00522 } 00523 durOfPhase = durOfPhase - diffToStart + StretchTimeOfPhase; 00524 myTo->changeStepAndDuration(myControl,step,currStep,durOfPhase); 00525 00526 currStep ++; 00527 if (currStep >= LogicTo->getPhases().size()) { 00528 currStep = 0; 00529 } 00530 00531 // stretch all other phases, if there is a "bereich" 00532 while (remainingStretchTime > 0) { 00533 for (unsigned int i=currStep; i<LogicTo->getPhases().size() && remainingStretchTime > 0; i++) { 00534 durOfPhase = LogicTo->getPhase(i).duration; 00535 size_t beginOfPhase = LogicTo->getOffsetFromIndex(i); 00536 size_t endOfPhase = beginOfPhase + durOfPhase; 00537 for (int j=0; j<noBereiche && remainingStretchTime > 0; j++) { 00538 StretchBereichDef def = getStretchBereichDef(myTo, j+1); 00539 size_t end = (size_t) def.end; 00540 SUMOReal fac = def.fac; 00541 if ((beginOfPhase <= end) && (endOfPhase >= end)) { 00542 SUMOReal actualfac = fac / facSum; 00543 StretchTimeOfPhase = (int)((float)remainingStretchTime * actualfac + 0.5) ; 00544 facSum -= fac; 00545 durOfPhase += StretchTimeOfPhase; 00546 remainingStretchTime -= StretchTimeOfPhase; 00547 } 00548 } 00549 LogicTo->addOverridingDuration(durOfPhase); 00550 } 00551 currStep = 0; 00552 } 00553 }
| void MSTLLogicControl::WAUTSwitchProcedure::switchToPos | ( | SUMOTime | simStep, | |
| MSSimpleTrafficLightLogic * | givenLogic, | |||
| unsigned int | toPos | |||
| ) | [inherited] |
Definition at line 269 of file MSTLLogicControl.cpp.
References MSSimpleTrafficLightLogic::changeStepAndDuration(), MSPhaseDefinition::duration, MSTLLogicControl::WAUTSwitchProcedure::getDiffToStartOfPhase(), MSSimpleTrafficLightLogic::getIndexFromOffset(), MSSimpleTrafficLightLogic::getPhase(), and MSTLLogicControl::WAUTSwitchProcedure::myControl.
Referenced by trySwitch(), and MSTLLogicControl::WAUTSwitchProcedure_GSP::trySwitch().
00269 { 00270 MSSimpleTrafficLightLogic *myLogic = givenLogic; 00271 unsigned int posTo = pos; 00272 unsigned int stepTo = myLogic->getIndexFromOffset(posTo); 00273 unsigned int diff = getDiffToStartOfPhase(myLogic, posTo); 00274 MSPhaseDefinition myPhase = myLogic->getPhase(stepTo); 00275 unsigned int dur = (unsigned int)myPhase.duration - diff; 00276 myLogic->changeStepAndDuration(myControl ,simStep, stepTo, dur); 00277 }
Determines whether a switch is possible.
switch to the next programm if the GSP is reached
Implements MSTLLogicControl::WAUTSwitchProcedure.
Definition at line 370 of file MSTLLogicControl.cpp.
References adaptLogic(), MSTLLogicControl::WAUTSwitchProcedure::getGSPValue(), MSTLLogicControl::WAUTSwitchProcedure::isPosAtGSP(), MSTLLogicControl::WAUTSwitchProcedure::myFrom, MSTLLogicControl::WAUTSwitchProcedure::mySwitchSynchron, MSTLLogicControl::WAUTSwitchProcedure::myTo, SUMOReal, and MSTLLogicControl::WAUTSwitchProcedure::switchToPos().
00370 { 00371 MSSimpleTrafficLightLogic *LogicFrom = (MSSimpleTrafficLightLogic*) myFrom; 00372 MSSimpleTrafficLightLogic *LogicTo = (MSSimpleTrafficLightLogic*) myTo; 00373 SUMOReal posTo = 0; 00375 if (isPosAtGSP(step, LogicFrom)==true) { 00376 posTo = getGSPValue(myTo); 00377 if (mySwitchSynchron) { 00378 adaptLogic(step, posTo); 00379 } else { 00380 switchToPos(step, LogicTo, (unsigned int) posTo); 00381 } 00382 return true; 00383 } 00384 return false; 00385 }
MSTLLogicControl& MSTLLogicControl::WAUTSwitchProcedure::myControl [protected, inherited] |
The control the logic belongs to.
Definition at line 504 of file MSTLLogicControl.h.
Referenced by MSTLLogicControl::WAUTSwitchProcedure_GSP::adaptLogic(), cutLogic(), stretchLogic(), and MSTLLogicControl::WAUTSwitchProcedure::switchToPos().
MSTrafficLightLogic* MSTLLogicControl::WAUTSwitchProcedure::myFrom [protected, inherited] |
The current program of the tls to switch.
Definition at line 492 of file MSTLLogicControl.h.
Referenced by trySwitch(), and MSTLLogicControl::WAUTSwitchProcedure_GSP::trySwitch().
bool MSTLLogicControl::WAUTSwitchProcedure::mySwitchSynchron [protected, inherited] |
Information whether to switch synchron (?).
Definition at line 498 of file MSTLLogicControl.h.
Referenced by trySwitch(), and MSTLLogicControl::WAUTSwitchProcedure_GSP::trySwitch().
MSTrafficLightLogic* MSTLLogicControl::WAUTSwitchProcedure::myTo [protected, inherited] |
The program to switch the tls to.
Definition at line 495 of file MSTLLogicControl.h.
Referenced by adaptLogic(), MSTLLogicControl::WAUTSwitchProcedure_GSP::adaptLogic(), cutLogic(), stretchLogic(), trySwitch(), and MSTLLogicControl::WAUTSwitchProcedure_GSP::trySwitch().
WAUT& MSTLLogicControl::WAUTSwitchProcedure::myWAUT [protected, inherited] |
1.5.6