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:
network is the instance of the
Network you created earlier).
Add an agent to the network.
const agent = new Agent(); environment.addAgent(agent); network.addAgent(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 will remain in the network but its connection to
a1 will be removed.
Removes all agents from the network, as well as all connections.
agent2. This method returns
true if the connection was successful, that is:
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).
Returns a boolean
true if the agents are connected,
false if they are not.
.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.
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 complete. Read more about complete graphs.
The clustering coefficient is a measure of how tightly interconnected agents in a network are. It ranges from 0 (not at all interconnected), to 1 (highly interconnected).
By calling this and passing an agent in the network as the single parameter, it returns the local clustering coefficient — a measure of how interconnected an agents’ neighbors are. A 0 value means that none of the agent’s neighbors are connected to each other, and a 1 means that each neighbor is connected to all the other neighbors. Returns
null if the agent has fewer than 2 neighbors.
If no parameter is passed, then this returns the global clustering coefficient, an aggregate measure across all agents in the network. Mathematically, it is based the ratio of the number of closed triplets (groups of three agents who are all connected to each other, i.e. a triangle) to the number of total triplets (groups of three agents who are connected by at least two connections, i.e. a V-shape or triangle).
The average clustering coefficient is an alternative network-level measurement to the global clustering coefficient. It simply takes the average value of all agent-level clustering coefficients (ignoring any agents with fewer than 2 neighbors).