An array of the Agent
s in this Network
(in the order they were added).
Add an agent to the network.
Returns true
if the Agent
was successfully added, false
otherwise.
const a = new Agent();
network.addAgent(a); // returns true
network.addAgent(a); // returns false since `a` was already in the `Network`
Given an Environment
, add all the Agent
s in that Environment
to this Network
. (This is a shortcut for calling environment.getAgents().forEach(a => network.addAgent(a)));
)
Returns true
if Agent
s a
and b
are connected, false
if they are not.
network.connect(a, b);
network.areConnected(a, b); // returns true since they have been connected
network.disconnect(a, b);
network.areConnected(a, b); // returns false since they have been disconnected
Returns the average clustering coefficient for the Network
(the average
of the local clustering coefficient across all Agent
s).
Note that this is a different measurement from the global clustering coefficient
(i.e. calling clusteringCoefficient
without any parameters).
Removes all Agent
s from the Network
.
const network = new Network();
network.addAgent(new Agent());
network.size(); // returns 1
network.clear();
network.size(); // returns 0
The clustering coefficient is a measure of how
closely connected either an individual Agent
's connections are or the Network
as a whole is.
If an Agent
is passed as the single parameter, returns the local clustering coefficient for that Agent
.
If no parameter is passed, returns the global clustering coefficient
of the Network
(an aggregate measure of how connected the Agent
s are).
Draw a connection between every pair of Agent
s in the Network
.
Attempts to create a connection between Agent
s a
and b
.
Returns true
if the connection was successfully created (i.e. if a
and b
were previously not connected and now are).
const a = new Agent();
const b = new Agent();
network.addAgent(a);
network.addAgent(b);
network.connect(a, b); // returns true
network.connect(a, b); // returns false since they are now already connected
const c = new Agent();
network.connect(a, c); // returns false since `c` is not in the `Network`
Returns false
otherwise, for example if a
and b
are the same Agent
, or if either is not in the Network
.
Attempts to sever the connection between Agent
s a
and b
.
Returns true
if the Agent
s were successfully disconnected, false
otherwise.
const a = new Agent();
const b = new Agent();
network.addAgent(a);
network.addAgent(b);
network.connect(a, b);
network.disconnect(a, b); // returns true since they were connected and are no longer
network.disconnect(a, b); // returns false since they were already not connected
Returns an array of Agent
s that are connected to the given Agent
(in no guaranteed order).
Returns null
if the given Agent
is not in the Network
.
// suppose a, b, and c are connected
network.neighbors(a); // returns [b, c] (or [c, b])
network.disconnect(a, c);
network.neighbors(a); // returns [b]
network.neighbors(c); // returns [b]
Removes an Agent
from the Network
.
const a = new Agent();
network.addAgent(a);
network.removeAgent(a); // returns true
network.removeAgent(a); // returns false since `a` was no longer in the `Network`
Returns true
if the agent was successfully removed.
Returns false
if the agent was not in the network to begin with.
Returns the number of Agent
s in the Network
.
const a = new Agent();
const b = new Agent();
const c = new Agent();
[a, b, c].forEach(agt => network.addAgent(agt));
network.size(); // returns 3
Generated using TypeDoc
A
Network
allowsAgent
s to be connected to each other.0.1.3