3 #include <simgrid/platf_generator.h>
4 #include "platf_generator_private.h"
6 #include <xbt/RngStream.h>
8 static xbt_graph_t platform_graph = NULL;
10 static RngStream rng_stream = NULL;
12 void platf_random_seed(unsigned long seed[6]) {
14 if(rng_stream == NULL) {
15 //stream not created yet, we do it now
16 rng_stream = RngStream_CreateStream(NULL);
19 RngStream_SetSeed(rng_stream, seed);
23 void platf_graph_init(int node_count) {
25 platform_graph = xbt_graph_new_graph(FALSE, NULL);
26 if(rng_stream == NULL) {
27 rng_stream = RngStream_CreateStream(NULL);
30 for(i=0 ; i<node_count ; i++) {
31 context_node_t node_data = NULL;
32 node_data = xbt_new(s_context_node_t, 1);
35 node_data->degree = 0;
36 node_data->kind = ROUTER;
37 xbt_graph_new_node(platform_graph, (void*) node_data);
41 void platf_node_connect(xbt_node_t node1, xbt_node_t node2) {
42 context_node_t node1_data;
43 context_node_t node2_data;
44 node1_data = (context_node_t) xbt_graph_node_get_data(node1);
45 node2_data = (context_node_t) xbt_graph_node_get_data(node2);
48 xbt_graph_new_edge(platform_graph, node1, node2, NULL);
51 void platf_graph_uniform(int node_count) {
52 xbt_dynar_t dynar_nodes = NULL;
53 xbt_node_t graph_node = NULL;
54 context_node_t node_data = NULL;
56 platf_graph_init(node_count);
57 dynar_nodes = xbt_graph_get_nodes(platform_graph);
58 xbt_dynar_foreach(dynar_nodes, i, graph_node) {
59 node_data = (context_node_t) xbt_graph_node_get_data(graph_node);
60 node_data->x = RngStream_RandU01(rng_stream);
61 node_data->y = RngStream_RandU01(rng_stream);
65 void platf_graph_interconnect_star(void) {
67 xbt_dynar_t dynar_nodes = NULL;
68 xbt_node_t graph_node = NULL;
69 xbt_node_t first_node = NULL;
72 dynar_nodes = xbt_graph_get_nodes(platform_graph);
73 xbt_dynar_foreach(dynar_nodes, i, graph_node) {
75 //Ok, we get the first node, let's keep it somewhere...
76 first_node = graph_node;
78 //All the other nodes are connected to the first one
79 platf_node_connect(graph_node, first_node);