Class SwarmEnvironment

java.lang.Object
com.tnsai.coordination.groups.swarm.SwarmEnvironment

public class SwarmEnvironment extends Object
Shared environment for swarm coordination.

SwarmEnvironment provides a shared space where agents can:

  • Store and retrieve data
  • Deposit and sense pheromones
  • Communicate indirectly (stigmergy)

Thread-safe for concurrent access by multiple agents.

  • Constructor Details

    • SwarmEnvironment

      public SwarmEnvironment()
      Creates a new environment with default decay rate.
    • SwarmEnvironment

      public SwarmEnvironment(double decayRate)
      Creates a new environment with specified decay rate.
      Parameters:
      decayRate - pheromone decay rate per tick (0.0 to 1.0)
  • Method Details

    • put

      public void put(String key, Object value)
      Stores a value in the environment.
      Parameters:
      key - key
      value - value
    • get

      public Object get(String key)
      Gets a value from the environment.
      Parameters:
      key - key
      Returns:
      value or null
    • get

      public <T> Optional<T> get(String key, Class<T> type)
      Gets a typed value from the environment.
      Type Parameters:
      T - value type
      Parameters:
      key - key
      type - expected type
      Returns:
      optional value
    • remove

      public Object remove(String key)
      Removes a value from the environment.
      Parameters:
      key - key
      Returns:
      removed value
    • contains

      public boolean contains(String key)
      Checks if key exists.
      Parameters:
      key - key
      Returns:
      true if exists
    • getAll

      public Map<String,Object> getAll()
      Gets all data in the environment.
      Returns:
      copy of all data
    • clearData

      public void clearData()
      Clears all data.
    • depositPheromone

      public void depositPheromone(String location, PheromoneType type, double intensity)
      Deposits pheromone at a location.
      Parameters:
      location - location identifier
      type - pheromone type
      intensity - intensity to add (0.0 to 1.0)
    • getPheromoneIntensity

      public double getPheromoneIntensity(String location, PheromoneType type)
      Gets pheromone intensity at a location.
      Parameters:
      location - location
      type - pheromone type
      Returns:
      intensity (0.0 to 1.0)
    • getPheromonesAt

      public Map<PheromoneType,Double> getPheromonesAt(String location)
      Gets all pheromones at a location.
      Parameters:
      location - location
      Returns:
      map of types to intensities
    • getPheromoneLocations

      public Set<String> getPheromoneLocations()
      Gets all locations with pheromones.
      Returns:
      set of locations
    • decayPheromones

      public void decayPheromones()
      Applies decay to all pheromones.
    • clearPheromones

      public void clearPheromones()
      Clears all pheromones.
    • getDecayRate

      public double getDecayRate()
      Gets the decay rate.
      Returns:
      decay rate
    • clear

      public void clear()
      Clears everything.
    • getStats

      public Map<String,Object> getStats()
      Gets environment statistics.
      Returns:
      stats map