diff --git a/ant.zip b/ant.zip new file mode 100644 index 0000000000000000000000000000000000000000..7f598ed6dbbf36c137aa684b8571ad27ef2c45db Binary files /dev/null and b/ant.zip differ diff --git a/ant/__init__.py b/ant/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/ant/agent.py b/ant/agent.py new file mode 100644 index 0000000000000000000000000000000000000000..0d1d88cbb18100b0dd0e5699468eb9d9882d527e --- /dev/null +++ b/ant/agent.py @@ -0,0 +1,57 @@ +import random +import sys + +from iotAmak.agent import Agent + + +class Ant(Agent): + + def __init__(self, identifier: int, broker_ip: str): + self.x = 250 + self.y = 250 + self.color = 0 + super().__init__(identifier, broker_ip) + + def on_initialization(self) -> None: + pass + + def on_cycle_begin(self) -> None: + pass + + def on_perceive(self) -> None: + self.neighbors = self.next_neighbors + self.next_neighbors = [] + + def on_decide(self) -> None: + pass + + def on_act(self) -> None: + self.x += random.randint(-5, +5) + self.y += random.randint(-5, +5) + + # count color + color = [0 for _ in range(5)] + for ant in self.next_neighbors: + color[ant.get("color")] += 1 + # set color + if color.index(max(color)) != 0: + self.color = color[color.index(max(color))] + # low chance to mutate + if random.randint(0, 1000) < 10: + self.color = random.randint(0, 4) + + def on_cycle_end(self) -> None: + pass + + def send_metric(self): + metric = super(Ant, self).send_metric() + + metric["x"] = self.x + metric["y"] = self.y + metric["color"] = self.color + return metric + + +if __name__ == '__main__': + a = Ant(int(sys.argv[1]), str(sys.argv[2])) + a.run() diff --git a/ant/amas.py b/ant/amas.py new file mode 100644 index 0000000000000000000000000000000000000000..267f8053cb2b8226972805e9e15d38fd3ee23e91 --- /dev/null +++ b/ant/amas.py @@ -0,0 +1,43 @@ +import sys +from math import sqrt + +from iotAmak.amas import Amas + + +class AntAmas(Amas): + + def __init__(self, broker_ip: str, clients, nbr_agent): + self.agent_to_create = nbr_agent + super().__init__(broker_ip, clients) + + def on_initial_agents_creation(self): + for _ in range(self.agent_to_create): + self.add_agent("ant") + + def is_neighbour(self, id_a, id_b): + if id_a == id_b: + return False + if self.agents_metric[id_a] == {}: + return False + if self.agents_metric[id_b] == {}: + return False + + x = self.agents_metric[id_a].get("x") - self.agents_metric[id_b].get("x") + y = self.agents_metric[id_a].get("y") - self.agents_metric[id_b].get("y") + + dist = sqrt(x * x + y * y) + return dist < 15 + + def on_cycle_begin(self) -> None: + + for i in range(self.next_id): + for j in range(i, self.next_id): + cond = self.is_neighbour(i, j) + if cond: + self.agent_neighbour(i, j) + self.agent_neighbour(j, i) + + +if __name__ == '__main__': + s = AntAmas(str(sys.argv[1]), sys.argv[2], 50) + s.run() diff --git a/ant/config.json b/ant/config.json new file mode 100644 index 0000000000000000000000000000000000000000..d9cf6abee796ca2399fffe1f5a9c97552e990ff9 --- /dev/null +++ b/ant/config.json @@ -0,0 +1,13 @@ +{ + "iotamak_version": "0.0.3", + + "seed" : 0, + + "canvas": { + "height" : 500, + "width" : 500, + "x" : "x", + "y": "y" + } + +} \ No newline at end of file diff --git a/ant/env.py b/ant/env.py new file mode 100644 index 0000000000000000000000000000000000000000..a4f1c425069ef147cbc87de425cd47ea57910ab0 --- /dev/null +++ b/ant/env.py @@ -0,0 +1,15 @@ +import sys + + +from iotAmak.environment import Environment + + +class AntEnv(Environment): + + def __init__(self, broker_ip): + super().__init__(broker_ip) + + +if __name__ == '__main__': + s = AntEnv(str(sys.argv[1])) + s.run() \ No newline at end of file diff --git a/ant/scheduler.py b/ant/scheduler.py new file mode 100644 index 0000000000000000000000000000000000000000..9aac6b62858864b24de49e4414435a3e307af319 --- /dev/null +++ b/ant/scheduler.py @@ -0,0 +1,7 @@ +import sys + +from iotAmak.scheduler import Scheduler + +if __name__ == '__main__': + a = Scheduler(str(sys.argv[1])) + a.run() \ No newline at end of file diff --git a/philosophers.zip b/philosophers.zip new file mode 100644 index 0000000000000000000000000000000000000000..36a06f59b5c16b862e0b44f85cc23505f35b0377 Binary files /dev/null and b/philosophers.zip differ diff --git a/philosophers/config.json b/philosophers/config.json index 84fb1a9b134349d10e0a750b3ac98d9355c279b5..9d9ff1568b6217714c8676964e8dd784c7c8e317 100644 --- a/philosophers/config.json +++ b/philosophers/config.json @@ -1,23 +1,23 @@ { - "broker" : "192.168.153.209", + "broker" : "192.168.71.209", "clients_ssh" : [ { - "hostname" : "192.168.153.18", + "hostname" : "192.168.71.18", "user" : "pi", "password" : "raspberry" }, { - "hostname" : "192.168.153.227", + "hostname" : "192.168.71.227", "user" : "pi", "password" : "raspberry" }, { - "hostname" : "192.168.153.61", + "hostname" : "192.168.71.61", "user" : "pi", "password" : "raspberry" }, { - "hostname" : "192.168.153.75", + "hostname" : "192.168.71.75", "user" : "pi", "password" : "raspberry" } diff --git a/philosophers/scheduler.py b/philosophers/scheduler.py index 05c5b41dfefb1b3b83477425f1552abf6317ec8a..9aac6b62858864b24de49e4414435a3e307af319 100644 --- a/philosophers/scheduler.py +++ b/philosophers/scheduler.py @@ -3,5 +3,5 @@ import sys from iotAmak.scheduler import Scheduler if __name__ == '__main__': - a = Scheduler(int(sys.argv[1]), str(sys.argv[2])) + a = Scheduler(str(sys.argv[1])) a.run() \ No newline at end of file