forked from mw10104587/LMServer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_neighbor.py
More file actions
53 lines (48 loc) · 1.72 KB
/
find_neighbor.py
File metadata and controls
53 lines (48 loc) · 1.72 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
42
43
44
45
46
47
48
49
50
51
52
53
import math
from igraph import *
def find_neighbor(queue, queue_m, g_q, g_m):
cand = set()
# print queue
queue_q = queue[0:len(queue_m)]
v_q = g_q.vs[queue_q[len(queue_q)-1]]
v_m = g_m.vs[queue_m[len(queue_m)-1]]
adj_edge_q_ids = g_q.incident(v_q, mode=ALL)
adj_edge_m_ids = g_m.incident(v_m, mode=ALL)
print "adj_edge_q_ids: ", adj_edge_q_ids
print "adj_edge_m_ids: ", adj_edge_m_ids
for adj_edge_q_id in adj_edge_q_ids:
adj_edge_q = g_q.es[adj_edge_q_id]
if adj_edge_q["checked"] == False:
for adj_edge_m_id in adj_edge_m_ids:
adj_edge_m = g_m.es[adj_edge_m_id]
if adj_edge_m["checked"] == False:
err = ang_dis(adj_edge_q, adj_edge_m, v_q["nid"], v_m["nid"])
if err == -1:
continue
else:
if adj_edge_m["n1"] != v_m["nid"]:
cand.add(int(adj_edge_m["n1"]))
else:
cand.add(int(adj_edge_m["n2"]))
else:
continue
else:
continue
return cand
def ang_dis(e_q, e_m, nid_q, nid_m, tolerance = 90): #Tolerence: Degree
# print e_q["n"][nid_q], e_m["n"][nid_m]
ang_err = rectify_sharp(math.fabs(e_q["n"][nid_q] - e_m["n"][nid_m]))
print "|(", e_q["n1"], ",", e_q["n2"], ") - (", e_m["n1"], ",", e_m["n2"], ")|: ", ang_err
if ang_err < tolerance:
return ang_err
else:
return -1
def rectify_sharp(theta):
if theta > 270:
return 360 - theta
if theta > 180:
return theta -180
elif theta > 90:
return 180 - theta
else:
return theta