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 321354 : MSQueueExport::write(OutputDevice& of, SUMOTime timestep) { 41 642708 : const SUMOTime begin = string2time(OptionsCont::getOptions().getString("begin")); 42 642708 : const SUMOTime period = string2time(OptionsCont::getOptions().getString("queue-output.period")); 43 321354 : if (period > 0 && (timestep - begin) % period != 0) { 44 : return; 45 : } 46 640548 : of.openTag("data").writeAttr("timestep", time2string(timestep)); 47 320274 : writeEdge(of); 48 640548 : of.closeTag(); 49 : } 50 : 51 : 52 : void 53 320274 : MSQueueExport::writeEdge(OutputDevice& of) { 54 320274 : of.openTag("lanes"); 55 320274 : MSEdgeControl& ec = MSNet::getInstance()->getEdgeControl(); 56 : const MSEdgeVector& edges = ec.getEdges(); 57 6773274 : for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) { 58 6453000 : MSEdge& edge = **e; 59 : const std::vector<MSLane*>& lanes = edge.getLanes(); 60 12925200 : for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) { 61 6472200 : writeLane(of, **lane); 62 : } 63 : } 64 320274 : of.closeTag(); 65 320274 : } 66 : 67 : 68 : void 69 6472200 : MSQueueExport::writeLane(OutputDevice& of, const MSLane& lane) { 70 : // maximum of all vehicle waiting times 71 6472200 : double queueing_time = 0.0; 72 : // back of last stopped vehicle (XXX does not check for continuous queue) 73 6472200 : double queueing_length = 0.0; 74 : // back of last slow vehicle (XXX does not check for continuous queue) 75 6472200 : double queueing_length2 = 0.0; 76 : const double threshold_velocity = 5 / 3.6; // slow 77 : 78 6472200 : if (!lane.empty()) { 79 64653206 : for (MSLane::VehCont::const_iterator it_veh = lane.myVehicles.begin(); it_veh != lane.myVehicles.end(); ++it_veh) { 80 62266208 : const MSVehicle& veh = **it_veh; 81 62266208 : if (!veh.isOnRoad()) { 82 0 : continue; 83 : } 84 : 85 62266208 : if (veh.getWaitingSeconds() > 0) { 86 61206864 : queueing_time = MAX2(veh.getWaitingSeconds(), queueing_time); 87 30603432 : const double veh_back_to_lane_end = (lane.getLength() - veh.getPositionOnLane()) + veh.getVehicleType().getLength(); 88 60481454 : queueing_length = MAX2(veh_back_to_lane_end, queueing_length); 89 : } 90 : 91 : //Experimental 92 62266208 : if (veh.getSpeed() < (threshold_velocity) && (veh.getPositionOnLane() > (veh.getLane()->getLength()) * 0.25)) { 93 26332968 : const double veh_back_to_lane_end = (lane.getLength() - veh.getPositionOnLane()) + veh.getVehicleType().getLength(); 94 51941772 : queueing_length2 = MAX2(veh_back_to_lane_end, queueing_length2); 95 : } 96 : } 97 : } 98 : 99 : //Output 100 6472200 : if (queueing_length > 1 || queueing_length2 > 1) { 101 2904176 : of.openTag("lane").writeAttr("id", lane.getID()).writeAttr("queueing_time", queueing_time).writeAttr("queueing_length", queueing_length); 102 2904176 : of.writeAttr("queueing_length_experimental", queueing_length2).closeTag(); 103 : } 104 6472200 : } 105 : 106 : 107 : /****************************************************************************/