Class SwarmEnvironment
java.lang.Object
com.tnsai.coordination.groups.swarm.SwarmEnvironment
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 Summary
ConstructorsConstructorDescriptionCreates a new environment with default decay rate.SwarmEnvironment(double decayRate) Creates a new environment with specified decay rate. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears everything.voidClears all data.voidClears all pheromones.booleanChecks if key exists.voidApplies decay to all pheromones.voiddepositPheromone(String location, PheromoneType type, double intensity) Deposits pheromone at a location.Gets a value from the environment.<T> Optional<T> Gets a typed value from the environment.getAll()Gets all data in the environment.doubleGets the decay rate.doublegetPheromoneIntensity(String location, PheromoneType type) Gets pheromone intensity at a location.Gets all locations with pheromones.getPheromonesAt(String location) Gets all pheromones at a location.getStats()Gets environment statistics.voidStores a value in the environment.Removes a value from the environment.
-
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
Stores a value in the environment.- Parameters:
key- keyvalue- value
-
get
Gets a value from the environment.- Parameters:
key- key- Returns:
- value or null
-
get
Gets a typed value from the environment.- Type Parameters:
T- value type- Parameters:
key- keytype- expected type- Returns:
- optional value
-
remove
Removes a value from the environment.- Parameters:
key- key- Returns:
- removed value
-
contains
Checks if key exists.- Parameters:
key- key- Returns:
- true if exists
-
getAll
Gets all data in the environment.- Returns:
- copy of all data
-
clearData
public void clearData()Clears all data. -
depositPheromone
Deposits pheromone at a location.- Parameters:
location- location identifiertype- pheromone typeintensity- intensity to add (0.0 to 1.0)
-
getPheromoneIntensity
Gets pheromone intensity at a location.- Parameters:
location- locationtype- pheromone type- Returns:
- intensity (0.0 to 1.0)
-
getPheromonesAt
Gets all pheromones at a location.- Parameters:
location- location- Returns:
- map of types to intensities
-
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
Gets environment statistics.- Returns:
- stats map
-