-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomWalker.py
More file actions
39 lines (29 loc) · 900 Bytes
/
RandomWalker.py
File metadata and controls
39 lines (29 loc) · 900 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import random
class RandomWalker:
def __init__(self, g):
self.g = g
def get_nodo_inicial(self):
nodes = list(self.g.nodes())
nodo_actual = random.choice(nodes)
return nodo_actual
def get_nodo_teletrans(self):
nodes = list(self.g.nodes())
nodo_actual = random.choice(nodes)
return nodo_actual
def get_nodo_vecinos(self, nodo):
neigh = list(self.g.out_edges(nodo))
caminos = []
if len(neigh) != 0:
for x in neigh:
caminos.append(x[1])
nodo_actual = random.choice(caminos)
return nodo_actual
else:
return nodo
def get_caminos(self, nodo):
neigh = list(self.g.out_edges(nodo))
caminos = []
if len(neigh) != 0:
for x in neigh:
caminos.append(x[1])
return caminos