Repository navigation
PredatorPrey_step11
RoiArthurB edited this page Jul 30, 2026
·
6 revisions
This 11th step illustrates how to save data in a text file.
- At each simulation step, write in a text file:
- The time step
- The number of prey and predator agents
- The min and max energy of the prey and predator agents
The main way to write data inside a file is to use the save statement:
save my_data format: file_type to: file_name;
With:
-
my_data: depends on the data to save and of the type of file -
file_type: string -
file_name: string
There are 3 main possible types:
-
shp(shapefile - GIS data): in that case,my_datais treated as a list of agents or geometries: all their geometries are saved in the file (with some variables as attributes), -
txt(text): in that case,my_datais treated as a string, which is written directly in the file, -
csv: in that case,my_datais treated as a list of values: [val1, val2, val3], that will be written in the file, separated by the,separator.
We use this statement (in a global reflex called save_result) to write:
- The cycle step: use of the
cyclekeyword that returns the current simulation step. - The number of prey and predator agents: use of
nb_preysandnb_predatorsvariables. - The min and max energy of the prey and predator agents: use of
list min_of expressionandlist max_of expressionkeywords.
reflex save_result when: (nb_preys > 0) and (nb_predators > 0){
save ("cycle: "+ cycle + "; nbPreys: " + nb_preys
+ "; minEnergyPreys: " + (prey min_of each.energy)
+ "; maxSizePreys: " + (prey max_of each.energy)
+ "; nbPredators: " + nb_predators
+ "; minEnergyPredators: " + (predator min_of each.energy)
+ "; maxSizePredators: " + (predator max_of each.energy))
to: "results.txt" type: "text" rewrite: (cycle = 0) ? true : false;
}
https://github.com/gama-platform/gama/blob/main/gama.library/tutorials/Predator%20Prey/models/Model%2011.gaml
- Installation and Launching
- Workspace, Projects and Models
- Editing Models
- Running Experiments
- Running Headless
- Exporting Projects As Simulation Launchers
- Preferences
- Troubleshooting
- Introduction
- Manipulate basic Species
- Global Species
- Defining Advanced Species
- Defining GUI Experiment
- Classes and Objects
- Exploring Models
- Optimizing Models
- Multi-Paradigm Modeling
- Manipulate OSM Data
- Cleaning OSM Data
- Diffusion
- Using Database
- Using Dataframes
- Using FIPA ACL
- Using BDI with BEN
- Using Driving Skill
- Manipulate dates
- Manipulate lights
- Using comodel
- Save and restore Simulations
- Using network
- Writing Unit Tests
- Ensure model's reproducibility
- Going further with extensions
- Built-in Species
- Built-in Skills
- Built-in Architecture
- Statements
- Data Type
- File Type
- Stats Extension
- Sound Extension
- BDI Extension
- FIPA Skill
- Expressions
- Exhaustive list of GAMA Keywords
- Installing the development version
- Developing Extensions
- Introduction to GAMA Java API
- Using GAMA flags
- Export plugin : Technical Documentation
- Creating a release of GAMA
- Documentation generation
- Predator Prey
- Road Traffic
- Incremental Model
- Luneray's flu
- BDI Agents
- Forager RL
- SIR Analysis
- 3D Model