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