Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / src / kernel / routing / DijkstraZone.cpp
index e7b9d2c..2169610 100644 (file)
@@ -1,28 +1,27 @@
-/* Copyright (c) 2009-2021. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2009-2023. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-#include "simgrid/kernel/routing/DijkstraZone.hpp"
-#include "simgrid/kernel/routing/NetPoint.hpp"
-#include "src/surf/network_interface.hpp"
-#include "surf/surf.hpp"
-#include "xbt/string.hpp"
+#include <simgrid/kernel/routing/DijkstraZone.hpp>
+#include <simgrid/kernel/routing/NetPoint.hpp>
+#include <xbt/string.hpp>
+
+#include "src/kernel/resource/NetworkModel.hpp"
 
 #include <climits>
 #include <queue>
 #include <vector>
 
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_dijkstra, surf, "Routing part of surf -- dijkstra routing logic");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_dijkstra, ker_platform, "Kernel Dijkstra Routing");
 
 namespace simgrid {
-namespace kernel {
-namespace routing {
+namespace kernel::routing {
 
 class GraphNodeData {
 public:
-  explicit GraphNodeData(int id) : id_(id) {}
-  int id_;
+  explicit GraphNodeData(unsigned long id) : id_(id) {}
+  unsigned long id_;
   unsigned long graph_id_ = UINT_MAX; /* used for caching internal graph id's */
 };
 
@@ -53,7 +52,7 @@ void DijkstraZone::do_seal()
 
       if (not found) {
         auto* route = new Route();
-        route->link_list_.push_back(get_network_model()->loopback_);
+        route->link_list_.push_back(get_network_model()->loopback_.get());
         xbt_graph_new_edge(route_graph_.get(), node, node, route);
       }
     }
@@ -68,7 +67,7 @@ void DijkstraZone::do_seal()
   }
 }
 
-xbt_node_t DijkstraZone::route_graph_new_node(int id)
+xbt_node_t DijkstraZone::route_graph_new_node(unsigned long id)
 {
   xbt_node_t node = xbt_graph_new_node(route_graph_.get(), new GraphNodeData(id));
   graph_node_map_.emplace(id, node);
@@ -76,7 +75,7 @@ xbt_node_t DijkstraZone::route_graph_new_node(int id)
   return node;
 }
 
-xbt_node_t DijkstraZone::node_map_search(int id)
+xbt_node_t DijkstraZone::node_map_search(unsigned long id)
 {
   auto ret = graph_node_map_.find(id);
   return ret == graph_node_map_.end() ? nullptr : ret->second;
@@ -87,8 +86,8 @@ xbt_node_t DijkstraZone::node_map_search(int id)
 void DijkstraZone::get_local_route(const NetPoint* src, const NetPoint* dst, Route* route, double* lat)
 {
   get_route_check_params(src, dst);
-  int src_id = src->id();
-  int dst_id = dst->id();
+  unsigned long src_id = src->id();
+  unsigned long dst_id = dst->id();
 
   const_xbt_dynar_t nodes = xbt_graph_get_nodes(route_graph_.get());
 
@@ -113,10 +112,10 @@ void DijkstraZone::get_local_route(const NetPoint* src, const NetPoint* dst, Rou
     insert_link_latency(route->link_list_, e_route->link_list_, lat);
   }
 
-  auto elm                             = route_cache_.emplace(src_id, std::vector<unsigned long>());
-  std::vector<unsigned long>& pred_arr = elm.first->second;
+  auto [elm, inserted]                 = route_cache_.try_emplace(src_id);
+  std::vector<unsigned long>& pred_arr = elm->second;
 
-  if (elm.second) { /* new element was inserted (not cached mode, or cache miss) */
+  if (inserted) { /* new element was inserted (not cached mode, or cache miss) */
     unsigned long nr_nodes = xbt_dynar_length(nodes);
     std::vector<unsigned long> cost_arr(nr_nodes); /* link cost from src to other hosts */
     pred_arr.resize(nr_nodes);              /* predecessors in path from src */
@@ -184,7 +183,7 @@ void DijkstraZone::get_local_route(const NetPoint* src, const NetPoint* dst, Rou
 
     if (get_hierarchy() == RoutingMode::recursive && v != dst_node_id &&
         gw_dst->get_name() != prev_gw_src->get_name()) {
-      std::vector<resource::LinkImpl*> e_route_as_to_as;
+      std::vector<resource::StandardLinkImpl*> e_route_as_to_as;
 
       const NetPoint* gw_dst_net_elm      = nullptr;
       const NetPoint* prev_gw_src_net_elm = nullptr;
@@ -218,9 +217,9 @@ void DijkstraZone::add_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, Net
              new_extended_route(get_hierarchy(), gw_dst, gw_src, get_link_list_impl(link_list, true), false));
 }
 
-void DijkstraZone::new_edge(int src_id, int dst_id, Route* route)
+void DijkstraZone::new_edge(unsigned long src_id, unsigned long dst_id, Route* route)
 {
-  XBT_DEBUG("Create Route from '%d' to '%d'", src_id, dst_id);
+  XBT_DEBUG("Create Route from '%lu' to '%lu'", src_id, dst_id);
 
   // Get the extremities, or create them if they don't exist yet
   xbt_node_t src = node_map_search(src_id);
@@ -245,8 +244,7 @@ void DijkstraZone::new_edge(int src_id, int dst_id, Route* route)
   // Finally add it
   xbt_graph_new_edge(route_graph_.get(), src, dst, route);
 }
-} // namespace routing
-} // namespace kernel
+} // namespace kernel::routing
 
 namespace s4u {
 NetZone* create_dijkstra_zone(const std::string& name, bool cache)