SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSInternalJunction.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // junction.
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12 // Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include "MSInternalJunction.h"
34 #include "MSLane.h"
35 #include "MSJunctionLogic.h"
36 #include "MSBitSetLogic.h"
37 #include <algorithm>
38 #include <cassert>
39 #include <cmath>
40 
41 #ifdef CHECK_MEMORY_LEAKS
42 #include <foreign/nvwa/debug_new.h>
43 #endif // CHECK_MEMORY_LEAKS
44 
45 
46 // ===========================================================================
47 // method definitions
48 // ===========================================================================
49 #ifdef HAVE_INTERNAL_LANES
50 MSInternalJunction::MSInternalJunction(const std::string& id,
51  const Position& position,
52  const PositionVector& shape,
53  std::vector<MSLane*> incoming,
54  std::vector<MSLane*> internal)
55  : MSLogicJunction(id, position, shape, incoming, internal) {}
56 
57 
58 
59 MSInternalJunction::~MSInternalJunction() {}
60 
61 
62 void
63 MSInternalJunction::postloadInit() {
64  if (myIncomingLanes.size() == 0) {
65  throw ProcessError("Internal junction " + getID() + " has no incoming lanes");
66  }
67  // the first lane in the list of incoming lanes is special. It defines the
68  // link that needs to do all the checking for this internal junction
69  assert(myIncomingLanes[0]->getLinkCont().size() == 1);
70  MSLink* thisLink = myIncomingLanes[0]->getLinkCont()[0];
71  // inform links where they have to report approaching vehicles to
72  unsigned int requestPos = 0;
73  for (std::vector<MSLane*>::iterator i = myInternalLanes.begin(); i != myInternalLanes.end(); ++i) {
74  const MSLinkCont& lc = (*i)->getLinkCont();
75  for (MSLinkCont::const_iterator q = lc.begin(); q != lc.end(); ++q) {
76  if ((*q)->getViaLane() != 0) {
77  myInternalLaneFoes.push_back((*q)->getViaLane());
78  } else {
79  myInternalLaneFoes.push_back(*i);
80  }
81  }
82 
83  }
84  for (std::vector<MSLane*>::const_iterator i = myIncomingLanes.begin() + 1; i != myIncomingLanes.end(); ++i) {
85  MSLane* l = *i;
86  const MSLinkCont& lc = l->getLinkCont();
87  for (MSLinkCont::const_iterator j = lc.begin(); j != lc.end(); ++j) {
88  MSLane* via = (*j)->getViaLane();
89  if (std::find(myInternalLanes.begin(), myInternalLanes.end(), via) == myInternalLanes.end()) {
90  continue;
91  }
92  myInternalLinkFoes.push_back(*j);
93  }
94  }
95  thisLink->setRequestInformation(requestPos, true, false, myInternalLinkFoes, myInternalLaneFoes);
96  assert(thisLink->getViaLane()->getLinkCont().size() == 1);
97  MSLink* exitLink = thisLink->getViaLane()->getLinkCont()[0];
98  exitLink->setRequestInformation(requestPos, false, false, std::vector<MSLink*>(),
99  myInternalLaneFoes, thisLink->getViaLane());
100  for (std::vector<MSLink*>::const_iterator k = myInternalLinkFoes.begin(); k != myInternalLinkFoes.end(); ++k) {
101  thisLink->addBlockedLink(*k);
102  (*k)->addBlockedLink(thisLink);
103  }
104 }
105 
106 
107 #endif
108 
109 
110 /****************************************************************************/
111 
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
A list of positions.
const MSLinkCont & getLinkCont() const
returns the container with all links !!!
Definition: MSLane.cpp:998
Representation of a lane in the micro simulation.
Definition: MSLane.h:77