Line data Source code
1 : /****************************************************************************/ 2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3 : // Copyright (C) 2006-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 : /****************************************************************************/ 14 : /// @file RODFDetectorFlow.cpp 15 : /// @author Daniel Krajzewicz 16 : /// @author Eric Nicolay 17 : /// @author Michael Behrisch 18 : /// @author Melanie Knocke 19 : /// @date Thu, 16.03.2006 20 : /// 21 : // Storage for flows within the DFROUTER 22 : /****************************************************************************/ 23 : #include <config.h> 24 : 25 : #include <iostream> 26 : #include <cassert> 27 : #include "RODFDetectorFlow.h" 28 : 29 : 30 : // =========================================================================== 31 : // method definitions 32 : // =========================================================================== 33 222 : RODFDetectorFlows::RODFDetectorFlows(SUMOTime startTime, SUMOTime endTime, 34 222 : SUMOTime stepOffset) 35 222 : : myBeginTime(startTime), myEndTime(endTime), myStepOffset(stepOffset), 36 222 : myMaxDetectorFlow(-1) {} 37 : 38 : 39 222 : RODFDetectorFlows::~RODFDetectorFlows() {} 40 : 41 : 42 : void 43 8067 : RODFDetectorFlows::addFlow(const std::string& id, SUMOTime t, const FlowDef& fd) { 44 8067 : if (myFastAccessFlows.find(id) == myFastAccessFlows.end()) { 45 962 : int noItems = (int)((myEndTime - myBeginTime) / myStepOffset); 46 962 : myFastAccessFlows[id] = std::vector<FlowDef>(noItems); 47 962 : std::vector<FlowDef>& cflows = myFastAccessFlows[id]; 48 : // initialise 49 493655 : for (std::vector<FlowDef>::iterator i = cflows.begin(); i < cflows.end(); ++i) { 50 492693 : (*i).qPKW = 0; 51 492693 : (*i).qLKW = 0; 52 492693 : (*i).vPKW = 0; 53 492693 : (*i).vLKW = 0; 54 492693 : (*i).fLKW = 0; 55 492693 : (*i).isLKW = 0; 56 492693 : (*i).firstSet = true; 57 : } 58 : } 59 8067 : const int index = (int)((t - myBeginTime) / myStepOffset); 60 : assert(index < (int) myFastAccessFlows[id].size()); 61 8067 : FlowDef& ofd = myFastAccessFlows[id][index]; 62 8067 : if (ofd.firstSet) { 63 8067 : ofd = fd; 64 8067 : ofd.firstSet = false; 65 : } else { 66 0 : ofd.qLKW = ofd.qLKW + fd.qLKW; 67 0 : ofd.qPKW = ofd.qPKW + fd.qPKW; 68 0 : ofd.vLKW = ofd.vLKW + fd.vLKW; //!!! mean value? 69 0 : ofd.vPKW = ofd.vPKW + fd.vPKW; //!!! mean value? 70 : } 71 8067 : if (ofd.qPKW != 0) { 72 6543 : ofd.fLKW = ofd.qLKW / (ofd.qLKW + ofd.qPKW); 73 : } else { 74 1524 : ofd.fLKW = 1; 75 1524 : ofd.isLKW = 1; 76 : } 77 8067 : } 78 : 79 : 80 : void 81 0 : RODFDetectorFlows::setFlows(const std::string& detector_id, 82 : std::vector<FlowDef>& flows) { 83 0 : for (std::vector<FlowDef>::iterator i = flows.begin(); i < flows.end(); ++i) { 84 : FlowDef& ofd = *i; 85 0 : if (ofd.qLKW != 0 && ofd.qPKW != 0) { 86 0 : ofd.fLKW = ofd.qLKW / ofd.qPKW; 87 : } else { 88 0 : ofd.fLKW = 0; 89 : } 90 : } 91 0 : myFastAccessFlows[detector_id] = flows; 92 0 : } 93 : 94 : 95 : void 96 7 : RODFDetectorFlows::removeFlow(const std::string& detector_id) { 97 : myFastAccessFlows.erase(detector_id); 98 7 : } 99 : 100 : 101 : bool 102 1587 : RODFDetectorFlows::knows(const std::string& det_id) const { 103 1587 : return myFastAccessFlows.find(det_id) != myFastAccessFlows.end(); 104 : } 105 : 106 : 107 : const std::vector<FlowDef>& 108 1068 : RODFDetectorFlows::getFlowDefs(const std::string& id) const { 109 : assert(myFastAccessFlows.find(id) != myFastAccessFlows.end()); 110 : assert(myFastAccessFlows.find(id)->second.size() != 0); 111 1068 : return myFastAccessFlows.find(id)->second; 112 : } 113 : 114 : 115 : double 116 0 : RODFDetectorFlows::getFlowSumSecure(const std::string& id) const { 117 : double ret = 0; 118 0 : if (knows(id)) { 119 : const std::vector<FlowDef>& flows = getFlowDefs(id); 120 0 : for (std::vector<FlowDef>::const_iterator i = flows.begin(); i != flows.end(); ++i) { 121 0 : ret += (*i).qPKW; 122 0 : ret += (*i).qLKW; 123 : } 124 : } 125 0 : return ret; 126 : } 127 : 128 : 129 : double 130 0 : RODFDetectorFlows::getMaxDetectorFlow() const { 131 0 : if (myMaxDetectorFlow < 0) { 132 : double max = 0; 133 : std::map<std::string, std::vector<FlowDef> >::const_iterator j; 134 0 : for (j = myFastAccessFlows.begin(); j != myFastAccessFlows.end(); ++j) { 135 : double curr = 0; 136 : const std::vector<FlowDef>& flows = (*j).second; 137 0 : for (std::vector<FlowDef>::const_iterator i = flows.begin(); i != flows.end(); ++i) { 138 0 : curr += (*i).qPKW; 139 0 : curr += (*i).qLKW; 140 : } 141 0 : if (max < curr) { 142 : max = curr; 143 : } 144 : } 145 0 : myMaxDetectorFlow = max; 146 : } 147 0 : return myMaxDetectorFlow; 148 : } 149 : 150 : 151 : void 152 0 : RODFDetectorFlows::mesoJoin(const std::string& nid, 153 : const std::vector<std::string>& oldids) { 154 0 : for (std::vector<std::string>::const_iterator i = oldids.begin(); i != oldids.end(); ++i) { 155 0 : if (!knows(*i)) { 156 0 : continue; 157 : } 158 0 : std::vector<FlowDef>& flows = myFastAccessFlows[*i]; 159 : int index = 0; 160 0 : for (SUMOTime t = myBeginTime; t != myEndTime; t += myStepOffset) { 161 0 : addFlow(nid, t, flows[index++]); // !!! 162 : } 163 : myFastAccessFlows.erase(*i); 164 : } 165 0 : } 166 : 167 : 168 : void 169 0 : RODFDetectorFlows::printAbsolute() const { 170 0 : for (std::map<std::string, std::vector<FlowDef> >::const_iterator i = myFastAccessFlows.begin(); i != myFastAccessFlows.end(); ++i) { 171 0 : std::cout << (*i).first << ":"; 172 : const std::vector<FlowDef>& flows = (*i).second; 173 : double qPKW = 0; 174 : double qLKW = 0; 175 0 : for (std::vector<FlowDef>::const_iterator j = flows.begin(); j != flows.end(); ++j) { 176 0 : qPKW += (*j).qPKW; 177 0 : qLKW += (*j).qLKW; 178 : } 179 : std::cout << qPKW << "/" << qLKW << std::endl; 180 : } 181 0 : } 182 : 183 : 184 : /****************************************************************************/