LCOV - code coverage report
Current view: top level - src/microsim/output - MSQueueExport.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 97.2 % 36 35
Test Date: 2024-11-20 15:55:46 Functions: 100.0 % 3 3

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2012-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    MSQueueExport.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Jakob Erdmann
      17              : /// @author  Mario Krumnow
      18              : /// @author  Michael Behrisch
      19              : /// @date    2012-04-26
      20              : ///
      21              : // Export the queueing length in front of a junction (very experimental!)
      22              : /****************************************************************************/
      23              : #include <config.h>
      24              : 
      25              : #include <microsim/MSEdgeControl.h>
      26              : #include <microsim/MSEdge.h>
      27              : #include <microsim/MSLane.h>
      28              : #include <microsim/MSGlobals.h>
      29              : #include <utils/options/OptionsCont.h>
      30              : #include <utils/iodevices/OutputDevice.h>
      31              : #include "MSQueueExport.h"
      32              : #include <microsim/MSNet.h>
      33              : #include <microsim/MSVehicle.h>
      34              : 
      35              : 
      36              : // ===========================================================================
      37              : // method definitions
      38              : // ===========================================================================
      39              : void
      40       162207 : MSQueueExport::write(OutputDevice& of, SUMOTime timestep) {
      41       162207 :     const SUMOTime begin = string2time(OptionsCont::getOptions().getString("begin"));
      42       162207 :     const SUMOTime period = string2time(OptionsCont::getOptions().getString("queue-output.period"));
      43       162207 :     if (period > 0 && (timestep - begin) % period != 0) {
      44              :         return;
      45              :     }
      46       322254 :     of.openTag("data").writeAttr("timestep", time2string(timestep));
      47       161127 :     writeEdge(of);
      48       322254 :     of.closeTag();
      49              : }
      50              : 
      51              : 
      52              : void
      53       161127 : MSQueueExport::writeEdge(OutputDevice& of) {
      54       161127 :     of.openTag("lanes");
      55       161127 :     MSEdgeControl& ec = MSNet::getInstance()->getEdgeControl();
      56              :     const MSEdgeVector& edges = ec.getEdges();
      57      3431187 :     for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
      58      3270060 :         MSEdge& edge = **e;
      59              :         const std::vector<MSLane*>& lanes = edge.getLanes();
      60      6559320 :         for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
      61      3289260 :             writeLane(of, **lane);
      62              :         }
      63              :     }
      64       161127 :     of.closeTag();
      65       161127 : }
      66              : 
      67              : 
      68              : void
      69      3289260 : MSQueueExport::writeLane(OutputDevice& of, const MSLane& lane) {
      70              :     // maximum of all vehicle waiting times
      71      3289260 :     double queueing_time = 0.0;
      72              :     // back of last stopped vehicle (XXX does not check for continuous queue)
      73      3289260 :     double queueing_length = 0.0;
      74              :     // back of last slow vehicle (XXX does not check for continuous queue)
      75      3289260 :     double queueing_length2 = 0.0;
      76              :     const double threshold_velocity = 5 / 3.6; // slow
      77              : 
      78      3289260 :     if (!lane.empty()) {
      79     32335167 :         for (MSLane::VehCont::const_iterator it_veh = lane.myVehicles.begin(); it_veh != lane.myVehicles.end(); ++it_veh) {
      80     31139812 :             const MSVehicle& veh = **it_veh;
      81     31139812 :             if (!veh.isOnRoad()) {
      82            0 :                 continue;
      83              :             }
      84              : 
      85     31139812 :             if (veh.getWaitingSeconds() > 0) {
      86     30606216 :                 queueing_time = MAX2(veh.getWaitingSeconds(), queueing_time);
      87     15303108 :                 const double veh_back_to_lane_end = (lane.getLength() - veh.getPositionOnLane()) + veh.getVehicleType().getLength();
      88     30243169 :                 queueing_length = MAX2(veh_back_to_lane_end, queueing_length);
      89              :             }
      90              : 
      91              :             //Experimental
      92     31139812 :             if (veh.getSpeed() < (threshold_velocity) && (veh.getPositionOnLane() > (veh.getLane()->getLength()) * 0.25)) {
      93     13167970 :                 const double veh_back_to_lane_end = (lane.getLength() - veh.getPositionOnLane()) + veh.getVehicleType().getLength();
      94     25973502 :                 queueing_length2 = MAX2(veh_back_to_lane_end, queueing_length2);
      95              :             }
      96              :         }
      97              :     }
      98              : 
      99              :     //Output
     100      3289260 :     if (queueing_length > 1 || queueing_length2 > 1) {
     101      1453512 :         of.openTag("lane").writeAttr("id", lane.getID()).writeAttr("queueing_time", queueing_time).writeAttr("queueing_length", queueing_length);
     102      1090134 :         of.writeAttr("queueing_length_experimental", queueing_length2).closeTag();
     103              :     }
     104      3289260 : }
     105              : 
     106              : 
     107              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1