Agent-based modeling in JavaScript in the browser or on the server. [v0.4.8]



The base flocc.Network class (from here on, just Network) stores agents in an undirected graph, allowing you to create and keep track of connections between agents.

An empty network can be instantiated by calling: const network = new Network();

Then, to make sure that your environment recognizes and can make use of the Network, make sure you call: environment.use(network) (where network is the instance of the Network you created earlier).



Add an agent to the network.

const agent = new Agent();


Add all agents from an environment to the network.



Remove a previously referenced agent from the network. If a1 is an agent removed from the network, and has a connection to a2, then a2 will remain in the network but its connection to a1 will be removed.



Removes all agents from the network, as well as all connections.

.connect(agent1, agent2)

Connects agent1 and agent2. This method returns true if the connection was successful, that is:

  • The agents were not previously connected
  • Both agents are in the network
  • The agents are now connected

It will return false if the connection was unsuccessful, for example if you try to connect an agent to itself, or to connect two already-connected agents, or to connect an/two agent/s not in the network (it will otherwise fail silently).

.areConnected(agent1, agent2)

Returns a boolean true if the agents are connected, false if they are not.

.disconnect(agent1, agent2)

Disconnects agent1 and agent2. Like .connect, this method returns true if the disconnection was successful and false if it was unsuccessful (it will otherwise fail silently).


Returns the number of agents in the network. Since the size of the network is distinct from the environment, you might have fewer agents in the network than are in the environment.


Returns a boolean true if the agent is in the network, false if it is not.


Returns a JavaScript array containing the neighbors (1st-degree connections) of an agent. If the agent does not have any neighbors, returns an empty array.


This helper function adds connections between every agent in the network to every other agent. Since there are no more possible connections that could be created, the network is now completeRead more about complete graphs.