-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmap.py
More file actions
87 lines (71 loc) · 2.68 KB
/
map.py
File metadata and controls
87 lines (71 loc) · 2.68 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#-*- coding:utf-8 -*-
# AUTHOR: yaolili
# FILE: map.py
# ROLE: current map result
# CREATED: 2015-11-28 20:55:11
# MODIFIED: 2015-12-04 16:01:43
from itertools import chain
from graph import GraphSet
class Map:
def __init__(self, result):
self.__subMap = []
self.__gMap = []
if type(result) is not dict:
print "Class Map __init__() argument type error! dict expected!"
exit()
if result:
for key in result:
self.__subMap.append(key)
self.__gMap.append(result[key])
def subMap(self):
return self.__subMap
def gMap(self):
return self.__gMap
#notice, here is subVertexSet
def isCovered(self, vertexSet):
if len(self.__subMap) == len(vertexSet):
return True
else:
return False
#type = 0, subGraph; type = 1, graph
def neighbor(self, offset, graph, type, isInMap):
if not isinstance(graph, GraphSet):
print "Class Map neighbor() argument type error!"
exit()
if not (type == 1 or type == 0):
print "Class Map neighbor() argument value error! type expected 0 or 1!"
exit()
if not (isInMap == True or isInMap == False):
print "Class Map neighbor() argument value error! isInMap expected True or False!"
exit()
VESet = graph.curVESet(offset)
neighbor = []
if type:
curMap = self.__gMap
else:
curMap = self.__subMap
#print "Class Map neighbor() VESet: ", VESet
#print "Class Map neighbor() curMap: ", curMap
for index in curMap:
aList = VESet[index]
#print "Class Map neighbor() aList: ", aList
for i in range(len(aList)):
v1, v2 = aList[i].strip().split(":")
if int(v1) != index:
v = int(v1)
elif int(v2) != index:
v = int(v2)
else:
print "Class Map subNeighbor() VESet error!"
exit()
if isInMap and (v not in neighbor):
neighbor.append(v)
elif v not in chain(neighbor, curMap):
neighbor.append(v)
else:
continue
if not neighbor:
for index in graph.curVSet(offset):
if index not in curMap:
neighbor.append(int(index))
return neighbor