agentscape
Version:
Agentscape is a library for creating agent-based simulations. It provides a simple API for defining agents and their behavior, and for defining the environment in which the agents interact. Agentscape is designed to be flexible and extensible, allowing
60 lines (59 loc) • 2.84 kB
TypeScript
export declare class GraphEdge<T, V> {
source: GraphNode<T, V>;
target: GraphNode<T, V>;
weight?: number;
context?: V;
constructor(source: GraphNode<T, V>, target: GraphNode<T, V>, weight?: number, context?: V);
get reverse(): GraphEdge<T, V>;
}
export declare class GraphNode<T, V> {
id: number;
edges: Set<GraphEdge<T, V>>;
context?: T;
constructor(id: number, context?: T);
get degree(): number;
get neighbors(): GraphNode<T, V>[];
addEdge(target: GraphNode<T, V>, weight?: number, context?: V): void;
removeEdge(target: GraphNode<T, V>): void;
hasEdge(target: GraphNode<T, V>): boolean;
getEdge(target: GraphNode<T, V>): GraphEdge<T, V> | undefined;
}
export default class Graph<T, V> {
nodes: Map<number, GraphNode<T, V>>;
static fromNodes<T, V>(nodes: GraphNode<T, V>[]): Graph<T, V>;
[Symbol.iterator](): Generator<[number, GraphNode<T, V>], void, unknown>;
forEachNode(callback: (node: GraphNode<T, V>, i: number) => void): void;
forEachEdge(callback: (edge: GraphEdge<T, V>, i: number) => void): void;
nodeCount(): number;
edgeCount(): number;
asArray(): GraphNode<T, V>[];
createNode(id: number, context?: T): GraphNode<T, V>;
addNode(node: GraphNode<T, V>): GraphNode<T, V>;
getNode(id: number): GraphNode<T, V> | undefined;
hasNode(id: number): boolean;
createEdge(source: GraphNode<T, V>, target: GraphNode<T, V>, weight?: number, context?: V): void;
removeEdge(source: GraphNode<T, V>, target: GraphNode<T, V>): void;
hasEdge(source: GraphNode<T, V>, target: GraphNode<T, V>): boolean;
getEdge(source: GraphNode<T, V>, target: GraphNode<T, V>): GraphEdge<T, V> | undefined;
getEdgesFromNode(node: GraphNode<T, V>): GraphEdge<T, V>[];
getEdgesToNode(node: GraphNode<T, V>): GraphEdge<T, V>[];
adjacencyMatrix(): number[][];
/**
* Gives the connectivity metrics of the graph.
*
* **Alpha**: The higher the alpha index, the more a network is connected. Trees and simple networks will have a value of 0. A value of 1 indicates a completely connected network.
*
* **Beta**: Trees and simple networks have Beta value of less than one. A connected network with one cycle has a value of 1.
*
* **Gamma**: Considers the relationship between the number of observed links and the number of possible links. The value of gamma is between 0 and 1 where a value of 1 indicates a completely connected network.
*/
getConnectivityMetrics(): {
alpha: number;
beta: number;
gamma: number;
};
/**
* Returns the shortest path between two nodes in the graph using Dijkstra's algorithm.
*/
shortestPath(source: GraphNode<T, V>, target: GraphNode<T, V>, metric?: (edge: GraphEdge<T, V>) => number): GraphNode<T, V>[];
}