Eclipse SUMO - Simulation of Urban MObility
MEInductLoop.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-2024 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 /****************************************************************************/
18 // An induction loop for mesoscopic simulation
19 /****************************************************************************/
20 
21 
22 /* =========================================================================
23  * included modules
24  * ======================================================================= */
25 #include <config.h>
26 
27 #include "MEInductLoop.h"
28 #include <cassert>
29 #include <numeric>
30 #include <utility>
31 #include <limits>
33 #include <utils/common/ToString.h>
34 #include <microsim/MSEdge.h>
36 #include <mesosim/MESegment.h>
40 
41 
42 // ===========================================================================
43 // method definitions
44 // ===========================================================================
45 MEInductLoop::MEInductLoop(const std::string& id,
46  MESegment* s,
47  double positionInMeters,
48  const std::string name, const std::string& vTypes,
49  const std::string& nextEdges,
50  int detectPersons) :
51  MSDetectorFileOutput(id, vTypes, nextEdges, detectPersons),
52  myName(name),
53  mySegment(s),
54  myPosition(positionInMeters),
55  myMeanData(nullptr, mySegment->getLength(), false, nullptr) {
56  myMeanData.setDescription("inductionLoop_" + id);
58 }
59 
60 
62 
63 
64 void
66  SUMOTime startTime, SUMOTime stopTime) {
70  myMeanData.write(dev, 0, stopTime - startTime, (int)mySegment->getEdge().getLanes().size(), mySegment->getEdge().getSpeedLimit(), -1.0);
71  myMeanData.reset();
72 }
73 
74 const MSEdge&
76  return mySegment->getEdge();
77 }
78 
79 /****************************************************************************/
long long int SUMOTime
Definition: GUI.h:35
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition: SUMOTime.cpp:69
@ SUMO_TAG_INTERVAL
an aggreagated-output interval
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_END
weights: time range end
@ SUMO_ATTR_ID
const MSEdge & getEdge() const
MESegment *const mySegment
mesoscopic edge segment the loop lies on
Definition: MEInductLoop.h:100
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
MSMeanData_Net::MSLaneMeanDataValues myMeanData
data collector for the loop
Definition: MEInductLoop.h:106
MEInductLoop()
Hidden default constructor.
A single mesoscopic segment (cell)
Definition: MESegment.h:49
void addDetector(MSMoveReminder *data, int queueIndex=-1)
Adds a data collector for a detector to this segment.
Definition: MESegment.cpp:254
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:359
void prepareDetectorForWriting(MSMoveReminder &data, int queueIndex=-1)
Removes a data collector for a detector from this segment.
Definition: MESegment.cpp:283
Base of value-generating classes (detectors)
A road/street connecting two junctions.
Definition: MSEdge.h:77
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:168
double getSpeedLimit() const
Returns the speed limit of the edge @caution The speed limit of the first lane is retured; should pro...
Definition: MSEdge.cpp:1106
virtual double getSamples() const
Returns the number of collected sample seconds.
Definition: MSMeanData.cpp:280
void write(OutputDevice &dev, long long int 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.
void reset(bool afterWrite=false)
Resets values so they may be used for the next interval.
void setDescription(const std::string &description)
std::string myID
The name of the object.
Definition: Named.h:125
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:254
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.