Skip to content
Snippets Groups Projects
Commit 33f2e89e authored by shinedday's avatar shinedday
Browse files

Update to 0.0.7

parent adfe1567
No related branches found
No related tags found
No related merge requests found
No preview for this file type
import random
import sys
from iotAmak.agent import Agent
from iotAmak.agent.agent import Agent
class Ant(Agent):
......@@ -67,6 +67,14 @@ class Ant(Agent):
metric["color"] = self.color
return metric
def to_canvas(self) -> dict:
return {
"id": self.id,
"x": self.x,
"y": self.y,
"color": self.color,
"cycle": self.nbr_cycle
}
if __name__ == '__main__':
a = Ant(str(sys.argv[1]))
......
import sys
from math import sqrt
from iotAmak.amas import Amas
from iotAmak.amas.amas import Amas
class AntAmas(Amas):
......
{
"iotamak_version": "0.0.4",
"seed" : 0,
"iotamak_version": "0.0.7",
"scheduling_type": "sync",
"canvas": {
"height" : 500,
......
import sys
from iotAmak.environment import Environment
from iotAmak.env.environment import Environment
class AntEnv(Environment):
......
import sys
from iotAmak.scheduler import Scheduler
from iotAmak.scheduler.scheduler import Scheduler
if __name__ == '__main__':
a = Scheduler(str(sys.argv[1]), str(sys.argv[2]), str(sys.argv[3]))
......
No preview for this file type
import random
import sys
from iotAmak.communicating_agent import CommunicatingAgent
from iotAmak.agent.communicating_agent import CommunicatingAgent
class Ant(CommunicatingAgent):
......@@ -65,13 +65,20 @@ class Ant(CommunicatingAgent):
for n in self.neighbors:
self.send_mail(n.get("id"), {"color": self.color})
def to_canvas(self) -> dict:
return {
"id": self.id,
"x": self.x,
"y": self.y,
"color": self.color,
"cycle": self.nbr_cycle
}
def send_metric(self):
metric = super(Ant, self).send_metric()
metric["x"] = self.x
metric["y"] = self.y
metric["color"] = self.color
return metric
......
import sys
from math import sqrt
from iotAmak.amas import Amas
from iotAmak.amas.amas import Amas
class AntAmas(Amas):
......
{
"iotamak_version": "0.0.4",
"seed" : 0,
"iotamak_version": "0.0.7",
"scheduling_type": "sync",
"canvas": {
"height" : 500,
......
import sys
from iotAmak.environment import Environment
from iotAmak.env.environment import Environment
class AntEnv(Environment):
......
import sys
from iotAmak.scheduler import Scheduler
from iotAmak.scheduler.scheduler import Scheduler
if __name__ == '__main__':
a = Scheduler(str(sys.argv[1]), str(sys.argv[2]), str(sys.argv[3]))
......
No preview for this file type
......@@ -10,34 +10,44 @@ class IotAgent(CommunicatingAgent):
self.nbr_agent: int = nbr_agent
self.values = []
self.asked = []
self.nei = []
super().__init__(arguments)
def on_initialization(self) -> None:
self.operator = random.choice(["+", "-", "*", "/"])
self.value = random.randint(0, 9999999)
self.value = random.randint(1, 10)
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))
pass
def on_perceive(self) -> None:
while len(self.nei) < 2:
self.get_new_nei()
self.values = []
for mail in self.mailbox:
if mail.payload == "AskValue":
self.asked.append(int(mail.sender_id))
elif mail.payload == "Remove":
self.asked.remove(int(mail.sender_id))
else:
self.values.append(int(mail.payload))
self.mailbox = []
if random.randint(0, 100) == 1:
self.nei = [self.nei[0]]
def on_decide(self) -> None:
pass
def on_act(self) -> None:
if self.value == 0:
self.value = random.randint(1, 10)
if self.value > 1000000:
self.value = random.randint(1, 10)
if len(self.values) == 2:
if self.operator == "+":
self.value = self.values[0] + self.values[1]
......@@ -46,7 +56,10 @@ class IotAgent(CommunicatingAgent):
elif self.operator == "*":
self.value = self.values[0] * self.values[1]
elif self.operator == "/":
self.value = self.values[0] / self.values[1]
if self.values[1] == 0:
self.nei = [self.nei[0]]
else:
self.value = self.values[0] / self.values[1]
def on_cycle_end(self) -> None:
for n in self.asked:
......@@ -55,6 +68,17 @@ class IotAgent(CommunicatingAgent):
" OP : " + self.operator
)
def get_new_nei(self):
nei = self.id
while self.id == nei:
nei = random.randint(0, self.nbr_agent - 1)
self.nei = [nei] + self.nei
self.send_mail(nei, "AskValue")
def remove_nei(self):
self.send_mail(self.nei[1], "Remove")
self.nei = [self.nei[0]]
if __name__ == '__main__':
a = IotAgent(str(sys.argv[1]), int(sys.argv[2]))
......
{
"iotamak_version": "0.0.6"
"iotamak_version": "0.0.7",
"scheduling_type": "sync",
"com_graph": {
"fun": "linear",
"refresh": 10
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment