|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // Parent object for all activities. Derived classes generate trips for each 00008 // household. 00009 /****************************************************************************/ 00010 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00011 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors 00012 // activitygen module 00013 // Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/) 00014 /****************************************************************************/ 00015 // 00016 // This program is free software; you can redistribute it and/or modify 00017 // it under the terms of the GNU General Public License as published by 00018 // the Free Software Foundation; either version 2 of the License, or 00019 // (at your option) any later version. 00020 // 00021 /****************************************************************************/ 00022 00023 00024 // =========================================================================== 00025 // included modules 00026 // =========================================================================== 00027 #ifdef _MSC_VER 00028 #include <windows_config.h> 00029 #else 00030 #include <config.h> 00031 #endif 00032 00033 #include <utils/common/RandHelper.h> 00034 #include "AGActivity.h" 00035 #include "../city/AGTime.h" 00036 00037 00038 // =========================================================================== 00039 // method definitions 00040 // =========================================================================== 00041 bool 00042 AGActivity::isGenerated() { 00043 return genDone; 00044 } 00045 00046 bool 00047 AGActivity::generateTrips() { 00048 return true; 00049 } 00050 00051 int 00052 AGActivity::possibleTranspMean(AGPosition destination) { 00053 int FOOT = 1; 00054 int BUS = 2; 00055 int CAR = 4; 00056 00057 int transp = 0; 00058 00059 if (destination.distanceTo(hh->getPosition()) <= ds->maxFootDistance) { 00060 transp = FOOT; 00061 if (hh->getCarNbr() != 0) { 00062 transp += CAR; 00063 } 00064 if (destination.minDistanceTo(ds->busStations) <= ds->maxFootDistance 00065 && hh->getPosition().minDistanceTo(ds->busStations) <= ds->maxFootDistance) { 00066 transp += BUS; 00067 } 00068 } else if (hh->getCarNbr() == 0) { 00069 SUMOReal d1 = destination.distanceTo(hh->getPosition()); 00070 SUMOReal d2 = destination.minDistanceTo(ds->busStations) + hh->getPosition().minDistanceTo(ds->busStations); 00071 00072 if (d1 > d2) { 00073 transp = BUS; 00074 } else { 00075 transp = FOOT; 00076 } 00077 } else if (hh->getCarNbr() != 0) { //all other cases 00078 if (destination.minDistanceTo(ds->busStations) > ds->maxFootDistance 00079 || hh->getPosition().minDistanceTo(ds->busStations) > ds->maxFootDistance) { 00080 transp = CAR; 00081 } else { 00082 transp = CAR + BUS; 00083 } 00084 } 00085 return transp; 00086 } 00087 00088 int 00089 AGActivity::availableTranspMeans(AGPosition from, AGPosition to) { 00090 int FOOT = 1; 00091 int BUS = 2; 00092 00093 int available = 0; 00094 00095 if (from.distanceTo(to) <= ds->maxFootDistance) { 00096 available += FOOT; 00097 } 00098 if (from.minDistanceTo(ds->busStations) <= ds->maxFootDistance 00099 && to.minDistanceTo(ds->busStations) <= ds->maxFootDistance) { 00100 available += BUS; 00101 } 00102 return available; 00103 } 00104 00105 int 00106 AGActivity::timeToDrive(AGPosition from, AGPosition to) { 00107 SUMOReal dist = from.distanceTo(to); 00108 return (int)(timePerKm * dist / 1000.0); 00109 } 00110 00111 int 00112 AGActivity::depHour(AGPosition from, AGPosition to, int arrival) { 00113 // ?? departure.addDays(1); // in case of negative time: arrival < timeToDrive 00114 //departure.setDay(0); // days are set to 0 because we want the time in the current day 00115 return (arrival - timeToDrive(from, to)); 00116 } 00117 00118 int 00119 AGActivity::arrHour(AGPosition from, AGPosition to, int departure) { 00120 return (departure + timeToDrive(from, to)); 00121 } 00122 00123 int 00124 AGActivity::randomTimeBetween(int begin, int end) { 00125 if (0 > begin || begin > end) { 00126 return -1; 00127 } 00128 if (begin == end) { 00129 return begin; 00130 } 00131 int tAlea = RandHelper::rand(end - begin); 00132 return (begin + tAlea); 00133 } 00134 00135 /****************************************************************************/ 00136 00137 00138 00139 00140 00141