SUMO - Simulation of Urban MObility
MSBusStop.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00007 // A lane area vehicles can halt at
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00011 /****************************************************************************/
00012 //
00013 //   This file is part of SUMO.
00014 //   SUMO is free software: you can redistribute it and/or modify
00015 //   it under the terms of the GNU General Public License as published by
00016 //   the Free Software Foundation, either version 3 of the License, or
00017 //   (at your option) any later version.
00018 //
00019 /****************************************************************************/
00020 
00021 
00022 // ===========================================================================
00023 // included modules
00024 // ===========================================================================
00025 #ifdef _MSC_VER
00026 #include <windows_config.h>
00027 #else
00028 #include <config.h>
00029 #endif
00030 
00031 #include <cassert>
00032 #include "MSTrigger.h"
00033 #include "MSBusStop.h"
00034 #include <utils/common/SUMOVehicle.h>
00035 #include <microsim/MSVehicleType.h>
00036 
00037 #ifdef CHECK_MEMORY_LEAKS
00038 #include <foreign/nvwa/debug_new.h>
00039 #endif // CHECK_MEMORY_LEAKS
00040 
00041 
00042 // ===========================================================================
00043 // method definitions
00044 // ===========================================================================
00045 MSBusStop::MSBusStop(const std::string& id,
00046                      const std::vector<std::string> &lines,
00047                      MSLane& lane,
00048                      SUMOReal begPos, SUMOReal endPos)
00049     : MSTrigger(id), myLines(lines), myLane(lane),
00050       myBegPos(begPos), myEndPos(endPos), myLastFreePos(endPos) {
00051     computeLastFreePos();
00052 }
00053 
00054 
00055 MSBusStop::~MSBusStop() {}
00056 
00057 
00058 const MSLane&
00059 MSBusStop::getLane() const {
00060     return myLane;
00061 }
00062 
00063 
00064 SUMOReal
00065 MSBusStop::getBeginLanePosition() const {
00066     return myBegPos;
00067 }
00068 
00069 
00070 SUMOReal
00071 MSBusStop::getEndLanePosition() const {
00072     return myEndPos;
00073 }
00074 
00075 
00076 void
00077 MSBusStop::enter(SUMOVehicle* what, SUMOReal beg, SUMOReal end) {
00078     myEndPositions[what] = std::pair<SUMOReal, SUMOReal>(beg, end);
00079     computeLastFreePos();
00080 }
00081 
00082 
00083 SUMOReal
00084 MSBusStop::getLastFreePos(SUMOVehicle &forVehicle) const {
00085     if(myLastFreePos!=myEndPos) {
00086         return myLastFreePos - forVehicle.getVehicleType().getMinGap();
00087     }
00088     return myLastFreePos;
00089 }
00090 
00091 
00092 void
00093 MSBusStop::leaveFrom(SUMOVehicle* what) {
00094     assert(myEndPositions.find(what) != myEndPositions.end());
00095     myEndPositions.erase(myEndPositions.find(what));
00096     computeLastFreePos();
00097 }
00098 
00099 
00100 void
00101 MSBusStop::computeLastFreePos() {
00102     myLastFreePos = myEndPos;
00103     std::map<SUMOVehicle*, std::pair<SUMOReal, SUMOReal> >::iterator i;
00104     for (i = myEndPositions.begin(); i != myEndPositions.end(); i++) {
00105         if (myLastFreePos > (*i).second.second) {
00106             myLastFreePos = (*i).second.second;
00107         }
00108     }
00109 }
00110 
00111 
00112 
00113 /****************************************************************************/
00114 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines