Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/jtrrouter/ROJTRRouter.cpp
169665 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 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
/****************************************************************************/
14
/// @file ROJTRRouter.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Jakob Erdmann
17
/// @author Michael Behrisch
18
/// @date Tue, 20 Jan 2004
19
///
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"
27
#include <utils/common/MsgHandler.h>
28
29
30
// ===========================================================================
31
// method definitions
32
// ===========================================================================
33
ROJTRRouter::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
46
ROJTRRouter::~ROJTRRouter() {}
47
48
49
bool
50
ROJTRRouter::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) {
74
if (myAcceptAllDestination) {
75
return true;
76
} else {
77
if (!silent) {
78
MsgHandler* mh = myUnbuildIsWarningOnly ? MsgHandler::getWarningInstance() : MsgHandler::getErrorInstance();
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
/****************************************************************************/
93
94