Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
ROJTRRouter.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
20// Computes routes using junction turning percentages
21/****************************************************************************/
22#include <config.h>
23
24#include <router/RONet.h>
25#include "ROJTRRouter.h"
26#include "ROJTREdge.h"
28
29
30// ===========================================================================
31// method definitions
32// ===========================================================================
33ROJTRRouter::ROJTRRouter(bool unbuildIsWarningOnly, bool acceptAllDestinations,
34 int maxEdges, bool ignoreClasses,
35 bool allowLoops,
36 bool discountSources) :
37 SUMOAbstractRouter<ROEdge, ROVehicle>("JTRRouter", unbuildIsWarningOnly, &ROEdge::getTravelTimeStatic, nullptr, false, false),
38 myUnbuildIsWarningOnly(unbuildIsWarningOnly),
39 myAcceptAllDestination(acceptAllDestinations), myMaxEdges(maxEdges),
40 myIgnoreClasses(ignoreClasses),
41 myAllowLoops(allowLoops),
42 myDiscountSources(discountSources)
43{ }
44
45
47
48
49bool
50ROJTRRouter::compute(const ROEdge* from, const ROEdge* to,
51 const ROVehicle* const vehicle,
52 SUMOTime time, ConstROEdgeVector& into, bool silent) {
53 const ROJTREdge* current = static_cast<const ROJTREdge*>(from);
54 if (myDiscountSources && current->getSourceFlow() <= 0) {
55 return true;
56 }
57 double timeS = STEPS2TIME(time);
58 std::set<const ROEdge*> avoidEdges;
59 // route until a sinks has been found
60 while (current != nullptr && current != to &&
61 (!current->isSink() || current == from || current->getSourceFlow() > 0) &&
62 (int)into.size() < myMaxEdges) {
63 into.push_back(current);
64 const_cast<ROJTREdge*>(current)->changeSourceFlow(-1);
65 if (!myAllowLoops) {
66 avoidEdges.insert(current);
67 }
68 timeS += current->getTravelTime(vehicle, timeS);
69 current = current->chooseNext(myIgnoreClasses ? nullptr : vehicle, timeS, avoidEdges);
70 assert(myIgnoreClasses || current == 0 || !current->prohibits(vehicle));
71 }
72 // check whether no valid ending edge was found
73 if (current == nullptr || (int) into.size() >= myMaxEdges) {
75 return true;
76 } else {
77 if (!silent) {
79 mh->inform("The route starting at edge '" + from->getID() + "' could not be closed.");
80 }
81 return false;
82 }
83 }
84 // append the sink
85 if (current != nullptr) {
86 into.push_back(current);
87 }
88 return true;
89}
90
91
92/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
std::vector< const ROEdge * > ConstROEdgeVector
Definition ROEdge.h:56
#define STEPS2TIME(x)
Definition SUMOTime.h:55
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
const std::string & getID() const
Returns the id.
Definition Named.h:74
A basic edge for routing applications.
Definition ROEdge.h:72
bool prohibits(const ROVehicle *const vehicle) const
Returns whether this edge prohibits the given vehicle to pass it.
Definition ROEdge.h:283
bool isSink() const
Returns whether the edge acts as a sink.
Definition ROEdge.h:216
double getTravelTime(const ROVehicle *const veh, double time) const
Returns the travel time for this edge.
Definition ROEdge.cpp:210
An edge the jtr-router may route through.
Definition ROJTREdge.h:48
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
int getSourceFlow() const
register source flow on this edge
Definition ROJTREdge.h:103
const bool myAcceptAllDestination
Whether all edges may be used as route end.
Definition ROJTRRouter.h:87
const bool myUnbuildIsWarningOnly
Whether unbuildable routes shall be reported as warniings, not errors.
Definition ROJTRRouter.h:84
const int myMaxEdges
The maximum number of edges a route may have.
Definition ROJTRRouter.h:90
~ROJTRRouter()
Destructor.
bool compute(const ROEdge *from, const ROEdge *to, const ROVehicle *const vehicle, SUMOTime time, ConstROEdgeVector &into, bool silent=false)
Computes a route.
const bool myIgnoreClasses
Whether vehicle class information shall be ignored.
Definition ROJTRRouter.h:93
const bool myDiscountSources
Whether upstream flows shall be discounted from source flows.
Definition ROJTRRouter.h:99
ROJTRRouter(bool unbuildIsWarningOnly, bool acceptAllDestinations, int maxEdges, bool ignoreClasses, bool allowLoops, bool discountSources)
Constructor.
const bool myAllowLoops
Whether a vehicle may reuse a road.
Definition ROJTRRouter.h:96
A vehicle as used by router.
Definition ROVehicle.h:50