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 AGWorkPosition.cpp 17 : /// @author Piotr Woznica 18 : /// @author Walter Bamberger 19 : /// @author Daniel Krajzewicz 20 : /// @author Michael Behrisch 21 : /// @author Mirko Barthauer 22 : /// @date July 2010 23 : /// 24 : // Location and schedules of a work position: linked with one adult 25 : /****************************************************************************/ 26 : #include <config.h> 27 : 28 : #include "AGWorkPosition.h" 29 : #include "AGStreet.h" 30 : #include "AGPosition.h" 31 : #include "AGDataAndStatistics.h" 32 : #include "AGAdult.h" 33 : #include <utils/common/RandHelper.h> 34 : #include <iostream> 35 : 36 : 37 : // =========================================================================== 38 : // method definitions 39 : // =========================================================================== 40 3170 : AGWorkPosition::AGWorkPosition(AGDataAndStatistics* ds, const AGStreet& inStreet) : 41 3170 : myStatData(ds), 42 3170 : myLocation(inStreet), 43 3170 : myAdult(nullptr), 44 3170 : myOpeningTime(generateOpeningTime(*ds)), 45 3170 : myClosingTime(generateClosingTime(*ds)) { 46 3170 : ds->workPositions++; 47 3170 : } 48 : 49 : 50 240 : AGWorkPosition::AGWorkPosition(AGDataAndStatistics* ds, const AGStreet& inStreet, double pos) : 51 240 : myStatData(ds), 52 240 : myLocation(inStreet, pos), 53 240 : myAdult(nullptr), 54 240 : myOpeningTime(generateOpeningTime(*ds)), 55 240 : myClosingTime(generateClosingTime(*ds)) { 56 240 : ds->workPositions++; 57 240 : } 58 : 59 10917 : AGWorkPosition::~AGWorkPosition() { 60 : // let(); 61 10917 : } 62 : 63 : 64 : void 65 0 : AGWorkPosition::print() const { 66 0 : std::cout << "- AGWorkPosition: open=" << myOpeningTime << " closingTime=" << myClosingTime << " taken=" << isTaken() << std::endl; 67 0 : std::cout << "\t"; 68 0 : myLocation.print(); 69 0 : } 70 : 71 : 72 : int 73 3410 : AGWorkPosition::generateOpeningTime(const AGDataAndStatistics& ds) { 74 3410 : double choice = RandHelper::rand(); 75 : double cumul = 0; 76 : 77 3410 : for (std::map<int, double>::const_iterator it = ds.beginWorkHours.begin(); 78 5794 : it != ds.beginWorkHours.end(); ++it) { 79 5794 : cumul += it->second; 80 5794 : if (cumul >= choice) { 81 3410 : return it->first; 82 : } 83 : } 84 : std::cout << "-- WARNING: work time distribution not complete (Sum(proportions) != 1): AUTODEFINED at 9.00am --" << std::endl; 85 0 : return 32400; 86 : } 87 : 88 : 89 : int 90 3410 : AGWorkPosition::generateClosingTime(const AGDataAndStatistics& ds) { 91 3410 : double choice = RandHelper::rand(); 92 : double cumul = 0; 93 3410 : for (std::map<int, double>::const_iterator it = ds.endWorkHours.begin(); 94 8238 : it != ds.endWorkHours.end(); ++it) { 95 8238 : cumul += it->second; 96 8238 : if (cumul >= choice) { 97 3410 : return it->first; 98 : } 99 : } 100 : std::cout << "-- WARNING: work time distribution not complete (Sum(proportions) != 1): AUTODEFINED at 5.00pm --" << std::endl; 101 0 : return 61200; 102 : } 103 : 104 : 105 : bool 106 2503340 : AGWorkPosition::isTaken() const { 107 2503340 : return (myAdult != nullptr); 108 : } 109 : 110 : 111 : void 112 0 : AGWorkPosition::let() { 113 0 : if (myAdult != nullptr) { 114 0 : myStatData->workPositions++; 115 0 : myAdult->lostWorkPosition(); 116 0 : myAdult = nullptr; 117 : } 118 0 : } 119 : 120 : 121 : void 122 2952 : AGWorkPosition::take(AGAdult* worker) { 123 2952 : if (myAdult == nullptr) { 124 2952 : myStatData->workPositions--; 125 2952 : myAdult = worker; 126 : } else { 127 0 : throw ProcessError(TL("Work position already occupied. Cannot give it to another adult.")); 128 : } 129 2952 : } 130 : 131 : 132 : AGPosition 133 8025 : AGWorkPosition::getPosition() const { 134 8025 : return myLocation; 135 : } 136 : 137 : 138 : int 139 977 : AGWorkPosition::getClosing() const { 140 977 : return myClosingTime; 141 : } 142 : 143 : 144 : int 145 1079 : AGWorkPosition::getOpening() const { 146 1079 : return myOpeningTime; 147 : } 148 : 149 : 150 : /****************************************************************************/