diff --git a/ant.zip b/ant.zip index 7f598ed6dbbf36c137aa684b8571ad27ef2c45db..64f65499b46aa579f4afbf1c9ddb7ad78e624126 100644 Binary files a/ant.zip and b/ant.zip differ diff --git a/ant/agent.py b/ant/agent.py index 0d1d88cbb18100b0dd0e5699468eb9d9882d527e..6492e4d766e821c54d18b4be05b8e386cd6aec39 100644 --- a/ant/agent.py +++ b/ant/agent.py @@ -5,12 +5,24 @@ from iotAmak.agent import Agent class Ant(Agent): + int_to_color = { + 0: "#000000", + 1: "#ff0000", + 2: "#00ff00", + 3: "#0000ff", + } + color_to_int = { + "#000000": 0, + "#ff0000": 1, + "#00ff00": 2, + "#0000ff": 3, + } - def __init__(self, identifier: int, broker_ip: str): - self.x = 250 - self.y = 250 - self.color = 0 - super().__init__(identifier, broker_ip) + def __init__(self, arguments: str): + self.x = 0 + self.y = 0 + self.color = "#000000" + super().__init__(arguments) def on_initialization(self) -> None: pass @@ -28,17 +40,21 @@ class Ant(Agent): def on_act(self) -> None: self.x += random.randint(-5, +5) self.y += random.randint(-5, +5) + if self.x < 0: + self.x = 0 + if self.y < 0: + self.y = 0 # count color - color = [0 for _ in range(5)] + color = [0 for _ in range(4)] for ant in self.next_neighbors: - color[ant.get("color")] += 1 + color[Ant.color_to_int.get(ant.get("color"))] += 1 # set color if color.index(max(color)) != 0: - self.color = color[color.index(max(color))] + self.color = Ant.int_to_color.get(color[color.index(max(color))]) # low chance to mutate if random.randint(0, 1000) < 10: - self.color = random.randint(0, 4) + self.color = Ant.int_to_color.get(random.randint(0, 3)) def on_cycle_end(self) -> None: pass @@ -53,5 +69,5 @@ class Ant(Agent): if __name__ == '__main__': - a = Ant(int(sys.argv[1]), str(sys.argv[2])) + a = Ant(str(sys.argv[1])) a.run() diff --git a/ant/amas.py b/ant/amas.py index 267f8053cb2b8226972805e9e15d38fd3ee23e91..db8368d8207df44e39b0ad50a3ecc276ad1c46a8 100644 --- a/ant/amas.py +++ b/ant/amas.py @@ -6,9 +6,9 @@ from iotAmak.amas import Amas class AntAmas(Amas): - def __init__(self, broker_ip: str, clients, nbr_agent): + def __init__(self, arguments: str, nbr_agent): self.agent_to_create = nbr_agent - super().__init__(broker_ip, clients) + super().__init__(arguments) def on_initial_agents_creation(self): for _ in range(self.agent_to_create): @@ -39,5 +39,5 @@ class AntAmas(Amas): if __name__ == '__main__': - s = AntAmas(str(sys.argv[1]), sys.argv[2], 50) + s = AntAmas(str(sys.argv[1]), 15) s.run() diff --git a/ant/config.json b/ant/config.json index d9cf6abee796ca2399fffe1f5a9c97552e990ff9..d96ea1da6a3d94a4476be1f68478f457da459350 100644 --- a/ant/config.json +++ b/ant/config.json @@ -1,13 +1,11 @@ { - "iotamak_version": "0.0.3", + "iotamak_version": "0.0.4", "seed" : 0, "canvas": { "height" : 500, - "width" : 500, - "x" : "x", - "y": "y" + "width" : 500 } } \ No newline at end of file diff --git a/ant/env.py b/ant/env.py index a4f1c425069ef147cbc87de425cd47ea57910ab0..ebadace645176216389d4ca3475162e0336649a8 100644 --- a/ant/env.py +++ b/ant/env.py @@ -6,8 +6,8 @@ from iotAmak.environment import Environment class AntEnv(Environment): - def __init__(self, broker_ip): - super().__init__(broker_ip) + def __init__(self, arguments): + super().__init__(arguments) if __name__ == '__main__': diff --git a/ant/scheduler.py b/ant/scheduler.py index 9aac6b62858864b24de49e4414435a3e307af319..01638e3b3187abb5977e9544ebb4792b9c590abc 100644 --- a/ant/scheduler.py +++ b/ant/scheduler.py @@ -3,5 +3,5 @@ import sys from iotAmak.scheduler import Scheduler if __name__ == '__main__': - a = Scheduler(str(sys.argv[1])) + a = Scheduler(str(sys.argv[1]), str(sys.argv[2]), str(sys.argv[3])) a.run() \ No newline at end of file diff --git a/ant_communicating.zip b/ant_communicating.zip new file mode 100644 index 0000000000000000000000000000000000000000..2db59209b24cdbea563f93791e888e8b9e7a2e14 Binary files /dev/null and b/ant_communicating.zip differ diff --git a/ant_communicating/__init__.py b/ant_communicating/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/ant_communicating/agent.py b/ant_communicating/agent.py new file mode 100644 index 0000000000000000000000000000000000000000..e6a074d613b299701659b77db9b3b73a0cb0ee37 --- /dev/null +++ b/ant_communicating/agent.py @@ -0,0 +1,80 @@ +import random +import sys + +from iotAmak.communicating_agent import CommunicatingAgent + + +class Ant(CommunicatingAgent): + int_to_color = { + 0: "#000000", + 1: "#ff0000", + 2: "#00ff00", + 3: "#0000ff", + } + color_to_int = { + "#000000": 0, + "#ff0000": 1, + "#00ff00": 2, + "#0000ff": 3, + } + + def __init__(self, arguments: str): + self.x = 0 + self.y = 0 + self.color = "#000000" + + self.other_color = [0 for _ in range(4)] + + super().__init__(arguments) + + 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 = [] + + self.other_color = [0 for _ in range(4)] + for mail in self.mailbox: + self.other_color[Ant.color_to_int.get(mail.payload.get("color"))] += 1 + self.mailbox = [] + + def on_decide(self) -> None: + pass + + def on_act(self) -> None: + self.x += random.randint(-5, +5) + self.y += random.randint(-5, +5) + if self.x < 0: + self.x = 0 + if self.y < 0: + self.y = 0 + + # count color + index_max = self.other_color.index(max(self.other_color[1:])) + if self.other_color[index_max] != 0: + self.color = Ant.int_to_color.get(self.other_color[index_max]) + # low chance to mutate + if random.randint(0, 1000) < 10: + self.color = Ant.int_to_color.get(random.randint(0, 3)) + + def on_cycle_end(self) -> None: + for n in self.neighbors: + self.send_mail(n.get("id"), {"color": self.color}) + + + 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(str(sys.argv[1])) + a.run() diff --git a/ant_communicating/amas.py b/ant_communicating/amas.py new file mode 100644 index 0000000000000000000000000000000000000000..f79ec7a10d5ec1140a2e519097335c0a214f3b04 --- /dev/null +++ b/ant_communicating/amas.py @@ -0,0 +1,43 @@ +import sys +from math import sqrt + +from iotAmak.amas import Amas + + +class AntAmas(Amas): + + def __init__(self, arguments: str, nbr_agent): + self.agent_to_create = nbr_agent + super().__init__(arguments) + + def on_initial_agents_creation(self): + for _ in range(self.agent_to_create): + self.add_agent("ant_communicating") + + 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 < 1500 + + 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]), 2) + s.run() diff --git a/ant_communicating/config.json b/ant_communicating/config.json new file mode 100644 index 0000000000000000000000000000000000000000..d96ea1da6a3d94a4476be1f68478f457da459350 --- /dev/null +++ b/ant_communicating/config.json @@ -0,0 +1,11 @@ +{ + "iotamak_version": "0.0.4", + + "seed" : 0, + + "canvas": { + "height" : 500, + "width" : 500 + } + +} \ No newline at end of file diff --git a/ant_communicating/env.py b/ant_communicating/env.py new file mode 100644 index 0000000000000000000000000000000000000000..ebadace645176216389d4ca3475162e0336649a8 --- /dev/null +++ b/ant_communicating/env.py @@ -0,0 +1,15 @@ +import sys + + +from iotAmak.environment import Environment + + +class AntEnv(Environment): + + def __init__(self, arguments): + super().__init__(arguments) + + +if __name__ == '__main__': + s = AntEnv(str(sys.argv[1])) + s.run() \ No newline at end of file diff --git a/ant_communicating/scheduler.py b/ant_communicating/scheduler.py new file mode 100644 index 0000000000000000000000000000000000000000..01638e3b3187abb5977e9544ebb4792b9c590abc --- /dev/null +++ b/ant_communicating/scheduler.py @@ -0,0 +1,7 @@ +import sys + +from iotAmak.scheduler import Scheduler + +if __name__ == '__main__': + a = Scheduler(str(sys.argv[1]), str(sys.argv[2]), str(sys.argv[3])) + a.run() \ No newline at end of file diff --git a/box.zip b/box.zip new file mode 100644 index 0000000000000000000000000000000000000000..1341005ebc9deb871cb11248c71264bfbc027384 Binary files /dev/null and b/box.zip differ diff --git a/box/__init__.py b/box/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/box/agent.py b/box/agent.py new file mode 100644 index 0000000000000000000000000000000000000000..7fcf405d4bf2eb52557b01e0ee28f7f3a636a040 --- /dev/null +++ b/box/agent.py @@ -0,0 +1,17 @@ +import sys + +from iotAmak.agent.async_agent import AsyncAgent + + +class BoxAgent(AsyncAgent): + + def __init__(self, arguments: str): + super().__init__(arguments) + + def on_act(self) -> None: + self.publish("box", "") + + +if __name__ == '__main__': + s = BoxAgent(str(sys.argv[1])) + s.run() diff --git a/box/amas.py b/box/amas.py new file mode 100644 index 0000000000000000000000000000000000000000..d9b787f3022a4d65133a0091ead97fce30568744 --- /dev/null +++ b/box/amas.py @@ -0,0 +1,18 @@ +import sys + +from iotAmak.amas.async_amas import AsyncAmas + + +class BoxAmas(AsyncAmas): + + def __init__(self, arguments: str): + super().__init__(arguments) + + def on_initial_agents_creation(self): + for i in range(len(self.clients)): + self.add_agent("box", client_ip=self.clients[i].hostname) + + +if __name__ == '__main__': + s = BoxAmas(str(sys.argv[1])) + s.run() \ No newline at end of file diff --git a/box/box.py b/box/box.py new file mode 100644 index 0000000000000000000000000000000000000000..041aad9fb3a15ea4d7c9dc82643e7100042942ae --- /dev/null +++ b/box/box.py @@ -0,0 +1,9 @@ + + +class Box: + + def __init__(self): + self.x = 0 + + def add(self): + self.x += 1 \ No newline at end of file diff --git a/box/config.json b/box/config.json new file mode 100644 index 0000000000000000000000000000000000000000..c771fea31203ce149b239937b64a7f043b94db44 --- /dev/null +++ b/box/config.json @@ -0,0 +1,4 @@ +{ + "iotamak_version": "0.0.7", + "scheduling_type": "async" +} \ No newline at end of file diff --git a/box/env.py b/box/env.py new file mode 100644 index 0000000000000000000000000000000000000000..64ddb934792055bd03d341da69fdf40fa0b1de01 --- /dev/null +++ b/box/env.py @@ -0,0 +1,27 @@ +import sys + +from iotAmak.env.async_env import AsyncEnvironment + +from box import Box + + +class BoxEnv(AsyncEnvironment): + + def __init__(self, arguments, nbr_box): + self.nbr_box = nbr_box + self.boxs = [Box() for _ in range(nbr_box)] + super().__init__(arguments) + for i in range(nbr_box): + self.subscribe("agent/"+str(i)+"/box", self.box_action) + + def box_action(self, client, userdata, message): + agent_id = int(str(message.topic).split("/")[1]) + self.boxs[agent_id].add() + + def behaviour(self) -> None: + for i in range(self.nbr_box): + print("Box : ",i," -> ",self.boxs[i].x) + +if __name__ == '__main__': + s = BoxEnv(str(sys.argv[1]), 4) + s.run() \ No newline at end of file diff --git a/demonstrator.zip b/demonstrator.zip new file mode 100644 index 0000000000000000000000000000000000000000..035d3cff04ceab08e99d3f5296d749f0af940548 Binary files /dev/null and b/demonstrator.zip differ diff --git a/demonstrator/__init__.py b/demonstrator/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/demonstrator/agent.py b/demonstrator/agent.py new file mode 100644 index 0000000000000000000000000000000000000000..6c256d0c2c1a60b53169000b4f80f2873fb7faa7 --- /dev/null +++ b/demonstrator/agent.py @@ -0,0 +1,61 @@ +import random +import sys + +from iotAmak.agent.communicating_agent import CommunicatingAgent + + +class IotAgent(CommunicatingAgent): + + def __init__(self, arguments: str, nbr_agent: int): + self.nbr_agent: int = nbr_agent + self.values = [] + self.asked = [] + super().__init__(arguments) + + def on_initialization(self) -> None: + self.operator = random.choice(["+", "-", "*", "/"]) + self.value = random.randint(0, 9999999) + + def on_cycle_begin(self) -> None: + if self.nbr_cycle == 0: + for i in range(2): + nei = self.id + while self.id == nei: + nei = random.randint(0, self.nbr_agent - 1) + self.send_mail(nei, "AskValue") + self.log("New nei "+str(nei)) + + def on_perceive(self) -> None: + self.values = [] + for mail in self.mailbox: + if mail.payload == "AskValue": + self.asked.append(int(mail.sender_id)) + else: + self.values.append(int(mail.payload)) + self.mailbox = [] + + def on_decide(self) -> None: + pass + + def on_act(self) -> None: + if len(self.values) == 2: + if self.operator == "+": + self.value = self.values[0] + self.values[1] + elif self.operator == "-": + self.value = self.values[0] - self.values[1] + elif self.operator == "*": + self.value = self.values[0] * self.values[1] + elif self.operator == "/": + self.value = self.values[0] / self.values[1] + + def on_cycle_end(self) -> None: + for n in self.asked: + self.send_mail(n, self.value) + self.log(" Value : " + str(self.value) + + " OP : " + self.operator + ) + + +if __name__ == '__main__': + a = IotAgent(str(sys.argv[1]), int(sys.argv[2])) + a.run() diff --git a/demonstrator/amas.py b/demonstrator/amas.py new file mode 100644 index 0000000000000000000000000000000000000000..775492b703f42d49d96ea448da95890baf8e4b19 --- /dev/null +++ b/demonstrator/amas.py @@ -0,0 +1,18 @@ +import sys + +from iotAmak.amas.amas import Amas + + +class IotAmas(Amas): + + def __init__(self, arguments: str): + super().__init__(arguments) + + def on_initial_agents_creation(self): + for i in range(len(self.clients)): + self.add_agent("demonstrator", client_ip=self.clients[i].hostname, args=[len(self.clients)]) + + +if __name__ == '__main__': + s = IotAmas(str(sys.argv[1])) + s.run() diff --git a/demonstrator/config.json b/demonstrator/config.json new file mode 100644 index 0000000000000000000000000000000000000000..6c22a082082886c132268731cac474811fdd6403 --- /dev/null +++ b/demonstrator/config.json @@ -0,0 +1,3 @@ +{ + "iotamak_version": "0.0.6" +} \ No newline at end of file diff --git a/demonstrator/env.py b/demonstrator/env.py new file mode 100644 index 0000000000000000000000000000000000000000..d3723efa4398718a0c80f3719ce1c13b6300a830 --- /dev/null +++ b/demonstrator/env.py @@ -0,0 +1,13 @@ +import sys +from iotAmak.env.environment import Environment + + +class IotEnv(Environment): + + def __init__(self, arguments): + super().__init__(arguments) + + +if __name__ == '__main__': + s = IotEnv(str(sys.argv[1])) + s.run() \ No newline at end of file diff --git a/demonstrator/scheduler.py b/demonstrator/scheduler.py new file mode 100644 index 0000000000000000000000000000000000000000..4a21e6145b8e0e84aa01b33f92a886f235a7d9d7 --- /dev/null +++ b/demonstrator/scheduler.py @@ -0,0 +1,7 @@ +import sys + +from iotAmak.scheduler.scheduler import Scheduler + +if __name__ == '__main__': + a = Scheduler(str(sys.argv[1]), str(sys.argv[2]), str(sys.argv[3])) + a.run() \ No newline at end of file