-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFuncoesUteis.py
More file actions
41 lines (30 loc) · 1.02 KB
/
FuncoesUteis.py
File metadata and controls
41 lines (30 loc) · 1.02 KB
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
35
36
37
38
39
40
41
import numpy as np
import pandas as pd
import networkx as nx
import scipy
import itertools
from scipy.spatial import distance
def GeradorDeTSP(i):
Manhattan = nx.Graph()
Euclidian = nx.Graph()
no = dict()
for i in range(pow(2, i)):
x = np.random.randint(0, 13000)
y = np.random.randint(0, 13000)
no[i] = (x, y)
Manhattan.add_node(i)
Euclidian.add_node(i)
for v in Manhattan.nodes():
if v == i: continue
man, euc = dist(no[v], (x, y))
Manhattan.add_weighted_edges_from([(v, i, man)])
Euclidian.add_weighted_edges_from([(v, i, euc)])
return Manhattan, Euclidian
def dist(a, b):
return distance.cityblock(a, b), distance.euclidean(a, b)
def printGrafo(g):
for n, nbrs in g.adj.items():
for nbr, eattr in nbrs.items():
wt = eattr['weight']
try: print(f"({n}, {nbr}, {wt:.3})")
except: print(f"({n}, {nbr}, {wt})")