agentjs-core
Version:
A comprehensive agent-based modeling framework with built-in p5.js visualization
165 lines • 4.85 kB
TypeScript
/**
* NetworkAgent - Agent with connection and relationship management
*/
import { BaseAgent } from './BaseAgent';
import type { Agent } from './Agent';
import type { AgentId, Position, AgentProperties } from '../../types/core';
/** Connection between agents */
export interface Connection {
readonly target: Agent;
readonly type: string;
readonly strength: number;
readonly createdAt: number;
readonly lastInteraction: number;
readonly metadata: Record<string, any>;
}
/** Network statistics */
export interface NetworkStats {
readonly connectionCount: number;
readonly strongConnections: number;
readonly weakConnections: number;
readonly averageStrength: number;
readonly mostConnectedAgent: AgentId | null;
readonly clusteringCoefficient: number;
}
/**
* NetworkAgent - Agent with social network capabilities
*
* Features:
* - Connection management with other agents
* - Relationship types and strength tracking
* - Network topology analysis
* - Information flow and influence modeling
*
* Educational Context: Represents community members who
* form social networks, influence relationships, and
* participate in information sharing and collective behaviors.
*/
export declare class NetworkAgent extends BaseAgent {
/** Outgoing connections to other agents */
protected connections: Map<AgentId, Connection>;
/** Incoming connections from other agents (for efficient lookup) */
protected incomingConnections: Set<AgentId>;
/** Network influence value */
protected influence: number;
/** Trust values for other agents */
protected trustLevels: Map<AgentId, number>;
constructor(id?: string | AgentId, initialProperties?: AgentProperties, initialPosition?: Position);
/**
* Basic step - can be overridden for network-specific behaviors
*/
step(): void;
/**
* Create connection to another agent
*/
connect(target: Agent, type?: string, strength?: number, metadata?: Record<string, any>): void;
/**
* Remove connection to another agent
*/
disconnect(target: Agent): boolean;
/**
* Check if connected to another agent
*/
isConnectedTo(target: Agent): boolean;
/**
* Get connection to specific agent
*/
getConnection(target: Agent): Connection | undefined;
/**
* Get all connections
*/
getAllConnections(): ReadonlyArray<Connection>;
/**
* Get connections of specific type
*/
getConnectionsByType(type: string): ReadonlyArray<Connection>;
/**
* Get connection count
*/
getConnectionCount(): number;
/**
* Get strong connections (strength > 0.7)
*/
getStrongConnections(): ReadonlyArray<Connection>;
/**
* Get weak connections (strength <= 0.3)
*/
getWeakConnections(): ReadonlyArray<Connection>;
/**
* Update connection strength
*/
updateConnectionStrength(target: Agent, newStrength: number): void;
/**
* Strengthen connection through interaction
*/
strengthenConnection(target: Agent, amount?: number): void;
/**
* Weaken connection
*/
weakenConnection(target: Agent, amount?: number): void;
/**
* Set trust level for another agent
*/
setTrust(target: Agent, trust: number): void;
/**
* Get trust level for another agent
*/
getTrust(target: Agent): number;
/**
* Get network influence
*/
getInfluence(): number;
/**
* Set network influence
*/
setInfluence(influence: number): void;
/**
* Get network neighbors (connected agents)
*/
getNeighbors(): ReadonlyArray<Agent>;
/**
* Get neighbors within a certain trust threshold
*/
getTrustedNeighbors(minTrust?: number): ReadonlyArray<Agent>;
/**
* Calculate network statistics
*/
getNetworkStats(): NetworkStats;
/**
* Add incoming connection reference
*/
addIncomingConnection(fromAgent: AgentId): void;
/**
* Remove incoming connection reference
*/
removeIncomingConnection(fromAgent: AgentId): void;
/**
* Get incoming connection count
*/
getIncomingConnectionCount(): number;
/**
* Calculate degree centrality (total connections)
*/
getDegreeCentrality(): number;
/**
* Decay connection strengths over time
*/
private decayConnections;
/**
* Update influence based on network position
*/
private updateInfluence;
/**
* Calculate clustering coefficient
*/
private calculateClusteringCoefficient;
/**
* Find the most connected neighbor
*/
private findMostConnectedNeighbor;
/**
* Emit connection event
*/
private emitConnectionEvent;
}
//# sourceMappingURL=NetworkAgent.d.ts.map