SUMO - Simulation of Urban MObility
AGActivity.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00009 // Parent object for all activities. Derived classes generate trips for each
00010 // household.
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 <utils/common/RandHelper.h>
00037 #include "AGActivity.h"
00038 #include "../city/AGTime.h"
00039 
00040 
00041 // ===========================================================================
00042 // method definitions
00043 // ===========================================================================
00044 bool
00045 AGActivity::isGenerated() {
00046     return genDone;
00047 }
00048 
00049 bool
00050 AGActivity::generateTrips() {
00051     return true;
00052 }
00053 
00054 int
00055 AGActivity::possibleTranspMean(AGPosition destination) {
00056     int FOOT = 1;
00057     int BUS = 2;
00058     int CAR = 4;
00059 
00060     int transp = 0;
00061 
00062     if (destination.distanceTo(hh->getPosition()) <= ds->maxFootDistance) {
00063         transp = FOOT;
00064         if (hh->getCarNbr() != 0) {
00065             transp += CAR;
00066         }
00067         if (destination.minDistanceTo(ds->busStations) <= ds->maxFootDistance
00068                 && hh->getPosition().minDistanceTo(ds->busStations) <= ds->maxFootDistance) {
00069             transp += BUS;
00070         }
00071     } else if (hh->getCarNbr() == 0) {
00072         SUMOReal d1 = destination.distanceTo(hh->getPosition());
00073         SUMOReal d2 = destination.minDistanceTo(ds->busStations) + hh->getPosition().minDistanceTo(ds->busStations);
00074 
00075         if (d1 > d2) {
00076             transp = BUS;
00077         } else {
00078             transp = FOOT;
00079         }
00080     } else if (hh->getCarNbr() != 0) { //all other cases
00081         if (destination.minDistanceTo(ds->busStations) > ds->maxFootDistance
00082                 || hh->getPosition().minDistanceTo(ds->busStations) > ds->maxFootDistance) {
00083             transp = CAR;
00084         } else {
00085             transp = CAR + BUS;
00086         }
00087     }
00088     return transp;
00089 }
00090 
00091 int
00092 AGActivity::availableTranspMeans(AGPosition from, AGPosition to) {
00093     int FOOT = 1;
00094     int BUS = 2;
00095 
00096     int available = 0;
00097 
00098     if (from.distanceTo(to) <= ds->maxFootDistance) {
00099         available += FOOT;
00100     }
00101     if (from.minDistanceTo(ds->busStations) <= ds->maxFootDistance
00102             && to.minDistanceTo(ds->busStations) <= ds->maxFootDistance) {
00103         available += BUS;
00104     }
00105     return available;
00106 }
00107 
00108 int
00109 AGActivity::timeToDrive(AGPosition from, AGPosition to) {
00110     SUMOReal dist = from.distanceTo(to);
00111     return (int)(timePerKm * dist / 1000.0);
00112 }
00113 
00114 int
00115 AGActivity::depHour(AGPosition from, AGPosition to, int arrival) {
00116     // ?? departure.addDays(1); // in case of negative time: arrival < timeToDrive
00117     //departure.setDay(0); // days are set to 0 because we want the time in the current day
00118     return (arrival - timeToDrive(from, to));
00119 }
00120 
00121 int
00122 AGActivity::arrHour(AGPosition from, AGPosition to, int departure) {
00123     return (departure + timeToDrive(from, to));
00124 }
00125 
00126 int
00127 AGActivity::randomTimeBetween(int begin, int end) {
00128     if (0 > begin || begin > end) {
00129         return -1;
00130     }
00131     if (begin == end) {
00132         return begin;
00133     }
00134     int tAlea = RandHelper::rand(end - begin);
00135     return (begin + tAlea);
00136 }
00137 
00138 /****************************************************************************/
00139 
00140 
00141 
00142 
00143 
00144 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines