Agricultural Markets Simulator
Overview
My role: System design through delivery.
Challenge: Build out and document an economic simulation system for a European university, then move it to a modern web UI
Solution: Reverse engineered the existing code and documented it for publication, then built new functionality for the simulation and the user interface
Impact: Enabled published research funded by the Deutsche Forschungsgemeinschaft (DFG).
Technologies: Java + Swing, then Quarkus, React and Plotly, GraalVM native image, Azure code signing
Produce and Consume
The system allows the simulation of agricultural markets used in a research program of a European university supported by the Deutsche Forschungsgemeinschaft. Agents, producers and consumers interact on the market. Their behaviours can be adjusted and the overall market behaviour observed. Shocks can be introduced to analyse the impact of extrinsic and intrinsic factor changes.
Simulation systems that can be actually used in a research context are fairly complex, in particular, repeatability and randomness need to be reconciled: the system must exhibit random behaviours (within limits) by the agents, but the overall experiment must be repeatable by researchers.
As such, the system must produce detailed logs of states and transitions so that the outcomes can be both analysed and verified.
Delivery and Technical Approach
The existing system required extensive reverse engineering: data structures, decision logic, configuration management, user interface, and the end-to-end simulation workflow. Large parts of the internal logic and structures were rewritten as part of making the system maintainable and publishable.
Repeatability and Configuration
Repeatability was ensured by keeping the same core Java libraries and deterministic seeding. Configuration was integral to the results: a simulation run and its configuration form a single package. Changing the configuration invalidates the results.
Modernising the UI
The original Java Swing UI was replaced with a web frontend, making the simulator significantly easier to use and more portable for researchers. The web UI was built with modern React and Plotly components.
Separating Simulation from Analytics
A key design element was to separate analytics from simulation:
- Simulation generates time-based events and outcomes.
- Analytics can be executed independently over different time periods.
Results accumulate into an ever-growing database: nothing is recalculated unnecessarily. When a new time period is accessed, only missing analytics are computed and cached.
Distribution and Code Signing
For delivery in restricted research environments, the Java application was also compiled into a native Windows executable using GraalVM, and signed via Azure code signing.
And as markets always get more complex, the agent behaviours as well as the market structure have been expanded to add new kinds of agents and decision functions as well as the ability to simulate multiple markets connected by agents operating on more than one market, with their own set of behaviours and decision functions.