SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-sim.org/
12 // Copyright (C) 2001-2014 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(RONet& net, bool unbuildIsWarningOnly, bool acceptAllDestinations,
47  int maxEdges, bool ignoreClasses, bool allowLoops) :
48  SUMOAbstractRouter<ROEdge, ROVehicle>("JTRRouter"),
49  myNet(net), 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, std::vector<const ROEdge*>& into) {
62  const ROJTREdge* current = static_cast<const ROJTREdge*>(from);
63  // route until a sinks has been found
64  while (current != 0
65  &&
66  current->getType() != ROEdge::ET_SINK
67  &&
68  (int) into.size() < myMaxEdges) {
69 
70  into.push_back(current);
71  time += (SUMOTime) current->getTravelTime(vehicle, time);
72  current = current->chooseNext(myIgnoreClasses ? 0 : vehicle, time);
73  assert(myIgnoreClasses || current == 0 || !current->prohibits(vehicle));
74  }
75  // check whether no valid ending edge was found
76  if ((int) into.size() >= myMaxEdges) {
78  return;
79  } else {
81  mh->inform("The route starting at edge '" + from->getID() + "' could not be closed.");
82  }
83  }
84  // append the sink
85  if (current != 0) {
86  into.push_back(current);
87  }
88 }
89 
90 
92 ROJTRRouter::recomputeCosts(const std::vector<const ROEdge*>& edges, const ROVehicle* const v, SUMOTime time) const {
93  SUMOReal costs = 0;
94  for (std::vector<const ROEdge*>::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:71
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:80
EdgeType getType() const
Returns the type of the edge.
Definition: ROEdge.h:172
SUMOReal recomputeCosts(const std::vector< const ROEdge * > &edges, const ROVehicle *const v, SUMOTime time) const
Recomputes the costs of a route.
Definition: ROJTRRouter.cpp:92
const bool myUnbuildIsWarningOnly
Whether unbuildable routes shall be reported as warniings, not errors.
Definition: ROJTRRouter.h:103
const int myMaxEdges
The maximum number of edges a route may have.
Definition: ROJTRRouter.h:109
void compute(const ROEdge *from, const ROEdge *to, const ROVehicle *const vehicle, SUMOTime time, std::vector< const ROEdge * > &into)
Computes a route.
Definition: ROJTRRouter.cpp:59
ROJTREdge * chooseNext(const ROVehicle *const veh, SUMOTime time) const
Returns the next edge to use.
Definition: ROJTREdge.cpp:83
ROJTRRouter(RONet &net, bool unbuildIsWarningOnly, bool acceptAllDestinations, int maxEdges, bool ignoreClasses, bool allowLoops)
Constructor.
Definition: ROJTRRouter.cpp:46
const bool myAcceptAllDestination
Whether all edges may be used as route end.
Definition: ROJTRRouter.h:106
const std::string & getID() const
Returns the id.
Definition: Named.h:60
A vehicle as used by router.
Definition: ROVehicle.h:59
~ROJTRRouter()
Destructor.
Definition: ROJTRRouter.cpp:55
const bool myIgnoreClasses
Whether vehicle class information shall be ignored.
Definition: ROJTRRouter.h:112
An edge the jtr-router may route through.
Definition: ROJTREdge.h:58
A basic edge for routing applications.
Definition: ROEdge.h:69
The router's network representation.
Definition: RONet.h:67
bool prohibits(const ROVehicle *const vehicle) const
Returns whether this edge prohibits the given vehicle to pass it.
Definition: ROEdge.h:238
void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:89
int SUMOTime
Definition: SUMOTime.h:43
#define SUMOReal
Definition: config.h:215
SUMOReal getTravelTime(const ROVehicle *const veh, SUMOReal time) const
Returns the travel time for this edge.
Definition: ROEdge.cpp:147
An edge where vehicles disappear (no vehicle may leave this edge)
Definition: ROEdge.h:83