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