Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Network

A Network allows Agents to be connected to each other.

since

0.1.3

Hierarchy

  • Network

Implements

  • EnvironmentHelper

Index

Constructors

constructor

Properties

agents

agents: Agent[] = ...

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

Methods

addAgent

  • addAgent(agent: Agent): boolean
  • Add an agent to the network.

    since

    0.1.3

    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`
    

addFromEnvironment

  • 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)));)

    since

    0.2.1

    Parameters

    Returns void

areConnected

  • since

    0.1.3

    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
    

averageClusteringCoefficient

  • averageClusteringCoefficient(): number

clear

  • clear(): void
  • Removes all Agents from the Network.

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

    0.2.1

    Returns void

clusteringCoefficient

  • clusteringCoefficient(agent?: Agent): number

complete

  • complete(): void

connect

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

    since

    0.1.3

    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.

disconnect

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

    since

    0.1.3

    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
    

forEach

  • forEach(callback: (agent: Agent, index: number) => any): void
  • 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.

    since

    0.1.3

    Parameters

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

          • agent: Agent
          • index: number

          Returns any

    Returns void

forEachRand

  • forEachRand(callback: (agent: Agent, index: number) => any): void
  • The same method as forEach, but executes in random order.

    since

    0.1.3

    Parameters

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

          • agent: Agent
          • index: number

          Returns any

    Returns void

get

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

    since

    0.1.3

    Parameters

    • i: number

    Returns Agent

indexOf

  • indexOf(agent: Agent): number

isClosedTriplet

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

    since

    0.5.17

    Parameters

    Returns boolean

isInNetwork

  • isInNetwork(agent: Agent): boolean

isTriplet

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

    since

    0.5.17

    Parameters

    Returns boolean

neighbors

  • 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]
    
    since

    0.1.3

    Parameters

    Returns Agent[]

removeAgent

  • removeAgent(agent: Agent): boolean
  • 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`
    
    since

    0.1.3

    Parameters

    Returns boolean

    Returns true if the agent was successfully removed.

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

size

  • size(): number
  • since

    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
    

Generated using TypeDoc