54 lines
1.5 KiB
Python
54 lines
1.5 KiB
Python
|
import numpy as np
|
||
|
from canget import canget
|
||
|
# 改好的!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||
|
|
||
|
def test(lenchrom, bound, code,final):
|
||
|
# code = np.array([4,5,6,4,6,7,2,8,2,7,1,5,4,5,4,6,3,5,3,3,7,6,7,1,7,1,4,1,8,4,8,5,6,7,2,1,2,3,6,3])
|
||
|
# lenchrom = np.array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
|
||
|
|
||
|
n = final*5
|
||
|
m = 4
|
||
|
repeated_row = np.array([1, final])
|
||
|
bound = np.repeat([repeated_row], n, axis=0)
|
||
|
|
||
|
|
||
|
# load adr
|
||
|
adr = np.load('adr.npy')
|
||
|
|
||
|
flag = 1
|
||
|
m = len(code)
|
||
|
n = 1
|
||
|
bj = np.zeros((bound[0][1],2))
|
||
|
bj[:,0] = np.arange(bound[0][0], bound[0][1]+1)
|
||
|
for i in range(m):
|
||
|
idx = np.where(bj[:]==code[i])[0][0]
|
||
|
bj[idx,1] += 1
|
||
|
if code[i] < bound[0][0] or code[i] > bound[0][1]:
|
||
|
flag = 0
|
||
|
if len(np.where(bj[:,1] < 2)[0]) > 0:
|
||
|
flag = 0
|
||
|
bj = np.zeros((bound[0][1],2))
|
||
|
bj[:,0] = np.arange(bound[0][0], bound[0][1]+1)
|
||
|
for i in range(bound[0][1]):
|
||
|
idx = np.where(code==i+1)[0]
|
||
|
b = adr[idx,:][:,idx]
|
||
|
P = canget(b)
|
||
|
Q = P | P.T | np.eye(P.shape[0], dtype=int)
|
||
|
b = (b != 0).astype('bool')
|
||
|
M = b | b.T
|
||
|
W = canget(M)
|
||
|
if P.all():
|
||
|
C = 1
|
||
|
elif Q.all():
|
||
|
C = 1
|
||
|
else:
|
||
|
if W.all():
|
||
|
C = 1
|
||
|
else:
|
||
|
C = 0
|
||
|
bj[i,1] = C
|
||
|
if len(np.where(bj[:,1]==0)[0]) > 0:
|
||
|
flag = 0
|
||
|
|
||
|
|
||
|
return flag
|