WIP: stochastic hill climber

This commit is contained in:
2025-09-26 10:48:28 +02:00
parent f4a8f22fc6
commit 0ace1cec3c
37 changed files with 1862 additions and 0 deletions

View 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