actors :: ClockAgent
Master of the simulation, it initiates the steps and waits for them to terminateactors :: ProxyAgent
pthreads :: concurrent_collections
Introduces thread-safe concurrent collectionscore :: union_find
union–find algorithm using an efficient disjoint-set data structureagent_simulation by refining the Agent class to make
			
# a "Framework" to make Multi-Agent Simulations in Nit
module agent_simulation is example, no_warning("missing-doc")
import actors
# Master of the simulation, it initiates the steps and waits for them to terminate
class ClockAgent
	actor
	# Number of steps to do in the simulation
	var nb_steps: Int
	# List of Agents in the simulation
	var agents: Array[Agent]
	# Number of agents that finished their step
	var nb_finished = 0
	fun do_step do
		for a in agents do a.async.do_step
		nb_steps -= 1
	end
	fun finished_step do
		nb_finished += 1
		if nb_finished == agents.length then
			nb_finished = 0
			if nb_steps != 0 then async.do_step
		end
	end
end
class Agent
	actor
	# Doing a step in the simulation
	fun do_step do
	end
	fun end_step do clock_agent.async.finished_step
end
redef class Sys
	var clock_agent: ClockAgent is noautoinit,writable
end
lib/actors/examples/agent_simulation/agent_simulation.nit:15,1--60,3