LCOV - code coverage report
Current view: top level - src/activitygen/city - AGAdult.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 63.9 % 36 23
Test Date: 2024-11-22 15:46:21 Functions: 62.5 % 8 5

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2010-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    AGAdult.cpp
      17              : /// @author  Piotr Woznica
      18              : /// @author  Walter Bamberger
      19              : /// @author  Daniel Krajzewicz
      20              : /// @author  Michael Behrisch
      21              : /// @date    July 2010
      22              : ///
      23              : // Person in working age: can be linked to a work position.
      24              : /****************************************************************************/
      25              : #include <config.h>
      26              : 
      27              : #include <iostream>
      28              : #include <utils/common/RandHelper.h>
      29              : #include <utils/common/UtilExceptions.h>
      30              : #include "AGWorkPosition.h"
      31              : #include "AGAdult.h"
      32              : 
      33              : 
      34              : // ===========================================================================
      35              : // method definitions
      36              : // ===========================================================================
      37              : AGWorkPosition*
      38         2952 : AGAdult::randomFreeWorkPosition(std::vector<AGWorkPosition>* wps) {
      39              :     std::vector<AGWorkPosition*> freePos;
      40      2506292 :     for (std::vector<AGWorkPosition>::iterator i = wps->begin(); i != wps->end(); ++i) {
      41      2503340 :         if (!i->isTaken()) {
      42      1418939 :             freePos.push_back(&*i);
      43              :         }
      44              :     }
      45         2952 :     if (freePos.empty()) {
      46              :         return nullptr;
      47              :     }
      48         2952 :     return RandHelper::getRandomFrom(freePos);
      49         2952 : }
      50              : 
      51              : 
      52         4045 : AGAdult::AGAdult(int age)
      53         4045 :     : AGPerson(age), work(nullptr) {}
      54              : 
      55              : 
      56              : void
      57            0 : AGAdult::print() const {
      58            0 :     std::cout << "- AGAdult: Age=" << age << " Work=" << work << std::endl;
      59            0 : }
      60              : 
      61              : 
      62              : void
      63         3092 : AGAdult::tryToWork(double rate, std::vector<AGWorkPosition>* wps) {
      64         3092 :     if (decide(rate)) {
      65              :         // Select the new work position before giving up the current one.
      66              :         // This avoids that the current one is the same as the new one.
      67         2952 :         AGWorkPosition* newWork = randomFreeWorkPosition(wps);
      68              : 
      69         2952 :         if (work != nullptr) {
      70            0 :             work->let();
      71              :         }
      72         2952 :         work = newWork;
      73         2952 :         if (work != nullptr) {
      74         2952 :             work->take(this);
      75              :         }
      76              :     } else {
      77          140 :         if (work != nullptr) {
      78              :             // Also sets work = 0 with the call back lostWorkPosition
      79            0 :             work->let();
      80              :         }
      81              :     }
      82         3092 : }
      83              : 
      84              : 
      85              : bool
      86         7452 : AGAdult::isWorking() const {
      87         7452 :     return (work != nullptr);
      88              : }
      89              : 
      90              : 
      91              : void
      92            0 : AGAdult::lostWorkPosition() {
      93            0 :     work = nullptr;
      94            0 : }
      95              : 
      96              : 
      97              : void
      98            0 : AGAdult::resignFromWorkPosition() {
      99            0 :     if (work != nullptr) {
     100            0 :         work->let();
     101              :     }
     102            0 : }
     103              : 
     104              : 
     105              : const AGWorkPosition&
     106        10081 : AGAdult::getWorkPosition() const {
     107        10081 :     if (work != nullptr) {
     108        10081 :         return *work;
     109              :     }
     110            0 :     throw ProcessError("AGAdult::getWorkPosition: Adult is unemployed.");
     111              : }
     112              : 
     113              : 
     114              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1