MSInternalJunction.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // junction.
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright 2001-2010 DLR (http://www.dlr.de/) and contributors
00011 /****************************************************************************/
00012 //
00013 //   This program is free software; you can redistribute it and/or modify
00014 //   it under the terms of the GNU General Public License as published by
00015 //   the Free Software Foundation; either version 2 of the License, or
00016 //   (at your option) any later version.
00017 //
00018 /****************************************************************************/
00019 
00020 
00021 // ===========================================================================
00022 // included modules
00023 // ===========================================================================
00024 #ifdef _MSC_VER
00025 #include <windows_config.h>
00026 #else
00027 #include <config.h>
00028 #endif
00029 
00030 #include "MSInternalJunction.h"
00031 #include "MSLane.h"
00032 #include "MSJunctionLogic.h"
00033 #include "MSBitSetLogic.h"
00034 #include <algorithm>
00035 #include <cassert>
00036 #include <cmath>
00037 
00038 #ifdef CHECK_MEMORY_LEAKS
00039 #include <foreign/nvwa/debug_new.h>
00040 #endif // CHECK_MEMORY_LEAKS
00041 
00042 
00043 // ===========================================================================
00044 // method definitions
00045 // ===========================================================================
00046 #ifdef HAVE_INTERNAL_LANES
00047 MSInternalJunction::MSInternalJunction(const std::string &id,
00048                                        const Position2D &position,
00049                                        const Position2DVector &shape,
00050                                        std::vector<MSLane*> incoming,
00051                                        std::vector<MSLane*> internal) throw()
00052         : MSLogicJunction(id, position, shape, incoming, internal) {}
00053 
00054 
00055 bool
00056 MSInternalJunction::clearRequests() {
00057     return true;
00058 }
00059 
00060 
00061 MSInternalJunction::~MSInternalJunction() {}
00062 
00063 
00064 void
00065 MSInternalJunction::postloadInit() throw(ProcessError) {
00066     // inform links where they have to report approaching vehicles to
00067     unsigned int requestPos = 0;
00068     myInternalLaneFoes = myInternalLanes;
00069     for (std::vector<MSLane*>::const_iterator i=myIncomingLanes.begin()+1; i!=myIncomingLanes.end(); ++i) {
00070         MSLane *l = *i;
00071         const MSLinkCont &lc = l->getLinkCont();
00072         for (MSLinkCont::const_iterator j=lc.begin(); j!=lc.end(); ++j) {
00073             myInternalLinkFoes.push_back(*j);
00074         }
00075     }
00076     if (myIncomingLanes.size()!=0) {
00077         // for the first incoming lane
00078         const MSLinkCont &links = myIncomingLanes[0]->getLinkCont();
00079         // ... set information for every link
00080         for (MSLinkCont::const_iterator j=links.begin(); j!=links.end(); j++) {
00081             (*j)->setRequestInformation(&myRequest, requestPos,
00082                                         &myRespond, requestPos,
00083                                         MSLogicJunction::LinkFoes(), true, false,
00084                                         myInternalLinkFoes, myInternalLaneFoes);
00085             requestPos++;
00086         }
00087     }
00088 }
00089 
00090 
00091 bool
00092 MSInternalJunction::setAllowed() {
00093     // Get myRespond from logic and check for deadlocks.
00094     myRespond.set(0, true);
00095     std::vector<MSLane*>::iterator i;
00096     if (myIncomingLanes.size()==0) {
00097         return true;
00098     }
00099 
00100     // do nothing if there is no vehicle
00101     if (!myRequest.test(0)) {
00102         return true;
00103     }
00104 
00105     // do not move if any other internal (foe) lane is set
00106     for (i=myInternalLanes.begin(); i!=myInternalLanes.end(); ++i) {
00107         if (!(*i)->empty()) {
00108             myRespond.set(0, false);
00109             return true;
00110         }
00111     }
00112     // do not move if a vehicle is approaching on a link from foe lanes
00113     //  the first entry is our lane itself, the following should be those that feed
00114     //  the internal lanes
00115     for (i=myIncomingLanes.begin()+1; i!=myIncomingLanes.end(); ++i) {
00116         MSLane *l = *i;
00117         const MSVehicle * const foe = l->getFirstVehicle();
00118         const MSLinkCont &lc = l->getLinkCont();
00119         for (MSLinkCont::const_iterator j=lc.begin(); j!=lc.end(); ++j) {
00120             if (find(myInternalLanes.begin(), myInternalLanes.end(), (*j)->getViaLane())!=myInternalLanes.end()) {
00121                 bool approached = foe!=0&&(*j)->getApproaching()==foe;
00122                 approached |= ((*j)->getViaLane()!=0&&!(*j)->getViaLane()->empty());
00123                 if (approached&&((*j)->opened(0, 0)||(*j)->havePriority())) {
00124                     myRespond.set(0, false);
00125                     return true;
00126                 }
00127             }
00128         }
00129     }
00130     /*
00131     // do not move if the destination lane is full
00132     // get the next lane
00133     // - recheck whether this is really needed !!!
00134     MSLane *l = myIncomingLanes[0];
00135     const MSLinkCont &lc1 = l->getLinkCont();
00136     MSLink *link = lc1[0];
00137     MSLane *dest = link->getLane();
00138     if (dest==0) {
00139         return true;
00140     }
00141     const MSVehicle * const lastOnDest = dest->getLastVehicle();
00142     if (lastOnDest!=0) {
00143         if (lastOnDest->getPositionOnLane()-lastOnDest->getLength()<5) { // !!! explcite vehicle length
00144             myRespond.set(0, false);
00145             return true;
00146         }
00147     }
00148     */
00149     return true;
00150 }
00151 
00152 
00153 #endif
00154 
00155 
00156 /****************************************************************************/
00157 

Generated on Wed May 5 00:06:31 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6