LCOV - code coverage report
Current view: top level - src/microsim/traffic_lights - MSSOTLPolicy5DStimulus.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 35 55 63.6 %
Date: 2024-05-19 15:37:39 Functions: 2 4 50.0 %

          Line data    Source code
       1             : /****************************************************************************/
       2             : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3             : // Copyright (C) 2013-2024 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         128 : MSSOTLPolicy5DStimulus::MSSOTLPolicy5DStimulus(std::string keyPrefix,
      30         128 :         const Parameterised::Map& parameters) :
      31         128 :     MSSOTLPolicyDesirability(keyPrefix, parameters) {
      32             : 
      33         128 :     stimCoxDVal = 1;
      34         128 :     stimOffsetInDVal = 1;
      35         128 :     stimOffsetOutDVal = 1;
      36         128 :     stimOffsetDispersionInDVal = 1;
      37         128 :     stimOffsetDispersionOutDVal = 1;
      38         128 :     stimDivInDVal = 1;
      39         128 :     stimDivOutDVal = 1;
      40         128 :     stimDivDispersionInDVal = 1;
      41         128 :     stimDivDispersionOutDVal = 1;
      42         128 :     stimCoxExpInDVal = 0;
      43         128 :     stimCoxExpOutDVal = 0;
      44         128 :     stimCoxExpDispersionInDVal = 0;
      45         128 :     stimCoxExpDispersionOutDVal = 0;
      46         128 : }
      47             : 
      48         160 : 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         160 :     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         160 :         double stimulus = getStimCox()
      68         160 :                           * exp(
      69         160 :                               -getStimCoxExpIn()
      70         160 :                               * pow(vehInMeasure - getStimOffsetIn(), 2)
      71         160 :                               / getStimDivisorIn()
      72         160 :                               - getStimCoxExpOut()
      73         160 :                               * pow(vehOutMeasure - getStimOffsetOut(), 2)
      74         160 :                               / getStimDivisorOut()
      75         160 :                               - getStimCoxExpDispersionIn()
      76         160 :                               * pow(vehInDispersionMeasure - getStimOffsetDispersionIn(), 2)
      77         160 :                               / getStimDivisorDispersionIn()
      78         160 :                               - getStimCoxExpDispersionOut()
      79         160 :                               * pow(vehOutDispersionMeasure - getStimOffsetDispersionOut(), 2)
      80         160 :                               / getStimDivisorDispersionOut()
      81             : 
      82         160 :                           );
      83         160 :         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 : }

Generated by: LCOV version 1.14