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-2017 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 
39 // ===========================================================================
40 // method definitions
41 // ===========================================================================
42 ROJTRRouter::ROJTRRouter(bool unbuildIsWarningOnly, bool acceptAllDestinations,
43  int maxEdges, bool ignoreClasses, bool allowLoops) :
44  SUMOAbstractRouter<ROEdge, ROVehicle>(0, "JTRRouter"),
45  myUnbuildIsWarningOnly(unbuildIsWarningOnly),
46  myAcceptAllDestination(acceptAllDestinations), myMaxEdges(maxEdges),
47  myIgnoreClasses(ignoreClasses), myAllowLoops(allowLoops) {
48 }
49 
50 
52 
53 
54 bool
55 ROJTRRouter::compute(const ROEdge* from, const ROEdge* to,
56  const ROVehicle* const vehicle,
57  SUMOTime time, ConstROEdgeVector& into) {
58  const ROJTREdge* current = static_cast<const ROJTREdge*>(from);
59  double timeS = STEPS2TIME(time);
60  std::set<const ROEdge*> avoidEdges;
61  // route until a sinks has been found
62  while (current != 0 && current != to &&
63  current->getFunc() != ROEdge::ET_SINK &&
64  (int)into.size() < myMaxEdges) {
65  into.push_back(current);
66  if (!myAllowLoops) {
67  avoidEdges.insert(current);
68  }
69  timeS += current->getTravelTime(vehicle, timeS);
70  current = current->chooseNext(myIgnoreClasses ? 0 : vehicle, timeS, avoidEdges);
71  assert(myIgnoreClasses || current == 0 || !current->prohibits(vehicle));
72  }
73  // check whether no valid ending edge was found
74  if (current == 0 || (int) into.size() >= myMaxEdges) {
76  return true;
77  } else {
79  mh->inform("The route starting at edge '" + from->getID() + "' could not be closed.");
80  return false;
81  }
82  }
83  // append the sink
84  if (current != 0) {
85  into.push_back(current);
86  }
87  return true;
88 }
89 
90 
91 double
92 ROJTRRouter::recomputeCosts(const ConstROEdgeVector& edges, const ROVehicle* const v, SUMOTime msTime) const {
93  const double time = STEPS2TIME(msTime);
94  double costs = 0;
95  for (ConstROEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
96  costs += (*i)->getTravelTime(v, time);
97  }
98  return costs;
99 }
100 
101 
102 
103 /****************************************************************************/
104 
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
Definition: MsgHandler.cpp:67
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:76
const bool myUnbuildIsWarningOnly
Whether unbuildable routes shall be reported as warniings, not errors.
Definition: ROJTRRouter.h:102
const int myMaxEdges
The maximum number of edges a route may have.
Definition: ROJTRRouter.h:108
bool compute(const ROEdge *from, const ROEdge *to, const ROVehicle *const vehicle, SUMOTime time, ConstROEdgeVector &into)
Computes a route.
Definition: ROJTRRouter.cpp:55
bool prohibits(const ROVehicle *const vehicle) const
Returns whether this edge prohibits the given vehicle to pass it.
Definition: ROEdge.h:263
std::vector< const ROEdge * > ConstROEdgeVector
Definition: ROEdge.h:62
const std::string & getID() const
Returns the id.
Definition: Named.h:66
const bool myAcceptAllDestination
Whether all edges may be used as route end.
Definition: ROJTRRouter.h:105
const bool myAllowLoops
Whether a vehicle may reuse a road.
Definition: ROJTRRouter.h:114
A vehicle as used by router.
Definition: ROVehicle.h:60
An edge where vehicles disappear (no vehicle may leave this edge)
Definition: ROEdge.h:91
EdgeFunc getFunc() const
Returns the function of the edge.
Definition: ROEdge.h:190
~ROJTRRouter()
Destructor.
Definition: ROJTRRouter.cpp:51
const bool myIgnoreClasses
Whether vehicle class information shall be ignored.
Definition: ROJTRRouter.h:111
double recomputeCosts(const ConstROEdgeVector &edges, const ROVehicle *const v, SUMOTime msTime) const
Recomputes the costs of a route.
Definition: ROJTRRouter.cpp:92
#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:77
ROJTRRouter(bool unbuildIsWarningOnly, bool acceptAllDestinations, int maxEdges, bool ignoreClasses, bool allowLoops)
Constructor.
Definition: ROJTRRouter.cpp:42
double getTravelTime(const ROVehicle *const veh, double time) const
Returns the travel time for this edge.
Definition: ROEdge.cpp:155
void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:85
ROJTREdge * chooseNext(const ROVehicle *const veh, double time, const std::set< const ROEdge *> &avoid) const
Returns the next edge to use.
Definition: ROJTREdge.cpp:79
long long int SUMOTime
Definition: TraCIDefs.h:52