fix: check if bitstring neighborhood does not erase sensors
This commit is contained in:
parent
9bce1e64b0
commit
6e83a121fb
1 changed files with 5 additions and 2 deletions
|
|
@ -63,13 +63,16 @@ def neighb_square(sol, scale, domain_width):
|
||||||
# Indices order is (y,x) in order to match
|
# Indices order is (y,x) in order to match
|
||||||
# coordinates of images (row,col).
|
# coordinates of images (row,col).
|
||||||
if sol[py][px] == 1:
|
if sol[py][px] == 1:
|
||||||
new[py][px] = 0 # Remove original position.
|
|
||||||
# Add a one somewhere around.
|
# Add a one somewhere around.
|
||||||
w = scale//2 * domain_width
|
w = scale//2 * domain_width
|
||||||
ny = np.random.randint(py-w,py+w)
|
ny = np.random.randint(py-w,py+w)
|
||||||
nx = np.random.randint(px-w,px+w)
|
nx = np.random.randint(px-w,px+w)
|
||||||
ny = min(max(0,ny),domain_width-1)
|
ny = min(max(0,ny),domain_width-1)
|
||||||
nx = min(max(0,nx),domain_width-1)
|
nx = min(max(0,nx),domain_width-1)
|
||||||
|
|
||||||
|
if new[nx][ny] != 1:
|
||||||
|
new[py][px] = 0 # Remove original position.
|
||||||
new[ny][nx] = 1
|
new[ny][nx] = 1
|
||||||
|
# else pass
|
||||||
return new
|
return new
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue