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 }
long long int SUMOTime
Definition: SUMOTime.h:35
MSSOTLPhasePolicy(const std::map< std::string, std::string > &parameters)
void init(std::string prefix, const Parameterised *parameterised)
bool pushButtonLogic(SUMOTime elapsed, bool pushButtonPressed, const MSPhaseDefinition *stage)
bool sigmoidLogic(SUMOTime elapsed, const MSPhaseDefinition *stage, int vehicleCount)
MSSOTLPolicyDesirability * getDesirabilityAlgorithm()
Definition: MSSOTLPolicy.h:121
void setKeyPrefix(std::string val)
void init(std::string prefix, const Parameterised *parameterised)
This class determines the desirability algorithm of a MSSOTLPolicy when used in combination with a hi...
const std::string getParameter(const std::string &key, const std::string &defaultValue="") const
Returns the value for a given key.
Class for a low-level policy.
Definition: MSSOTLPolicy.h:65
SUMOTime minDuration
The minimum duration of the phase.
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:240
The definition of a single phase of a tls logic.
bool canRelease(SUMOTime elapsed, bool thresholdPassed, bool pushButtonPressed, const MSPhaseDefinition *stage, int vehicleCount)