-
Notifications
You must be signed in to change notification settings - Fork 18
/
CheckingConnectivity.py
53 lines (45 loc) · 1.01 KB
/
CheckingConnectivity.py
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 numpy as np
def Valid(i,limit,flag,value) :
if i>=0 and i<=limit-1 and value[i] == 255 and flag[i] == 0 :
return True
return False
def Checking(graph) :
stack = []
x,y = graph.shape
graph1 = np.reshape(graph,-1)
limit = len(graph1)
flag = np.zeros([len(graph1)])
stack.append(0)
flag[0] = 1
while (len(stack)>0 and not flag[limit-1] == 1) :
element = stack.pop()
#print element
'''
if Valid(element-1,limit,flag,graph1) and not element%x == 0 :
stack.append(element-1)
flag[element-1] = 1
'''
if Valid(element+1,limit,flag,graph1) and not (element+1)%x == 0:
stack.append(element+1)
flag[element+1] = 1
'''
if Valid(element-x,limit,flag,graph1) :
stack.append(element-x)
flag[element-x] = 1
'''
if Valid(element+x,limit,flag,graph1) :
stack.append(element+x)
flag[element+x] = 1
if flag[limit-1] == 1 :
return True
return False
'''
a = np.zeros([25,25])
a[0][1] = 1
a[1][1] = 1
a[2][0] = 1
if Checking(a) :
print 'True'
else :
print 'False'
'''