Skip to content

Commit 011b23d

Browse files
committed
[+/-] bugfix in condition 1
1 parent 71a40d2 commit 011b23d

File tree

5 files changed

+25
-19
lines changed

5 files changed

+25
-19
lines changed

README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
## Pymoebots: Stochastic Algorithms Simulator for the Amoebot Model
22

3-
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![build status](
4-
http://img.shields.io/travis/aayux/pymoebots/master.svg?style=flat)](
5-
https://travis-ci.com/aayux/pymoebots.svg?token=5ykcpxpsSYeM1yqgzqww&branch=master)
3+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Build Status](https://travis-ci.com/aayux/pymoebots.svg?token=5ykcpxpsSYeM1yqgzqww&branch=master)](https://travis-ci.com/aayux/pymoebots)
64

75
### Acknowledgements
86

amoebot/elements/bot/functional.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -343,13 +343,21 @@ def _verify_compression_property_1(
343343
G[ix] = [ix_lookup[_n] for _n in node_neighbors \
344344
if _n in neighborhood]
345345

346+
# an empty list to store visited status for each neighbour
347+
connectivity = None
348+
346349
graph = GraphAlgorithms(G)
347350
for n in common_neighbors:
348-
# bfs each common neighbour to find a path in the union
349-
connectivity += graph.bfs(root=ix_lookup[n])
351+
# dfs each common neighbour to find a path in the union
352+
if connectivity is None:
353+
connectivity = graph.dfs(root=ix_lookup[n])
354+
else:
355+
connectivity = np.logical_or(
356+
connectivity,
357+
graph.dfs(root=ix_lookup[n])
358+
)
350359

351-
if connectivity == len(common_neighbors): return np.uint8(1)
352-
else: return np.uint8(0)
360+
return np.uint8(np.all(connectivity))
353361

354362
def _verify_compression_property_2(
355363
nmap:defaultdict,
@@ -409,7 +417,7 @@ def _verify_compression_property_2(
409417
graph_h, graph_t = GraphAlgorithms(G_h), GraphAlgorithms(G_t)
410418
for graph in [graph_h, graph_t]:
411419
# dfs each subgraph and find a path connecting it
412-
connectivity += graph.dfs(root=0)
420+
connectivity += np.uint8(np.all(graph.dfs(root=0)))
413421

414422
if connectivity == 2: return np.uint8(1)
415423
else: return np.uint8(0)

amoebot/elements/bot/manager.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,13 @@ def exec_sequential(
146146
self.shared = SharedObjects(self.config_num, data=self.amoebots)
147147

148148
# iteratively execute the algorithm over each amoebot for fixed rounds
149-
for _ in range(max_rnds):
149+
for iter_ in range(max_rnds):
150150
exec_seq = list(self.amoebots.keys())
151151
np.random.shuffle(exec_seq)
152152
for __id in exec_seq:
153153
amoebot_t = (__id, self.amoebots[__id])
154154
self.amoebots[__id] = self._exec_one_step(
155-
amoebot_t,
155+
amoebot_t, iter_,
156156
algorithm=algorithm,
157157
async_mode=False
158158
)
@@ -197,6 +197,7 @@ def _exec_async_with_interpreter_lock(
197197
def _exec_one_step(
198198
self,
199199
amoebot_t:tuple,
200+
iter_:int=1,
200201
algorithm:str=None,
201202
async_mode:bool=True
202203
) -> Agent:
@@ -207,6 +208,8 @@ def _exec_one_step(
207208
208209
amoebot_t (tuple) :: a tuple with `Agent` and its respective
209210
identifier.
211+
iter_ (int) default: 1 :: the current iteration number,
212+
defaults to 1 when all iterations are saved.
210213
algorithm (str) default: None :: algorithm being performed in
211214
current step, one of "random_move" and "compress"...
212215
async_mode (bool) default: True :: if True, execute the local,
@@ -236,7 +239,6 @@ def _exec_one_step(
236239
amoebot.tail,
237240
amoebot.tau0
238241
)
239-
240-
self.tracker.update(__id, state)
242+
if iter_ % 1 == 0: self.tracker.update(__id, state)
241243

242244
return amoebot

amoebot/elements/node/core.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,13 @@ def get_all_ports(self) -> np.ndarray:
135135

136136
@property
137137
def is_occupied(self) -> bool:
138-
return np.uint8(1) if self.occupied is not 0 else np.uint8(0)
138+
return np.uint8(1) if self.occupied != 0 else np.uint8(0)
139139

140140
@property
141141
def is_trace(self) -> bool:
142-
return np.uint8(1) if self.occupied is 2 else np.uint8(0)
142+
return np.uint8(1) if self.occupied == 2 else np.uint8(0)
143143

144144
@property
145145
def is_wall(self) -> bool:
146-
return np.uint8(1) if self.occupied is 3 else np.uint8(0)
146+
return np.uint8(1) if self.occupied == 3 else np.uint8(0)
147147

amoebot/utils/graphs.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ def bfs(self, root:int) -> np.uint8:
4343
visited[u] = np.uint8(1)
4444
queue.append(u)
4545

46-
if np.all(visited): return np.uint8(1)
47-
return np.uint8(0)
46+
return visited
4847

4948
def dfs(self, root:int) -> np.uint8:
5049
r"""
@@ -68,5 +67,4 @@ def dfs(self, root:int) -> np.uint8:
6867
visited[u] = np.uint8(1)
6968
stack.append(u)
7069

71-
if np.all(visited): return np.uint8(1)
72-
return np.uint8(0)
70+
return visited

0 commit comments

Comments
 (0)