SUMO - Simulation of Urban MObility
ROJTRRouter.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Computes routes using junction turning percentages
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2015 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 <router/RONet.h>
34 #include "ROJTRRouter.h"
35 #include "ROJTREdge.h"
37 
38 #ifdef CHECK_MEMORY_LEAKS
39 #include <foreign/nvwa/debug_new.h>
40 #endif // CHECK_MEMORY_LEAKS
41 
42 
43 // ===========================================================================
44 // method definitions
45 // ===========================================================================
46 ROJTRRouter::ROJTRRouter(bool unbuildIsWarningOnly, bool acceptAllDestinations,
47  int maxEdges, bool ignoreClasses, bool allowLoops) :
48  SUMOAbstractRouter<ROEdge, ROVehicle>(0, "JTRRouter"),
49  myUnbuildIsWarningOnly(unbuildIsWarningOnly),
50  myAcceptAllDestination(acceptAllDestinations), myMaxEdges(maxEdges),
51  myIgnoreClasses(ignoreClasses), myAllowLoops(allowLoops)
52 { }
53 
54 
56 
57 
58 void
59 ROJTRRouter::compute(const ROEdge* from, const ROEdge* to,
60  const ROVehicle* const vehicle,
61  SUMOTime time, ConstROEdgeVector& into) {
62  const ROJTREdge* current = static_cast<const ROJTREdge*>(from);
63  SUMOReal timeS = STEPS2TIME(time);
64  std::set<const ROEdge*> avoidEdges;
65  // route until a sinks has been found
66  while (current != 0 && current != to &&
67  current->getFunc() != ROEdge::ET_SINK &&
68  (int)into.size() < myMaxEdges) {
69  into.push_back(current);
70  if (!myAllowLoops) {
71  avoidEdges.insert(current);
72  }
73  timeS += current->getTravelTime(vehicle, timeS);
74  current = current->chooseNext(myIgnoreClasses ? 0 : vehicle, timeS, avoidEdges);
75  assert(myIgnoreClasses || current == 0 || !current->prohibits(vehicle));
76  }
77  // check whether no valid ending edge was found
78  if (current == 0 || (int) into.size() >= myMaxEdges) {
80  return;
81  } else {
83  mh->inform("The route starting at edge '" + from->getID() + "' could not be closed.");
84  }
85  }
86  // append the sink
87  if (current != 0) {
88  into.push_back(current);
89  }
90 }
91 
92 
94 ROJTRRouter::recomputeCosts(const ConstROEdgeVector& edges, const ROVehicle* const v, SUMOTime time) const {
95  SUMOReal costs = 0;
96  for (ConstROEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
97  costs += (*i)->getTravelTime(v, time);
98  }
99  return costs;
100 }
101 
102 
103 
104 /****************************************************************************/
105 
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
Definition: MsgHandler.cpp:71
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:80
long long int SUMOTime
Definition: SUMOTime.h:43
const bool myUnbuildIsWarningOnly
Whether unbuildable routes shall be reported as warniings, not errors.
Definition: ROJTRRouter.h:101
const int myMaxEdges
The maximum number of edges a route may have.
Definition: ROJTRRouter.h:107
ROJTREdge * chooseNext(const ROVehicle *const veh, SUMOReal time, const std::set< const ROEdge * > &avoid) const
Returns the next edge to use.
Definition: ROJTREdge.cpp:83
EdgeFunc getFunc() const
Returns the function of the edge.
Definition: ROEdge.h:186
std::vector< const ROEdge * > ConstROEdgeVector
Definition: ROEdge.h:59
const bool myAcceptAllDestination
Whether all edges may be used as route end.
Definition: ROJTRRouter.h:104
void compute(const ROEdge *from, const ROEdge *to, const ROVehicle *const vehicle, SUMOTime time, ConstROEdgeVector &into)
Computes a route.
Definition: ROJTRRouter.cpp:59
const bool myAllowLoops
Whether a vehicle may reuse a road.
Definition: ROJTRRouter.h:113
SUMOReal recomputeCosts(const ConstROEdgeVector &edges, const ROVehicle *const v, SUMOTime time) const
Recomputes the costs of a route.
Definition: ROJTRRouter.cpp:94
const std::string & getID() const
Returns the id.
Definition: Named.h:65
A vehicle as used by router.
Definition: ROVehicle.h:60
An edge where vehicles disappear (no vehicle may leave this edge)
Definition: ROEdge.h:87
~ROJTRRouter()
Destructor.
Definition: ROJTRRouter.cpp:55
const bool myIgnoreClasses
Whether vehicle class information shall be ignored.
Definition: ROJTRRouter.h:110
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
An edge the jtr-router may route through.
Definition: ROJTREdge.h:58
A basic edge for routing applications.
Definition: ROEdge.h:73
ROJTRRouter(bool unbuildIsWarningOnly, bool acceptAllDestinations, int maxEdges, bool ignoreClasses, bool allowLoops)
Constructor.
Definition: ROJTRRouter.cpp:46
bool prohibits(const ROVehicle *const vehicle) const
Returns whether this edge prohibits the given vehicle to pass it.
Definition: ROEdge.h:235
void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:89
#define SUMOReal
Definition: config.h:214
SUMOReal getTravelTime(const ROVehicle *const veh, SUMOReal time) const
Returns the travel time for this edge.
Definition: ROEdge.cpp:160