agentjs-core
Version:
A comprehensive agent-based modeling framework with built-in p5.js visualization
166 lines • 5.03 kB
TypeScript
/**
* NetworkManager - Social network management system
*/
import { EventEmitter } from 'eventemitter3';
import type { AgentId } from '../../types/core';
/** Connection types in the social network */
export declare enum ConnectionType {
SUPPORTIVE = "supportive",// Positive influence, mutual benefit
EXPLOITATIVE = "exploitative",// One-sided benefit, negative influence
ECONOMIC = "economic"
}
/** Represents a connection between two agents */
export interface NetworkConnection {
readonly id: string;
readonly source: AgentId;
readonly target: AgentId;
readonly type: ConnectionType;
weight: number;
readonly createdAt: number;
lastInteraction: number;
metadata: Record<string, any>;
}
/** Network formation configuration */
export interface NetworkConfig {
readonly maxConnections: number;
readonly connectionDecayRate: number;
readonly minConnectionWeight: number;
readonly enableAutoDecay: boolean;
readonly proximityRadius: number;
readonly similarityThreshold: number;
}
/** Network analysis result */
export interface NetworkAnalysis {
readonly nodeCount: number;
readonly edgeCount: number;
readonly averageDegree: number;
readonly density: number;
readonly clustering: number;
readonly components: number;
}
/** Path finding result */
export interface PathResult {
readonly found: boolean;
readonly path: AgentId[];
readonly distance: number;
readonly hops: number;
}
/**
* NetworkManager - Manages social networks between agents
*
* Features:
* - Weighted, directed graph representation
* - Multiple connection types with different behaviors
* - Dynamic network formation and dissolution
* - Social influence propagation
* - Network analysis and pathfinding
* - Connection lifecycle management
*
* Educational Context: Simulates social dynamics in
* communities, allowing modeling of support networks,
* economic relationships, and social influence patterns.
*/
export declare class NetworkManager extends EventEmitter {
/** Adjacency list representation of the network */
private readonly adjacencyList;
/** Quick lookup for connections by ID */
private readonly connections;
/** Reverse index for incoming connections */
private readonly incomingConnections;
/** Network configuration */
private config;
/** Connection ID counter */
private connectionIdCounter;
/** Network statistics cache */
private statsCache;
constructor(config?: Partial<NetworkConfig>);
/**
* Add a connection between two agents
*/
addConnection(source: AgentId, target: AgentId, type: ConnectionType, weight?: number, metadata?: Record<string, any>): NetworkConnection | null;
/**
* Remove a connection
*/
removeConnection(connectionId: string): boolean;
/**
* Get all connections for an agent
*/
getConnections(agentId: AgentId): ReadonlyArray<NetworkConnection>;
/**
* Get incoming connections for an agent
*/
getIncomingConnections(agentId: AgentId): ReadonlyArray<NetworkConnection>;
/**
* Check if connection exists between agents
*/
hasConnection(source: AgentId, target: AgentId): boolean;
/**
* Get connection between two agents
*/
getConnection(source: AgentId, target: AgentId): NetworkConnection | undefined;
/**
* Update connection weight
*/
updateConnectionWeight(connectionId: string, delta: number): boolean;
/**
* Strengthen connection based on interaction
*/
strengthenConnection(source: AgentId, target: AgentId, amount?: number): boolean;
/**
* Weaken connection
*/
weakenConnection(source: AgentId, target: AgentId, amount?: number): boolean;
/**
* Apply decay to all connections
*/
applyDecay(): void;
/**
* Get agent degree (number of connections)
*/
getDegree(agentId: AgentId): {
in: number;
out: number;
total: number;
};
/**
* Find shortest path between agents (BFS)
*/
findPath(source: AgentId, target: AgentId): PathResult;
/**
* Get network statistics
*/
getNetworkAnalysis(): NetworkAnalysis;
/**
* Get total number of connections in the network
*/
getConnectionCount(): number;
/**
* Count connected components
*/
private countComponents;
/**
* DFS visit for component counting
*/
private dfsVisit;
/**
* Clear all connections
*/
clear(): void;
/**
* Get current configuration
*/
getConfig(): NetworkConfig;
/**
* Update configuration
*/
updateConfig(newConfig: Partial<NetworkConfig>): void;
/**
* Get all connections in the network
*/
getAllConnections(): ReadonlyArray<NetworkConnection>;
/**
* Get connection by ID
*/
getConnectionById(id: string): NetworkConnection | undefined;
}
//# sourceMappingURL=NetworkManager.d.ts.map