1 from distalgs import Network
2 import math
3 import random
4 import pdb
5
7 """A Network of n Processes arranged in a ring. Each edge is directed
8 from a Process to its clockwise neighbor, that is, messages can
9 only be sent in a clockwise direction."""
10 - def __init__(self, n, index_to_UID = None):
14
16 """A Network of n Processes arranged in a ring. Each edge between a Process
17 and its neighbor is undirected, that is, messages can be sent in both
18 the clockwise and the counterclockwise directions."""
19 - def __init__(self, n, index_to_UID = None):
24
26 """A Network of n Processes arranged in a line. Each edge is directed
27 from a Process to its clockwise neighbor, that is, messages can
28 only be sent in a clockwise direction."""
29 - def __init__(self, n, index_to_UID = None):
33
35 """A Network of n Processes arranged in a line. Each edge between a Process
36 and its neighbor is undirected, that is, messages can be sent in both
37 the clockwise and the counterclockwise directions."""
38 - def __init__(self, n, index_to_UID = None):
42
44 """A Network of n Processes arranged at the vertices of a Complete undirected
45 graph of size n."""
46 - def __init__(self, n, index_to_UID = None):
47 Network.__init__(self, n, index_to_UID)
48 for i in range(n-1):
49 for j in range(i+1,n):
50 self[i].bi_link(self[j])
51
53 """A Network of n processes arranged randomly at the vertices of a connected
54 undirected line graph of size n. Additional pairs of vertices are connected
55 at random with a probability that is inversely proportional to the difference
56 in their positions on the line.
57
58 For example, the Process at index 3 is guaranteed to be connected to the Process
59 at index 4, and is more likely to be connected to the Process at index 5 than to
60 the Process at index 8. """
62 """
63 sparsity = 0 --> a Complete_Graph(n)
64 sparsity = infinity --> a Bidirectional_Line(n)
65 """
66 Network.__init__(self, n)
67 def sigmoid(t):
68 if t > 100: return 1.
69 if t < -100: return 0.
70 return 1./(1.+math.exp(-t))
71
72 for i in range(n-1):
73 self[i].bi_link(self[(i+1)])
74 for j in range(i+2, n):
75 if random.random() < sigmoid( -((i-j)**2)/(float(n)**0.5)*sparsity) *2.:
76 self[i].bi_link(self[j])
77