The AgentSimulation project is a Java-based simulation framework designed to model the behavior of social and anti-social agents in a 3D landscape. The project allows for the exploration of how different parameters such as agent count, social radius, and social count influence the movement and interaction of agents within a defined space.
- Agent Types: Supports two types of agents -
SocialAgentandAntiSocialAgent. - Landscape: A 3D grid-based landscape where agents can move and interact.
- Simulation: Runs multiple simulations with varying parameters to study agent behavior.
- Visualization: Generates line charts to visualize the results of the simulations.
- Agent: Abstract base class for all agents. Defines common properties and methods.
- SocialAgent: A type of agent that moves if it has fewer neighbors than its social count.
- AntiSocialAgent: A type of agent that moves if it has more neighbors than its social count.
- Landscape: Manages the 3D grid and the agents within it. Provides methods to add agents, get neighbors, and update the state of agents.
- AgentSimulation: The main class that orchestrates the simulation. It runs multiple experiments with different parameters and generates charts to visualize the results.
-
Clone the Repository: Ensure you have the project files on your local machine.
-
Compile the Code: Use a Java compiler to compile all the
.javafiles.javac *.java -
Run the Simulation: Execute the
AgentSimulationclass.java AgentSimulation
-
View Results: The simulation will generate charts in the
chartsdirectory. These charts visualize the minimum, maximum, and average iterations for different combinations of parameters.
- Width, Height, Depth: Dimensions of the 3D landscape.
- Social Radius: The radius within which a social agent considers other agents as neighbors.
- Anti Radius: The radius within which an anti-social agent considers other agents as neighbors.
- Social Count: The threshold number of neighbors that determine the movement of social and anti-social agents.
-
Agent Movement (
updateStatemethod):- SocialAgent/AntiSocialAgent: The time complexity is
O(N), whereNis the number of neighbors within the radius. This is because the method iterates over all neighbors to count them.
- SocialAgent/AntiSocialAgent: The time complexity is
-
Landscape Neighbor Search (
getNeighborsmethod):- The time complexity is
O(1)for accessing the grid cell, butO(M)for checking agents within the cell, whereMis the number of agents in the cell. Since the grid size is proportional to the radius, the overall complexity isO(M).
- The time complexity is
-
Simulation (
runExperimentsmethod):- The time complexity is
O(T * S * A), whereTis the number of trials,Sis the number of social agent positions, andAis the number of anti-social agent positions. This is because the method runs multiple experiments for each combination of agent positions.
- The time complexity is
-
Combination Generation (
generateCombinationsmethod):- The time complexity is
O(C(n, k)), wherenis the total number of coordinates andkis the number of agents. This is because the method generates all possible combinations of sizekfromncoordinates.
- The time complexity is
-
Agent Storage:
- The space complexity is
O(N), whereNis the total number of agents in the landscape.
- The space complexity is
-
Grid Storage:
- The space complexity is
O(G), whereGis the number of grid cells. Each cell stores a list of agents, so the overall space complexity isO(G * M), whereMis the average number of agents per cell.
- The space complexity is
-
Simulation Data:
- The space complexity is
O(T * S * A)for storing the results of all experiments, whereTis the number of trials,Sis the number of social agent positions, andAis the number of anti-social agent positions.
- The space complexity is
submit different landscapes to different processors and iterate over social and antiSocial radius and social and antiSocial counts:
public static void main(String[] args) {
try (ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())) {
for (int width = 1; width < SIDE_LENGTH; width++) {
for (int height = 1; height < width; height++) {
for (int depth = 1; depth < height; depth++) {
Landscape scape = new Landscape(width, height, depth);
int finalVolume = width * height * depth;
int finalMaxRadius = (int) (Math.cbrt(finalVolume) / 2);
executor.submit(() -> {
for (double socialRadius = 1; socialRadius < finalMaxRadius; socialRadius += 0.25) {
for (double antiRadius = 1; antiRadius < finalMaxRadius; antiRadius += 0.25) {
for (int socialSocialCount = 1; socialSocialCount < finalVolume; socialSocialCount++) {
for (int antiSocialCount = 1; antiSocialCount < finalVolume; antiSocialCount++) {
processCombination(scape, finalVolume, socialRadius, antiRadius, socialSocialCount, antiSocialCount);
}
}
}
}
} );
}
}
}
executor.shutdown(); // make sure executor services are shut down, while try with resources statement automatically shuts down executor services
}
}The simulation generates PNG images of line charts in the charts directory. Each chart represents the results of a specific combination of parameters, showing the minimum, maximum, and average iterations required for the agents to stabilize.
- Java 8 or higher
java.awtfor graphics and visualizationjavax.swingfor chart panel creationjava.util.concurrentfor managing simulation threads
Contributions are welcome! Please fork the repository and submit a pull request with your changes
For any questions or suggestions, please contact the project maintainer at txiao28@colby.edu or xtp20210316@163.com