Skip to content

YcZen/EIMOD

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

I. Institution Framework Architecture and Integration Guide

Architecture Overview

The Institution Framework is a modular system designed to simulate policy-making institutions that interact with environmental / ecological / economic models. The architecture follows a clear separation of concerns with distinct components:

  1. Institution Framework Core

    • InstitutionManager: Coordinates multiple institutions and handles communication with target models
    • Institution: Represents a policy-making entity with decision-making capabilities
    • Policy: Defines specific policy instruments with parameters and constraints
  2. Integration Layer

    • TargetModelOutput: Data structure for transferring model state to institutions
    • InstitutionOutput: Data structure for transferring policy decisions to models
    • ModelOutputProvider: Interface that target models should implement
  3. Example Implementation

    • SimpleLandUseModel2: Example model implementing the ModelOutputProvider interface
    • TestRunner2: Demonstration of how to connect the framework with a model

Component Relationships

┌──────────────────────┐      ┌───────────────────────┐
│  Target Model        │      │  Institution Framework│
│  (implements         │◄────►│                       │
│  ModelOutputProvider)│      │                       │
└──────────────────────┘      └───────────────────────┘
         ▲                              ▲
         │                              │
         │                              │
         │                              │
         ▼                              ▼
┌─────────────────────┐      ┌───────────────────────┐
│  Data Transfer      │      │  Policy Decision      │
│  Objects            │      │  Logic                │
│  (TargetModelOutput,│      │  (Fuzzy Logic,        │
│  InstitutionOutput) │      │  Optimization)        │
└─────────────────────┘      └───────────────────────┘

Key Components in Detail

InstitutionManager

The serves as the main entry point for the framework. It:

  • Loads institution configurations from JSON
  • Coordinates multiple institutions
  • Handles communication between institutions and the target model
  • Provides methods to initialize policies and process model outputs

Institution

The class represents a policy-making entity that:

  • Evaluates gaps between current state and policy goals
  • Uses fuzzy logic to determine policy changes
  • Applies constraints like inertia and budget limitations
  • Produces policy outputs that affect the target model

ModelOutputProvider Interface

The interface defines the contract that target models must implement:

  • prepModelOutput(): Provides time series data of model variables
  • prepEstimatedQuantities(): Provides estimated quantities for policies
  • prepBudget(): Provides available budget for each institution
  • getOutput(): Combines the above into a TargetModelOutput object

Data Transfer Objects

  • : Carries model state to institutions
  • : Carries policy decisions to the target model

Integration Process

1. Implement the ModelOutputProvider Interface

Your model must implement the interface:

public class YourModel implements ModelOutputProvider {
    @Override
    public HashMap<String, ArrayList<Double>> prepModelOutput() {
        // Return time series data for each variable
        // Example: {"crop_production": [100, 105, 110], "biodiversity": [80, 75, 70]}
    }

    @Override
    public HashMap<String, HashMap<String, Double>> prepEstimatedQuantities() {
        // Return estimated quantities for each policy by institution
        // Example: {"AgriInst": {"crop_subs": 1.0, "meat_subs": 1.0}}
    }

    @Override
    public HashMap<String, Double> prepBudget() {
        // Return available budget for each institution
        // Example: {"AgriInst": 10000.0, "EnvInst": 5000.0}
    }

    @Override
    public TargetModelOutput step(InstitutionOutput institutionOutput) {
        // Update model state based on policy values
        // Return model output for institutions
    }
}

2. Create Configuration Files

Institutions JSON File

Define your institutions and policies in a JSON file. For example:

{
  "institutions": [
    {
      "institutionName": "AgriInst",
      "policies": [
        {
          "policyName": "crop_subs",
          "block": "crop_subsidy_block",
          "inputNameToGoal": {
            "crop_production": 800.0
          },
          "unitCost": 10.0,
          "weights": 1.0,
          "policyLow": 0.0,
          "policyUp": 100.0,
          "inertiaLow": -5.0,
          "inertiaUp": 5.0,
          "stepSize": 1.0
        }
      ]
    }
  ]
}

Fuzzy Control Language (FCL) File

Define fuzzy logic rules for policy decisions. For example:

FUNCTION_BLOCK crop_subsidy_block
  VAR_INPUT
    crop_production_gap: REAL;
  END_VAR
  
  VAR_OUTPUT
    intervention: REAL;
  END_VAR
  
  FUZZIFY crop_production_gap
    TERM negative := (-1000, 1) (-100, 1) (0, 0);
    TERM zero := (-50, 0) (0, 1) (50, 0);
    TERM positive := (0, 0) (100, 1) (1000, 1);
  END_FUZZIFY
  
  DEFUZZIFY intervention
    TERM decrease := (-10, 1) (-5, 1) (0, 0);
    TERM maintain := (-2, 0) (0, 1) (2, 0);
    TERM increase := (0, 0) (5, 1) (10, 1);
    METHOD: COG;
    DEFAULT := 0;
  END_DEFUZZIFY
  
  RULEBLOCK No1
    RULE 1: IF crop_production_gap IS negative THEN intervention IS increase;
    RULE 2: IF crop_production_gap IS zero THEN intervention IS maintain;
    RULE 3: IF crop_production_gap IS positive THEN intervention IS decrease;
  END_RULEBLOCK
END_FUNCTION_BLOCK

3. Connect Your Model with the Institution Framework

public class YourSimulation {
    public static void main(String[] args) {
        try {
            // Initialize institution manager
            InstitutionManager institutionManager = new InstitutionManager();
            institutionManager.loadInstitutions(
                "path/to/institutions.json", // JSON file path for institutions and policies
                "path/to/fuzzy_rules.fcl", // FCL file path for fuzzy logic rules
                10,  // Time lag for PID calculations
                true // Start policy evaluation at step 0
            );
            
            // Initialize your model
            YourModel model = new YourModel();
            
            // Get initial policy values
            InstitutionOutput institutionOutput = institutionManager.getInitPolicies();
            
            // Run simulation
            for (int i = 0; i < 1000; i++) {
                // Step model with current policies
                TargetModelOutput modelOutput = model.step(institutionOutput);
                
                // Get updated policies from institutions
                institutionOutput = institutionManager.step(modelOutput);
            }
            
            // Process and save results
            
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Example: SimpleLandUseModel

The SimpleLandUseModel class (in the test folder) demonstrates how to implement the ModelOutputProvider interface:

  1. It maintains state variables (land allocation, production, environmental indicators)
  2. It implements the required methods:
    • prepModelOutput(): Returns time series of model variables
    • prepEstimatedQuantities(): Returns policy quantities (set to 1.0 in this example)
    • prepBudget(): Returns available budget for each institution
  3. In its step() method, it:
    • Updates land allocation based on current state
    • Updates indicators based on new land allocation
    • Applies policy effects from the institution output
    • Records the current state for later analysis

Component Relationships

Sequence diagram of the interaction of SimpleLandUseModel and Institution

Best Practices for Integration

  1. Clear Variable Naming: Ensure variable names in your model match those in the institution configuration.

  2. Time Series Management: Maintain time series data for all relevant variables to provide historical context for policy decisions.

  3. Policy Effect Implementation: Create clear mechanisms for how policies affect your model's behaviour.

  4. Budget Considerations: If using budget constraints, implement realistic estimations of policy costs.

  5. Testing: Start with simple configurations and gradually increase complexity to ensure correct integration.

  6. Data Collection: Implement comprehensive data collection for analysis and visualization.

II. Mathematical Documentation of SimpleLandUseModel

This document provides a comprehensive explanation of the mathematical foundations underlying the SimpleLandUseModel implementation. The model simulates land allocation, economic production, and environmental indicators with various policy interventions.

1. Model State Variables

The model tracks several state variables that evolve over time:

  • Land Allocation (hectares)

    • Agricultural Land: $A_t$
    • Forest Land: $F_t$
    • Urban Land: $U_t$
  • Production Outputs

    • Crop Production (tons): $C_t$
    • Meat Production (tons): $M_t$
    • Sustainable Agriculture Index: $S_t$
  • Environmental Indicators

    • Carbon Sequestration (tons): $CS_t$
    • Biodiversity Index: $B_t$

2. Core Parameters

The model is governed by the following parameters:

  • Total Land: $L_{total} = 10,000$ hectares
  • Crop Yield: $Y_c = 5.0$ tons per hectare
  • Meat Yield: $Y_m = 1.0$ tons per hectare
  • Forest Carbon Sequestration: $\sigma_f = 10.0$ tons per hectare
  • Meat Carbon Emission: $\epsilon_m = 50.0$ tons per ton of meat
  • Crop Carbon Emission: $\epsilon_c = 5.0$ tons per ton of crop
  • Carbon per Forest Hectare: $\kappa_f = 100.0$ tons per hectare

3. Policy Effects

Four policy instruments influence the model dynamics:

  • Crop Subsidy Effect: $\alpha_c$
  • Meat Subsidy Effect: $\alpha_m$
  • Biodiversity Subsidy Effect: $\alpha_b$
  • Carbon Tax Effect: $\alpha_t$

4. Land Allocation Dynamics

The model updates land allocation in each time step according to:

4.1 Conversion Pressures

agriConversionPressure = 0.02 * (1 + cropSubsidyEffect/100 + meatSubsidyEffect/100)
forestProtectionFactor = 0.01 * (1 + bioSubsidyEffect/100)
carbonReductionFactor = 0.01 * (1 + carbonTaxEffect/100)

Mathematically: $$P_{agri} = 0.02 \times (1 + \frac{\alpha_c}{100} + \frac{\alpha_m}{100}) + \xi$$

Where $\xi$ represents random noise from a uniform distribution $U(-0.005, 0.005)$

$$P_{forest} = 0.01 \times (1 + \frac{\alpha_b}{100})$$

$$P_{carbon} = 0.01 \times (1 + \frac{\alpha_t}{100})$$

4.2 Land Conversion

Forest to agricultural land conversion is calculated as: $$\Delta F \rightarrow A = F_t \times (P_{agri} - P_{forest} - P_{carbon})$$

Then the land areas are updated: $$F_{t+1} = F_t - \Delta F \rightarrow A$$ $$A_{t+1} = A_t + \Delta F \rightarrow A$$

4.3 Land Conservation Constraint

The model enforces that total land remains constant: $$A_t + F_t + U_t = L_{total}$$

If this constraint is violated, an adjustment factor is applied: $$\text{adjustmentFactor} = \frac{L_{total}}{A_t + F_t + U_t}$$

And all land types are scaled: $$A_t = A_t \times \text{adjustmentFactor}$$ $$F_t = F_t \times \text{adjustmentFactor}$$ $$U_t = U_t \times \text{adjustmentFactor}$$

5. Production Calculations

5.1 Production Weight Allocation

The model uses a sigmoid function to determine the balance between crop and meat production: $$W_{crop} = \sigma(\alpha_c - \alpha_m) = \frac{1}{1 + e^{-(\alpha_c - \alpha_m)/10}}$$ $$W_{meat} = 1 - W_{crop}$$

5.2 Production Calculation

Crop and meat production are calculated based on allocated agricultural land: $$C_t = A_t \times Y_c \times W_{crop} \times (1 + \eta_c)$$ $$M_t = A_t \times Y_m \times W_{meat} \times (1 + \eta_m)$$

Where:

  • $\eta_c$ and $\eta_m$ are random noise terms from $U(-0.05, 0.05)$

5.3 Sustainable Agriculture Index

The sustainable agriculture index is calculated as the proportion of crop production to total agricultural production: $$S_t = \frac{C_t}{C_t + M_t} \times 100$$

6. Environmental Indicators

6.1 Carbon Sequestration

The net carbon sequestration accounts for forest absorption minus agricultural emissions: $$CS_t = F_t \times \sigma_f - (C_t \times \epsilon_c + M_t \times \epsilon_m)$$

6.2 Biodiversity Index

The biodiversity index is primarily based on forest cover ratio, enhanced by biodiversity subsidies: $$B_t = \frac{F_t}{L_{total}} \times 1000 \times (1 + \frac{\alpha_b}{200}) \times (1 + \eta_b)$$

Where:

  • $\eta_b$ is a random noise term from $U(-0.025, 0.025)$

7. Sigmoid Function

The model uses a sigmoid function to transform the difference between crop and meat subsidies into a production weight:

$$\sigma(x) = \frac{1}{1 + e^{-x/10}}$$

This function has several important properties:

  • Output always between 0 and 1
  • When $x = 0$ (equal subsidies), $\sigma(0) = 0.5$
  • As $x \rightarrow \infty$ (crop subsidies dominate), $\sigma(x) \rightarrow 1$
  • As $x \rightarrow -\infty$ (meat subsidies dominate), $\sigma(x) \rightarrow 0$
  • The division by 10 in the exponent controls the steepness of the transition

8. Policy Application Mechanism

The model processes policy inputs from institutional frameworks, applying them to the respective effect variables:

  • AgriInst:crop_subs → cropSubsidyEffect
  • AgriInst:meat_subs → meatSubsidyEffect
  • EnvInst:bio_subs → bioSubsidyEffect
  • EnvInst:carbon_tax → carbonTaxEffect

9. Initialization

The model initializes with:

  • Agricultural Land: $A_0 = 1,000$ hectares
  • Forest Land: $F_0 = 8,500$ hectares
  • Urban Land: $U_0 = 500$ hectares
  • All policy effects initialized to 0

10. Model Feedback Loops

The model incorporates several important feedback mechanisms:

  1. Agricultural Expansion: Higher agricultural subsidies increase conversion pressure from forests to agricultural land.

  2. Forest Protection: Biodiversity subsidies and carbon taxes reduce the rate of forest conversion.

  3. Production Composition: The relative balance of crop and meat subsidies shifts production toward the more subsidized output through the sigmoid function.

  4. Environmental Impact: The model captures the trade-off between agricultural production and environmental indicators (biodiversity and carbon sequestration).

11. Simulation Process

For each time step, the model follows this sequence:

  1. Update land allocation based on current policy effects
  2. Calculate new production and environmental indicators
  3. Apply new policy effects
  4. Record state variables and policy values

How to run the example model?

To run a Maven project in Eclipse, you need to ensure that Maven is properly integrated with Eclipse. Eclipse does not come with Maven by default (in most distributions), so you must either install it or use an Eclipse version that already includes Maven support (like Eclipse IDE for Java Developers or Eclipse IDE for Java EE Developers). Here’s a step-by-step guide to set up Maven in Eclipse and run your Maven project:


Step 1: Install Maven Support in Eclipse

  1. Open Eclipse.
  2. Go to Help > Eclipse Marketplace.
  3. In the "Eclipse Marketplace", search for "Maven".
  4. Look for "Maven Integration for Eclipse (m2e)" and click Install.
  5. Follow the prompts and restart Eclipse when prompted. If you’re using a version like Eclipse IDE for Java Developers, it likely already includes Maven support (m2e).

Step 2: Import the Maven Project (if you have already imported, please ignore this)

  1. Go to File > Import.
  2. Choose: Maven > Existing Maven Projects > Click Next.
  3. Browse to the root folder of the downloaded Maven project (where the pom.xml file is located).
  4. Select the project and click Finish.

Step 3: Build and Run the Maven Project • To build the project: Right-click the project > Run As > Maven install or Maven build. • Run the program through .bat file in the Command Line Interface integrated within Eclipse. (If not exist in Eclipse, you can download it from the Marketplace like you did for Maven above.) Use the “cd” command to go to the “institution” folder where the file “run_test.bat” is located, and then type “run_test.bat” and hit “Enter” to get the model running. Please see the screenshot below, which shows how to run it on my laptop. The reason why running the program through .bat instead of using a main class directly is presented at the end of the doc.

Alternatively, you could use the default Windows Command Line Interface to do it, which means you don’t need Eclipse, steps and screenshot shown below: Open CMD Manually and Navigate

  1. Press Windows + R, type: cmd and press Enter.
  2. In the terminal, change directory to your project folder: cd path\to\EIMOD\institution Example: cd C:\EIMOD\institution
  3. Run the batch file: run_test.bat

Why use .bat? Using batch (.bat) files to run Java applications offers a practical alternative to running code directly within an IDE like Eclipse. While Eclipse is ideal for development and debugging, batch files allow for consistent, repeatable execution of applications, especially useful in testing, deployment, or automation scenarios. They can encapsulate build steps, environment configuration, and runtime commands, making them valuable for both developers and non-developers who need to run the application outside the IDE. In this project, .bat is best for running the program (institutions + simple land use model) as a whole. There is no issue if the user only uses the reusable snippets (related to institution decision-making) in their own model through their own “main” functions.

About

No description, website, or topics provided.

Resources

License

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors