Eclipse SUMO - Simulation of Urban MObility
MSSOTLPhasePolicy.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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // The class for SOTL Phase logics
17 /****************************************************************************/
18 
19 #include "MSSOTLPhasePolicy.h"
20 #include <cmath>
22 
23 
24 MSSOTLPhasePolicy::MSSOTLPhasePolicy(const std::map<std::string, std::string>& parameters) :
25  MSSOTLPolicy("Phase", parameters) {
26  init();
27 }
28 
30  MSSOTLPolicy("Phase", desirabilityAlgorithm) {
32  init();
33 }
34 
36  const std::map<std::string, std::string>& parameters) :
37  MSSOTLPolicy("Phase", desirabilityAlgorithm, parameters) {
39  init();
40 }
41 
42 bool MSSOTLPhasePolicy::canRelease(SUMOTime elapsed, bool thresholdPassed, bool pushButtonPressed,
43  const MSPhaseDefinition* stage, int vehicleCount) {
44 // DBG(
45  std::ostringstream str;
46  str << "MSSOTLPhasePolicy::canRelease threshold " << thresholdPassed << " vehicle " << vehicleCount << " elapsed " << elapsed << " min " << stage->minDuration;
47  WRITE_MESSAGE(str.str());
48 // );
49  if (elapsed >= stage->minDuration) {
50  if (pushButtonLogic(elapsed, pushButtonPressed, stage)) {
51  return true;
52  }
53  if (thresholdPassed) {
54  return thresholdPassed;
55  } else if (m_useVehicleTypesWeights) {
56  if (sigmoidLogic(elapsed, stage, vehicleCount)) {
57  return true;
58  }
59  }
60  }
61  return false;
62 }
63 
65  PushButtonLogic::init("MSSOTLPhasePolicy", this);
66  SigmoidLogic::init("MSSOTLPhasePolicy", this);
67  m_useVehicleTypesWeights = getParameter("USE_VEHICLE_TYPES_WEIGHTS", "0") == "1";
68 }
MSSOTLPolicy
Class for a low-level policy.
Definition: MSSOTLPolicy.h:65
SigmoidLogic::init
void init(std::string prefix, const Parameterised *parameterised)
Definition: MSSOTLPolicy.cpp:45
SigmoidLogic::sigmoidLogic
bool sigmoidLogic(SUMOTime elapsed, const MSPhaseDefinition *stage, int vehicleCount)
Definition: MSSOTLPolicy.cpp:61
MSSOTLPolicyDesirability::setKeyPrefix
void setKeyPrefix(std::string val)
Definition: MSSOTLPolicyDesirability.h:59
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:35
MSSOTLPhasePolicy::MSSOTLPhasePolicy
MSSOTLPhasePolicy(const std::map< std::string, std::string > &parameters)
Definition: MSSOTLPhasePolicy.cpp:24
PushButtonLogic::init
void init(std::string prefix, const Parameterised *parameterised)
Definition: MSSOTLPolicy.cpp:25
Parameterised::getParameter
const std::string getParameter(const std::string &key, const std::string &defaultValue="") const
Returns the value for a given key.
Definition: Parameterised.cpp:71
MSSOTLPolicy::getDesirabilityAlgorithm
MSSOTLPolicyDesirability * getDesirabilityAlgorithm()
Definition: MSSOTLPolicy.h:121
MSSOTLPhasePolicy::init
void init()
Definition: MSSOTLPhasePolicy.cpp:64
PushButtonLogic::pushButtonLogic
bool pushButtonLogic(SUMOTime elapsed, bool pushButtonPressed, const MSPhaseDefinition *stage)
Definition: MSSOTLPolicy.cpp:31
RandHelper.h
MSSOTLPhasePolicy.h
MSPhaseDefinition
The definition of a single phase of a tls logic.
Definition: MSPhaseDefinition.h:52
MSSOTLPhasePolicy::canRelease
bool canRelease(SUMOTime elapsed, bool thresholdPassed, bool pushButtonPressed, const MSPhaseDefinition *stage, int vehicleCount)
Definition: MSSOTLPhasePolicy.cpp:42
MSSOTLPolicyDesirability
This class determines the desirability algorithm of a MSSOTLPolicy when used in combination with a hi...
Definition: MSSOTLPolicyDesirability.h:36
WRITE_MESSAGE
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:240
MSSOTLPhasePolicy::m_useVehicleTypesWeights
bool m_useVehicleTypesWeights
Definition: MSSOTLPhasePolicy.h:47
MSPhaseDefinition::minDuration
SUMOTime minDuration
The minimum duration of the phase.
Definition: MSPhaseDefinition.h:77