LCOV - code coverage report
Current view: top level - src/activitygen/activities - AGActivity.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 89.5 % 38 34
Test Date: 2024-11-22 15:46:21 Functions: 77.8 % 9 7

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
       4              : // activitygen module
       5              : // Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/)
       6              : // This program and the accompanying materials are made available under the
       7              : // terms of the Eclipse Public License 2.0 which is available at
       8              : // https://www.eclipse.org/legal/epl-2.0/
       9              : // This Source Code may also be made available under the following Secondary
      10              : // Licenses when the conditions for such availability set forth in the Eclipse
      11              : // Public License 2.0 are satisfied: GNU General Public License, version 2
      12              : // or later which is available at
      13              : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
      14              : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
      15              : /****************************************************************************/
      16              : /// @file    AGActivity.cpp
      17              : /// @author  Piotr Woznica
      18              : /// @author  Daniel Krajzewicz
      19              : /// @author  Walter Bamberger
      20              : /// @date    July 2010
      21              : ///
      22              : // Parent object for all activities. Derived classes generate trips for each
      23              : // household.
      24              : /****************************************************************************/
      25              : #include <config.h>
      26              : 
      27              : #include <utils/common/RandHelper.h>
      28              : #include <activitygen/city/AGHousehold.h>
      29              : #include <activitygen/city/AGTime.h>
      30              : #include "AGActivity.h"
      31              : 
      32              : 
      33              : // ===========================================================================
      34              : // method definitions
      35              : // ===========================================================================
      36              : bool
      37            0 : AGActivity::isGenerated() {
      38            0 :     return genDone;
      39              : }
      40              : 
      41              : 
      42              : bool
      43            0 : AGActivity::generateTrips() {
      44            0 :     return true;
      45              : }
      46              : 
      47              : int
      48         4272 : AGActivity::possibleTranspMean(AGPosition destination) {
      49              :     int FOOT = 1;
      50              :     int BUS = 2;
      51              :     int CAR = 4;
      52              : 
      53              :     int transp = 0;
      54              : 
      55         4272 :     if (destination.distanceTo(myHousehold->getPosition()) <= myStatData->maxFootDistance) {
      56              :         transp = FOOT;
      57          282 :         if (myHousehold->getCarNbr() != 0) {
      58              :             transp += CAR;
      59              :         }
      60          282 :         if (destination.minDistanceTo(myStatData->busStations) <= myStatData->maxFootDistance
      61          555 :                 && myHousehold->getPosition().minDistanceTo(myStatData->busStations) <= myStatData->maxFootDistance) {
      62          270 :             transp += BUS;
      63              :         }
      64         3990 :     } else if (myHousehold->getCarNbr() == 0) {
      65          945 :         double d1 = destination.distanceTo(myHousehold->getPosition());
      66          945 :         double d2 = destination.minDistanceTo(myStatData->busStations) + myHousehold->getPosition().minDistanceTo(myStatData->busStations);
      67              : 
      68          945 :         if (d1 > d2) {
      69              :             transp = BUS;
      70              :         } else {
      71              :             transp = FOOT;
      72              :         }
      73         3045 :     } else if (myHousehold->getCarNbr() != 0) { //all other cases
      74         3045 :         if (destination.minDistanceTo(myStatData->busStations) > myStatData->maxFootDistance
      75         5781 :                 || myHousehold->getPosition().minDistanceTo(myStatData->busStations) > myStatData->maxFootDistance) {
      76              :             transp = CAR;
      77              :         } else {
      78              :             transp = CAR + BUS;
      79              :         }
      80              :     }
      81         4272 :     return transp;
      82              : }
      83              : 
      84              : int
      85          570 : AGActivity::availableTranspMeans(AGPosition from, AGPosition to) {
      86              :     int FOOT = 1;
      87              :     int BUS = 2;
      88              : 
      89              :     int available = 0;
      90              : 
      91          570 :     if (from.distanceTo(to) <= myStatData->maxFootDistance) {
      92              :         available += FOOT;
      93              :     }
      94          570 :     if (from.minDistanceTo(myStatData->busStations) <= myStatData->maxFootDistance
      95          570 :             && to.minDistanceTo(myStatData->busStations) <= myStatData->maxFootDistance) {
      96          481 :         available += BUS;
      97              :     }
      98          570 :     return available;
      99              : }
     100              : 
     101              : 
     102              : int
     103         1052 : AGActivity::timeToDrive(AGPosition from, AGPosition to) {
     104         1052 :     double dist = from.distanceTo(to);
     105         1052 :     return (int)(timePerKm * dist / 1000.0);
     106              : }
     107              : 
     108              : 
     109              : int
     110          726 : AGActivity::depHour(AGPosition from, AGPosition to, int arrival) {
     111              :     // ?? departure.addDays(1); // in case of negative time: arrival < timeToDrive
     112              :     //departure.setDay(0); // days are set to 0 because we want the time in the current day
     113          726 :     return (arrival - timeToDrive(from, to));
     114              : }
     115              : 
     116              : 
     117              : int
     118          326 : AGActivity::arrHour(AGPosition from, AGPosition to, int departure) {
     119          326 :     return (departure + timeToDrive(from, to));
     120              : }
     121              : 
     122              : 
     123              : int
     124          652 : AGActivity::randomTimeBetween(int begin, int end) {
     125          652 :     if (0 > begin || begin > end) {
     126              :         return -1;
     127              :     }
     128          652 :     if (begin == end) {
     129              :         return begin;
     130              :     }
     131          652 :     int tAlea = RandHelper::rand(end - begin);
     132          652 :     return (begin + tAlea);
     133              : }
     134              : 
     135              : 
     136              : std::list<AGTrip>&
     137         3011 : AGActivity::getPartialActivityTrips() {
     138         3011 :     return myPartialActivityTrips;
     139              : }
     140              : 
     141              : 
     142              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1