LCOV - code coverage report
Current view: top level - src/microsim/transportables - MSStageTranship.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 59 69 85.5 %
Date: 2024-05-07 15:28:01 Functions: 9 10 90.0 %

          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      109548 : MSStageTranship::MSStageTranship(const std::vector<const MSEdge*>& route,
      46             :                                  MSStoppingPlace* toStop,
      47             :                                  double speed,
      48      109548 :                                  double departPos, double arrivalPos) :
      49      219096 :     MSStageMoving(MSStageType::TRANSHIP, route, "", toStop, speed, departPos, arrivalPos, 0., -1) {
      50      109548 :     myDepartPos = SUMOVehicleParameter::interpretEdgePos(
      51             :                       departPos, myRoute.front()->getLength(), SUMO_ATTR_DEPARTPOS,
      52      219096 :                       "container getting transhipped from " + myRoute.front()->getID());
      53      109548 :     myArrivalPos = SUMOVehicleParameter::interpretEdgePos(
      54             :                        arrivalPos, route.back()->getLength(), SUMO_ATTR_ARRIVALPOS,
      55      109548 :                        "container getting transhipped to " + route.back()->getID());
      56      109548 : }
      57             : 
      58             : 
      59      219096 : MSStageTranship::~MSStageTranship() {
      60      219096 : }
      61             : 
      62             : 
      63             : MSStage*
      64      109105 : MSStageTranship::clone() const {
      65      109105 :     MSStage* const clon = new MSStageTranship(myRoute, myDestinationStop, mySpeed, myDepartPos, myArrivalPos);
      66      109105 :     clon->setParameters(*this);
      67      109105 :     return clon;
      68             : }
      69             : 
      70             : 
      71             : void
      72      109548 : MSStageTranship::proceed(MSNet* net, MSTransportable* transportable, SUMOTime now, MSStage* previous) {
      73      109548 :     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      109548 :     myRouteStep = myRoute.end() - 1;
      78      109548 :     myDepartPos = previous->getEdgePos(now);
      79      109548 :     if (transportable->isPerson()) {
      80           0 :         myPState = net->getPersonControl().getNonInteractingModel()->add(transportable, this, now);
      81           0 :         (*myRouteStep)->addTransportable(transportable);
      82             :     } else {
      83      109548 :         myPState = net->getContainerControl().getNonInteractingModel()->add(transportable, this, now);
      84      109548 :         (*myRouteStep)->addTransportable(transportable);
      85             :     }
      86      109548 : }
      87             : 
      88             : 
      89             : double
      90         448 : MSStageTranship::getDistance() const {
      91         448 :     if (myArrived >= 0) {
      92         448 :         const SUMOTime duration = myArrived - myDeparted;
      93         448 :         return mySpeed * STEPS2TIME(duration);
      94             :     } else {
      95             :         return -1;
      96             :     }
      97             : }
      98             : 
      99             : 
     100             : void
     101         448 : MSStageTranship::tripInfoOutput(OutputDevice& os, const MSTransportable* const) const {
     102         448 :     os.openTag("tranship");
     103         896 :     os.writeAttr("depart", time2string(myDeparted));
     104         448 :     os.writeAttr("departPos", myDepartPos);
     105         896 :     os.writeAttr("arrival", time2string(myArrived));
     106         448 :     os.writeAttr("arrivalPos", myArrivalPos);
     107         896 :     os.writeAttr("duration", myArrived >= 0 ? time2string(getDuration()) : "-1");
     108         448 :     os.writeAttr("routeLength", getDistance());
     109         448 :     os.writeAttr("maxSpeed", mySpeed);
     110         448 :     os.closeTag();
     111         448 : }
     112             : 
     113             : 
     114             : void
     115          44 : MSStageTranship::routeOutput(const bool /*isPerson*/, OutputDevice& os, const bool withRouteLength, const MSStage* const /* previous */) const {
     116          44 :     os.openTag("tranship").writeAttr(SUMO_ATTR_EDGES, myRoute);
     117          44 :     std::string comment = "";
     118          44 :     if (myDestinationStop != nullptr) {
     119           8 :         os.writeAttr(toString(myDestinationStop->getElement()), myDestinationStop->getID());
     120          16 :         if (myDestinationStop->getMyName() != "") {
     121           0 :             comment =  " <!-- " + StringUtils::escapeXML(myDestinationStop->getMyName(), true) + " -->";
     122             :         }
     123             :     }
     124          44 :     os.writeAttr(SUMO_ATTR_SPEED, mySpeed);
     125          44 :     if (withRouteLength) {
     126           0 :         os.writeAttr("routeLength", mySpeed * STEPS2TIME(myArrived - myDeparted));
     127             :     }
     128          88 :     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          88 :     if (OptionsCont::getOptions().getBool("vehroute-output.cost")) {
     133           0 :         os.writeAttr(SUMO_ATTR_COST, getCosts());
     134             :     }
     135          44 :     os.closeTag(comment);
     136          44 : }
     137             : 
     138             : 
     139             : bool
     140      109548 : MSStageTranship::moveToNextEdge(MSTransportable* transportable, SUMOTime currentTime, int /*prevDir*/, MSEdge* /* nextInternal */) {
     141      109548 :     getEdge()->removeTransportable(transportable);
     142             :     // transship does a direct move so we are already at our destination
     143      109548 :     if (myDestinationStop != nullptr) {
     144       25270 :         myDestinationStop->addTransportable(transportable);    //jakob
     145             :     }
     146      109548 :     if (!transportable->proceed(MSNet::getInstance(), currentTime)) {
     147      109340 :         if (transportable->isPerson()) {
     148           0 :             MSNet::getInstance()->getPersonControl().erase(transportable);
     149             :         } else {
     150      109340 :             MSNet::getInstance()->getContainerControl().erase(transportable);
     151             :         }
     152             :     }
     153      109548 :     return true;
     154             : }
     155             : 
     156             : 
     157             : std::string
     158           0 : MSStageTranship::getStageSummary(const bool /*isPerson*/) const {
     159             :     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 1.14