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 /****************************************************************************/
10 /// @file MSSOTLPhasePolicy.cpp
11 /// @author Gianfilippo Slager
12 /// @author Federico Caselli
13 /// @date Feb 2010
14 /// @version $Id$
15 ///
16 // The class for SOTL Phase logics
17 /****************************************************************************/
18
19 #include "MSSOTLPhasePolicy.h"
20 #include <cmath>
21 #include "utils/common/RandHelper.h"
22
23
MSSOTLPhasePolicy(const std::map<std::string,std::string> & parameters)24 MSSOTLPhasePolicy::MSSOTLPhasePolicy(const std::map<std::string, std::string>& parameters) :
25 MSSOTLPolicy("Phase", parameters) {
26 init();
27 }
28
MSSOTLPhasePolicy(MSSOTLPolicyDesirability * desirabilityAlgorithm)29 MSSOTLPhasePolicy::MSSOTLPhasePolicy(MSSOTLPolicyDesirability* desirabilityAlgorithm) :
30 MSSOTLPolicy("Phase", desirabilityAlgorithm) {
31 getDesirabilityAlgorithm()->setKeyPrefix("PHASE");
32 init();
33 }
34
MSSOTLPhasePolicy(MSSOTLPolicyDesirability * desirabilityAlgorithm,const std::map<std::string,std::string> & parameters)35 MSSOTLPhasePolicy::MSSOTLPhasePolicy(MSSOTLPolicyDesirability* desirabilityAlgorithm,
36 const std::map<std::string, std::string>& parameters) :
37 MSSOTLPolicy("Phase", desirabilityAlgorithm, parameters) {
38 getDesirabilityAlgorithm()->setKeyPrefix("PHASE");
39 init();
40 }
41
canRelease(SUMOTime elapsed,bool thresholdPassed,bool pushButtonPressed,const MSPhaseDefinition * stage,int vehicleCount)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
init()64 void MSSOTLPhasePolicy::init() {
65 PushButtonLogic::init("MSSOTLPhasePolicy", this);
66 SigmoidLogic::init("MSSOTLPhasePolicy", this);
67 m_useVehicleTypesWeights = getParameter("USE_VEHICLE_TYPES_WEIGHTS", "0") == "1";
68 }
69