3 #include "simgrid/platf_generator.h"
4 #include "platf_generator_private.h"
6 #include "xbt/RngStream.h"
9 static xbt_graph_t platform_graph = NULL;
11 static RngStream rng_stream = NULL;
13 static unsigned long last_link_id = 0;
15 xbt_graph_t platf_graph_get(void) {
16 // We need some debug, so let's add this function
17 // WARNING : shold be removed when it becomes useless
18 return platform_graph;
21 void platf_random_seed(unsigned long seed[6]) {
23 if(rng_stream == NULL) {
24 //stream not created yet, we do it now
25 rng_stream = RngStream_CreateStream(NULL);
28 RngStream_SetSeed(rng_stream, seed);
32 void platf_graph_init(unsigned long node_count) {
34 platform_graph = xbt_graph_new_graph(FALSE, NULL);
35 if(rng_stream == NULL) {
36 rng_stream = RngStream_CreateStream(NULL);
39 for(i=0 ; i<node_count ; i++) {
40 context_node_t node_data = NULL;
41 node_data = xbt_new(s_context_node_t, 1);
45 node_data->degree = 0;
46 node_data->kind = ROUTER;
47 xbt_graph_new_node(platform_graph, (void*) node_data);
54 void platf_node_connect(xbt_node_t node1, xbt_node_t node2) {
55 context_node_t node1_data;
56 context_node_t node2_data;
57 node1_data = (context_node_t) xbt_graph_node_get_data(node1);
58 node2_data = (context_node_t) xbt_graph_node_get_data(node2);
62 unsigned long *link_id = xbt_new(unsigned long, 1);
63 *link_id = ++last_link_id;
65 xbt_graph_new_edge(platform_graph, node1, node2, (void*)link_id);
68 void platf_graph_uniform(unsigned long node_count) {
69 xbt_dynar_t dynar_nodes = NULL;
70 xbt_node_t graph_node = NULL;
71 context_node_t node_data = NULL;
73 platf_graph_init(node_count);
74 dynar_nodes = xbt_graph_get_nodes(platform_graph);
75 xbt_dynar_foreach(dynar_nodes, i, graph_node) {
76 node_data = (context_node_t) xbt_graph_node_get_data(graph_node);
77 node_data->x = RngStream_RandU01(rng_stream);
78 node_data->y = RngStream_RandU01(rng_stream);
82 void platf_graph_heavytailed(unsigned long node_count) {
83 xbt_dynar_t dynar_nodes = NULL;
84 xbt_node_t graph_node = NULL;
85 context_node_t node_data = NULL;
87 platf_graph_init(node_count);
88 dynar_nodes = xbt_graph_get_nodes(platform_graph);
89 xbt_dynar_foreach(dynar_nodes, i, graph_node) {
90 node_data = (context_node_t) xbt_graph_node_get_data(graph_node);
91 node_data->x = random_pareto(0, 1, 1.0/*K*/, 10e9/*P*/, 1.0/*alpha*/);
92 node_data->y = random_pareto(0, 1, 1.0/*K*/, 10e9/*P*/, 1.0/*alpha*/);
96 void platf_graph_interconnect_star(void) {
97 /* All the nodes are connected to the first one */
98 xbt_dynar_t dynar_nodes = NULL;
99 xbt_node_t graph_node = NULL;
100 xbt_node_t first_node = NULL;
103 dynar_nodes = xbt_graph_get_nodes(platform_graph);
104 xbt_dynar_foreach(dynar_nodes, i, graph_node) {
106 //Ok, we get the first node, let's keep it somewhere...
107 first_node = graph_node;
109 //All the other nodes are connected to the first one
110 platf_node_connect(graph_node, first_node);
115 void platf_graph_interconnect_line(void) {
116 /* Node are connected to the previous and the next node, in a line */
117 xbt_dynar_t dynar_nodes = NULL;
118 xbt_node_t graph_node = NULL;
119 xbt_node_t old_node = NULL;
122 dynar_nodes = xbt_graph_get_nodes(platform_graph);
123 xbt_dynar_foreach(dynar_nodes, i, graph_node) {
124 if(old_node != NULL) {
125 platf_node_connect(graph_node, old_node);
127 old_node = graph_node;
131 void platf_graph_interconnect_ring(void) {
132 /* Create a simple topology where all nodes are connected along a ring */
133 xbt_dynar_t dynar_nodes = NULL;
134 xbt_node_t graph_node = NULL;
135 xbt_node_t old_node = NULL;
136 xbt_node_t first_node = NULL;
139 dynar_nodes = xbt_graph_get_nodes(platform_graph);
140 xbt_dynar_foreach(dynar_nodes, i, graph_node) {
142 // this is the first node, let's keep it somewhere
143 first_node = graph_node;
145 //connect each node to the previous one
146 platf_node_connect(graph_node, old_node);
148 old_node = graph_node;
150 //we still have to connect the first and the last node together
151 platf_node_connect(first_node, graph_node);
156 /* Functions used to generate interesting random values */
158 double random_pareto(double min, double max, double K, double P, double ALPHA) {
159 double x = RngStream_RandU01(rng_stream);
160 double den = pow(1.0 - x + x*pow(K/P, ALPHA), 1.0/ALPHA);
161 double res = (1/den);
162 res += min - 1; // pareto is on [1, infinity) by default