Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/dfrouter/RODFDetFlowLoader.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 RODFDetFlowLoader.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Eric Nicolay
17
/// @author Jakob Erdmann
18
/// @author Michael Behrisch
19
/// @date Thu, 16.03.2006
20
///
21
// A loader for detector flows
22
/****************************************************************************/
23
#include <config.h>
24
25
#include <string>
26
#include <fstream>
27
#include <sstream>
28
#include <utils/importio/LineReader.h>
29
#include <utils/options/OptionsCont.h>
30
#include <utils/common/StringTokenizer.h>
31
#include <utils/common/MsgHandler.h>
32
#include <utils/common/FileHelpers.h>
33
#include <utils/common/StringUtils.h>
34
#include <utils/common/UtilExceptions.h>
35
#include "RODFDetFlowLoader.h"
36
37
38
// ===========================================================================
39
// method definitions
40
// ===========================================================================
41
RODFDetFlowLoader::RODFDetFlowLoader(const RODFDetectorCon& dets,
42
RODFDetectorFlows& into,
43
SUMOTime startTime, SUMOTime endTime,
44
SUMOTime timeOffset, SUMOTime timeScale)
45
: myStorage(into), myTimeOffset(timeOffset), myTimeScale(timeScale),
46
myStartTime(startTime), myEndTime(endTime), myDetectorContainer(dets),
47
myHaveWarnedAboutOverridingBoundaries(false), myHaveWarnedAboutPartialDefs(false) {}
48
49
50
51
RODFDetFlowLoader::~RODFDetFlowLoader() {}
52
53
54
void
55
RODFDetFlowLoader::read(const std::string& file) {
56
LineReader lr(file);
57
// parse first line
58
myLineHandler.reinit(lr.readLine(), ";", ";", true, true);
59
// parse values
60
while (lr.hasMore()) {
61
std::string line = lr.readLine();
62
if (line.find(';') == std::string::npos) {
63
continue;
64
}
65
myLineHandler.parseLine(line);
66
try {
67
std::string detName = myLineHandler.get("detector");
68
if (!myDetectorContainer.knows(detName)) {
69
continue;
70
}
71
const SUMOTime time = (SUMOTime)(StringUtils::toDouble(myLineHandler.get("time")) * (double)myTimeScale + .5) - myTimeOffset;
72
// parsing as float to handle values which would cause int overflow
73
if (time < myStartTime || time >= myEndTime) {
74
if (!myHaveWarnedAboutOverridingBoundaries) {
75
myHaveWarnedAboutOverridingBoundaries = true;
76
WRITE_WARNING(TL("At least one value lies beyond given time boundaries."));
77
}
78
continue;
79
}
80
FlowDef fd;
81
fd.isLKW = 0;
82
fd.qPKW = StringUtils::toDouble(myLineHandler.get("qpkw"));
83
fd.vPKW = 0;
84
if (myLineHandler.know("vPKW")) {
85
fd.vPKW = StringUtils::toDouble(myLineHandler.get("vpkw"));
86
}
87
fd.qLKW = 0;
88
if (myLineHandler.know("qLKW")) {
89
fd.qLKW = StringUtils::toDouble(myLineHandler.get("qlkw"));
90
}
91
fd.vLKW = 0;
92
if (myLineHandler.know("vLKW")) {
93
fd.vLKW = StringUtils::toDouble(myLineHandler.get("vlkw"));
94
}
95
if (fd.qLKW < 0) {
96
fd.qLKW = 0;
97
}
98
if (fd.qPKW < 0) {
99
fd.qPKW = 0;
100
}
101
myStorage.addFlow(detName, time, fd);
102
if (!myHaveWarnedAboutPartialDefs && !myLineHandler.hasFullDefinition()) {
103
myHaveWarnedAboutPartialDefs = true;
104
WRITE_WARNING(TL("At least one line does not contain the correct number of columns."));
105
}
106
continue;
107
} catch (ProcessError& e) {
108
throw ProcessError(toString(e.what()) + " in '" + lr.getFileName() + "', line " + toString(lr.getLineNumber()) + ";\n"
109
+ " The following values must be supplied : 'Detector', 'Time', 'qPKW'\n"
110
+ " The according column names must be given in the first line of the file.");
111
}
112
}
113
}
114
115
116
/****************************************************************************/
117
118