simpy_terms/graph_n.py

40 lines
944 B
Python
Raw Normal View History

2026-05-24 14:39:44 +03:00
import queue
import threading
import simpy.rt
2026-06-20 13:26:29 +03:00
from processes import input_thread, node, render_process, user_input_process
from tern import Tern
2026-05-24 14:39:44 +03:00
2026-06-20 13:26:29 +03:00
def initial_values(edges) -> dict[str, Tern]:
return {x: Tern.U for triple in edges for x in triple}
2026-05-24 14:39:44 +03:00
2026-06-20 13:26:29 +03:00
def main():
from graph_view import active_edges, render_graph_process
2026-05-24 14:39:44 +03:00
2026-06-20 13:26:29 +03:00
edges = active_edges()
values = initial_values(edges)
commands: queue.Queue[tuple[str, Tern]] = queue.Queue()
2026-05-24 14:39:44 +03:00
2026-06-20 13:26:29 +03:00
env = simpy.rt.RealtimeEnvironment(factor=1.0, strict=False)
threading.Thread(
target=input_thread,
args=(commands,),
daemon=True,
).start()
for n in edges:
_ = env.process(node(env, n, values))
_ = env.process(user_input_process(env, values, commands))
_ = env.process(render_process(env, values))
_ = env.process(render_graph_process(env, values))
_ = env.run(until=float("inf"))
2026-05-24 14:39:44 +03:00
2026-06-20 13:26:29 +03:00
if __name__ == "__main__":
main()