Flocc
    Preparing search index...

    Class Network

    A Network allows Agents to be connected to each other.

    0.1.3

    Implements

    • EnvironmentHelper
    Index

    Constructors

    Properties

    agents: Agent[] = []

    An array of the Agents in this Network (in the order they were added).

    Methods

    • Add an agent to the network.

      Parameters

      Returns boolean

      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`

      0.1.3

    • Given an Environment, add all the Agents in that Environment to this Network. (This is a shortcut for calling environment.getAgents().forEach(a => network.addAgent(a)));)

      Parameters

      Returns void

      0.2.1

    • Parameters

      Returns boolean

      Returns true if Agents 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

      0.1.3

    • Removes all Agents from the Network.

      const network = new Network();
      network.addAgent(new Agent());
      network.size(); // returns 1

      network.clear();
      network.size(); // returns 0

      Returns void

      0.2.1

    • Draw a connection between every pair of Agents in the Network.

      Returns void

      0.1.3

    • Attempts to create a connection between Agents a and b.

      Parameters

      Returns boolean

      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.

      0.1.3

    • Attempts to sever the connection between Agents a and b.

      Parameters

      Returns boolean

      Returns true if the Agents 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

      0.1.3

    • Loop over all the Agents in the Network (in the order they were added), and invoke the callback function with the Agent and an index passed as parameters.

      Parameters

      • callback: (agent: Agent, index: number) => any

      Returns void

      0.1.3

    • The same method as forEach, but executes in random order.

      Parameters

      • callback: (agent: Agent, index: number) => any

      Returns void

      0.1.3

    • Returns the Agent at index i, where i = 0 is the first Agent added to the Network, i = 1 the second, etc.

      Negative indices are allowed, so network.get(-1) returns the Agent that was most recently added to the Network, -2 the second-most recent, etc.

      Parameters

      • i: number

      Returns Agent

      0.1.3

    • Returns true if Agents a, b, and c form a 'closed triplet' — if each of the three are connected to the other two. Returns false otherwise.

      Parameters

      Returns boolean

      0.5.17

    • Returns true if the given Agent is in the Network, false if it is not.

      Parameters

      Returns boolean

      0.1.3

    • Returns true if Agents a, b, and c form a 'triplet' — if (at least) one of the three is connected to the other two. Returns false otherwise.

      Parameters

      Returns boolean

      0.5.17

    • Returns an array of Agents 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]

      Parameters

      Returns Agent[]

      0.1.3

    • 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`

      Parameters

      Returns boolean

      Returns true if the agent was successfully removed.

      Returns false if the agent was not in the network to begin with.

      0.1.3

    • Returns number

      Returns the number of Agents 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

      0.1.3