def _act(self): """Broadcast new sysconf and candidate to all neighbors.""" wm = self.wm for neighbor in wm.neighbors: wm.msgs_out += 1 logger.debug('%s sending message %d' % (self.agent.name, wm.msgs_out)) aiomas.create_task(neighbor.update(wm.sysconf, wm.candidate))
async def init_negotiation(self): """ Initialize negotiation by sending initial sysconf and candidate to all neighbors """ for neighbor in self.wm.neighbors: self.wm.msgs_out += 1 logger.debug('%s sending message %d' % (self.agent.name, self.wm.msgs_out)) aiomas.create_task( neighbor.update(self.wm.sysconf, self.wm.candidate)) logger.debug('%s updating Observer from init_negotiation' % self.agent.name) await self._update_obs_agent(True)
def __scheduleTasks(self): this_clock = self.container.clock gran_sec = CF.granularity * 60 task = aiomas.create_task(self.communicateBlockchain) this_clock.call_in(1 * gran_sec, task, '2015-01-15 00:15:00', None, None, 'UPDATE_ACTUAL') # this_clock.call_in(2 * gran_sec, self.communicateBlockchain, self.__bc_address, '2015-01-15 00:30:00', None, None, 'UPDATE_ACTUAL') # this_clock.call_in(3 * gran_sec, self.communicateBlockchain, self.__bc_address, None, '2015-01-15 00:15:00', '2015-01-15 00:45:00', 'RETRIEVE_IMBALANCE') return True
def __init__(self, container, *, start_date, check_interval, max_windpark_feedin): super().__init__(container) self.start_date = start_date self.check_interval = check_interval self.max_windpark_feedin = max_windpark_feedin self.wecs = [] # List of WecsAgent proxies registered with us. # Schedule the cyclic wind park feed-in check: self.cycle_done = asyncio.Future() self.t_check_feedin = aiomas.create_task(self.check_windpark_feedin())
async def store_topology(self, _, neighbors, target_schedule, weights, resolution, intervals, startdate): """Inform this agent about its neighbors.""" # connect to neighbors futs = [self.agent.container.connect(n) for n in neighbors] neighbors = await asyncio.gather(*futs) assert intervals == len(target_schedule) # get possible schedules possible_schedules = self.agent.model.generate_schedules( startdate, resolution, intervals, None) logger.debug("%s found %s possible schedules" % (self.agent.name, len(possible_schedules))) # create an initial WorkingMemory self.wm = WorkingMemory(neighbors=neighbors, start=startdate, res=resolution, intervals=intervals, ts=target_schedule, weights=weights, ps=possible_schedules, sysconf=None, candidate=None) # Take the first possible OS and ignore its utility (not important yet) schedule_id, _, op_sched = possible_schedules[0] # create sysconf with only the first possible OS sysconf = SystemConfig(idx={self.name: 0}, cs=np.array([op_sched], dtype=float), sids=[schedule_id], cnt=[0]) # store it in your wm self.wm.sysconf = sysconf # get performance of this sysconf perf = self.wm.objective_function(sysconf.cs) # create a candidate equivalent to the sysconf candidate = Candidate(agent=self.name, idx={self.name: 0}, cs=np.array([op_sched], dtype=float), sids=[schedule_id], perf=perf) # store it in your wm self.wm.candidate = candidate # check your inbox and for the negotiation_stop signal self.task_negotiation_stop = False self.task_negotiation = aiomas.create_task(self.process_inbox())
def _reset_negotiation_setup(self): self._candidates = [] self._solution = None self._solution_determined = asyncio.Future() self._task_finish_neg = aiomas.create_task(self._wait_finish_neg())