Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Doctype as changed.
[simgrid.git] / examples / msg / chord / generate.py
1 #!/usr/bin/python
2
3 import sys, random
4
5 if len(sys.argv) != 4:
6         print("Usage: python generate.py nb_nodes nb_bits end_date > deployment_file.xml")
7         sys.exit(1)
8
9 nb_nodes = int(sys.argv[1])
10 nb_bits = int(sys.argv[2])
11 end_date = int(sys.argv[3])
12
13 max_id = 2 ** nb_bits - 1
14 all_ids = [42]
15
16 sys.stdout.write("<?xml version='1.0'?>\n"
17 "<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid.dtd\">\n"
18 "<platform version=\"3\">\n"
19 "  <process host=\"c-0.me\" function=\"node\"><argument value=\"42\"/><argument value=\"%d\"/></process>\n" % end_date)
20
21 for i in range(1, nb_nodes):
22
23         ok = False
24         while not ok:
25                 my_id = random.randint(0, max_id)
26                 ok = not my_id in all_ids
27
28         known_id = all_ids[random.randint(0, len(all_ids) - 1)]
29         start_date = i * 10
30         line = "  <process host=\"c-%d.me\" function=\"node\"><argument value=\"%d\" /><argument value=\"%d\" /><argument value=\"%d\" /><argument value=\"%d\" /></process>\n" % (i, my_id, known_id, start_date, end_date)
31         sys.stdout.write(line)
32         all_ids.append(my_id)
33
34 sys.stdout.write("</platform>")
35