/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2002-2026 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file RORoutable.h14/// @author Michael Behrisch15/// @date Oct 201516///17// A routable thing such as a vehicle or person18/****************************************************************************/19#pragma once20#include <config.h>2122#include <string>23#include <iostream>24#include <utils/common/StdDefs.h>25#include <utils/common/SUMOTime.h>26#include <utils/common/RandHelper.h>27#include <utils/router/RouterProvider.h>28#include <utils/vehicle/SUMOVehicleParameter.h>29#include <utils/vehicle/SUMOVTypeParameter.h>3031// ===========================================================================32// class declarations33// ===========================================================================34class OutputDevice;35class ROEdge;36class ROLane;37class RONode;38class ROVehicle;3940typedef std::vector<const ROEdge*> ConstROEdgeVector;41typedef IntermodalRouter<ROEdge, ROLane, RONode, ROVehicle> ROIntermodalRouter;42typedef RouterProvider<ROEdge, ROLane, RONode, ROVehicle> RORouterProvider;434445// ===========================================================================46// class definitions47// ===========================================================================48/**49* @class RORoutable50* @brief A routable thing such as a vehicle or person51*/52class RORoutable {53public:54/** @brief Constructor55*56* @param[in] pars Parameter of this routable57* @param[in] type The type of the routable58*/59RORoutable(const SUMOVehicleParameter& pars, const SUMOVTypeParameter* type) :60myParameter(pars),61myType(type),62myRandomSeed(RandHelper::murmur3_32(pars.id, RandHelper::getSeed())),63myRoutingSuccess(false) {}646566/// @brief Destructor67virtual ~RORoutable() {}686970/** @brief Returns the definition of the vehicle / person parameter71*72* @return The vehicle / person's parameter73*/74inline const SUMOVehicleParameter& getParameter() const {75return myParameter;76}777879/** @brief Returns the type of the routable80*81* @return The routable's type82*83* @todo Why not return a reference?84*/85inline const SUMOVTypeParameter* getType() const {86return myType;87}888990/** @brief Returns the id of the routable91*92* @return The id of the routable93*/94inline const std::string& getID() const {95return myParameter.id;96}9798/// @brief return vehicle-specific random number99long long int getRandomSeed() const {100return myRandomSeed;101}102103/** @brief Returns an upper bound for the speed factor of this vehicle104* @return the maximum speed factor105*/106inline double getChosenSpeedFactor() const {107return getParameter().wasSet(VEHPARS_SPEEDFACTOR_SET) ? getParameter().speedFactor : getType()->speedFactor.getParameter(0);108}109110/** @brief Returns the time the vehicle starts at, -1 for triggered vehicles111*112* @return The vehicle's depart time113*/114inline SUMOTime getDepart() const {115return myParameter.depart;116}117118/// @brief update depart time (for triggered persons)119inline void setDepart(SUMOTime t) {120myParameter.depart = t;121}122123inline SUMOVehicleClass getVClass() const {124return getType() != 0 ? getType()->vehicleClass : SVC_IGNORING;125}126127/** @brief Returns whether this object is ignoring transient permission128* changes (during routing)129*/130bool ignoreTransientPermissions() const {131return false;132};133134/// @brief Returns the vehicle's maximum speed135inline double getMaxSpeed() const {136return MIN2(getType()->maxSpeed,137getType()->desiredMaxSpeed * getChosenSpeedFactor());138}139140virtual const ROEdge* getDepartEdge() const = 0;141142143inline bool isPublicTransport() const {144return myParameter.line != "";145}146147inline bool isPartOfFlow() const {148return myParameter.repetitionNumber >= 0;149}150151virtual void computeRoute(const RORouterProvider& provider,152const bool removeLoops, MsgHandler* errorHandler) = 0;153154155/** @brief Saves the routable including the vehicle type (if it was not saved before).156*157* @param[in] os The routes - output device to store the vehicle's description into158* @param[in] altos The route alternatives - output device to store the vehicle's description into159* @param[in] typeos The types - output device to store the vehicle types into160* @exception IOError If something fails (not yet implemented)161*/162void write(OutputDevice* os, OutputDevice* const altos,163OutputDevice* const typeos, OptionsCont& options, int quota) const {164for (int i = 0; i < quota; i++) {165if (os != nullptr) {166if (altos == nullptr && typeos == nullptr) {167saveAsXML(*os, os, false, options, i);168} else {169saveAsXML(*os, typeos, false, options, i);170}171}172if (altos != nullptr) {173saveAsXML(*altos, typeos, true, options, i);174}175}176}177178179inline bool getRoutingSuccess() const {180return myRoutingSuccess;181}182183184protected:185/** @brief Saves the complete routable description.186*187* Saves the routable itself including the route and stops.188*189* @param[in] os The routes or alternatives output device to store the routable's description into190* @param[in] typeos The types - output device to store additional types into191* @param[in] asAlternatives Whether the route shall be saved as route alternatives192* @param[in] options to find out about defaults and whether exit times for the edges shall be written193* @exception IOError If something fails (not yet implemented)194*/195virtual void saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options, int cloneIndex = 0) const = 0;196197198private:199/// @brief The vehicle's parameter200SUMOVehicleParameter myParameter;201202/// @brief The type of the vehicle203const SUMOVTypeParameter* const myType;204205/// @brief object-specific random constant206const long long int myRandomSeed;207208protected:209/// @brief Whether the last routing was successful210bool myRoutingSuccess;211212213private:214/// @brief Invalidated copy constructor215RORoutable(const RORoutable& src);216217/// @brief Invalidated assignment operator218RORoutable& operator=(const RORoutable& src);219220};221222223