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.org/sumo
3 // Copyright (C) 2001-2020 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& vTypes) :
49  MSDetectorFileOutput(id, vTypes), mySegment(s),
50  myPosition(positionInMeters),
51  myMeanData(nullptr, mySegment->getLength(), false, nullptr) {
52  myMeanData.setDescription("inductionLoop_" + id);
54 }
55 
56 
58 
59 
60 void
62  SUMOTime startTime, SUMOTime stopTime) {
66  myMeanData.write(dev, 0, stopTime - startTime, (double)mySegment->getEdge().getLanes().size(), -1.0);
67  myMeanData.reset();
68 }
69 
70 
71 /****************************************************************************/
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
long long int SUMOTime
Definition: SUMOTime.h:31
@ SUMO_TAG_INTERVAL
an aggreagated-output interval
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_END
weights: time range end
@ SUMO_ATTR_ID
MESegment *const mySegment
mesoscopic edge segment the loop lies on
Definition: MEInductLoop.h:89
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
MSMeanData_Net::MSLaneMeanDataValues myMeanData
data collector for the loop
Definition: MEInductLoop.h:95
MEInductLoop()
Hidden default constructor.
A single mesoscopic segment (cell)
Definition: MESegment.h:47
void prepareDetectorForWriting(MSMoveReminder &data)
Updates data of a detector for all vehicle queues.
Definition: MESegment.cpp:269
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:325
void addDetector(MSMoveReminder *data)
Adds a data collector for a detector to this segment.
Definition: MESegment.cpp:244
Base of value-generating classes (detectors)
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:166
virtual double getSamples() const
Returns the number of collected sample seconds.
Definition: MSMeanData.cpp:277
void write(OutputDevice &dev, long long int attributeMask, const SUMOTime period, const double numLanes, 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:124
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:60
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:239
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.