Skip to content

Commit

Permalink
Removed newline/whitespace changes
Browse files Browse the repository at this point in the history
Signed-off-by: Max <mcschrader@crimson.ua.edu>
  • Loading branch information
mschrader15 authored and namdre committed Mar 1, 2024
1 parent 3e1817e commit dd3357e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/microsim/traffic_lights/NEMAController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <netload/NLDetectorBuilder.h>
#include "NEMAController.h"


// ===========================================================================
// parameter defaults definitions
// ===========================================================================
Expand Down Expand Up @@ -281,11 +282,13 @@ NEMALogic::constructTimingAndPhaseDefs(std::string& barriers, std::string& coord
defaultP[1]->forceEnter(this);
}


#ifdef DEBUG_NEMA
//print to check the rings and barriers active phase
std::cout << "After init, active ring1 phase is " << myActivePhaseObjs[0]->phaseName << std::endl;
std::cout << "After init, active ring2 phase is " << myActivePhaseObjs[1]->phaseName << std::endl;


//print to check the phase definition is correct
std::cout << "Print to check NEMA phase definitions\n";
for (auto& p : myPhaseObjs) {
Expand All @@ -299,11 +302,13 @@ NEMALogic::constructTimingAndPhaseDefs(std::string& barriers, std::string& coord
}
#endif


#ifdef DEBUG_NEMA
std::cout << "After init, r1/r2 barrier phase = " << defaultBarrierPhases[0][1]->phaseName << " and " << defaultBarrierPhases[1][1]->phaseName << std::endl;
std::cout << "After init, r1/r2 coordinate phase = " << defaultBarrierPhases[0][0]->phaseName << " and " << defaultBarrierPhases[1][0]->phaseName << std::endl;
#endif


#ifdef DEBUG_NEMA
std::cout << "R1State = " << myActivePhaseObjs[0]->phaseName << " and its state = " << std::to_string((int)myActivePhaseObjs[0]->getCurrentState()) << std::endl;
std::cout << "R2State = " << myActivePhaseObjs[1]->phaseName << " and its state = " << std::to_string((int)myActivePhaseObjs[0]->getCurrentState()) << std::endl;
Expand Down Expand Up @@ -637,6 +642,7 @@ NEMALogic::setNewSplits(std::vector<double> newSplits) {
}
}


void
NEMALogic::setNewMaxGreens(std::vector<double> newMaxGreens) {
for (auto& p : myPhaseObjs) {
Expand All @@ -647,18 +653,21 @@ NEMALogic::setNewMaxGreens(std::vector<double> newMaxGreens) {
}
}


void
NEMALogic::setNewCycleLength(double newCycleLength) {
// set the controller's next cycle length. This will be implemented when implementTraciChanges is called
myNextCycleLength = TIME2STEPS(newCycleLength);
}


void
NEMALogic::setNewOffset(double newOffset) {
// set the controller's offset. This will be implemented when implementTraciChanges is called
myNextOffset = TIME2STEPS(newOffset);
}


std::vector<int> NEMALogic::readParaFromString(std::string s) {
std::vector<int> output;
for (char c : s) {
Expand Down Expand Up @@ -696,6 +705,7 @@ int NEMALogic::measureRingDistance(int p1, int p2, int ringNum) {
return d;
}


SUMOTime
NEMALogic::ModeCycle(SUMOTime a, SUMOTime b) {
SUMOTime c = a - b;
Expand All @@ -708,6 +718,7 @@ NEMALogic::ModeCycle(SUMOTime a, SUMOTime b) {
return c;
}


void
NEMALogic::getLaneInfoFromNEMAState(std::string state, StringVector& laneIDs, IntVector& stateIndex) {
std::set<std::string> output;
Expand Down Expand Up @@ -747,6 +758,7 @@ NEMALogic::hasMajor(const std::string& state, const LaneVector& lanes) const {
return false;
}


void
NEMALogic::activateProgram() {
MSTrafficLightLogic::activateProgram();
Expand Down Expand Up @@ -778,6 +790,7 @@ int NEMALogic::string2int(std::string s) {
return ret;
}


const std::string
NEMALogic::getParameter(const std::string& key, const std::string defaultValue) const {
if (StringUtils::startsWith(key, "NEMA.")) {
Expand Down Expand Up @@ -805,6 +818,7 @@ NEMALogic::getParameter(const std::string& key, const std::string defaultValue)
}
}


void
NEMALogic::setParameter(const std::string& key, const std::string& value) {
queuedTraciChanges = true;
Expand Down Expand Up @@ -1090,6 +1104,7 @@ NEMALogic::getNextPhases(TransitionPairs& transitions) {
}
}


std::string
NEMALogic::composeLightString() {
// FIX with plan to support #10742
Expand Down Expand Up @@ -1117,6 +1132,7 @@ NEMALogic::composeLightString() {
return out;
}


SUMOTime
NEMALogic::trySwitch() {
#ifdef DEBUG_NEMA_SWITCH
Expand Down Expand Up @@ -1181,6 +1197,7 @@ NEMALogic::trySwitch() {
p->clearMyDetectors();
}


#ifdef FUZZ_TESTING
// Basic Assertion to ensure that the Barrier is not crossed
assert(myActivePhaseObjs[0]->barrierNum == myActivePhaseObjs[1]->barrierNum);
Expand All @@ -1190,6 +1207,7 @@ NEMALogic::trySwitch() {
return DELTA_T;
}


void
NEMALogic::implementTraciChanges(void) {
// Implement Traci Updates on the start of ring1 coordinated phase (rising edge of it turning green)
Expand All @@ -1205,6 +1223,7 @@ NEMALogic::implementTraciChanges(void) {
}
}


// ===========================================================================
// NEMAPhase Definitions
// ===========================================================================
Expand Down Expand Up @@ -1288,6 +1307,7 @@ NEMAPhase::recalculateTiming(void) {
vehExt = myCorePhase->vehext;
}


// TODO: this can be computed once.
char
NEMAPhase::getNEMAChar(int i) {
Expand Down Expand Up @@ -1718,6 +1738,7 @@ PhaseTransitionLogic::coordBase(NEMALogic* controller) {
return false;
}


bool
PhaseTransitionLogic::fromBarrier(NEMALogic* controller) {
if (freeBase(controller)) {
Expand All @@ -1742,6 +1763,7 @@ PhaseTransitionLogic::fromBarrier(NEMALogic* controller) {
return false;
}


bool
PhaseTransitionLogic::fromCoord(NEMALogic* controller) {
if (coordBase(controller)) {
Expand Down
13 changes: 12 additions & 1 deletion src/microsim/traffic_lights/NEMAController.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "microsim/output/MSE2Collector.h"
#include "MSPhaseDefinition.h"


// ===========================================================================
// class declarations
// ===========================================================================
Expand All @@ -52,6 +53,7 @@ enum class LightState {
GreenRest,
};


// ===========================================================================
// class definitions
// ===========================================================================
Expand Down Expand Up @@ -102,6 +104,7 @@ class NEMALogic : public MSSimpleTrafficLightLogic {
const std::map<std::string, std::string>& parameter,
const std::string& basePath);


/** @brief Initialises the tls with information about incoming lanes
* @param[in] nb The detector builder
* @exception ProcessError If something fails on initialisation
Expand All @@ -123,6 +126,7 @@ class NEMALogic : public MSSimpleTrafficLightLogic {
const MSPhaseDefinition& getCurrentPhaseDef() const override;
/// @}


void activateProgram() override;
void deactivateProgram() override;

Expand Down Expand Up @@ -152,6 +156,7 @@ class NEMALogic : public MSSimpleTrafficLightLogic {
*/
SUMOTime ModeCycle(SUMOTime a, SUMOTime b);


/**
* @brief returns the IDs of the phase's controlled lanes.
* Found by looking for the "G" in the light state string
Expand Down Expand Up @@ -217,6 +222,7 @@ class NEMALogic : public MSSimpleTrafficLightLogic {
return (simTime - cycleRefPoint - offset) % myCycleLength;
}


/// @brief set the active phase
void setActivePhase(PhasePtr phase);

Expand Down Expand Up @@ -377,6 +383,7 @@ class NEMALogic : public MSSimpleTrafficLightLogic {
/// @brief storing the detector info in a vector
std::vector<DetectorInfo> myDetectorInfoVector;


/// @brief return whether there is a major link from the given lane in the given phase
bool hasMajor(const std::string& state, const LaneVector& lanes) const;

Expand Down Expand Up @@ -516,6 +523,7 @@ class NEMALogic : public MSSimpleTrafficLightLogic {
}
}


/// @brief calculate the initial phases for the TS2 style controller to start in
void calculateInitialPhasesTS2();
/// @brief calculate the initial phases for Type 170
Expand All @@ -534,6 +542,7 @@ class NEMALogic : public MSSimpleTrafficLightLogic {
}
};


/**
* @class NEMAPhase
* @brief One phase in the NEMAController
Expand Down Expand Up @@ -617,6 +626,7 @@ class NEMAPhase {
return myDetectorInfo.detectors;
}


/// @brief sets the detectors for the phase
inline void setDetectors(std::vector<MSE2Collector*> detectors) {
myDetectorInfo.detectors = detectors;
Expand Down Expand Up @@ -720,7 +730,7 @@ class NEMAPhase {
bool readyToSwitch;

/**
* @brief Get the Transition Time give the current simulation time and phase state
* @brief Get the Transition Time
*
* @param controller
* @return SUMOTime
Expand Down Expand Up @@ -866,6 +876,7 @@ class NEMAPhase {

};


/**
* @class PhaseTransitionLogic
* @brief This class handles the transition logic between two phases
Expand Down

0 comments on commit dd3357e

Please sign in to comment.