Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/libsumo/Person.h
169667 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2012-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 Person.h
15
/// @author Leonhard Luecken
16
/// @date 15.09.2017
17
///
18
// C++ TraCI client API implementation
19
/****************************************************************************/
20
#pragma once
21
#include <vector>
22
#include <libsumo/TraCIDefs.h>
23
#include <libsumo/VehicleType.h>
24
25
26
// ===========================================================================
27
// class declarations
28
// ===========================================================================
29
#ifndef LIBTRACI
30
class MSPerson;
31
class MSStage;
32
struct Reservation;
33
class PositionVector;
34
#endif
35
36
37
// ===========================================================================
38
// class definitions
39
// ===========================================================================
40
/**
41
* @class Person
42
* @brief C++ TraCI client API implementation
43
*/
44
namespace LIBSUMO_NAMESPACE {
45
class Person {
46
public:
47
static double getSpeed(const std::string& personID);
48
static libsumo::TraCIPosition getPosition(const std::string& personID, const bool includeZ = false);
49
static libsumo::TraCIPosition getPosition3D(const std::string& personID);
50
static std::string getRoadID(const std::string& personID);
51
static std::string getLaneID(const std::string& personID);
52
static std::string getTypeID(const std::string& personID);
53
static double getWaitingTime(const std::string& personID);
54
static std::string getNextEdge(const std::string& personID);
55
static std::string getVehicle(const std::string& personID);
56
static int getRemainingStages(const std::string& personID);
57
static libsumo::TraCIStage getStage(const std::string& personID, int nextStageIndex = 0);
58
static std::vector<std::string> getEdges(const std::string& personID, int nextStageIndex = 0);
59
static double getAngle(const std::string& personID);
60
static double getSlope(const std::string& personID);
61
static double getLanePosition(const std::string& personID);
62
static double getWalkingDistance(const std::string& personID, const std::string& edgeID, double pos, int laneIndex = 0);
63
static double getWalkingDistance2D(const std::string& personID, double x, double y);
64
65
static std::vector<libsumo::TraCIReservation> getTaxiReservations(int onlyNew = 0);
66
static std::string splitTaxiReservation(std::string reservationID, const std::vector<std::string>& personIDs);
67
68
LIBSUMO_ID_PARAMETER_API
69
LIBSUMO_VEHICLE_TYPE_GETTER
70
71
static void add(const std::string& personID, const std::string& edgeID, double pos, double depart = libsumo::DEPARTFLAG_NOW, const std::string typeID = "DEFAULT_PEDTYPE");
72
static void appendStage(const std::string& personID, const libsumo::TraCIStage& stage);
73
static void replaceStage(const std::string& personID, const int stageIndex, const libsumo::TraCIStage& stage);
74
static void appendWaitingStage(const std::string& personID, double duration, const std::string& description = "waiting", const std::string& stopID = "");
75
static void appendWalkingStage(const std::string& personID, const std::vector<std::string>& edges, double arrivalPos, double duration = -1, double speed = -1, const std::string& stopID = "");
76
static void appendDrivingStage(const std::string& personID, const std::string& toEdge, const std::string& lines, const std::string& stopID = "");
77
static void removeStage(const std::string& personID, int nextStageIndex);
78
static void rerouteTraveltime(const std::string& personID);
79
static void moveTo(const std::string& personID, const std::string& laneID, double pos, double posLat = libsumo::INVALID_DOUBLE_VALUE);
80
static void moveToXY(const std::string& personID, const std::string& edgeID, const double x, const double y, double angle = libsumo::INVALID_DOUBLE_VALUE, const int keepRoute = 1, double matchThreshold = 100);
81
static void remove(const std::string& personID, char reason = libsumo::REMOVE_VAPORIZED);
82
static void setSpeed(const std::string& personID, double speed);
83
static void setType(const std::string& personID, const std::string& typeID);
84
85
LIBSUMO_VEHICLE_TYPE_SETTER
86
87
LIBSUMO_SUBSCRIPTION_API
88
89
#ifndef LIBTRACI
90
#ifndef SWIG
91
/** @brief Saves the shape of the requested object in the given container
92
* @param id The id of the poi to retrieve
93
* @param shape The container to fill
94
*/
95
static void storeShape(const std::string& id, PositionVector& shape);
96
97
static std::shared_ptr<VariableWrapper> makeWrapper();
98
99
static bool handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData);
100
101
private:
102
static MSPerson* getPerson(const std::string& id);
103
static MSStage* convertTraCIStage(const TraCIStage& stage, const std::string personID);
104
static bool filterReservation(int stateFilter, const Reservation* res, std::vector<libsumo::TraCIReservation>& reservations);
105
106
/// @brief clase for CW Sorter
107
class reservation_by_id_sorter {
108
public:
109
/// @brief constructor
110
reservation_by_id_sorter() {};
111
112
/// @brief comparing operation for sort
113
int operator()(const TraCIReservation& r1, const TraCIReservation& r2) const;
114
};
115
116
private:
117
static SubscriptionResults mySubscriptionResults;
118
static ContextSubscriptionResults myContextSubscriptionResults;
119
#endif
120
#endif
121
122
private:
123
/// @brief invalidated standard constructor
124
Person() = delete;
125
126
};
127
128
129
}
130
131