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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
18 // The class for SOTL Phase logics
19 /****************************************************************************/
20 
21 #include "MSSOTLPhasePolicy.h"
22 #include <cmath>
24 
25 
26 MSSOTLPhasePolicy::MSSOTLPhasePolicy(const std::map<std::string, std::string>& parameters) :
27  MSSOTLPolicy("Phase", parameters) {
28  init();
29 }
30 
32  MSSOTLPolicy("Phase", desirabilityAlgorithm) {
34  init();
35 }
36 
38  const std::map<std::string, std::string>& parameters) :
39  MSSOTLPolicy("Phase", desirabilityAlgorithm, parameters) {
41  init();
42 }
43 
44 bool MSSOTLPhasePolicy::canRelease(SUMOTime elapsed, bool thresholdPassed, bool pushButtonPressed,
45  const MSPhaseDefinition* stage, int vehicleCount) {
46 // DBG(
47  std::ostringstream str;
48  str << "MSSOTLPhasePolicy::canRelease threshold " << thresholdPassed << " vehicle " << vehicleCount << " elapsed " << elapsed << " min " << stage->minDuration;
49  WRITE_MESSAGE(str.str());
50 // );
51  if (elapsed >= stage->minDuration) {
52  if (pushButtonLogic(elapsed, pushButtonPressed, stage)) {
53  return true;
54  }
55  if (thresholdPassed) {
56  return thresholdPassed;
57  } else if (m_useVehicleTypesWeights) {
58  if (sigmoidLogic(elapsed, stage, vehicleCount)) {
59  return true;
60  }
61  }
62  }
63  return false;
64 }
65 
67  PushButtonLogic::init("MSSOTLPhasePolicy", this);
68  SigmoidLogic::init("MSSOTLPhasePolicy", this);
69  m_useVehicleTypesWeights = getParameter("USE_VEHICLE_TYPES_WEIGHTS", "0") == "1";
70 }
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:127
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:71
SUMOTime minDuration
The minimum duration of the phase.
long long int SUMOTime
Definition: TraCIDefs.h:51
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:200
The definition of a single phase of a tls logic.
bool canRelease(SUMOTime elapsed, bool thresholdPassed, bool pushButtonPressed, const MSPhaseDefinition *stage, int vehicleCount)