Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2013-2025 German Aerospace Center (DLR) and others.
4 : // This program and the accompanying materials are made available under the
5 : // terms of the Eclipse Public License 2.0 which is available at
6 : // https://www.eclipse.org/legal/epl-2.0/
7 : // This Source Code may also be made available under the following Secondary
8 : // Licenses when the conditions for such availability set forth in the Eclipse
9 : // Public License 2.0 are satisfied: GNU General Public License, version 2
10 : // or later which is available at
11 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 : /****************************************************************************/
14 : /// @file MSSOTLPolicy5DStimulus.cpp
15 : /// @author Riccardo Belletti
16 : /// @author Simone Bacchilega
17 : /// @date 2014-09-30
18 : ///
19 : // The class for Swarm-based low-level policy
20 : /****************************************************************************/
21 :
22 : #include "MSSOTLPolicy5DStimulus.h"
23 : //#define SWARM_DEBUG
24 :
25 :
26 : // ===========================================================================
27 : // method definitions
28 : // ===========================================================================
29 64 : MSSOTLPolicy5DStimulus::MSSOTLPolicy5DStimulus(std::string keyPrefix,
30 64 : const Parameterised::Map& parameters) :
31 64 : MSSOTLPolicyDesirability(keyPrefix, parameters) {
32 :
33 64 : stimCoxDVal = 1;
34 64 : stimOffsetInDVal = 1;
35 64 : stimOffsetOutDVal = 1;
36 64 : stimOffsetDispersionInDVal = 1;
37 64 : stimOffsetDispersionOutDVal = 1;
38 64 : stimDivInDVal = 1;
39 64 : stimDivOutDVal = 1;
40 64 : stimDivDispersionInDVal = 1;
41 64 : stimDivDispersionOutDVal = 1;
42 64 : stimCoxExpInDVal = 0;
43 64 : stimCoxExpOutDVal = 0;
44 64 : stimCoxExpDispersionInDVal = 0;
45 64 : stimCoxExpDispersionOutDVal = 0;
46 64 : }
47 :
48 80 : double MSSOTLPolicy5DStimulus::computeDesirability(double vehInMeasure, double vehOutMeasure, double vehInDispersionMeasure, double vehOutDispersionMeasure) {
49 : #ifdef SWARM_DEBUG
50 : std::ostringstream str;
51 : str << "cox=" << getStimCox() << ", cox_exp_in=" << getStimCoxExpIn() << ", cox_exp_out=" << getStimCoxExpOut()
52 : << ", off_in=" << getStimOffsetIn() << ", off_out=" << getStimOffsetOut() << ", div_in=" << getStimDivisorIn() << ", div_out=" << getStimDivisorOut();
53 : WRITE_MESSAGE(str.str());
54 : #endif
55 : // it seems to be not enough, a strange segmentation fault appears...
56 : // if((getStimCoxExpIn()!=0.0 && getStimDivisorIn()==0.0)||(getStimCoxExpOut()!=0.0 && getStimDivisorOut()==0.0)){
57 80 : if (getStimDivisorIn() == 0 || getStimDivisorOut() == 0) {
58 0 : std::ostringstream errorMessage;
59 : errorMessage << "INCORRECT VALUES" << "\nStimCoxExpIn="
60 0 : << getStimCoxExpIn() << ", StimDivisorIn=" << getStimDivisorIn()
61 0 : << ", StimCoxExpOut=" << getStimCoxExpOut()
62 0 : << ", StimDivisorOut=" << getStimDivisorOut();
63 0 : WRITE_ERROR(errorMessage.str());
64 : assert(-1);
65 : return -1;
66 0 : } else {
67 80 : double stimulus = getStimCox()
68 80 : * exp(
69 80 : -getStimCoxExpIn()
70 80 : * pow(vehInMeasure - getStimOffsetIn(), 2)
71 80 : / getStimDivisorIn()
72 80 : - getStimCoxExpOut()
73 80 : * pow(vehOutMeasure - getStimOffsetOut(), 2)
74 80 : / getStimDivisorOut()
75 80 : - getStimCoxExpDispersionIn()
76 80 : * pow(vehInDispersionMeasure - getStimOffsetDispersionIn(), 2)
77 80 : / getStimDivisorDispersionIn()
78 80 : - getStimCoxExpDispersionOut()
79 80 : * pow(vehOutDispersionMeasure - getStimOffsetDispersionOut(), 2)
80 80 : / getStimDivisorDispersionOut()
81 :
82 80 : );
83 80 : return stimulus;
84 : }
85 : }
86 :
87 0 : double MSSOTLPolicy5DStimulus::computeDesirability(double vehInMeasure, double vehOutMeasure) {
88 :
89 0 : return computeDesirability(vehInMeasure, vehOutMeasure, 0, 0);
90 : }
91 0 : std::string MSSOTLPolicy5DStimulus::getMessage() {
92 0 : std::ostringstream _str;
93 0 : _str << " stimCox " << getStimCox()
94 0 : << " StimOffsetIn " << getStimOffsetIn()
95 0 : << " StimOffsetOut " << getStimOffsetOut()
96 0 : << " StimDivisorIn " << getStimDivisorIn()
97 0 : << " StimDivisorOut " << getStimDivisorOut()
98 0 : << " StimCoxExpIn " << getStimCoxExpIn()
99 0 : << " StimCoxExpOut " << getStimCoxExpOut()
100 0 : << " .";
101 0 : return _str.str();
102 0 : }
|