Class DefaultSwarm

java.lang.Object
com.tnsai.coordination.groups.DefaultAgentGroup
com.tnsai.coordination.groups.swarm.DefaultSwarm
All Implemented Interfaces:
com.tnsai.agents.groups.AgentGroup, Swarm

public class DefaultSwarm extends DefaultAgentGroup implements Swarm
Default implementation of Swarm.

Provides decentralized agent coordination with:

  • Pheromone-based indirect communication
  • Configurable neighbor detection
  • Multiple swarm intelligence algorithms
  • Automatic tick-based updates
  • Constructor Details

    • DefaultSwarm

      public DefaultSwarm(String id, String name, String description, SwarmBehavior behavior, SwarmIntelligence intelligence, NeighborDetection neighborDetection, int neighborRadius, double pheromoneDecay, com.tnsai.agents.groups.GroupPolicy policy)
      Creates a new DefaultSwarm.
      Parameters:
      id - swarm ID
      name - swarm name
      description - description
      behavior - initial behavior
      intelligence - intelligence algorithm
      neighborDetection - neighbor detection strategy
      neighborRadius - neighbor radius
      pheromoneDecay - pheromone decay rate
      policy - group policy
  • Method Details

    • getBehavior

      public SwarmBehavior getBehavior()
      Description copied from interface: Swarm
      Gets the current swarm behavior.
      Specified by:
      getBehavior in interface Swarm
      Returns:
      behavior type
    • setBehavior

      public void setBehavior(SwarmBehavior behavior)
      Description copied from interface: Swarm
      Sets the swarm behavior.
      Specified by:
      setBehavior in interface Swarm
      Parameters:
      behavior - new behavior
    • getIntelligence

      public SwarmIntelligence getIntelligence()
      Description copied from interface: Swarm
      Gets the swarm intelligence strategy.
      Specified by:
      getIntelligence in interface Swarm
      Returns:
      intelligence strategy
    • getNeighborDetection

      public NeighborDetection getNeighborDetection()
      Description copied from interface: Swarm
      Gets the neighbor detection strategy.
      Specified by:
      getNeighborDetection in interface Swarm
      Returns:
      neighbor detection
    • depositPheromone

      public void depositPheromone(String location, PheromoneType type, double intensity)
      Description copied from interface: Swarm
      Deposits a pheromone at the specified location.

      Pheromones are indirect signals that influence other swarm members' behavior.

      Specified by:
      depositPheromone in interface Swarm
      Parameters:
      location - location identifier
      type - pheromone type
      intensity - signal strength (0.0 to 1.0)
    • getPheromoneIntensity

      public double getPheromoneIntensity(String location, PheromoneType type)
      Description copied from interface: Swarm
      Gets the pheromone intensity at a location.
      Specified by:
      getPheromoneIntensity in interface Swarm
      Parameters:
      location - location identifier
      type - pheromone type
      Returns:
      intensity (0.0 to 1.0)
    • getPheromonesAt

      public Map<PheromoneType,Double> getPheromonesAt(String location)
      Description copied from interface: Swarm
      Gets all pheromones at a location.
      Specified by:
      getPheromonesAt in interface Swarm
      Parameters:
      location - location identifier
      Returns:
      map of pheromone types to intensities
    • getPheromoneDecay

      public double getPheromoneDecay()
      Description copied from interface: Swarm
      Gets the pheromone decay rate.
      Specified by:
      getPheromoneDecay in interface Swarm
      Returns:
      decay rate per tick
    • decayPheromones

      public void decayPheromones()
      Description copied from interface: Swarm
      Triggers pheromone decay across all locations.
      Specified by:
      decayPheromones in interface Swarm
    • getNeighbors

      public List<com.tnsai.agents.Agent> getNeighbors(String agentId)
      Description copied from interface: Swarm
      Gets neighbors of an agent within detection radius.
      Specified by:
      getNeighbors in interface Swarm
      Parameters:
      agentId - agent to check
      Returns:
      list of neighboring agents
    • getNeighborRadius

      public int getNeighborRadius()
      Description copied from interface: Swarm
      Gets the neighbor detection radius.
      Specified by:
      getNeighborRadius in interface Swarm
      Returns:
      radius (interpretation depends on detection strategy)
    • setNeighborRadius

      public void setNeighborRadius(int radius)
      Description copied from interface: Swarm
      Sets the neighbor detection radius.
      Specified by:
      setNeighborRadius in interface Swarm
      Parameters:
      radius - new radius
    • explore

      public SwarmResult explore(String task)
      Description copied from interface: Swarm
      Executes a collective exploration task.

      Agents spread out and share discoveries via pheromones.

      Specified by:
      explore in interface Swarm
      Parameters:
      task - exploration task
      Returns:
      collective result
    • explore

      public SwarmResult explore(String task, Map<String,Object> context)
      Description copied from interface: Swarm
      Executes a collective exploration task with context.
      Specified by:
      explore in interface Swarm
      Parameters:
      task - exploration task
      context - additional context
      Returns:
      collective result
    • solve

      public SwarmResult solve(String problem)
      Description copied from interface: Swarm
      Executes a collective optimization/solving task.

      Agents collaborate using swarm intelligence algorithms.

      Specified by:
      solve in interface Swarm
      Parameters:
      problem - problem description
      Returns:
      optimized solution
    • solve

      public SwarmResult solve(String problem, Map<String,Object> context)
      Description copied from interface: Swarm
      Executes a collective optimization with context.
      Specified by:
      solve in interface Swarm
      Parameters:
      problem - problem description
      context - additional context
      Returns:
      optimized solution
    • exploreAsync

      public CompletableFuture<SwarmResult> exploreAsync(String task)
      Description copied from interface: Swarm
      Async exploration.
      Specified by:
      exploreAsync in interface Swarm
      Parameters:
      task - exploration task
      Returns:
      future result
    • solveAsync

      public CompletableFuture<SwarmResult> solveAsync(String problem)
      Description copied from interface: Swarm
      Async solving.
      Specified by:
      solveAsync in interface Swarm
      Parameters:
      problem - problem description
      Returns:
      future result
    • getState

      public SwarmState getState()
      Description copied from interface: Swarm
      Gets current swarm state snapshot.
      Specified by:
      getState in interface Swarm
      Returns:
      swarm state
    • getEnvironment

      public SwarmEnvironment getEnvironment()
      Description copied from interface: Swarm
      Gets the shared environment/blackboard.
      Specified by:
      getEnvironment in interface Swarm
      Returns:
      shared environment
    • tick

      public void tick()
      Description copied from interface: Swarm
      Triggers one swarm tick (update cycle).

      During a tick:

      • Pheromones decay
      • Agents update positions
      • Neighbors are recalculated
      • Behaviors are executed
      Specified by:
      tick in interface Swarm
    • run

      public void run(Duration duration, Duration tickInterval)
      Description copied from interface: Swarm
      Runs the swarm for specified duration.
      Specified by:
      run in interface Swarm
      Parameters:
      duration - how long to run
      tickInterval - time between ticks
    • stop

      public void stop()
      Description copied from interface: Swarm
      Stops the swarm execution.
      Specified by:
      stop in interface com.tnsai.agents.groups.AgentGroup
      Specified by:
      stop in interface Swarm
      Overrides:
      stop in class DefaultAgentGroup
    • isRunning

      public boolean isRunning()
      Description copied from interface: Swarm
      Checks if swarm is currently running.
      Specified by:
      isRunning in interface Swarm
      Returns:
      true if running
    • toString

      public String toString()
      Overrides:
      toString in class DefaultAgentGroup