LCOV - code coverage report
Current view: top level - src/microsim - Command_RouteReplacement.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 76.5 % 17 13
Test Date: 2024-11-22 15:46:21 Functions: 100.0 % 4 4

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-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    Command_RouteReplacement.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Michael Behrisch
      17              : /// @date    15 Feb 2004
      18              : ///
      19              : // Writes the state of the tls to a file (in each second)
      20              : /****************************************************************************/
      21              : #include <config.h>
      22              : 
      23              : #include <utils/vehicle/SUMOVehicle.h>
      24              : #include <microsim/MSNet.h>
      25              : #include <microsim/MSVehicleControl.h>
      26              : #include <microsim/MSRoute.h>
      27              : #include <microsim/MSGlobals.h>
      28              : #include "Command_RouteReplacement.h"
      29              : 
      30              : 
      31              : // ===========================================================================
      32              : // method definitions
      33              : // ===========================================================================
      34         1791 : Command_RouteReplacement::Command_RouteReplacement(const std::string& vehID, ConstMSRoutePtr route) :
      35         1791 :     myVehID(vehID),
      36         1791 :     myRoute(route) {
      37         1791 : }
      38              : 
      39              : 
      40         5373 : Command_RouteReplacement::~Command_RouteReplacement() { }
      41              : 
      42              : 
      43              : SUMOTime
      44         1791 : Command_RouteReplacement::execute(SUMOTime /*currentTime*/) {
      45         1791 :     SUMOVehicle* veh = MSNet::getInstance()->getVehicleControl().getVehicle(myVehID);
      46              :     // if the vehicle is not available anymore, silently ignore replacement
      47         1791 :     if (veh != nullptr) {
      48              :         std::string errorPrefix = ("Replayed route replacement failed for vehicle '"
      49         5373 :                                    + veh->getID() + "' route=" + myRoute->getID() + " time=" + time2string(SIMSTEP));
      50              :         std::string msg;
      51         3582 :         if (!veh->hasValidRoute(msg, myRoute)) {
      52            0 :             WRITE_WARNING("Invalid route replacement for vehicle '" + veh->getID() + "'. " + msg);
      53            0 :             if (MSGlobals::gCheckRoutes) {
      54            0 :                 throw ProcessError(errorPrefix + ".");
      55              :             }
      56              :         }
      57              :         std::string errorMsg;
      58         5373 :         if (!veh->replaceRoute(myRoute, "replayRerouting", veh->getLane() == nullptr,
      59         1791 :                                veh->getRoute().getReplacedIndex(), true, true, &errorMsg)) {
      60            0 :             throw ProcessError(errorPrefix + " (" + errorMsg + ").");
      61              :         }
      62              :     }
      63         1791 :     return 0;
      64              : }
      65              : 
      66              : 
      67              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1