/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2002-2025 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 RORouteDef.h14/// @author Daniel Krajzewicz15/// @author Michael Behrisch16/// @author Jakob Erdmann17/// @date Sept 200218///19// Base class for a vehicle's route definition20/****************************************************************************/21#pragma once22#include <config.h>2324#include <string>25#include <iostream>26#include <utils/common/Named.h>27#include <utils/router/SUMOAbstractRouter.h>28#include "RORoute.h"293031// ===========================================================================32// class declarations33// ===========================================================================34class ROEdge;35class OptionsCont;36class ROVehicle;37class OutputDevice;383940// ===========================================================================41// class definitions42// ===========================================================================43/**44* @class RORouteDef45* @brief Base class for a vehicle's route definition46*47* This class resembles what a vehicle knows about his route when being loaded48* into a router. Whether it is just the origin and the destination, the whole49* route through the network or even a route with alternatives depends on50* the derived class.51*/52class RORouteDef : public Named {53public:54/** @brief Constructor55*56* @param[in] id The id of the route57* @param[in] color The color of the route58*/59RORouteDef(const std::string& id, const int lastUsed,60const bool tryRepair, const bool mayBeDisconnected);616263/// @brief Destructor64virtual ~RORouteDef();656667/** @brief Adds a single alternative loaded from the file68An alternative may also be generated during DUA */69void addLoadedAlternative(RORoute* alternative);7071/** @brief Adds an alternative loaded from the file */72void addAlternativeDef(const RORouteDef* alternative);7374/** @brief Triggers building of the complete route (via75* preComputeCurrentRoute) or returns precomputed route */76RORoute* buildCurrentRoute(SUMOAbstractRouter<ROEdge, ROVehicle>& router, SUMOTime begin,77const ROVehicle& veh) const;7879/** @brief Builds the complete route80* (or chooses her from the list of alternatives, when existing) */81void preComputeCurrentRoute(SUMOAbstractRouter<ROEdge, ROVehicle>& router, SUMOTime begin,82const ROVehicle& veh) const;8384/** @brief Builds the complete route85* (or chooses her from the list of alternatives, when existing) */86bool repairCurrentRoute(SUMOAbstractRouter<ROEdge, ROVehicle>& router, SUMOTime begin,87const ROVehicle& veh, ConstROEdgeVector oldEdges, ConstROEdgeVector& newEdges,88bool isTrip = false) const;8990/** @brief Adds an alternative to the list of routes91*92* (This may be the new route) */93void addAlternative(SUMOAbstractRouter<ROEdge, ROVehicle>& router,94const ROVehicle* const, RORoute* current, SUMOTime begin);9596const ROEdge* getOrigin() const;97const ROEdge* getDestination() const;9899const RORoute* getFirstRoute() const {100if (myAlternatives.empty()) {101return 0;102}103return myAlternatives.front();104}105106const RORoute* getUsedRoute() const {107return myAlternatives[myLastUsed];108}109110/** @brief Saves the built route / route alternatives111*112* Writes the route into the given stream.113*114* @param[in] dev The device to write the route into115* @param[in] asAlternatives Whether the route shall be saved as route alternatives116* @return The same device for further usage117*/118OutputDevice& writeXMLDefinition(OutputDevice& dev, const ROVehicle* const veh,119bool asAlternatives, bool withExitTimes, bool withCost, bool withLength) const;120121122/** @brief Returns a deep copy of the route definition.123*124* The resulting route definition contains copies of all125* routes contained in this one126*127* @param[in] id The id for the new route definition128* @param[in] stopOffset The offset time for "until"-stops defined in the original route129* @return the new route definition130*/131RORouteDef* copy(const std::string& id, const SUMOTime stopOffset) const;132133/** @brief Returns the sum of the probablities of the contained routes */134double getOverallProb() const;135136137/// @brief whether this route shall be silently discarded138bool discardSilent() const {139return myDiscardSilent;140}141142143static void setUsingJTRR() {144myUsingJTRR = true;145}146147protected:148/// @brief backtrack to last mandatory edge and route to next mandatory149static bool backTrack(SUMOAbstractRouter<ROEdge, ROVehicle>& router,150ConstROEdgeVector::const_iterator& i, int lastMandatory, ConstROEdgeVector::iterator nextMandatory,151ConstROEdgeVector& newEdges, const ROVehicle& veh, SUMOTime begin);152153protected:154/// @brief precomputed route for out-of-order computation155mutable RORoute* myPrecomputed;156157/// @brief Index of the route used within the last step158mutable int myLastUsed;159160/// @brief The alternatives161std::vector<RORoute*> myAlternatives;162163/// @brief Routes which are deleted someplace else164std::set<RORoute*> myRouteRefs;165166/// @brief Information whether a new route was generated167mutable bool myNewRoute;168169const bool myTryRepair;170const bool myMayBeDisconnected;171172/// @brief Whether this route should be silently discarded173mutable bool myDiscardSilent;174175static bool myUsingJTRR;176177private:178/// @brief Invalidated copy constructor179RORouteDef(const RORouteDef& src) = delete;180181/// @brief Invalidated assignment operator182RORouteDef& operator=(const RORouteDef& src) = delete;183184};185186187