SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00010 // Location and schedules of a work position: linked with one adult 00011 /****************************************************************************/ 00012 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00013 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00014 // activitygen module 00015 // Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/) 00016 /****************************************************************************/ 00017 // 00018 // This file is part of SUMO. 00019 // SUMO is free software: you can redistribute it and/or modify 00020 // it under the terms of the GNU General Public License as published by 00021 // the Free Software Foundation, either version 3 of the License, or 00022 // (at your option) any later version. 00023 // 00024 /****************************************************************************/ 00025 00026 00027 // =========================================================================== 00028 // included modules 00029 // =========================================================================== 00030 #ifdef _MSC_VER 00031 #include <windows_config.h> 00032 #else 00033 #include <config.h> 00034 #endif 00035 00036 #include "AGWorkPosition.h" 00037 #include "AGStreet.h" 00038 #include "AGPosition.h" 00039 #include "AGDataAndStatistics.h" 00040 #include "AGAdult.h" 00041 #include <utils/common/RandHelper.h> 00042 #include <iostream> 00043 00044 00045 // =========================================================================== 00046 // method definitions 00047 // =========================================================================== 00048 AGWorkPosition::AGWorkPosition(const AGStreet& inStreet, AGDataAndStatistics* ds) : 00049 location(inStreet), 00050 openingTime(generateOpeningTime(*ds)), 00051 closingTime(generateClosingTime(*ds)), 00052 ds(ds), 00053 adult(0) { 00054 ds->workPositions++; 00055 } 00056 00057 /****************************************************************************/ 00058 00059 AGWorkPosition::AGWorkPosition(const AGStreet& inStreet, SUMOReal pos, AGDataAndStatistics* ds) : 00060 location(inStreet, pos), 00061 openingTime(generateOpeningTime(*ds)), 00062 closingTime(generateClosingTime(*ds)), 00063 ds(ds), 00064 adult(0) { 00065 ds->workPositions++; 00066 } 00067 00068 AGWorkPosition::~AGWorkPosition() { 00069 // let(); 00070 } 00071 00072 /****************************************************************************/ 00073 00074 void 00075 AGWorkPosition::print() const { 00076 std::cout << "- AGWorkPosition: open=" << openingTime << " closingTime=" << closingTime << " taken=" << isTaken() << std::endl; 00077 std::cout << "\t"; 00078 location.print(); 00079 } 00080 00081 /****************************************************************************/ 00082 00083 int 00084 AGWorkPosition::generateOpeningTime(const AGDataAndStatistics& ds) { 00085 SUMOReal choice = RandHelper::rand(); 00086 SUMOReal cumul = 0; 00087 00088 for (std::map<int, SUMOReal>::const_iterator it = ds.beginWorkHours.begin(); 00089 it != ds.beginWorkHours.end(); ++it) { 00090 cumul += it->second; 00091 if (cumul >= choice) { 00092 return it->first; 00093 } 00094 } 00095 std::cout << "-- WARNING: work time distribution not complete (Sum(proportions) != 1): AUTODEFINED at 9.00am --" << std::endl; 00096 return 900; 00097 } 00098 00099 /****************************************************************************/ 00100 00101 int 00102 AGWorkPosition::generateClosingTime(const AGDataAndStatistics& ds) { 00103 SUMOReal choice = RandHelper::rand(); 00104 SUMOReal cumul = 0; 00105 for (std::map<int, SUMOReal>::const_iterator it = ds.endWorkHours.begin(); 00106 it != ds.endWorkHours.end(); ++it) { 00107 cumul += it->second; 00108 if (cumul >= choice) { 00109 return it->first; 00110 } 00111 } 00112 std::cout << "-- WARNING: work time distribution not complete (Sum(proportions) != 1): AUTODEFINED at 5.00pm --" << std::endl; 00113 return 1700; 00114 } 00115 00116 /****************************************************************************/ 00117 00118 bool 00119 AGWorkPosition::isTaken() const { 00120 return (adult != 0); 00121 } 00122 00123 /****************************************************************************/ 00124 00125 void 00126 AGWorkPosition::let() { 00127 if (adult != 0) { 00128 ds->workPositions++; 00129 adult->lostWorkPosition(); 00130 adult = 0; 00131 } 00132 } 00133 00134 /****************************************************************************/ 00135 00136 void 00137 AGWorkPosition::take(AGAdult* worker) throw(std::runtime_error) { 00138 if (adult == 0) { 00139 ds->workPositions--; 00140 adult = worker; 00141 } else { 00142 throw(std::runtime_error("Work position already occupied. Cannot give it to another adult.")); 00143 } 00144 } 00145 00146 /****************************************************************************/ 00147 00148 AGPosition 00149 AGWorkPosition::getPosition() const { 00150 return location; 00151 } 00152 00153 /****************************************************************************/ 00154 00155 int 00156 AGWorkPosition::getClosing() const { 00157 return closingTime; 00158 } 00159 00160 /****************************************************************************/ 00161 00162 int 00163 AGWorkPosition::getOpening() const { 00164 return openingTime; 00165 } 00166 00167 /****************************************************************************/