Eclipse SUMO - Simulation of Urban MObility
MSSOTLPlatoonPolicy.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2010-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
19 // The class for SOTL Platoon logics
20 /****************************************************************************/
21 
22 #include "MSSOTLPlatoonPolicy.h"
23 
24 
25 MSSOTLPlatoonPolicy::MSSOTLPlatoonPolicy(const std::map<std::string, std::string>& parameters) :
26  MSSOTLPolicy("Platoon", parameters) {
27  init();
28 }
29 
31  MSSOTLPolicy("Platoon", desirabilityAlgorithm) {
33  init();
34 }
35 
37  const std::map<std::string, std::string>& parameters) :
38  MSSOTLPolicy("Platoon", desirabilityAlgorithm, parameters) {
40  init();
41 }
42 
43 bool MSSOTLPlatoonPolicy::canRelease(SUMOTime elapsed, bool thresholdPassed, bool pushButtonPressed,
44  const MSPhaseDefinition* stage, int vehicleCount) {
45 // DBG(std::ostringstream str; str << "invoked MSTLPlatoonPolicy::canRelease()"; WRITE_MESSAGE(str.str()););
46  DBG(
47  std::ostringstream str;
48  str << "MSSOTLPlatoonPolicy::canRelease elapsed " << elapsed << " threshold " << thresholdPassed << " pushbutton " << pushButtonPressed << " vcount " << vehicleCount
49  << " minD " << stage->minDuration << " maxD " << stage->maxDuration; str << " will return " << ((thresholdPassed && ((vehicleCount == 0) || (elapsed >= stage->maxDuration))) ? "true" : "false");
50  WRITE_MESSAGE(str.str());
51  );
52  if (elapsed >= stage->minDuration) {
53  if (pushButtonLogic(elapsed, pushButtonPressed, stage)) {
54  return true;
55  }
56  if (thresholdPassed) {
57  //If there are no other vehicles approaching green lights
58  //or the declared maximum duration has been reached
59  return ((vehicleCount == 0) || (elapsed >= stage->maxDuration));
60  } else {
61  if (sigmoidLogic(elapsed, stage, vehicleCount)) {
62  return true;
63  }
64  }
65  }
66  return false;
67 }
68 
70  SigmoidLogic::init("MSSOTLPlatoonPolicy", this);
71  PushButtonLogic::init("MSSOTLPlatoonPolicy", this);
72 }
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:278
long long int SUMOTime
Definition: SUMOTime.h:31
#define DBG(X)
Definition: SwarmDebug.h:30
The definition of a single phase of a tls logic.
SUMOTime maxDuration
The maximum duration of the phase.
SUMOTime minDuration
The minimum duration of the phase.
MSSOTLPlatoonPolicy(const std::map< std::string, std::string > &parameters)
bool canRelease(SUMOTime elapsed, bool thresholdPassed, bool pushButtonPressed, const MSPhaseDefinition *stage, int vehicleCount)
This class determines the desirability algorithm of a MSSOTLPolicy when used in combination with a hi...
void setKeyPrefix(std::string val)
Class for a low-level policy.
Definition: MSSOTLPolicy.h:63
MSSOTLPolicyDesirability * getDesirabilityAlgorithm()
Definition: MSSOTLPolicy.h:119
bool pushButtonLogic(SUMOTime elapsed, bool pushButtonPressed, const MSPhaseDefinition *stage)
void init(std::string prefix, const Parameterised *parameterised)
void init(std::string prefix, const Parameterised *parameterised)
bool sigmoidLogic(SUMOTime elapsed, const MSPhaseDefinition *stage, int vehicleCount)