Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSMeanData_Amitran.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-2026 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/****************************************************************************/
19// Network state mean data collector for edges/lanes
20/****************************************************************************/
21#include <config.h>
22
24#include <microsim/MSEdge.h>
25#include <microsim/MSLane.h>
26#include <microsim/MSVehicle.h>
30#include "MSMeanData_Amitran.h"
31#include <limits>
32
33
34// ===========================================================================
35// method definitions
36// ===========================================================================
37// ---------------------------------------------------------------------------
38// MSMeanData_Amitran::MSLaneMeanDataValues - methods
39// ---------------------------------------------------------------------------
41 const double length,
42 const bool doAdd,
43 const MSMeanData_Amitran* parent)
44 : MSMeanData::MeanDataValues(lane, length, doAdd, parent), amount(0) {}
45
46
49
50
51void
53 amount = 0;
54 typedAmount.clear();
55 typedSamples.clear();
56 typedTravelDistance.clear();
57 resetTime = SIMSTEP;
58}
59
60
61void
64 v.amount += amount;
65 v.sampleSeconds += sampleSeconds;
66 v.travelledDistance += travelledDistance;
67 for (std::map<const MSVehicleType*, int>::const_iterator it = typedAmount.begin(); it != typedAmount.end(); ++it) {
68 v.typedAmount[it->first] += it->second;
69 }
70 for (std::map<const MSVehicleType*, double>::const_iterator it = typedSamples.begin(); it != typedSamples.end(); ++it) {
71 v.typedSamples[it->first] += it->second;
72 }
73 for (std::map<const MSVehicleType*, double>::const_iterator it = typedTravelDistance.begin(); it != typedTravelDistance.end(); ++it) {
74 v.typedTravelDistance[it->first] += it->second;
75 }
76}
77
78
79void
80MSMeanData_Amitran::MSLaneMeanDataValues::notifyMoveInternal(const SUMOTrafficObject& veh, const double /* frontOnLane */, const double timeOnLane, const double /*meanSpeedFrontOnLane*/, const double /*meanSpeedVehicleOnLane*/, const double /*travelledDistanceFrontOnLane*/, const double travelledDistanceVehicleOnLane, const double /* meanLengthOnLane */) {
81 sampleSeconds += timeOnLane;
82 travelledDistance += travelledDistanceVehicleOnLane;
83 typedSamples[&veh.getVehicleType()] += timeOnLane;
84 typedTravelDistance[&veh.getVehicleType()] += travelledDistanceVehicleOnLane;
85}
86
87
88bool
90 if (myParent->vehicleApplies(veh)) {
91 if (getLane() == nullptr || getLane() == static_cast<MSVehicle&>(veh).getLane()) {
93 ++amount;
94 typedAmount[&veh.getVehicleType()]++;
95 }
96 }
97 return true;
98 }
99 return false;
100}
101
102
103bool
105 return sampleSeconds == 0 && amount == 0;
106}
107
108
109void
111 const int /* numLanes */, const double /*speedLimit*/, const double defaultTravelTime, const int /* numVehicles */) const {
112 int averageSpeed;
113 if (sampleSeconds > 0) {
114 averageSpeed = int(100 * travelledDistance / sampleSeconds);
115 } else if (defaultTravelTime >= 0.) {
116 averageSpeed = int(100 * myLaneLength / defaultTravelTime);
117 } else {
118 averageSpeed = -1;
119 }
120 dev.writeOptionalAttr(SUMO_ATTR_AMOUNT, amount, attributeMask);
121 dev.writeOptionalAttr(SUMO_ATTR_AVERAGESPEED, averageSpeed, attributeMask);
122
123 if (myParent->isTyped()) {
124 for (std::map<const MSVehicleType*, int>::const_iterator it = typedAmount.begin(); it != typedAmount.end(); ++it) {
125 dev.openTag("actorConfig");
126 const int typedAvgSpeed = int(100 * typedTravelDistance.find(it->first)->second / typedSamples.find(it->first)->second);
127 dev.writeAttr(SUMO_ATTR_ID, it->first->getNumericalID());
128 dev.writeOptionalAttr(SUMO_ATTR_AMOUNT, it->second, attributeMask);
129 dev.writeOptionalAttr(SUMO_ATTR_AVERAGESPEED, typedAvgSpeed, attributeMask);
130 dev.closeTag();
131 }
132 }
133 dev.closeTag();
134}
135
136// ---------------------------------------------------------------------------
137// MSMeanData_Amitran - methods
138// ---------------------------------------------------------------------------
140 const SUMOTime dumpBegin,
141 const SUMOTime dumpEnd, const bool useLanes,
142 const std::string& excludeEmpty,
143 const bool withInternal,
144 const bool trackVehicles,
145 const int detectPersons,
146 const double maxTravelTime,
147 const double minSamples,
148 const double haltSpeed,
149 const std::string& vTypes,
150 const std::string& writeAttributes,
151 const std::vector<MSEdge*>& edges,
152 AggregateType aggregate) :
153 MSMeanData(id, dumpBegin, dumpEnd, useLanes, excludeEmpty,
154 withInternal, trackVehicles, detectPersons, maxTravelTime, minSamples, vTypes, writeAttributes, edges, aggregate),
155 myHaltSpeed(haltSpeed) {
156}
157
158
160
161
162void
164 dev.writeXMLHeader("linkData", "amitran/linkdata.xsd");
165}
166
167
168std::string
170 return toString(edge->getNumericalID());
171}
172
173
174void
175MSMeanData_Amitran::openInterval(OutputDevice& dev, const SUMOTime startTime, const SUMOTime stopTime) {
176 const int duration = int(1000 * STEPS2TIME(stopTime - startTime) + 0.5);
178}
179
180
181void
182MSMeanData_Amitran::writePrefix(OutputDevice& dev, const MeanDataValues& values, const SumoXMLTag /* tag */, const std::string id) const {
183 dev.openTag("link").writeAttr(SUMO_ATTR_ID, id);
184}
185
186
188MSMeanData_Amitran::createValues(MSLane* const lane, const double length, const bool doAdd) const {
189 return new MSLaneMeanDataValues(lane, length, doAdd, this);
190}
191
192
193/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define STEPS2TIME(x)
Definition SUMOTime.h:58
#define SIMSTEP
Definition SUMOTime.h:64
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_TIMESLICE
std::bitset< 96 > SumoXMLAttrMask
AggregateType
Numbers representing special SUMO-XML-attribute values Information on edgeData/laneData output should...
@ SUMO_ATTR_AVERAGESPEED
@ SUMO_ATTR_STARTTIME
@ SUMO_ATTR_ID
@ SUMO_ATTR_DURATION
@ SUMO_ATTR_AMOUNT
MSMeanData_Amitran.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
A road/street connecting two junctions.
Definition MSEdge.h:77
int getNumericalID() const
Returns the numerical id of the edge.
Definition MSEdge.h:307
Representation of a lane in the micro simulation.
Definition MSLane.h:84
Data structure for mean (aggregated) edge/lane values.
Definition MSMeanData.h:66
double travelledDistance
The sum of the distances the vehicles travelled.
Definition MSMeanData.h:190
Data structure for mean (aggregated) edge/lane values.
void notifyMoveInternal(const SUMOTrafficObject &veh, const double, const double timeOnLane, const double, const double meanSpeedVehicleOnLane, const double travelledDistanceFrontOnLane, const double travelledDistanceVehicleOnLane, const double)
Internal notification about the vehicle moves.
MSLaneMeanDataValues(MSLane *const lane, const double length, const bool doAdd, const MSMeanData_Amitran *parent)
Constructor.
void addTo(MSMeanData::MeanDataValues &val) const
Add the values of this to the given one and store them there.
void write(OutputDevice &dev, const SumoXMLAttrMask &attributeMask, const SUMOTime period, const int numLanes, const double speedLimit, const double defaultTravelTime, const int numVehicles=-1) const
Writes output values into the given stream.
bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Computes current values and adds them to their sums.
void reset(bool afterWrite=false)
Resets values so they may be used for the next interval.
bool isEmpty() const
Returns whether any data was collected.
std::map< const MSVehicleType *, double > typedTravelDistance
The sum of the distances the vehicles travelled by type.
std::map< const MSVehicleType *, int > typedAmount
The number of vehicles that entered this lane within the sample interval by type.
std::map< const MSVehicleType *, double > typedSamples
The number of sampled vehicle movements by type (in s)
Network state mean data collector for edges/lanes.
virtual void openInterval(OutputDevice &dev, const SUMOTime startTime, const SUMOTime stopTime)
Writes the interval opener.
virtual void writeXMLDetectorProlog(OutputDevice &dev) const
Opens the XML-output using "netstats" as root element.
MSMeanData::MeanDataValues * createValues(MSLane *const lane, const double length, const bool doAdd) const
Create an instance of MeanDataValues.
virtual void writePrefix(OutputDevice &dev, const MeanDataValues &values, const SumoXMLTag tag, const std::string id) const
Writes the surrounding element into the given stream.
virtual std::string getEdgeID(const MSEdge *const edge)
Return the relevant edge id.
virtual ~MSMeanData_Amitran()
Destructor.
const double myHaltSpeed
the minimum sample seconds
MSMeanData_Amitran(const std::string &id, const SUMOTime dumpBegin, const SUMOTime dumpEnd, const bool useLanes, const std::string &excludeEmpty, const bool withInternal, const bool trackVehicles, const int detectPersons, const double maxTravelTime, const double minSamples, const double haltSpeed, const std::string &vTypes, const std::string &writeAttributes, const std::vector< MSEdge * > &edges, AggregateType aggregate)
Constructor.
Data collector for edges/lanes.
Definition MSMeanData.h:57
Notification
Definition of a vehicle state.
@ NOTIFICATION_DEPARTED
The vehicle has departed (was inserted into the network)
@ NOTIFICATION_JUNCTION
The vehicle arrived at a junction.
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
bool writeXMLHeader(const std::string &rootElement, const std::string &schemaFile, std::map< SumoXMLAttr, std::string > attrs=std::map< SumoXMLAttr, std::string >(), bool includeConfig=true)
Writes an XML header with optional configuration.
OutputDevice & writeOptionalAttr(const SumoXMLAttr attr, const T &val, const SumoXMLAttrMask &attributeMask, const bool isNull=false)
writes a named attribute unless filtered
Representation of a vehicle, person, or container.
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.