file cleanup.
This commit is contained in:
55
experiments/stochastic_hillclimber/actuator.py
Normal file
55
experiments/stochastic_hillclimber/actuator.py
Normal file
@@ -0,0 +1,55 @@
|
||||
# actors/actuator.py
|
||||
import asyncio
|
||||
|
||||
from actor import Actor
|
||||
|
||||
|
||||
class Actuator(Actor):
|
||||
def __init__(self, aid, cx_pid, name, fanin_ids, expect_count, scape=None):
|
||||
super().__init__(f"Actuator-{aid}")
|
||||
self.aid = aid
|
||||
self.cx_pid = cx_pid
|
||||
self.aname = name
|
||||
self.fanin_ids = fanin_ids
|
||||
self.expect = expect_count
|
||||
self.received = {}
|
||||
self.scape = scape
|
||||
self.scape_inbox = asyncio.Queue()
|
||||
|
||||
async def run(self):
|
||||
|
||||
while True:
|
||||
msg = await self.inbox.get()
|
||||
tag = msg[0]
|
||||
|
||||
if tag == "forward":
|
||||
_, from_id, vec = msg
|
||||
self.received[from_id] = vec
|
||||
|
||||
if len(self.received) == self.expect:
|
||||
print("ACTUATOR: collected all signals...")
|
||||
output = []
|
||||
for fid in self.fanin_ids:
|
||||
output.extend(self.received[fid])
|
||||
|
||||
if self.aname == "pts":
|
||||
print(f"Actuator output: {output}")
|
||||
fitness, halt_flag = 1.0, 0
|
||||
elif self.aname == "xor_SendOutput" and self.scape:
|
||||
print("ACTUATOR: sending action to scape...")
|
||||
await self.scape.send(("action", output, self))
|
||||
while True:
|
||||
resp = await self.inbox.get()
|
||||
if resp[0] == "result":
|
||||
print("ACTUATOR: got scape response: ", resp)
|
||||
fitness, halt_flag = resp[1], resp[2]
|
||||
break
|
||||
else:
|
||||
fitness, halt_flag = 0.0, 0
|
||||
|
||||
await self.cx_pid.send(("sync", self.aid, fitness, halt_flag))
|
||||
print("ACTUATOR: sent sync message to cortex.")
|
||||
self.received.clear()
|
||||
|
||||
elif tag == "terminate":
|
||||
return
|
||||
Reference in New Issue
Block a user