def __init__(self, algo: AlgorithmDef, cg: ComputationGraph, agent_mapping: Distribution, comm: CommunicationLayer, dcop: DCOP, infinity=float('inf'), collector: Queue=None, collect_moment: str='value_change', collect_period: float=None, ui_port: int = None): self._own_agt = Agent(ORCHESTRATOR, comm, ui_port=ui_port) self.directory = Directory(self._own_agt.discovery) self._own_agt.add_computation(self.directory.directory_computation) self._own_agt.discovery.use_directory(ORCHESTRATOR, self._own_agt.address) self.discovery = self._own_agt.discovery self.messaging = comm.messaging self.logger = self._own_agt.logger self.dcop = dcop self.status = 'OK' # For scenario execution self._events_iterator = None self._event_timer = None # type: threading.Timer self._timeout_timer = None self._stopping = threading.Event() self.mgt = AgentsMgt(algo, cg, agent_mapping, dcop, self._own_agt, self, infinity, collector=collector, collect_moment=collect_moment, collect_period=collect_period)
def directory_discovery(): # Agent hosting the directory agt_dir = Agent('agt_dir', InProcessCommunicationLayer()) directory = Directory(agt_dir.discovery) agt_dir.add_computation(directory.directory_computation) agt_dir.discovery.use_directory('agt_dir', agt_dir.address) agt_dir.start() agt_dir.run(directory.directory_computation.name) # standard agents agt1 = Agent('agt1', InProcessCommunicationLayer()) agt1.discovery.use_directory('agt_dir', agt_dir.address) agt1.start() agt2 = Agent('agt2', InProcessCommunicationLayer()) agt2.discovery.use_directory('agt_dir', agt_dir.address) agt2.start() yield agt_dir, agt1, agt2 for c in agt1.computations(): agt1.remove_computation(c.name) for c in agt1.discovery.agent_computations(agt1.name): agt1.discovery.unregister_computation(c) for c in agt2.computations(): agt2.remove_computation(c.name) for c in agt2.discovery.agent_computations(agt2.name): agt2.discovery.unregister_computation(c) wait_run() agt1.stop() agt2.stop() agt_dir.stop()
def agents(): # Agent hosting the directory agt_dir = Agent('agt_dir', InProcessCommunicationLayer()) directory = Directory(agt_dir.discovery) agt_dir.add_computation(directory.directory_computation) agt_dir.discovery.use_directory('agt_dir', agt_dir.address) agt_dir.start() agt_dir.run(directory.directory_computation.name) # standard agents agt1 = Agent('agt1', InProcessCommunicationLayer()) agt1.discovery.use_directory('agt_dir', agt_dir.address) agt1.start() agt2 = Agent('agt2', InProcessCommunicationLayer()) agt2.discovery.use_directory('agt_dir', agt_dir.address) agt2.start() yield agt_dir, agt1, agt2 agt1.stop() agt2.stop() agt_dir.stop()