/****************************************************************************/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 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 removes invalid alternatives and raise an error or warning **/75void validateAlternatives(const ROVehicle* veh, MsgHandler* errorHandler);7677/** @brief Triggers building of the complete route (via78* preComputeCurrentRoute) or returns precomputed route */79RORoute* buildCurrentRoute(SUMOAbstractRouter<ROEdge, ROVehicle>& router, SUMOTime begin,80const ROVehicle& veh) const;8182/** @brief Builds the complete route83* (or chooses her from the list of alternatives, when existing) */84void preComputeCurrentRoute(SUMOAbstractRouter<ROEdge, ROVehicle>& router, SUMOTime begin,85const ROVehicle& veh) const;8687/** @brief Builds the complete route88* (or chooses her from the list of alternatives, when existing) */89bool repairCurrentRoute(SUMOAbstractRouter<ROEdge, ROVehicle>& router, SUMOTime begin,90const ROVehicle& veh, ConstROEdgeVector oldEdges, ConstROEdgeVector& newEdges,91bool isTrip = false) const;9293/** @brief Adds an alternative to the list of routes94*95* (This may be the new route) */96void addAlternative(SUMOAbstractRouter<ROEdge, ROVehicle>& router,97const ROVehicle* const, RORoute* current, SUMOTime begin,98MsgHandler* errorHandler);99100const ROEdge* getOrigin() const;101const ROEdge* getDestination() const;102103const RORoute* getFirstRoute() const {104if (myAlternatives.empty()) {105return 0;106}107return myAlternatives.front();108}109110const RORoute* getUsedRoute() const {111return myAlternatives[myLastUsed];112}113114/** @brief Saves the built route / route alternatives115*116* Writes the route into the given stream.117*118* @param[in] dev The device to write the route into119* @param[in] asAlternatives Whether the route shall be saved as route alternatives120* @return The same device for further usage121*/122OutputDevice& writeXMLDefinition(OutputDevice& dev, const ROVehicle* const veh,123bool asAlternatives, bool withExitTimes, bool withCost, bool withLength) const;124125126/** @brief Returns a deep copy of the route definition.127*128* The resulting route definition contains copies of all129* routes contained in this one130*131* @param[in] id The id for the new route definition132* @param[in] stopOffset The offset time for "until"-stops defined in the original route133* @return the new route definition134*/135RORouteDef* copy(const std::string& id, const SUMOTime stopOffset) const;136137/** @brief Returns the sum of the probablities of the contained routes */138double getOverallProb() const;139140141/// @brief whether this route shall be silently discarded142bool discardSilent() const {143return myDiscardSilent;144}145146147static void setUsingJTRR() {148myUsingJTRR = true;149}150151static void setSkipNew() {152mySkipNewRoutes = true;153}154155protected:156/// @brief backtrack to last mandatory edge and route to next mandatory157static bool backTrack(SUMOAbstractRouter<ROEdge, ROVehicle>& router,158ConstROEdgeVector::const_iterator& i, int lastMandatory, const ROEdge* nextMandatory,159ConstROEdgeVector& newEdges, const ROVehicle& veh, SUMOTime begin);160161protected:162/// @brief precomputed route for out-of-order computation163mutable RORoute* myPrecomputed;164165/// @brief Index of the route used within the last step166mutable int myLastUsed;167168/// @brief The alternatives169std::vector<RORoute*> myAlternatives;170171/// @brief Routes which are deleted someplace else172std::set<RORoute*> myRouteRefs;173174/// @brief Information whether a new route was generated175mutable bool myNewRoute;176177const bool myTryRepair;178const bool myMayBeDisconnected;179180/// @brief Whether this route should be silently discarded181mutable bool myDiscardSilent;182183static bool myUsingJTRR;184static bool mySkipNewRoutes;185186private:187/// @brief Invalidated copy constructor188RORouteDef(const RORouteDef& src) = delete;189190/// @brief Invalidated assignment operator191RORouteDef& operator=(const RORouteDef& src) = delete;192193};194195196