Skip to content

Latest commit

 

History

History
119 lines (68 loc) · 5.93 KB

README.md

File metadata and controls

119 lines (68 loc) · 5.93 KB

FARMIND (FARM INteraction and Decision)

This is an agent-based model for the simulation of farm level decision-making developed by the Agricultural Economics and Policy Group at ETH Zurich (www.aecp.ethz.ch).

The model represents each farm as an agent as well as a node in social networks. Each agent chooses a strategy for perform activities based on the satisfaction and uncertainty about its output. A set of activity options is determined for each agent according to the strategy it chooses and by considering its personal preference and social interactions with its peers.

A linear programming model, integrated into the agent-based model, is then used to select an optimal activity for each agent to perform and generate an income value. Agents' satisfaction and uncertainty are updated accordingly. This sets the base for decision-making of next period.

Running the ABM

After extraction into a jar file, run the program using the 'run_java_ABM.bat' batch file or directly from the command line. The ABM requires the control.properties file to run and indicates the runtime parameters for the model.

java -jar ABM.jar 

will start the ABM based on the information in the control.properties file.

You can indicate an OPTIONAL year value in the command line and this will overwrite the value in the properties file.

java -jar ABM.jar 5

will start the ABM for five years and use the other properties indicated in the control.properties file.

control.properties file

This is the structure of the control file for the model. If you want to use the abm.jar with the gams model, make sure to set the debug flag to 0. This changes the run_gams.bat file that is created so the abm will interface with the actual desired gams model.

The year flag can be overwritten in the command line as shown above.

data_folder = data

modelName = WEEDCONTROL

uncertainty = 1

year = 5

project_folder = projdir

debug = 0

The debug flag is set to 1 when testing with eclipse as this indicates that it should copy a results file for testing. When set to 1 it will actually start the gams model and wait for the results.

ABM Requirements

  1. /data/ folder containing input data files:

    The initial conditions of the agents with all parameters need to be specified in the /data/ directory before starting the model. The /test_data/ folder contains example initialization files.

  2. /projdir/ folder containing the MP optimization model

Java JAR File Extraction

To extract the required JAR file for the external MP model integration in eclipse do the following:

  1. In eclipse right click on the /src/ folder and select 'Export'

  2. Under 'Java' select 'Runnable JAR File' and select 'Next'

  3. Make sure the "Launch Configuration" is set to "FARMIND - Consumat" as the entry point for the program and make sure to select 'Extract required libraries' to ensure that the jar file is a stand alone file.

  4. Choose a file location and hit 'Finish'.

Library Installation in Eclipse

All of the those libraries should already be downloaded and included in the /lib/ directory.

  1. In Eclipse Open: Window->Preferences->java->Build Path->User Libraries

  2. Select "New" and input the name of the library: Either jgrapht, or commons-math3-3.6.1

  3. After creating the library, link the new library with the jar files. Select "Add JAR" and select the JAR files from the /lib/ folder in the project that correspond to the library name.

  4. In the main Eclipse window, right click on the "FARMIND" project and select "Build Path->Add Libraries".

  5. In the window, select "User Libraries" and then select the newly created library.

  6. Refresh the project (F5) and compile.

The libraries can be downloaded here if required:

  1. Download jgrapht-1.1.0.zip file from here: http://jgrapht.org/
  2. Download commons-math3-3.6.1-bin.zip from here: http://commons.apache.org/proper/commons-math/download_math.cgi

Eclipse Development Environment

The code is developed and debugged using eclipse 4.7 or greater using JUnit5 for unit testing.

  1. Clone the github repository to your computer

  2. After opening eclipse, right click on the command window (left side) and select "Import"

  3. Under "General" select "Projects from folders or archives" and select the git repository.

  4. Install libraries in eclipse from the \lib folder and compile.

Troubleshooting Guide

  1. Issue related to graph library:

Exception in thread "main" java.lang.Error: Unresolved compilation problems: Graph cannot be resolved to a type DefaultEdge cannot be resolved to a type

To fix this issue ensure that you have installed all libraries as shown in the Library Installation in Eclipse section. If the issue persists, try removing the libraries and reinstalling them again.

  1. Program hangs after printing "Waiting output generated by MP model":

    This is the expected program operation. It has generated the gams file and started the gams simulation. The gams program will produce a results file for the ABM to process. Until then it will wait.

    When the model is running in test mode, the batch file 'run_gams.bat' will copy a output file (stored in /data/ folder as 'Grossmargin_P4,00').

  2. "java.io.FileNotFoundException: .\data\data-weedcontrol\social_networks.csv (The system cannot find the path specified)."

    There is an issue with the control.properties file. There is an error with the "data_folder" path and the ABM is unable to find the required data files.

  3. "java.io.FileNotFoundException: projdir\p_AllowedStratPrePost.csv (The system cannot find the path specified)"

    There is an issue with the control.properties file. There is an error with the "project_folder" path and the ABM is unable to find the required files.

  4. Error relating to JNI issues when running jar file OR issues related to library usage.

    JNI issues come from incorrect library settings. The easiest option to fix library issues is usually to uninstall all user libraries and re-add the libraries.