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 /****************************************************************************/
15 // The class for SOTL Phase logics
16 /****************************************************************************/
17 
18 #include "MSSOTLPhasePolicy.h"
19 #include <cmath>
21 
22 
23 MSSOTLPhasePolicy::MSSOTLPhasePolicy(const std::map<std::string, std::string>& parameters) :
24  MSSOTLPolicy("Phase", parameters) {
25  init();
26 }
27 
29  MSSOTLPolicy("Phase", desirabilityAlgorithm) {
31  init();
32 }
33 
35  const std::map<std::string, std::string>& parameters) :
36  MSSOTLPolicy("Phase", desirabilityAlgorithm, parameters) {
38  init();
39 }
40 
41 bool MSSOTLPhasePolicy::canRelease(SUMOTime elapsed, bool thresholdPassed, bool pushButtonPressed,
42  const MSPhaseDefinition* stage, int vehicleCount) {
43 // DBG(
44  std::ostringstream str;
45  str << "MSSOTLPhasePolicy::canRelease threshold " << thresholdPassed << " vehicle " << vehicleCount << " elapsed " << elapsed << " min " << stage->minDuration;
46  WRITE_MESSAGE(str.str());
47 // );
48  if (elapsed >= stage->minDuration) {
49  if (pushButtonLogic(elapsed, pushButtonPressed, stage)) {
50  return true;
51  }
52  if (thresholdPassed) {
53  return thresholdPassed;
54  } else if (m_useVehicleTypesWeights) {
55  if (sigmoidLogic(elapsed, stage, vehicleCount)) {
56  return true;
57  }
58  }
59  }
60  return false;
61 }
62 
64  PushButtonLogic::init("MSSOTLPhasePolicy", this);
65  SigmoidLogic::init("MSSOTLPhasePolicy", this);
66  m_useVehicleTypesWeights = getParameter("USE_VEHICLE_TYPES_WEIGHTS", "0") == "1";
67 }
MSSOTLPolicy
Class for a low-level policy.
Definition: MSSOTLPolicy.h:64
SigmoidLogic::init
void init(std::string prefix, const Parameterised *parameterised)
Definition: MSSOTLPolicy.cpp:44
SigmoidLogic::sigmoidLogic
bool sigmoidLogic(SUMOTime elapsed, const MSPhaseDefinition *stage, int vehicleCount)
Definition: MSSOTLPolicy.cpp:60
MSSOTLPolicyDesirability::setKeyPrefix
void setKeyPrefix(std::string val)
Definition: MSSOTLPolicyDesirability.h:58
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
MSSOTLPhasePolicy::MSSOTLPhasePolicy
MSSOTLPhasePolicy(const std::map< std::string, std::string > &parameters)
Definition: MSSOTLPhasePolicy.cpp:23
PushButtonLogic::init
void init(std::string prefix, const Parameterised *parameterised)
Definition: MSSOTLPolicy.cpp:24
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:72
MSSOTLPolicy::getDesirabilityAlgorithm
MSSOTLPolicyDesirability * getDesirabilityAlgorithm()
Definition: MSSOTLPolicy.h:120
MSSOTLPhasePolicy::init
void init()
Definition: MSSOTLPhasePolicy.cpp:63
PushButtonLogic::pushButtonLogic
bool pushButtonLogic(SUMOTime elapsed, bool pushButtonPressed, const MSPhaseDefinition *stage)
Definition: MSSOTLPolicy.cpp:30
RandHelper.h
MSSOTLPhasePolicy.h
MSPhaseDefinition
The definition of a single phase of a tls logic.
Definition: MSPhaseDefinition.h:51
MSSOTLPhasePolicy::canRelease
bool canRelease(SUMOTime elapsed, bool thresholdPassed, bool pushButtonPressed, const MSPhaseDefinition *stage, int vehicleCount)
Definition: MSSOTLPhasePolicy.cpp:41
MSSOTLPolicyDesirability
This class determines the desirability algorithm of a MSSOTLPolicy when used in combination with a hi...
Definition: MSSOTLPolicyDesirability.h:35
WRITE_MESSAGE
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:277
MSSOTLPhasePolicy::m_useVehicleTypesWeights
bool m_useVehicleTypesWeights
Definition: MSSOTLPhasePolicy.h:46
MSPhaseDefinition::minDuration
SUMOTime minDuration
The minimum duration of the phase.
Definition: MSPhaseDefinition.h:76