LCOV - code coverage report
Current view: top level - src/microsim/transportables - MSStageTranship.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 84.3 % 70 59
Test Date: 2024-12-21 15:45:41 Functions: 90.0 % 10 9

            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    MSStageTranship.cpp
      15              : /// @author  Melanie Weber
      16              : /// @author  Andreas Kendziorra
      17              : /// @date    Thu, 12 Jun 2014
      18              : ///
      19              : // The class for modelling transportable movements without interaction
      20              : /****************************************************************************/
      21              : #include <config.h>
      22              : 
      23              : #include <string>
      24              : #include <vector>
      25              : #include <utils/iodevices/OutputDevice.h>
      26              : #include <utils/options/OptionsCont.h>
      27              : #include <utils/common/ToString.h>
      28              : #include <utils/common/StringUtils.h>
      29              : #include <utils/geom/GeomHelper.h>
      30              : #include <microsim/MSNet.h>
      31              : #include <microsim/MSEdge.h>
      32              : #include <microsim/MSLane.h>
      33              : #include <microsim/MSStoppingPlace.h>
      34              : #include <microsim/transportables/MSPModel.h>
      35              : #include <microsim/transportables/MSTransportableControl.h>
      36              : #include <microsim/MSInsertionControl.h>
      37              : #include <microsim/MSVehicle.h>
      38              : #include <microsim/MSVehicleControl.h>
      39              : #include "MSStageTranship.h"
      40              : 
      41              : 
      42              : // ===========================================================================
      43              : // method definitions
      44              : // ===========================================================================
      45       134051 : MSStageTranship::MSStageTranship(const std::vector<const MSEdge*>& route,
      46              :                                  MSStoppingPlace* toStop,
      47              :                                  double speed,
      48       134051 :                                  double departPos, double arrivalPos) :
      49       268102 :     MSStageMoving(MSStageType::TRANSHIP, route, "", toStop, speed, departPos, arrivalPos, 0., -1) {
      50       134051 :     myDepartPos = SUMOVehicleParameter::interpretEdgePos(
      51              :                       departPos, myRoute.front()->getLength(), SUMO_ATTR_DEPARTPOS,
      52       268102 :                       "container getting transhipped from " + myRoute.front()->getID());
      53       134051 :     myArrivalPos = SUMOVehicleParameter::interpretEdgePos(
      54              :                        arrivalPos, route.back()->getLength(), SUMO_ATTR_ARRIVALPOS,
      55       134051 :                        "container getting transhipped to " + route.back()->getID());
      56       134051 : }
      57              : 
      58              : 
      59       268102 : MSStageTranship::~MSStageTranship() {
      60       268102 : }
      61              : 
      62              : 
      63              : MSStage*
      64       133564 : MSStageTranship::clone() const {
      65       133564 :     MSStage* const clon = new MSStageTranship(myRoute, myDestinationStop, mySpeed, myDepartPos, myArrivalPos);
      66       133564 :     clon->setParameters(*this);
      67       133564 :     return clon;
      68              : }
      69              : 
      70              : 
      71              : void
      72       130239 : MSStageTranship::proceed(MSNet* net, MSTransportable* transportable, SUMOTime now, MSStage* previous) {
      73       130239 :     myDeparted = now;
      74              :     //MSPModel_NonInteracting moves the transportable straight from start to end in
      75              :     //a single step and assumes that moveToNextEdge is only called once)
      76              :     //therefore we define that the transportable is already on its destination edge
      77       130239 :     myRouteStep = myRoute.end() - 1;
      78       130239 :     myDepartPos = previous->getEdgePos(now);
      79       130239 :     if (transportable->isPerson()) {
      80            0 :         myPState = net->getPersonControl().getNonInteractingModel()->add(transportable, this, now);
      81            0 :         (*myRouteStep)->addTransportable(transportable);
      82              :     } else {
      83       130239 :         myPState = net->getContainerControl().getNonInteractingModel()->add(transportable, this, now);
      84       130239 :         (*myRouteStep)->addTransportable(transportable);
      85              :     }
      86       130239 : }
      87              : 
      88              : 
      89              : double
      90          464 : MSStageTranship::getDistance() const {
      91          464 :     if (myArrived >= 0) {
      92          464 :         const SUMOTime duration = myArrived - myDeparted;
      93          464 :         return mySpeed * STEPS2TIME(duration);
      94              :     } else {
      95              :         return -1;
      96              :     }
      97              : }
      98              : 
      99              : 
     100              : void
     101          464 : MSStageTranship::tripInfoOutput(OutputDevice& os, const MSTransportable* const) const {
     102          464 :     os.openTag("tranship");
     103          928 :     os.writeAttr("depart", time2string(myDeparted));
     104          464 :     os.writeAttr("departPos", myDepartPos);
     105          928 :     os.writeAttr("arrival", time2string(myArrived));
     106          464 :     os.writeAttr("arrivalPos", myArrivalPos);
     107          928 :     os.writeAttr("duration", myArrived >= 0 ? time2string(getDuration()) : "-1");
     108          464 :     os.writeAttr("routeLength", getDistance());
     109          464 :     os.writeAttr("maxSpeed", mySpeed);
     110          464 :     os.closeTag();
     111          464 : }
     112              : 
     113              : 
     114              : void
     115           60 : MSStageTranship::routeOutput(const bool /*isPerson*/, OutputDevice& os, const bool withRouteLength, const MSStage* const /* previous */) const {
     116           60 :     os.openTag("tranship").writeAttr(SUMO_ATTR_EDGES, myRoute);
     117           60 :     std::string comment = "";
     118           60 :     if (myDestinationStop != nullptr) {
     119           16 :         os.writeAttr(toString(myDestinationStop->getElement()), myDestinationStop->getID());
     120           16 :         if (myDestinationStop->getMyName() != "") {
     121            0 :             comment =  " <!-- " + StringUtils::escapeXML(myDestinationStop->getMyName(), true) + " -->";
     122              :         }
     123              :     }
     124           60 :     os.writeAttr(SUMO_ATTR_SPEED, mySpeed);
     125           60 :     if (withRouteLength) {
     126            0 :         os.writeAttr("routeLength", mySpeed * STEPS2TIME(myArrived - myDeparted));
     127              :     }
     128          120 :     if (OptionsCont::getOptions().getBool("vehroute-output.exit-times")) {
     129           12 :         os.writeAttr(SUMO_ATTR_STARTED, myDeparted >= 0 ? time2string(myDeparted) : "-1");
     130           24 :         os.writeAttr(SUMO_ATTR_ENDED, myArrived >= 0 ? time2string(myArrived) : "-1");
     131              :     }
     132          120 :     if (OptionsCont::getOptions().getBool("vehroute-output.cost")) {
     133            0 :         os.writeAttr(SUMO_ATTR_COST, getCosts());
     134              :     }
     135           60 :     os.closeTag(comment);
     136           60 : }
     137              : 
     138              : 
     139              : bool
     140       128527 : MSStageTranship::moveToNextEdge(MSTransportable* transportable, SUMOTime currentTime, int /*prevDir*/, MSEdge* /* nextInternal */, const bool /* isReplay */) {
     141       128527 :     getEdge()->removeTransportable(transportable);
     142              :     // transship does a direct move so we are already at our destination
     143       128527 :     if (myDestinationStop != nullptr) {
     144        26788 :         myDestinationStop->addTransportable(transportable);    //jakob
     145              :     }
     146       128527 :     if (!transportable->proceed(MSNet::getInstance(), currentTime)) {
     147       128299 :         if (transportable->isPerson()) {
     148            0 :             MSNet::getInstance()->getPersonControl().erase(transportable);
     149              :         } else {
     150       128299 :             MSNet::getInstance()->getContainerControl().erase(transportable);
     151              :         }
     152              :     }
     153       128527 :     return true;
     154              : }
     155              : 
     156              : 
     157              : std::string
     158            0 : MSStageTranship::getStageSummary(const bool /*isPerson*/) const {
     159            0 :     const std::string dest = (getDestinationStop() == nullptr ?
     160            0 :                               " edge '" + getDestination()->getID() + "'" :
     161            0 :                               " stop '" + getDestinationStop()->getID() + "'");
     162            0 :     return "transhipped to " + dest;
     163              : }
     164              : 
     165              : 
     166              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1