Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Platform generation : Add a function to interconnect nodes
[simgrid.git] / src / surf / platf_generator.c
index 0acd807..c8f4937 100644 (file)
@@ -3,7 +3,6 @@
 #include <simgrid/platf_generator.h>
 #include "platf_generator_private.h"
 #include <xbt.h>
-#include <xbt/graph.h>
 #include <xbt/RngStream.h>
 
 static xbt_graph_t platform_graph = NULL;
@@ -23,7 +22,7 @@ void platf_random_seed(unsigned long seed[6]) {
 
 void platf_graph_init(int node_count) {
   int i;
-  platform_graph = xbt_graph_new_graph(TRUE, NULL);
+  platform_graph = xbt_graph_new_graph(FALSE, NULL);
   if(rng_stream == NULL) {
     rng_stream = RngStream_CreateStream(NULL);
   }
@@ -39,6 +38,16 @@ void platf_graph_init(int node_count) {
   }
 }
 
+void platf_node_connect(xbt_node_t node1, xbt_node_t node2) {
+  context_node_t node1_data;
+  context_node_t node2_data;
+  node1_data = (context_node_t) xbt_graph_node_get_data(node1);
+  node2_data = (context_node_t) xbt_graph_node_get_data(node2);
+  node1_data->degree++;
+  node2_data->degree++;
+  xbt_graph_new_edge(platform_graph, node1, node2, NULL);
+}
+
 void platf_graph_uniform(int node_count) {
   xbt_dynar_t dynar_nodes = NULL;
   xbt_node_t graph_node = NULL;
@@ -52,3 +61,22 @@ void platf_graph_uniform(int node_count) {
     node_data->y = RngStream_RandU01(rng_stream);
   }
 }
+
+void platf_graph_interconnect_star(void) {
+
+  xbt_dynar_t dynar_nodes = NULL;
+  xbt_node_t graph_node = NULL;
+  xbt_node_t first_node = NULL;
+  unsigned int i;
+
+  dynar_nodes = xbt_graph_get_nodes(platform_graph);
+  xbt_dynar_foreach(dynar_nodes, i, graph_node) {
+    if(i==0) {
+      //Ok, we get the first node, let's keep it somewhere...
+      first_node = graph_node;
+    } else {
+      //All the other nodes are connected to the first one
+      platf_node_connect(graph_node, first_node);
+    }
+  }
+}