Skip to content

farm

agents.farm

Farm agent module for the EcoWHEATaly model.

Defines the Farm agent representing Italian wheat farms. Each farm optimizes production inputs (nitrogen, herbicide, insecticide), evaluates agri-environmental policy adoption, performs life cycle impact assessment, and harvests wheat yield subject to stochastic risk.

C_daly = np.array(lca_matrices.cDalyM) module-attribute

LCA characterization matrix for DALY

C_species = np.array(lca_matrices.cSpeciesM) module-attribute

LCA characterization matrix for species

f_vec = [0, 0, 1] module-attribute

LCA final demand vector

Farm

Bases: Agent

Repast4py agent representing an Italian wheat farm.

Each farm decides production inputs by maximizing profit given a Cobb-Douglas-like production function, optionally constrained by agri-environmental policies (eco-schemes and SRA interventions). After input decisions, the farm performs an LCA impact assessment and harvests wheat yield drawn from a stochastic distribution.

Attributes:

Name Type Description
TYPE

Agent type identifier used by repast4py context.

updateWheatPrice(tmpmodel)

Update the expected wheat price from the policy maker ghost.

Retrieves the last 12 Italian market wheat prices stored by the policy maker ghost agent, computes their average, and updates the farm's price variables used in input optimization.

Parameters:

Name Type Description Default
tmpmodel

The simulation Model instance providing access to the repast4py context and schedule.

required

compute_unconstrained_production_inputs()

Compute optimal production inputs without policy constraints.

Solves the first-order conditions to find the profit-maximizing target yield and derives the corresponding input levels for nitrogen, herbicide, and insecticide. Results are stored in the unconstrained_* attributes.

compute_constrained_production_inputs()

Compute production inputs under mandatory policy constraints.

For inputs flagged as mandatory by the adopted policy, uses the constrained input levels to determine a feasible target yield. The yield is set to the minimum across constrained inputs. Results are stored in the constrained_* attributes.

decide_production_inputs()

Decide production inputs and compute final yield target.

Solves the profit-maximization problem to determine optimal nitrogen, herbicide, and insecticide levels. Applies policy multipliers to adjust inputs and yield if a policy is adopted. Also computes tractor hours based on altimetry and profit per hectare.

keep_or_change_policy(tmpmodel)

Evaluate whether to adopt, keep, or abandon an agri-environmental policy.

Compares the net benefit of each available policy (payment minus profit loss minus administrative costs) against the current situation. Uses a logistic adoption probability to decide whether to switch policy. If a policy is adopted, computes the corresponding input multipliers.

Parameters:

Name Type Description Default
tmpmodel

The simulation Model instance providing access to the policy maker ghost agent.

required

perform_life_cyle_impact_assessment()

Perform a simplified Life Cycle Impact Assessment for this farm.

Customizes the LCA technology (A) and biosphere (B) matrices with the farm's actual input levels (tractor energy, nitrogen fertilizer, herbicide, insecticide) and computes ReCiPe 2016 endpoint indicators for human health (DALY) and ecosystem quality (species-year).

harvest()

Simulate the wheat harvest with stochastic yield.

Draws the actual harvested yield from a normal distribution centred on the policy-adjusted target yield, bounded by zero and the target. Computes total production by multiplying yield per hectare by wheat acreage.

add_to_aggregate_variables(aggregate_log)

Accumulate this farm's outputs into aggregate statistics.

Adds production, input usage, and policy adoption acreage to the shared aggregate data log used for MPI reduction.

Parameters:

Name Type Description Default
aggregate_log AggregateData

Mutable data object collecting totals across all farms in this rank.

required

save()

Serialize the agent state for MPI communication.

Returns:

Type Description
Tuple

The agent's unique identifier tuple (id, type, rank).