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 /****************************************************************************/
10 // junction.
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include "MSInternalJunction.h"
35 #include "MSLane.h"
36 #include "MSJunctionLogic.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  SumoXMLNodeType type,
52  const Position& position,
53  const PositionVector& shape,
54  std::vector<MSLane*> incoming,
55  std::vector<MSLane*> internal)
56  : MSLogicJunction(id, type, position, shape, incoming, internal) {}
57 
58 
59 
60 MSInternalJunction::~MSInternalJunction() {}
61 
62 
63 void
64 MSInternalJunction::postloadInit() {
65  if (myIncomingLanes.size() == 0) {
66  throw ProcessError("Internal junction " + getID() + " has no incoming lanes");
67  }
68  // the first lane in the list of incoming lanes is special. It defines the
69  // link that needs to do all the checking for this internal junction
70  assert(myIncomingLanes[0]->getLinkCont().size() == 1);
71  MSLink* thisLink = myIncomingLanes[0]->getLinkCont()[0];
72  // inform links where they have to report approaching vehicles to
73  unsigned int requestPos = 0;
74  for (std::vector<MSLane*>::iterator i = myInternalLanes.begin(); i != myInternalLanes.end(); ++i) {
75  const MSLinkCont& lc = (*i)->getLinkCont();
76  for (MSLinkCont::const_iterator q = lc.begin(); q != lc.end(); ++q) {
77  if ((*q)->getViaLane() != 0) {
78  myInternalLaneFoes.push_back((*q)->getViaLane());
79  } else {
80  myInternalLaneFoes.push_back(*i);
81  }
82  }
83 
84  }
85  for (std::vector<MSLane*>::const_iterator i = myIncomingLanes.begin() + 1; i != myIncomingLanes.end(); ++i) {
86  MSLane* l = *i;
87  const MSLinkCont& lc = l->getLinkCont();
88  for (MSLinkCont::const_iterator j = lc.begin(); j != lc.end(); ++j) {
89  MSLane* via = (*j)->getViaLane();
90  if (std::find(myInternalLanes.begin(), myInternalLanes.end(), via) == myInternalLanes.end()) {
91  continue;
92  }
93  myInternalLinkFoes.push_back(*j);
94  }
95  }
96  // thisLinks is itself an exitLink of the preceding internal lane
97  thisLink->setRequestInformation((int)requestPos, true, false, myInternalLinkFoes, myInternalLaneFoes, thisLink->getViaLane()->getLogicalPredecessorLane());
98  assert(thisLink->getViaLane()->getLinkCont().size() == 1);
99  MSLink* exitLink = thisLink->getViaLane()->getLinkCont()[0];
100  exitLink->setRequestInformation((int)requestPos, false, false, std::vector<MSLink*>(),
101  myInternalLaneFoes, thisLink->getViaLane());
102  for (std::vector<MSLink*>::const_iterator k = myInternalLinkFoes.begin(); k != myInternalLinkFoes.end(); ++k) {
103  thisLink->addBlockedLink(*k);
104  (*k)->addBlockedLink(thisLink);
105  }
106 }
107 
108 
109 #endif
110 
111 
112 /****************************************************************************/
113 
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
A list of positions.
SumoXMLNodeType
Numbers representing special SUMO-XML-attribute values for representing node- (junction-) types used ...
const MSLinkCont & getLinkCont() const
returns the container with all links !!!
Definition: MSLane.cpp:1039
Representation of a lane in the micro simulation.
Definition: MSLane.h:77