Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/mesosim/MEInductLoop.cpp
169665 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-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 MEInductLoop.cpp
15
/// @author Daniel Krajzewicz
16
/// @date Tue, May 2005
17
///
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>
32
#include <utils/common/WrappingCommand.h>
33
#include <utils/common/ToString.h>
34
#include <microsim/MSEdge.h>
35
#include <microsim/MSEventControl.h>
36
#include <mesosim/MESegment.h>
37
#include <utils/common/MsgHandler.h>
38
#include <utils/common/UtilExceptions.h>
39
#include <utils/common/StringUtils.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);
57
s->addDetector(&myMeanData);
58
}
59
60
61
MEInductLoop::~MEInductLoop() {}
62
63
64
void
65
MEInductLoop::writeXMLOutput(OutputDevice& dev,
66
SUMOTime startTime, SUMOTime stopTime) {
67
mySegment->prepareDetectorForWriting(myMeanData);
68
dev.openTag(SUMO_TAG_INTERVAL).writeAttr(SUMO_ATTR_BEGIN, time2string(startTime)).writeAttr(SUMO_ATTR_END, time2string(stopTime));
69
dev.writeAttr(SUMO_ATTR_ID, StringUtils::escapeXML(myID)).writeAttr("sampledSeconds", myMeanData.getSamples());
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&
75
MEInductLoop::getEdge() const {
76
return mySegment->getEdge();
77
}
78
79
/****************************************************************************/
80
81