SUMO - Simulation of Urban MObility
ROJTRRouter.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // Computes routes using junction turning percentages
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <router/RONet.h>
33 #include "ROJTRRouter.h"
34 #include "ROJTREdge.h"
36 
37 
38 // ===========================================================================
39 // method definitions
40 // ===========================================================================
41 ROJTRRouter::ROJTRRouter(bool unbuildIsWarningOnly, bool acceptAllDestinations,
42  int maxEdges, bool ignoreClasses, bool allowLoops) :
43  SUMOAbstractRouter<ROEdge, ROVehicle>(0, "JTRRouter"),
44  myUnbuildIsWarningOnly(unbuildIsWarningOnly),
45  myAcceptAllDestination(acceptAllDestinations), myMaxEdges(maxEdges),
46  myIgnoreClasses(ignoreClasses), myAllowLoops(allowLoops) {
47 }
48 
49 
51 
52 
53 bool
54 ROJTRRouter::compute(const ROEdge* from, const ROEdge* to,
55  const ROVehicle* const vehicle,
56  SUMOTime time, ConstROEdgeVector& into) {
57  const ROJTREdge* current = static_cast<const ROJTREdge*>(from);
58  double timeS = STEPS2TIME(time);
59  std::set<const ROEdge*> avoidEdges;
60  // route until a sinks has been found
61  while (current != 0 && current != to &&
62  !current->isSink() &&
63  (int)into.size() < myMaxEdges) {
64  into.push_back(current);
65  if (!myAllowLoops) {
66  avoidEdges.insert(current);
67  }
68  timeS += current->getTravelTime(vehicle, timeS);
69  current = current->chooseNext(myIgnoreClasses ? 0 : vehicle, timeS, avoidEdges);
70  assert(myIgnoreClasses || current == 0 || !current->prohibits(vehicle));
71  }
72  // check whether no valid ending edge was found
73  if (current == 0 || (int) into.size() >= myMaxEdges) {
75  return true;
76  } else {
78  mh->inform("The route starting at edge '" + from->getID() + "' could not be closed.");
79  return false;
80  }
81  }
82  // append the sink
83  if (current != 0) {
84  into.push_back(current);
85  }
86  return true;
87 }
88 
89 
90 double
91 ROJTRRouter::recomputeCosts(const ConstROEdgeVector& edges, const ROVehicle* const v, SUMOTime msTime) const {
92  const double time = STEPS2TIME(msTime);
93  double costs = 0;
94  for (ConstROEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
95  costs += (*i)->getTravelTime(v, time);
96  }
97  return costs;
98 }
99 
100 
101 
102 /****************************************************************************/
103 
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
Definition: MsgHandler.cpp:66
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:75
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
bool compute(const ROEdge *from, const ROEdge *to, const ROVehicle *const vehicle, SUMOTime time, ConstROEdgeVector &into)
Computes a route.
Definition: ROJTRRouter.cpp:54
bool prohibits(const ROVehicle *const vehicle) const
Returns whether this edge prohibits the given vehicle to pass it.
Definition: ROEdge.h:269
std::vector< const ROEdge * > ConstROEdgeVector
Definition: ROEdge.h:62
const std::string & getID() const
Returns the id.
Definition: Named.h:74
const bool myAcceptAllDestination
Whether all edges may be used as route end.
Definition: ROJTRRouter.h:104
const bool myAllowLoops
Whether a vehicle may reuse a road.
Definition: ROJTRRouter.h:113
A vehicle as used by router.
Definition: ROVehicle.h:59
~ROJTRRouter()
Destructor.
Definition: ROJTRRouter.cpp:50
const bool myIgnoreClasses
Whether vehicle class information shall be ignored.
Definition: ROJTRRouter.h:110
double recomputeCosts(const ConstROEdgeVector &edges, const ROVehicle *const v, SUMOTime msTime) const
Recomputes the costs of a route.
Definition: ROJTRRouter.cpp:91
#define STEPS2TIME(x)
Definition: SUMOTime.h:64
An edge the jtr-router may route through.
Definition: ROJTREdge.h:57
A basic edge for routing applications.
Definition: ROEdge.h:77
bool isSink() const
Returns whether the edge acts as a sink.
Definition: ROEdge.h:196
ROJTRRouter(bool unbuildIsWarningOnly, bool acceptAllDestinations, int maxEdges, bool ignoreClasses, bool allowLoops)
Constructor.
Definition: ROJTRRouter.cpp:41
double getTravelTime(const ROVehicle *const veh, double time) const
Returns the travel time for this edge.
Definition: ROEdge.cpp:174
void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:84
ROJTREdge * chooseNext(const ROVehicle *const veh, double time, const std::set< const ROEdge *> &avoid) const
Returns the next edge to use.
Definition: ROJTREdge.cpp:78
long long int SUMOTime
Definition: TraCIDefs.h:51