/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-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 RODFRouteCont.h14/// @author Daniel Krajzewicz15/// @author Michael Behrisch16/// @date Thu, 16.03.200617///18// A container for routes19/****************************************************************************/20#pragma once21#include <config.h>2223#include <vector>24#include <map>25#include <utils/common/UtilExceptions.h>26#include "RODFRouteDesc.h"272829// ===========================================================================30// class declarations31// ===========================================================================32class RODFNet;33class OutputDevice;343536// ===========================================================================37// class definitions38// ===========================================================================39/**40* @class RODFRouteCont41* @brief A container for DFROUTER-routes42*43* The route id is (re)set as soon as the route is added.44*45* As sometimes several routes can be used between two edges and have to be46* identified, the number of routes connecting them is stored for each47* edge pair "myConnectionOccurrences" and the route is named using this48* information, @see addRouteDesc.49*50* @see RODFRouteDesc51*/52class RODFRouteCont {53public:54/// @brief Constructor55RODFRouteCont();5657/// @brief Destructor58~RODFRouteCont();596061/** @brief Adds a route to the container62*63* If the same route is already known, its "overallProb" is increased64* by the value stored in the given route.65*66* An id for the route is generated if it is unset, yet. The id is67* computed and set via "setID".68*69* @param[in] desc The route description to add70* @see setID71*/72void addRouteDesc(RODFRouteDesc& desc);737475/** @brief Removes the given route description from the container76*77* All routes are regarded as being same if they pass the same edges.78* This is done via the "route_finder".79*80* @param[in] desc The route description to remove81* @return Whether the route was removed (a similar was found)82* @see RODFRouteCont::route_finder83*/84bool removeRouteDesc(RODFRouteDesc& desc);858687/** @brief Saves routes88*89* @param[in, out] saved The list of ids of routes that shall not be saved (were saved before)90* @param[in] prependix The prependix for route names91* @param[out] out The device the routes shall written to92* @return Whether at least one route was saved93* @exception IOError not yet implemented94*/95bool save(std::vector<std::string>& saved,96const std::string& prependix, OutputDevice& out);979899/** @brief Returns the container of stored routes100* @return The stored routes101*/102std::vector<RODFRouteDesc>& get() {103return myRoutes;104}105106107/** @brief Sorts routes by their distance (length)108*109* Done using by_distance_sorter.110* @see RODFRouteCont::by_distance_sorter111*/112void sortByDistance();113114115/** @brief Removes "illegal" routes116*117* "illegal" routes means edge combinations that shall not be passed.118*119* @param[in] illegals List of edge combinations that shall not be passed120* @todo Not used, yet121*/122void removeIllegal(const std::vector<ROEdgeVector >& illegals);123124125protected:126/** @brief Computes and sets the id of a route127*128* The id is <FIRST_EDGE>_to_<LAST_EDGE>_<RUNNING> where <RUNNING>129* is the number of routes which connect <FIRST_EDGE> and <LAST_EDGE>.130*131* @param[in] desc The route description to add132*/133void setID(RODFRouteDesc& desc) const;134135136/** @brief A class for sorting route descriptions by their length */137class by_distance_sorter {138public:139/// @brief Constructor140explicit by_distance_sorter() { }141142/// @brief Sorting function; compares RODFRouteDesc::distance2Last143int operator()(const RODFRouteDesc& p1, const RODFRouteDesc& p2) {144return p1.distance2Last < p2.distance2Last;145}146};147148149/** @brief A class for finding a same route (one that passes the same edges) */150class route_finder {151public:152/** @brief onstructor153* @param[in] desc The route description to which a same shall be found154*/155explicit route_finder(const RODFRouteDesc& desc) : myDesc(desc) { }156157/** @brief The comparing function; compares passed edges */158bool operator()(const RODFRouteDesc& desc) {159return myDesc.edges2Pass == desc.edges2Pass;160}161162private:163/// @brief The route description for which a same shall be found164const RODFRouteDesc& myDesc;165};166167protected:168/// @brief Stored route descriptions169std::vector<RODFRouteDesc> myRoutes;170171/// @brief Counts how many routes connecting the key-edges were already stored172mutable std::map<std::pair<ROEdge*, ROEdge*>, int> myConnectionOccurrences;173174175};176177178