SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RODFRouteCont.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // A container for routes
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 <fstream>
34 #include <cassert>
35 #include "RODFRouteDesc.h"
36 #include "RODFRouteCont.h"
37 #include "RODFNet.h"
38 #include <router/ROEdge.h>
39 #include <utils/common/ToString.h>
41 
42 #ifdef CHECK_MEMORY_LEAKS
43 #include <foreign/nvwa/debug_new.h>
44 #endif // CHECK_MEMORY_LEAKS
45 
46 
47 // ===========================================================================
48 // method definitions
49 // ===========================================================================
51 
52 
54 }
55 
56 
57 void
59  // routes may be duplicate as in-between routes may have different starting points
60  if (find_if(myRoutes.begin(), myRoutes.end(), route_finder(desc)) == myRoutes.end()) {
61  // compute route id
62  setID(desc);
63  myRoutes.push_back(desc);
64  } else {
65  RODFRouteDesc& prev = *find_if(myRoutes.begin(), myRoutes.end(), route_finder(desc));
66  prev.overallProb += desc.overallProb;
67  }
68 }
69 
70 
71 bool
73  std::vector<RODFRouteDesc>::const_iterator j = find_if(myRoutes.begin(), myRoutes.end(), route_finder(desc));
74  if (j == myRoutes.end()) {
75  return false;
76  }
77  return true;
78 }
79 
80 
81 bool
82 RODFRouteCont::save(std::vector<std::string>& saved,
83  const std::string& prependix, OutputDevice& out) {
84  bool haveSavedOneAtLeast = false;
85  for (std::vector<RODFRouteDesc>::const_iterator j = myRoutes.begin(); j != myRoutes.end(); ++j) {
86  const RODFRouteDesc& desc = (*j);
87  if (find(saved.begin(), saved.end(), desc.routename) != saved.end()) {
88  continue;
89  }
90  saved.push_back((*j).routename);
91  assert(desc.edges2Pass.size() >= 1);
92  out.openTag(SUMO_TAG_ROUTE).writeAttr(SUMO_ATTR_ID, prependix + desc.routename);
93  out << " edges=\"";
94  for (std::vector<ROEdge*>::const_iterator k = desc.edges2Pass.begin(); k != desc.edges2Pass.end(); k++) {
95  if (k != desc.edges2Pass.begin()) {
96  out << ' ';
97  }
98  out << (*k)->getID();
99  }
100  out << '"';
101  out.closeTag();
102  haveSavedOneAtLeast = true;
103  }
104  return haveSavedOneAtLeast;
105 }
106 
107 
108 void
110  sort(myRoutes.begin(), myRoutes.end(), by_distance_sorter());
111 }
112 
113 
114 void
115 RODFRouteCont::removeIllegal(const std::vector<std::vector<ROEdge*> >& illegals) {
116  for (std::vector<RODFRouteDesc>::iterator i = myRoutes.begin(); i != myRoutes.end();) {
117  RODFRouteDesc& desc = *i;
118  bool remove = false;
119  for (std::vector<std::vector<ROEdge*> >::const_iterator j = illegals.begin(); !remove && j != illegals.end(); ++j) {
120  int noFound = 0;
121  for (std::vector<ROEdge*>::const_iterator k = (*j).begin(); !remove && k != (*j).end(); ++k) {
122  if (find(desc.edges2Pass.begin(), desc.edges2Pass.end(), *k) != desc.edges2Pass.end()) {
123  noFound++;
124  if (noFound > 1) {
125  remove = true;
126  }
127  }
128  }
129  }
130  if (remove) {
131  i = myRoutes.erase(i);
132  } else {
133  ++i;
134  }
135  }
136 }
137 
138 
139 void
141  std::pair<ROEdge*, ROEdge*> c(desc.edges2Pass[0], desc.edges2Pass.back());
142  desc.routename = c.first->getID() + "_to_" + c.second->getID();
143  if (myConnectionOccurences.find(c) == myConnectionOccurences.end()) {
144  myConnectionOccurences[c] = 0;
145  } else {
147  desc.routename = desc.routename + "_" + toString(myConnectionOccurences[c]);
148  }
149 }
150 
151 
152 
153 /****************************************************************************/
154