The code base for my Bachelor's thesis at Heidelberg University. The files in the topmost directory are used to run "regular" agent based PPM simulations. The more interesting parts are "hidden" in the actor-critic directory.
The PDF of the thesis can be found here.
Important files:
ABM.py
: grid environment and agents for the simulationsimulation.py
: the script to run the simulationsimconfig.yml
: the yamlfile to configure the simulation, e.g. gridsize etc.
To run a simulation, make sure that simulation.py
and simconfig.yml
are in the same directory and that a directory called plots
exists. Then invoke
python3 simulation.py
because the simconfig file will be read in automatically.
Important files in actor-critic subdirectory:
actor_critic.py
: the policy classes as well as the means for action-selection and training the network (finish episode)agents.py
:Agent
base-class, andPredator
andPrey
classes which inherit fromAgent
, as well as theOrientedPredator
andOrientedPrey
classes.environment.py
:Environment
base-class, and theGridPPM
andGridOrientedPPM
classes that inherit from the base class. The environments provide all the interactions between agents, as well as the initial population of a grid. They also provide methods to run a simulation likereset
,step
andrender
.simulation.py
: script to run the simulation; takes two optional arguments:--config <configfile.yml>
and--resume <simulation_snapshot.pth.tar>
, where the latter resumes from a certain point during training. The frequency of snapshot outputs can be set in the configuration file.tools.py
: a collection of tools used for the simulation, like a input check for the internal functions, or a keyboard interrupt handler (very useful :D)rcParams.yml
: a small file to specify some arguments for matplotlib to make plots look nicersimulation_config.yml
: the acutal simulation config file. specifies things like gridsize, densities, rewards for the agents, sizes of layer in the NN (but not their topology), whether a gpu or cpu should be used..simulation_oriented.py
: the script to run the oriented agent simulation, takes the same arguments as abovesimulation_oriented_config.yml
: configuration file for the oriented PPM simulation; has additional parameters, hence the new file
Additional files are:
environment_slow_fR_decrease.py
: a version of the environment with a smaller decrease in foodreserve per turn, unfortunately hardcoded in the file. this issue was fixed in the orientedPPM versionsimulation_slow_fR_decrease.py
: needed because the different environment file must be loaded initially
To run a simulation, invoke
python3 simulation_oriented.py --config simulation_oriented_config.yml
The location of the plots can be specified in the config file.
The output are png files of the grid configurations, and additionally every N episodes a .pth.tar
snapshot containing the current NN weights, and more simulation data like rewards, population sizes, etc.