Line data Source code
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 MSStopOptimizer.h
15 : /// @author Jakob Erdmann
16 : /// @date Nov 2025
17 : ///
18 : // Optimizes prioritized stops
19 : /****************************************************************************/
20 : #pragma once
21 : #include <config.h>
22 :
23 : #include <string>
24 : #include <vector>
25 : #include "MSBaseVehicle.h"
26 :
27 : // ===========================================================================
28 : // class declarations
29 : // ===========================================================================
30 :
31 : typedef MSBaseVehicle::StopEdgeInfo StopEdgeInfo;
32 :
33 : // ===========================================================================
34 : // class definitions
35 : // ===========================================================================
36 : /**
37 : * @class MSStopOptimizer
38 : * @brief Finds a sequence of skips and stop alternatives to maximize priority
39 : * of reached stops
40 : */
41 : class MSStopOptimizer {
42 :
43 : friend class StopPathNode;
44 :
45 : public:
46 : /** @brief Constructor
47 : *
48 : * @param[in] id The id of the lane speed trigger
49 : * @param[in] net The net the lane speed trigger belongs to
50 : * @param[in] destLanes List of lanes affected by this speed trigger
51 : * @param[in] file Name of the file to read the speeds to set from
52 : */
53 45 : MSStopOptimizer(MSBaseVehicle* veh, SUMOAbstractRouter<MSEdge, SUMOVehicle>& router, SUMOTime t, SUMOTime maxDelay) :
54 45 : myVehicle(veh),
55 45 : myRouter(router),
56 45 : myT(t),
57 45 : myMaxDelay(maxDelay)
58 : {}
59 :
60 : /** @brief Destructor */
61 192 : virtual ~MSStopOptimizer() {}
62 :
63 :
64 : ConstMSEdgeVector optimizeSkipped(const MSEdge* source, double sourcePos, std::vector<StopEdgeInfo>& stops, ConstMSEdgeVector edges) const;
65 :
66 :
67 : private:
68 : MSBaseVehicle* myVehicle;
69 : SUMOAbstractRouter<MSEdge, SUMOVehicle>& myRouter;
70 : SUMOTime myT;
71 : SUMOTime myMaxDelay;
72 :
73 : private:
74 :
75 : /// @brief information used during skip/alternative optimization
76 : struct StopPathNode : public StopEdgeInfo, std::enable_shared_from_this<StopPathNode> {
77 2223 : StopPathNode(const MSStopOptimizer& _so, const StopEdgeInfo& o):
78 2223 : StopEdgeInfo(o.edge, o.priority, o.arrival, o.pos),
79 2223 : so(_so) {
80 : nameTag = o.nameTag;
81 2223 : delay = o.delay;
82 2223 : routeIndex = o.routeIndex;
83 2223 : }
84 :
85 : // ordering criterion (minimize in order)
86 : const MSStopOptimizer& so;
87 : // @brief sum of skipped stop priority between source and this node
88 : double skippedPrio = 0;
89 : // @brief sum of reached stop priority between source and this node
90 : double reachedPrio = 0;
91 : // @brief number of reached mandatory stops
92 : int reachedMandatory = 0;
93 :
94 : int trackChanges = 0;
95 : double cost = 0;
96 :
97 : int stopIndex;
98 : int numSkipped = 0;
99 : int altIndex = -1;
100 : bool checked = false;
101 : ConstMSEdgeVector edges;
102 : std::shared_ptr<StopPathNode> prev = nullptr;
103 :
104 : std::shared_ptr<StopPathNode> getSuccessor(const std::vector<StopEdgeInfo>& stops, double minSkipped);
105 :
106 : // for finding the best final node
107 : bool operator<(StopPathNode& b) const {
108 2691 : if (reachedMandatory == b.reachedMandatory) {
109 375 : if (reachedPrio == b.reachedPrio) {
110 148 : if (trackChanges == b.trackChanges) {
111 148 : return cost > b.cost;
112 : }
113 0 : return trackChanges > b.trackChanges;
114 : }
115 227 : return reachedPrio < b.reachedPrio;
116 : }
117 2316 : return reachedMandatory < b.reachedMandatory;
118 : }
119 : };
120 :
121 : // for setting the exploration order: nodes with fewer skips should be
122 : // explored first but they aren't strictly better
123 : struct spnCompare {
124 14498 : bool operator()(const std::shared_ptr<StopPathNode>& a,
125 : const std::shared_ptr<StopPathNode>& b) const {
126 14498 : if (a->skippedPrio == b->skippedPrio) {
127 8625 : if (a->stopIndex == b->stopIndex) {
128 : return *a < *b;
129 : }
130 8625 : return a->stopIndex < b->stopIndex;
131 : }
132 5873 : return a->skippedPrio > b->skippedPrio;
133 : }
134 : };
135 :
136 : bool reachableInTime(const MSEdge* from, double fromPos,
137 : const MSEdge* to, double toPos,
138 : SUMOTime arrival, ConstMSEdgeVector& into, double& cost) const;
139 :
140 : };
|