Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/microsim/MSLaneChangerSublane.h
185785 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2002-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 MSLaneChangerSublane.h
15
/// @author Jakob Erdmann
16
/// @author Leonhard Luecken
17
/// @date Oct 2015
18
///
19
// Performs sub-lane changing of vehicles
20
/****************************************************************************/
21
#pragma once
22
#include <config.h>
23
24
#include <microsim/lcmodels/MSAbstractLaneChangeModel.h>
25
#include "MSLaneChanger.h"
26
27
28
// ===========================================================================
29
// class declarations
30
// ===========================================================================
31
32
33
// ===========================================================================
34
// class definitions
35
// ===========================================================================
36
/**
37
* @class MSLaneChangerSublane
38
* @brief Performs lane changing of vehicles
39
*/
40
class MSLaneChangerSublane : public MSLaneChanger {
41
public:
42
/// Constructor
43
MSLaneChangerSublane(const std::vector<MSLane*>* lanes, bool allowChanging);
44
45
/// Destructor.
46
~MSLaneChangerSublane();
47
48
protected:
49
50
/** Find a new candidate and try to change it. */
51
virtual bool change();
52
53
/// @brief Initialize the changer before looping over all vehicles.
54
virtual void initChanger();
55
56
/** After the possible change, update the changer. */
57
virtual void updateChanger(bool vehHasChanged);
58
59
/** @brief check whether sub-lane changing in the given direction is desirable
60
* and possible
61
* @param[in] laneOffset The direction in which changing should be checked
62
* @param[in] leaders The candidate vehicle's leaders
63
* @param[in] preb The bestLanse of the candidaet vehicle
64
* @param[out] latDist The distance by which the vehicle changes laterally
65
* @param[out] maneuverDist The lateral distance for the complete envisioned maneuver
66
* (used for maneuver continuation in non-actionsteps).
67
*/
68
int checkChangeSublane(
69
int laneOffset,
70
LaneChangeAction alternatives,
71
const std::vector<MSVehicle::LaneQ>& preb,
72
double& latDist,
73
double& maneuverDist) const;
74
75
/* @brief call lanechange model to check the merits of an opposite-direction
76
* change and update state accordingly */
77
bool checkChangeOpposite(
78
MSVehicle* vehicle,
79
int laneOffset,
80
MSLane* targetLane,
81
const std::pair<MSVehicle* const, double>& leader,
82
const std::pair<MSVehicle* const, double>& neighLead,
83
const std::pair<MSVehicle* const, double>& neighFollow,
84
const std::vector<MSVehicle::LaneQ>& preb);
85
86
87
/// @brief Continue a sublane-lane change maneuver and return whether the midpoint was passed in this step
88
// (used to continue sublane changing in non-action steps).
89
bool continueChangeSublane(MSVehicle* vehicle, ChangerIt& from);
90
91
/// @brief change by the specified amount and return whether a new lane was entered
92
bool startChangeSublane(MSVehicle* vehicle, ChangerIt& from, double latDist, double maneuverDist);
93
94
/// @brief check whether the given vehicle has entered the new lane 'to->lane' during a sublane LC-step
95
bool checkChangeToNewLane(MSVehicle* vehicle, const int direction, ChangerIt from, ChangerIt to);
96
97
/// @brief get leaders for ego on the given lane
98
MSLeaderDistanceInfo getLeaders(const ChangerIt& target, const MSVehicle* ego) const;
99
100
/// @brief immediately stop lane-changing and register vehicle as unchanged
101
void abortLCManeuver(MSVehicle* vehicle);
102
103
typedef MSAbstractLaneChangeModel::StateAndDist StateAndDist;
104
/// @brief helper function that calls checkChangeSublane and sets blocker information
105
StateAndDist checkChangeHelper(MSVehicle* vehicle, int laneOffset, LaneChangeAction alternatives);
106
107
/// @brief find the closest leader that prevents ego vehicle from passing on the current lane
108
static std::pair<MSVehicle*, double> findClosestLeader(const MSLeaderDistanceInfo& leaders, const MSVehicle* vehicle);
109
110
/// @brief optional output for start of lane-change maneuvre
111
void outputLCStarted(MSVehicle* vehicle, ChangerIt& from, ChangerIt& to, int direction, double maneuverDist);
112
/// @brief optional output for end of lane-change maneuvre
113
void outputLCEnded(MSVehicle* vehicle, ChangerIt& from, ChangerIt& to, int direction);
114
115
void addOutsideLeaders(const MSVehicle* vehicle, MSLeaderDistanceInfo& leaders) const;
116
117
/// @brief whether checkChangeOpposite was called for the current vehicle
118
bool myCheckedChangeOpposite;
119
120
private:
121
/// Default constructor.
122
MSLaneChangerSublane();
123
124
/// Copy constructor.
125
MSLaneChangerSublane(const MSLaneChangerSublane&);
126
127
/// Assignment operator.
128
MSLaneChangerSublane& operator=(const MSLaneChangerSublane&);
129
};
130
131