SUMO - Simulation of Urban MObility

AGTrip.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // Class containing all information of a given trip (car, bus)
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 "AGTrip.h"
00033 
00034 
00035 // ===========================================================================
00036 // method definitions
00037 // ===========================================================================
00038 bool
00039 AGTrip::operator <(AGTrip& trip) {
00040     if (getDay() < trip.getDay()) {
00041         return true;
00042     }
00043     if (getDay() == trip.getDay())
00044         if (getTime() < trip.getTime()) {
00045             return true;
00046         }
00047     return false;
00048 }
00049 
00050 void
00051 AGTrip::print() {
00052     std::cout << "Trip: " << std::endl;
00053     std::cout << "\t-From= ";
00054     from.print();
00055     std::cout << "\t-To= ";
00056     to.print();
00057     std::cout << "\t-At= " << atTime << " -Day= " << day << std::endl;
00058     std::cout << "\t-Vehicle= " << vehicle << std::endl;
00059     std::cout << "\t-type= " << type << std::endl;
00060 }
00061 
00062 void
00063 AGTrip::addLayOver(AGPosition by) {
00064     passBy.push_back(by);
00065 }
00066 
00067 void
00068 AGTrip::addLayOver(AGTrip& trip) {
00069     std::list<AGPosition>::iterator it;
00070     for (it=trip.passBy.begin() ; it!=trip.passBy.end() ; ++it) {
00071         passBy.push_back(*it);
00072     }
00073     passBy.push_back(trip.to);
00074 }
00075 
00076 void
00077 AGTrip::addLayOverWithoutDestination(AGTrip& trip) {
00078     std::list<AGPosition>::iterator it;
00079     for (it=trip.passBy.begin() ; it!=trip.passBy.end() ; ++it) {
00080         passBy.push_back(*it);
00081     }
00082 }
00083 
00084 std::list<AGPosition>*
00085 AGTrip::getPassed() {
00086     return &passBy;
00087 }
00088 
00089 std::string
00090 AGTrip::getType() {
00091     return type;
00092 }
00093 
00094 void
00095 AGTrip::setType(std::string type) {
00096     this->type = type;
00097 }
00098 
00099 AGPosition
00100 AGTrip::getDep() {
00101     return from;
00102 }
00103 
00104 AGPosition
00105 AGTrip::getArr() {
00106     return to;
00107 }
00108 
00109 int
00110 AGTrip::getTime() {
00111     return atTime;
00112 }
00113 
00114 int
00115 AGTrip::getTimeTrip(SUMOReal secPerKm) {
00116     SUMOReal dist = 0;
00117     std::list<AGPosition> positions;
00118     positions.push_back(from);
00119     std::list<AGPosition>::iterator it;
00120     for (it=passBy.begin() ; it!=passBy.end() ; ++it) {
00121         positions.push_back(*it);
00122     }
00123     positions.push_back(to);
00124 
00125     bool firstPass = true;
00126     AGPosition* temp;
00127     for (it=positions.begin() ; it!=positions.end() ; ++it) {
00128         if (firstPass) {
00129             temp = &*it;
00130             continue;
00131         }
00132         dist += temp->distanceTo(*it);
00133         temp = &*it;
00134     }
00135     return (int)(secPerKm *(dist / 1000.0));
00136 }
00137 
00138 int
00139 AGTrip::getArrTime(SUMOReal secPerKm) {
00140     int arrTime = atTime + getTimeTrip(secPerKm);
00141     return arrTime;
00142 }
00143 
00144 int
00145 AGTrip::getRideBackArrTime(SUMOReal secPerKm) {
00146     int arrAtTime = getArrTime(secPerKm);
00147     int time = (int)(secPerKm * to.distanceTo(from) /1000.0);
00148     int arrTime = arrAtTime + time;
00149     return arrTime;
00150 }
00151 
00152 void
00153 AGTrip::setDepTime(int time) {
00154     atTime = time;
00155 }
00156 
00157 int
00158 AGTrip::estimateDepTime(int arrTime, SUMOReal secPerKm) {
00159     int depTime = arrTime - getTimeTrip(secPerKm);
00160     return depTime;
00161 }
00162 
00163 std::string
00164 AGTrip::getVehicleName() {
00165     return vehicle;
00166 }
00167 
00168 void
00169 AGTrip::setVehicleName(std::string name) {
00170     vehicle = name;
00171 }
00172 
00173 void
00174 AGTrip::setArr(AGPosition arrival) {
00175     to = *new AGPosition(arrival.getStreet(), arrival.getPosition());
00176 }
00177 
00178 void
00179 AGTrip::setDep(AGPosition departure) {
00180     from = *new AGPosition(departure.getStreet(), departure.getPosition());
00181 }
00182 
00183 bool
00184 AGTrip::isDaily() {
00185     if (day == 0) {
00186         return true;
00187     } else {
00188         return false;
00189     }
00190 }
00191 
00192 int
00193 AGTrip::getDay() {
00194     return day;
00195 }
00196 
00197 void
00198 AGTrip::setDay(int d) {
00199     day = d;
00200 }
00201 
00202 /****************************************************************************/
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines