Eclipse 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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // Computes routes using junction turning percentages
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <router/RONet.h>
27 #include "ROJTRRouter.h"
28 #include "ROJTREdge.h"
30 
31 
32 // ===========================================================================
33 // method definitions
34 // ===========================================================================
35 ROJTRRouter::ROJTRRouter(bool unbuildIsWarningOnly, bool acceptAllDestinations,
36  int maxEdges, bool ignoreClasses, bool allowLoops) :
37  SUMOAbstractRouter<ROEdge, ROVehicle>("JTRRouter", unbuildIsWarningOnly, &ROEdge::getTravelTimeStatic),
38  myUnbuildIsWarningOnly(unbuildIsWarningOnly),
39  myAcceptAllDestination(acceptAllDestinations), myMaxEdges(maxEdges),
40  myIgnoreClasses(ignoreClasses), myAllowLoops(allowLoops) {
41 }
42 
43 
45 
46 
47 bool
48 ROJTRRouter::compute(const ROEdge* from, const ROEdge* to,
49  const ROVehicle* const vehicle,
50  SUMOTime time, ConstROEdgeVector& into, bool silent) {
51  const ROJTREdge* current = static_cast<const ROJTREdge*>(from);
52  double timeS = STEPS2TIME(time);
53  std::set<const ROEdge*> avoidEdges;
54  // route until a sinks has been found
55  while (current != nullptr && current != to &&
56  !current->isSink() &&
57  (int)into.size() < myMaxEdges) {
58  into.push_back(current);
59  if (!myAllowLoops) {
60  avoidEdges.insert(current);
61  }
62  timeS += current->getTravelTime(vehicle, timeS);
63  current = current->chooseNext(myIgnoreClasses ? nullptr : vehicle, timeS, avoidEdges);
64  assert(myIgnoreClasses || current == 0 || !current->prohibits(vehicle));
65  }
66  // check whether no valid ending edge was found
67  if (current == nullptr || (int) into.size() >= myMaxEdges) {
69  return true;
70  } else {
71  if (!silent) {
73  mh->inform("The route starting at edge '" + from->getID() + "' could not be closed.");
74  }
75  return false;
76  }
77  }
78  // append the sink
79  if (current != nullptr) {
80  into.push_back(current);
81  }
82  return true;
83 }
84 
85 
86 /****************************************************************************/
87 
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
Definition: MsgHandler.cpp:72
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:81
long long int SUMOTime
Definition: SUMOTime.h:35
const bool myUnbuildIsWarningOnly
Whether unbuildable routes shall be reported as warniings, not errors.
Definition: ROJTRRouter.h:95
const int myMaxEdges
The maximum number of edges a route may have.
Definition: ROJTRRouter.h:101
bool compute(const ROEdge *from, const ROEdge *to, const ROVehicle *const vehicle, SUMOTime time, ConstROEdgeVector &into, bool silent=false)
Computes a route.
Definition: ROJTRRouter.cpp:48
bool prohibits(const ROVehicle *const vehicle) const
Returns whether this edge prohibits the given vehicle to pass it.
Definition: ROEdge.h:262
std::vector< const ROEdge * > ConstROEdgeVector
Definition: ROEdge.h:57
const std::string & getID() const
Returns the id.
Definition: Named.h:77
const bool myAcceptAllDestination
Whether all edges may be used as route end.
Definition: ROJTRRouter.h:98
const bool myAllowLoops
Whether a vehicle may reuse a road.
Definition: ROJTRRouter.h:107
A vehicle as used by router.
Definition: ROVehicle.h:53
~ROJTRRouter()
Destructor.
Definition: ROJTRRouter.cpp:44
const bool myIgnoreClasses
Whether vehicle class information shall be ignored.
Definition: ROJTRRouter.h:104
#define STEPS2TIME(x)
Definition: SUMOTime.h:57
An edge the jtr-router may route through.
Definition: ROJTREdge.h:51
A basic edge for routing applications.
Definition: ROEdge.h:73
bool isSink() const
Returns whether the edge acts as a sink.
Definition: ROEdge.h:195
ROJTRRouter(bool unbuildIsWarningOnly, bool acceptAllDestinations, int maxEdges, bool ignoreClasses, bool allowLoops)
Constructor.
Definition: ROJTRRouter.cpp:35
double getTravelTime(const ROVehicle *const veh, double time) const
Returns the travel time for this edge.
Definition: ROEdge.cpp:184
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:118
ROJTREdge * chooseNext(const ROVehicle *const veh, double time, const std::set< const ROEdge *> &avoid) const
Returns the next edge to use.
Definition: ROJTREdge.cpp:72