SUMO - Simulation of Urban MObility
AGTrip.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00009 // Class containing all information of a given trip (car, bus)
00010 /****************************************************************************/
00011 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00012 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00013 // activitygen module
00014 // Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/)
00015 /****************************************************************************/
00016 //
00017 //   This file is part of SUMO.
00018 //   SUMO is free software: you can redistribute it and/or modify
00019 //   it under the terms of the GNU General Public License as published by
00020 //   the Free Software Foundation, either version 3 of the License, or
00021 //   (at your option) any later version.
00022 //
00023 /****************************************************************************/
00024 
00025 
00026 // ===========================================================================
00027 // included modules
00028 // ===========================================================================
00029 #ifdef _MSC_VER
00030 #include <windows_config.h>
00031 #else
00032 #include <config.h>
00033 #endif
00034 
00035 #include "AGTrip.h"
00036 
00037 
00038 // ===========================================================================
00039 // method definitions
00040 // ===========================================================================
00041 bool
00042 AGTrip::operator <(AGTrip& trip) {
00043     if (getDay() < trip.getDay()) {
00044         return true;
00045     }
00046     if (getDay() == trip.getDay())
00047         if (getTime() < trip.getTime()) {
00048             return true;
00049         }
00050     return false;
00051 }
00052 
00053 void
00054 AGTrip::print() {
00055     std::cout << "Trip: " << std::endl;
00056     std::cout << "\t-From= ";
00057     from.print();
00058     std::cout << "\t-To= ";
00059     to.print();
00060     std::cout << "\t-At= " << atTime << " -Day= " << day << std::endl;
00061     std::cout << "\t-Vehicle= " << vehicle << std::endl;
00062     std::cout << "\t-type= " << type << std::endl;
00063 }
00064 
00065 void
00066 AGTrip::addLayOver(AGPosition by) {
00067     passBy.push_back(by);
00068 }
00069 
00070 void
00071 AGTrip::addLayOver(AGTrip& trip) {
00072     std::list<AGPosition>::iterator it;
00073     for (it = trip.passBy.begin() ; it != trip.passBy.end() ; ++it) {
00074         passBy.push_back(*it);
00075     }
00076     passBy.push_back(trip.to);
00077 }
00078 
00079 void
00080 AGTrip::addLayOverWithoutDestination(AGTrip& trip) {
00081     std::list<AGPosition>::iterator it;
00082     for (it = trip.passBy.begin() ; it != trip.passBy.end() ; ++it) {
00083         passBy.push_back(*it);
00084     }
00085 }
00086 
00087 std::list<AGPosition>*
00088 AGTrip::getPassed() {
00089     return &passBy;
00090 }
00091 
00092 std::string
00093 AGTrip::getType() {
00094     return type;
00095 }
00096 
00097 void
00098 AGTrip::setType(std::string type) {
00099     this->type = type;
00100 }
00101 
00102 AGPosition
00103 AGTrip::getDep() {
00104     return from;
00105 }
00106 
00107 AGPosition
00108 AGTrip::getArr() {
00109     return to;
00110 }
00111 
00112 int
00113 AGTrip::getTime() {
00114     return atTime;
00115 }
00116 
00117 int
00118 AGTrip::getTimeTrip(SUMOReal secPerKm) {
00119     SUMOReal dist = 0;
00120     std::list<AGPosition> positions;
00121     positions.push_back(from);
00122     std::list<AGPosition>::iterator it;
00123     for (it = passBy.begin() ; it != passBy.end() ; ++it) {
00124         positions.push_back(*it);
00125     }
00126     positions.push_back(to);
00127 
00128     bool firstPass = true;
00129     AGPosition* temp;
00130     for (it = positions.begin() ; it != positions.end() ; ++it) {
00131         if (firstPass) {
00132             temp = &*it;
00133             continue;
00134         }
00135         dist += temp->distanceTo(*it);
00136         temp = &*it;
00137     }
00138     return (int)(secPerKm * (dist / 1000.0));
00139 }
00140 
00141 int
00142 AGTrip::getArrTime(SUMOReal secPerKm) {
00143     int arrTime = atTime + getTimeTrip(secPerKm);
00144     return arrTime;
00145 }
00146 
00147 int
00148 AGTrip::getRideBackArrTime(SUMOReal secPerKm) {
00149     int arrAtTime = getArrTime(secPerKm);
00150     int time = (int)(secPerKm * to.distanceTo(from) / 1000.0);
00151     int arrTime = arrAtTime + time;
00152     return arrTime;
00153 }
00154 
00155 void
00156 AGTrip::setDepTime(int time) {
00157     atTime = time;
00158 }
00159 
00160 int
00161 AGTrip::estimateDepTime(int arrTime, SUMOReal secPerKm) {
00162     int depTime = arrTime - getTimeTrip(secPerKm);
00163     return depTime;
00164 }
00165 
00166 std::string
00167 AGTrip::getVehicleName() {
00168     return vehicle;
00169 }
00170 
00171 void
00172 AGTrip::setVehicleName(std::string name) {
00173     vehicle = name;
00174 }
00175 
00176 void
00177 AGTrip::setArr(AGPosition arrival) {
00178     to = *new AGPosition(arrival.getStreet(), arrival.getPosition());
00179 }
00180 
00181 void
00182 AGTrip::setDep(AGPosition departure) {
00183     from = *new AGPosition(departure.getStreet(), departure.getPosition());
00184 }
00185 
00186 bool
00187 AGTrip::isDaily() {
00188     if (day == 0) {
00189         return true;
00190     } else {
00191         return false;
00192     }
00193 }
00194 
00195 int
00196 AGTrip::getDay() {
00197     return day;
00198 }
00199 
00200 void
00201 AGTrip::setDay(int d) {
00202     day = d;
00203 }
00204 
00205 /****************************************************************************/
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines