Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove an indirection and fix memory leak.
[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_route_cache_element_t {
18   int* pred_arr;
19   int size;
20 };
21 typedef s_route_cache_element_t* route_cache_element_t;
22
23 namespace simgrid {
24 namespace kernel {
25 namespace routing {
26
27 /***********
28  * Classes *
29  ***********/
30
31 /** @ingroup ROUTING_API
32  *  @brief NetZone with an explicit routing computed on need with Dijsktra
33  *
34  *  The path between components is computed each time you request it,
35  *  using the Dijkstra algorithm. A cache can be used to reduce the computation.
36  *
37  *  This result in rather small platform file, very fast initialization, and very low memory requirements, but somehow long path resolution times.
38  */
39 class XBT_PRIVATE DijkstraZone : public RoutedZone {
40 public:
41   DijkstraZone(NetZone* father, std::string name, bool cached);
42   void seal() override;
43
44   ~DijkstraZone() override;
45   xbt_node_t routeGraphNewNode(int id, int graph_id);
46   xbt_node_t nodeMapSearch(int id);
47   void newRoute(int src_id, int dst_id, sg_platf_route_cbarg_t e_route);
48   /* For each vertex (node) already in the graph,
49    * make sure it also has a loopback link; this loopback
50    * can potentially already be in the graph, and in that
51    * case nothing will be done.
52    *
53    * If no loopback is specified for a node, we will use
54    * the loopback that is provided by the routing platform.
55    *
56    * After this function returns, any node in the graph
57    * will have a loopback attached to it.
58    */
59   void getLocalRoute(NetPoint* src, NetPoint* dst, sg_platf_route_cbarg_t route, double* lat) override;
60   void addRoute(sg_platf_route_cbarg_t route) override;
61
62   xbt_graph_t routeGraph_  = nullptr; /* xbt_graph */
63   std::map<int, xbt_node_t> graphNodeMap_;               /* map */
64   std::map<int, route_cache_element_t> routeCache_;      /* use in cache mode */
65 };
66 }
67 }
68 } // namespaces
69
70 #endif /* SURF_ROUTING_DIJKSTRA_HPP_ */