Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
dicts to maps in Dijkstra
[simgrid.git] / src / kernel / routing / DijkstraZone.hpp
1 /* Copyright (c) 2013-2017. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef SURF_ROUTING_DIJKSTRA_HPP_
7 #define SURF_ROUTING_DIJKSTRA_HPP_
8
9 #include "src/kernel/routing/RoutedZone.hpp"
10
11 struct s_graph_node_data_t {
12   int id;
13   int graph_id; /* used for caching internal graph id's */
14 };
15 typedef s_graph_node_data_t* graph_node_data_t;
16
17 struct s_graph_node_map_element_t {
18   xbt_node_t node;
19 };
20 typedef s_graph_node_map_element_t* graph_node_map_element_t;
21
22 struct s_route_cache_element_t {
23   int* pred_arr;
24   int size;
25 };
26 typedef s_route_cache_element_t* route_cache_element_t;
27
28 namespace simgrid {
29 namespace kernel {
30 namespace routing {
31
32 /***********
33  * Classes *
34  ***********/
35
36 /** @ingroup ROUTING_API
37  *  @brief NetZone with an explicit routing computed on need with Dijsktra
38  *
39  *  The path between components is computed each time you request it,
40  *  using the Dijkstra algorithm. A cache can be used to reduce the computation.
41  *
42  *  This result in rather small platform file, very fast initialization, and very low memory requirements, but somehow long path resolution times.
43  */
44 class XBT_PRIVATE DijkstraZone : public RoutedZone {
45 public:
46   DijkstraZone(NetZone* father, std::string name, bool cached);
47   void seal() override;
48
49   ~DijkstraZone() override;
50   xbt_node_t routeGraphNewNode(int id, int graph_id);
51   graph_node_map_element_t nodeMapSearch(int id);
52   void newRoute(int src_id, int dst_id, sg_platf_route_cbarg_t e_route);
53   /* For each vertex (node) already in the graph,
54    * make sure it also has a loopback link; this loopback
55    * can potentially already be in the graph, and in that
56    * case nothing will be done.
57    *
58    * If no loopback is specified for a node, we will use
59    * the loopback that is provided by the routing platform.
60    *
61    * After this function returns, any node in the graph
62    * will have a loopback attached to it.
63    */
64   void getLocalRoute(NetPoint* src, NetPoint* dst, sg_platf_route_cbarg_t route, double* lat) override;
65   void addRoute(sg_platf_route_cbarg_t route) override;
66
67   xbt_graph_t routeGraph_  = nullptr; /* xbt_graph */
68   std::map<int, graph_node_map_element_t> graphNodeMap_; /* map */
69   std::map<int, route_cache_element_t> routeCache_;      /* use in cache mode */
70 };
71 }
72 }
73 } // namespaces
74
75 #endif /* SURF_ROUTING_DIJKSTRA_HPP_ */