예제 #1
0
 async def run(self):
     msg = await self.receive(timeout=1)
     if msg:
         LogManager.received(self.agent.name)
         tm = json.loads(msg.body)
         self.agent._orders.append(Order(tm["min_time"],
                                         tm["priority"]))
예제 #2
0
 async def setup(self):
     LogManager.log(self.name, "StatisticalAgent starting...")
     t1 = Template(metadata={"performative": "temp"})
     t2 = Template(metadata={"performative": "query"})
     stat_presence_behav = self.PresenceNotificationBehav(1)
     time_rec_behav = self.TimeReceiverBehav(1)
     statistic_behav = self.StatisticalBehav(1)
     self.add_behaviour(stat_presence_behav)
     self.add_behaviour(time_rec_behav, t1)
     self.add_behaviour(statistic_behav, t2)
예제 #3
0
 async def run(self):
     msg = await self.receive(timeout=5)
     if (msg):
         LogManager.received(self.agent.name)
         stat = json.loads(msg.body)
         self.agent._ranking = stat["ranking"]
         self.agent._tot_score = stat["tot_score"]
         self.agent._avg_time = stat["avg_time"]
         self.agent._tot_orders = stat["tot_orders"]
         self.agent._errors = stat["errors"]
예제 #4
0
 async def __notify_highway(self):
     """
             Method that sends statistics to the subscripted HighwayAgent.
         """
     b = MessageManager.get_statistic_to_highway_message(
         self.agent._statistics._ranking)
     msg = Message(to=JIDEnum.HIGH.value,
                   sender=self.agent._jid,
                   body=b,
                   metadata={"performative": "stat"})
     await self.send(msg)
     LogManager.sent(self.agent.name)
예제 #5
0
 async def run(self):
     if self.agent._highwayAvailable:
         if self.agent._orders.__len__() > 0:
             o = self.agent.get_order_at(0)
             b = MessageManager.get_order_message(
                 o._min_execution_time, o._priority)
             msg = Message(to=JIDEnum.HIGH.value,
                           sender=self.agent._jid,
                           body=b,
                           metadata={"performative": "query"})
             await self.send(msg)
             LogManager.sent(self.agent.name)
예제 #6
0
 async def setup(self):
     LogManager.log(self.name, "HighwayAgent is starting...")
     high_presence_behav = self.PresenceNotificationBehav(1)
     self.add_behaviour(high_presence_behav)
     t1 = Template(metadata={"performative": "query"})
     receiveOrderBehav = self.ReceiveOrderBehav(1)
     self.add_behaviour(receiveOrderBehav, t1)
     t3 = Template(metadata={"performative": "stat"})
     receiveRankingBehav = self.ReceiveRankingBehav(1)
     self.add_behaviour(receiveRankingBehav, t3)
     simpleSwitchOrderBehav = self.SwitchOrderBehav(1)
     self.add_behaviour(simpleSwitchOrderBehav)
예제 #7
0
 async def setup(self):
     LogManager.log(self.name, "GUIAgent is starting...")
     t1 = Template(metadata={"performative": "inform"})
     t2 = Template(metadata={"performative": "query"})
     t3 = Template(metadata={"performative": "temp"})
     gui_presence_behav = self.PresenceNotificationBehav(1)
     gui_stat_behav = self.GUIStatisticsBehav(1)
     gui_work_behav = self.GUIWorkingBehav(1)
     gui_temp_behav = self.TemporalWorkingBehav()
     self.add_behaviour(gui_presence_behav)
     self.add_behaviour(gui_stat_behav, t1)
     self.add_behaviour(gui_work_behav, t2)
     self.add_behaviour(gui_temp_behav, t3)
예제 #8
0
 async def __notify_statistics(self):
     """
             Method that informs the subscripted StatisticalAgent about the job just done by this GUIAgent.
         """
     b = MessageManager.get_GUI_to_statistic_message(
         self._high_message["min_time"], self.agent._time,
         self._high_message["priority"])
     msg = Message(to=JIDEnum.STAT.value,
                   sender=self.agent._jid,
                   body=b,
                   metadata={"performative": "query"})
     await self.send(msg)
     LogManager.sent(self.agent.name)
예제 #9
0
    async def setup(self):
        self._orders = []
        self._historyOrders = []
        self._lastLenght = 0
        self._highwayAvailable = False
        self._jid = JIDEnum.CENT.value
        LogManager.log(self.name, "CentralOrderAgent is starting...")
        cent_presence_behav = self.PresenceNotificationBehav(1)
        self.add_behaviour(cent_presence_behav)

        sort_behav = self.SortBehav(1)
        self.add_behaviour(sort_behav)
        send_behav = self.SendOrderBehav(1)
        self.add_behaviour(send_behav)
예제 #10
0
 async def __notify_gui(self):
     """
             Method that sends statistics to all the subscripted GUIAgents.
         """
     for jid in self.agent._gui:
         b = MessageManager.get_statistic_to_GUI_message(
             self.agent._statistics.get_ranking_by_name(jid),
             self.agent._statistics.get_tot_score_by_name(jid),
             self.agent._statistics.get_avg_time_by_name(jid),
             self.agent._executed_orders[jid],
             self.agent._statistics.get_errors_by_name(jid))
         msg = Message(to=jid,
                       sender=self.agent._jid,
                       body=b,
                       metadata={"performative": "inform"})
         await self.send(msg)
         LogManager.sent(self.agent.name)
예제 #11
0
        async def run(self):
            if (self.agent._listAvaibleAgent):
                if (self.agent._orders):
                    order = self.agent._orders.pop()
                    b = MessageManager.get_order_message(
                        order._min_execution_time, order._priority)

                    if self.agent._simpleSwitching:
                        jid = self.agent._listAvaibleAgent.pop()
                        msg = Message(to=jid,
                                      sender=self.agent._jid,
                                      body=b,
                                      metadata={"performative": "query"})
                        self.presence.unsubscribe(jid)
                    else:
                        jid = str(self.agent._first_available_in_ranking())
                        msg = Message(to=jid,
                                      sender=self.agent._jid,
                                      body=b,
                                      metadata={"performative": "query"})

                    await self.send(msg)
                    LogManager.sent(self.agent.name)
                    self.presence.unsubscribe(jid)
예제 #12
0
 async def run(self):
     msg = await self.receive(timeout=60)
     if (msg):
         LogManager.received(self.agent.name)
         if (self.agent._is_working):
             self.agent._time += 1
예제 #13
0
 async def setup(self):
     LogManager.log(self.name, "TemporalAgent starting...")
     temp_presence_behav = self.PresenceNotificationBehav(1)
     temporal_behav = self.TemporalBehav(1)
     self.add_behaviour(temp_presence_behav)
     self.add_behaviour(temporal_behav)
예제 #14
0
 async def run(self):
     msg = await self.receive(timeout=1)
     if msg:
         LogManager.received(self.agent.name)
         tm = json.loads(msg.body)
         self.agent._ranking = tm["ranking"]