GH2-ABM_UNINA

GH2-ABM_UNINA preview image

1 collaborator

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by the author
Model was written in NetLogo 7.0.0 • Viewed 36 times • Downloaded 5 times • Run 0 times
Download the 'GH2-ABM_UNINA' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


WHAT IS IT?

This model simulates the environmental, economic, and social dynamics of green hydrogen (GH2) value chains under alternative territorial configurations and scaling strategies of the technology adopted. It was developed within Work Package 5 of the GH2 project (HORIZON-EIC-2021-PATHFINDERCHALLENGE-S-01-04, Project no. 101070721) by the University of Naples Federico II. The GH2-ABM represents the hydrogen value chain as a network of heterogeneous agents operating across production, logistics, market, and regulatory domains. It supports scenario-based assessments of deployment strategies for GH2 produced from water and bioalcohols using full solar spectrum technology, with a focus on comparative analysis of transnational hydrogen valley configurations.

HOW IT WORKS

The model comprises six agent classes (breeds) arranged along the value chain:

-Farmers supply raw biomass (sugarcane) to first production plants. -FT (First Transporters) handle the logistics between farmers and first production plants. -FPP (First Production Plants) process raw biomass into bioethanol and other intermediate products. -ST (Second Transporters) manage intercontinental transport of bioethanol. -SPP (Second Production Plants) produce green hydrogen and co-products (acetic acid, acetaldehyde, or acetal) from bioethanol using solar-assisted reactor technology. Regulators oversee compliance with certification and sustainability requirements.

The simulation unfolds across three sequential phases, governed by explicit gate-based transition logic:

-Network Formation: Agents search for partners and form complete value-chain configurations. -Network Development and Production: Complete networks activate production and exchange dynamics; environmental, economic, and social indicators are computed endogenously. -Network Growth and Certification Access: Stable and compliant networks can expand, access certification mechanisms, and enter co-product markets.

At each tick (representing one month), agents execute purchases, update production levels, compute emissions and resource consumption, adjust prices, check compliance conditions, and potentially resign or expand. Only networks that satisfy both structural (Gate 1) and sustainability/compliance (Gate 2) criteria are allowed to progress to the next phase.

Sustainability performance is assessed through a multi-dimensional index combining:

-Environmental indicators: CO₂ emissions, energy consumption, water consumption, waste generation. -Social indicators: employment growth and workforce dynamics. -Economic indicators: revenues, R&D investments, and turnover contribution to GDP

The model includes a lab-scale multiplier that translates laboratory reactor performance into deployable production capacity, allowing alternative technological scale-up regimes to be tested without modifying stoichiometric relations or behavioural rules.

HOW TO USE IT

Setup parameters

Nfarmers, NFirsttransp., NFirstProdPlant, NSecondtransp., NSecondProdPlant, Nregulators: Set the number of agents per class.

Bigfarmers, #BigFPP, #Big_SPP: Set the number of large-size agents within each production breed.

GH2Demand: Set the target level of green hydrogen demand to be satisfied (e.g., regional or national demand by 2030). lab-scale: Controls the multiplicative scaling factor applied to baseline SPP production capacity. A value of 100 represents a small insular deployment (e.g., Palma de Mallorca); a value of 10,000 represents a large industrial-scale configuration (e.g., Netherlands). Dis-C1-C2: Sets the distance (in km) between production and consumption regions, used to compute transport costs and emissions. co-productscenario: Selects the co-product pathway generated by the bioethanol conversion technology. The process produces hydrogen as the main output together with one of the following co-products: acetic acid, acetaldehyde, or acetal. mean-CBIO-price: Sets the reference price for CBIO certificates. CO2emissionforsugarcaneproduction: Emission factor for upstream agricultural activity.

Running the model Press SETUP to initialise agents with their production capacities, capital endowments, prices, and cost structures. Press GO to run the simulation. The model stops automatically once the GH2 demand target is satisfied. Outputs The interface monitors aggregate system indicators over time, including:

-Total SPP production -Total CO₂ emissions -Total energy and water consumption -Total dismissed employees -Expansion count and network stability indicators -Distribution of green certificates and CBIO credits

THINGS TO NOTICE

As the simulation runs, observe how network formation dynamics determine which value-chain configurations survive across phases. Not all networks will reach Gate 2: configurations with insufficient production capacity or poor sustainability performance will be excluded from certification access. Notice how the co-product scenario affects the speed of demand satisfaction. Under the acetic acid configuration, the system typically reaches the demand target faster than under acetaldehyde or acetal pathways. Observe the trade-off between scale and stakeholder diversity: when the lab-scale parameter is increased, the system tends to satisfy demand more quickly and with lower resource intensity, but with fewer active participants in the value chain.

THINGS TO TRY

Try running the model with lab-scale = 100 (insular setting, analogous to Palma de Mallorca) and compare results with lab-scale = 10,000 (continental industrial hub, analogous to Northern Netherlands). How does the time to demand satisfaction change? How do environmental and social outputs differ? Vary the NSecondProdPlant (NSPP) parameter from 1 to 5 and observe how increasing installed production capacity affects both the completion time and the environmental burden per unit of hydrogen produced. Can you identify the configuration that best balances speed and sustainability? Switch between the three co-product scenarios and compare how the choice of co-product affects employment dynamics within the simulated chain.

EXTENDING THE MODEL

The GH2-ABM could be extended to include explicit macroeconomic shocks or geopolitical disruptions affecting transport costs or feedstock availability. Adding heterogeneous regulatory environments across regions would allow simulation of the effect of different national policy frameworks on value-chain stability and certification dynamics. A more granular representation of the co-product market — including downstream conversion capacity and offtake agreements — could improve the realism of economic performance assessment, particularly for the acetaldehyde pathway. The model could also be adapted to include electrolysis-based hydrogen pathways as a parallel agent class, enabling direct comparison between GH2 solar-assisted technology and conventional production routes within the same simulation environment.

NETLOGO FEATURES

The model uses directed link breeds (supplier-links and client-links) to represent asymmetric value-chain relationships among agents. This allows the model to distinguish between the direction of material flows and of contractual relationships within the value chain. A gate-based progression logic controls transitions across the three simulation phases, ensuring that only networks satisfying structural and compliance criteria can access production and certification mechanisms. This architecture prevents premature phase transitions and makes the model suitable for policy-relevant scenario analysis. The lab-scale global parameter acts as a multiplicative factor applied to SPP production capacity, operationalising the translation from laboratory-scale reactor prototypes to industrial deployment configurations without modifying the underlying stoichiometric logic.

RELATED MODELS

Supply Chain

HOW TO CITE

If you mention this model in a publication, please include the following citation:

De Cristofaro R., Ponsiglione C., Primario S. (2026). GH2-ABM: Agent-Based Model of the Green Hydrogen Value Chain. University of Naples Federico II (UNINA), developed within the GH2 Project (HORIZON-EIC-2021-PATHFINDERCHALLENGE-S-01-04, Project no. 101070721).

For the NetLogo platform:

Please cite the NetLogo software as:

CREDITS AND REFERENCES

The GH2-ABM was developed by the research team at the University of Naples Federico II (UNINA). The first prototype of the model and its conceptualization were developed in collaboration with Vincenzo Del Duca and Serena Strazzullo.

COPYRIGHT AND LICENSE

© 2026 University of Naples Federico II (UNINA). Developed within the GH2 Project funded by the European Innovation Council under the Horizon Europe programme (Grant Agreement no. 101070721). All rights reserved.

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

directed-link-breed [supplier-links supplier-link]
directed-link-breed [client-links client-link]

breed [farmers farmer]
breed [F_T First_transportation]
breed [FPP First_production_plant]
breed [S_T Second_transportation]
breed [SPP Second_production_plant]
breed [regulators regulator]
breed [startups startup]

turtles-own [
  demand
  my-dem
  prod_capacity
  prod_level
  prod_offer
  raw-material
  capital
  social_capital
  revenue
  portfolio
  my-partner
  mydis
  price
  cost
  profit
  employee
  initial-employee
  employee-factor
  daily-working-hours
  w-factor
  technology-level
  t-factor
  my_score
  sustainability_attitude
  innovativeness
  transported_found
  suppliers_found
  cost-ton
  CO2_emissions
  energy_consumption
  water_consumption
  green-certificates
  R&D_count
  R&D_cost
  gate1
  expanded
  gate2_p
  gate2_pp
  emission-factor
  my_green_certificates_revenue
  my_dismissed_employees
  green_certificate_revenue
  my_turnover_ec
  my_R&D_cost
  my-diff-innovativeness
  my-diff-sustainability
  fpp_total_demand
  far_total_supply
  spp_total_demand
  fpp_total_supply
  revenue-conventional-market
  ton_transport_rate
  mean-price-farmers
  mean-price-FPP
]

Farmers-own [
  ordered-clients
]

FPP-own [
  ordered-clients
  ordered-suppliers
  ordered-transport
  CBIO-price
  missing_CBIO
  frevenue-conventional-market
]

SPP-own [
  ordered-suppliers
  ordered-transport
  total-green-emissions
  total-gray-emissions
  certificate-price
  potential-certificates
  cost-kg
]


links-own [
  link-counter
  type-link
  cost_transport
  real_cost_transport
  certified
  dis
]

globals [
  simulation-running
  total-spp-production
  avg-sustainability
  avg-innovativeness
  total_dismissed_employees
  total_initial_employees
  dead-agents
  my-dead-agents
  expansion-count
  total-Co2-emissions
  total_energy_consumption
  total_water_consumption
  total-green-certificates
  rewarded-certificates
  rewarded-CBIO
  certificates-acquired
  CBIO-acquired
  bonsucro-certificates
  Far_turnover_ec
  FPP_turnover_ec
  SPP_turnover_ec
  Far_R&D_cost
  FPP_R&D_cost
  SPP_R&D_cost
  Far_green_certificates_revenue
  FPP_green_certificates_revenue
  SPP_green_certificates_revenue
  Far_CO2_emissions
  FPP_CO2_emissions
  SPP_CO2_emissions
  Far_energy_consumption
  FPP_energy_consumption
  SPP_energy_consumption
  Far_water_consumption
  FPP_water_consumption
  SPP_water_consumption
  Far-diff-innovativeness
  FPP-diff-innovativeness
  SPP-diff-innovativeness
  Far-diff-sustainability
  FPP-diff-sustainability
  SPP-diff-sustainability
  Far_dismissed_employees
  FPP_my_dismissed_employees
  SPP_my_dismissed_employees
  Far-dead-agents
  FPP-dead-agents
  SPP-dead-agents
]

to setup
  clear-all
  set simulation-running true
  set total-spp-production 0
  set avg-sustainability 0
  set avg-innovativeness 0
  set total_dismissed_employees 0
  set dead-agents 0
  set expansion-count 0

  create_agents
  agents_inizialization
  ask turtles [
    set_prod_capacity
    set_capital
    set_score
    set_price
    set_prod_cost
  ]

  visual
  reset-ticks
end 

to create_agents
  create-farmers N_farmers
  create-F_T N_First_transp.
  create-FPP N_First_Prod_Plant
  create-S_T N_Second_transp.
  create-SPP N_Second_Prod_Plant
  create-regulators N_regulators
end 

to agents_inizialization
  ask turtles [
    set gate1 0
    set prod_offer 0
    set demand 0
    set my-dem 0
    set CO2_emissions 0
    set water_consumption 0
    set total-green-certificates 0
    set rewarded-certificates 0
    set rewarded-CBIO 0
    set certificates-acquired 0
    set bonsucro-certificates 0
    set CBIO-acquired 0
    set prod_level 0.001
    set portfolio [0 0 0]
    set capital 0
    set price [0 0 0]
    set green-certificates 0
    set technology-level 0
    set daily-working-hours 0
    set energy_consumption 0
    set total_initial_employees 0
    set R&D_count 0
    set my-partner []
    set R&D_cost 0
    set green_certificate_revenue 0
    set my_green_certificates_revenue 0
    set transported_found false
    set suppliers_found false
    set gate2_p false
    set gate2_pp false
    set revenue-conventional-market 0
    set cost-ton 0
    set ton_transport_rate 0
    set mean-price-farmers 0
    set mean-price-FPP 0

    if breed = farmers [set emission-factor CO2_emission_for_sugarcane_production] ;partner di progetto
    if breed = FPP [ set emission-factor (0.2 + random-float (1.6 - 0.2 ) )] ; https://pmc.ncbi.nlm.nih.gov/articles/PMC7923501/ - alì
    ;0,04824 KgCO2eq/kg https://eur-lex.europa.eu/legal-content/IT/TXT/HTML/?uri=CELEX:32018L2001 convertito
    if breed = SPP [ set emission-factor ( 2.1 + random-float (4.3 - 2.1) )] ;CO2equivalenti per le configurazioni autonome che producono h2 https://pubs.rsc.org/en/content/articlehtml/2022/ee/d2ee01023b
    if breed = F_T [set emission-factor  0.037] ;0.037 kgCO2/kgH2
    if breed = S_T [set emission-factor 0.021 ] ;0.021 kgCO2/ton*km

    if breed = farmers [
      set ordered-clients []
    ]


    if breed = FPP [
      set ordered-clients []
      set ordered-suppliers []
      set ordered-transport []
      set CBIO-price (mean-CBIO-price + random-float 1)
      set raw-material 0
    ]


    if breed = SPP [
      set ordered-suppliers []
      set ordered-transport []
      set certificate-price 0
      set potential-certificates 0
      set total-gray-emissions 0
      set total-green-emissions 0
      set raw-material 0


;   ;ipotesi: gli SPP hanno livello di innovazione massimo quindi il t-factor = 1
;   ;https://h2v.eu/analysis/statistics/financing/hydrogen-cost-and-sales-prices
;   set cost-kg precision (random-float (6.67 - 6.63) + 6.63) 2
;   set cost-ton (1000 * cost-kg)
    ]
  ]
end 

to set_prod_capacity
  set initial-employee 0


  if breed = farmers [ ;IPOTESI NON TUTTI SMALL (3 BIG)
    set prod_capacity 100 * ( random (9320 - 8000 + 1) + 8000 ) ;tonnellate/anno
    set employee random 50 + 10 ;numero di dipendenti per piccole imprese
    set initial-employee employee
  ]

  if breed = FPP [ ;IPOTESI TUTTI BIG: capacità uguali
    set prod_capacity 10 * (random (1030000 - 1000000 + 1) + 1000000 ) ;tonnellate/anno
    set employee random 50 + 10
    set initial-employee employee
  ]

  if breed = SPP [
    let prod_capacity_unit random (70 - 50 + 1) + 50   ; tonnellate/anno
    set prod_capacity ( prod_capacity_unit * lab-scale )
    ;set prod_capacity 1000

    set employee random 50 + 10
    set initial-employee employee
  ]

  if breed = F_T or breed = S_T [ ;non producono ma hanno CAPACITA' LOGISTICA
    set prod_capacity random (50000000 - 10000000 + 1) + 10000000
    set employee random 50 + 10
    set initial-employee employee
  ]

  ask n-of #Big_farmers farmers [
    set size 1.1
    set prod_capacity 100 * ( random (858000 - 833000 + 1) + 833000 )
    set employee random 100 + 50 ;numero di dipendenti per grandi imprese
    set initial-employee employee
  ]
  ask n-of #Big_FPP FPP [
    set size 1.1
    set prod_capacity 10 * ( random (1030000 - 1000000 + 1) + 1000000 )
    set employee random 100 + 50
    set initial-employee employee
  ]
  ask n-of #Big_SPP SPP [
    set size 1.1
    set prod_capacity random (7000 - 5000 + 1) + 5000  ;tonnellate/anno
    set employee random 100 + 50
    set initial-employee employee
  ]
  set prod_capacity prod_capacity / 12
end 

to set_capital
  set social_capital 10000

  if breed = farmers [
    set capital 100 * ( social_capital +  random (910378 - 606918 + 1) + 606918 )
  ]

  if breed = FPP [
    set capital 10 * ( social_capital + random (92664000 - 61776000 + 1) + 61776000 )
  ]

  if breed = SPP [
   set capital (social_capital + random (11371200000 - 7580800000 + 1) + 7580800000 )
  ]

  if breed = F_T or breed = S_T [
    set capital social_capital + random (50000000 - 10000000 + 1) + 10000000

  ]

  ask n-of #Big_farmers farmers [
    set capital 100 * (  social_capital + random (20550600  - 18593400 + 1) + 18593400 )

  ]
  ask n-of #Big_FPP FPP [
    set capital 10 * ( social_capital +  random (83809440 - 55872960 + 1) + 55872960 )

  ]
  ask n-of #Big_SPP SPP [
    set capital social_capital + random (11371200000 - 7580800000 + 1) + 7580800000

  ]
end 

to set_score

  set sustainability_attitude random 100 + 1
  set innovativeness random 100 + 1

  if breed = SPP [
    set innovativeness 100
    set sustainability_attitude 100
  ]
  set technology-level innovativeness / 100
  set my_score precision ( innovativeness + sustainability_attitude ) 2
end 

to set_price
  ;file excel media prezzi
  if breed = farmers [
    let price_sugarcane random-float one-of (range 0.080 0.091 0.001) ;euro al chilo
    set price replace-item 0 price precision (1000 * price_sugarcane) 2 ;euro a tonnellata
  ]

  if breed = FPP [

    ;https://studiolegalelavorospoltore.it/imprenditore/costa/quanto-costa-1-litro-di-bioetanolo/
    let price_bioethanol random-float one-of (range 0.59 0.92 0.01) ;convertito in euro al chilo
    let price_sugar random-float one-of (range 0.1 0.7 0.01)
    let price_bioeletr random-float one-of (range 0.080 0.090 0.001)
    set price replace-item 0 price precision (1000 * price_bioethanol) 2 ;euro a tonnellata
    set price replace-item 1 price precision (1000 * price_sugar) 2
    set price replace-item 2 price precision (1000 * price_bioeletr) 2

  ]

  if breed = SPP [

    let price_h2 random-float one-of (range 7.1 8.1 0.1) ;euro/kg
    set price replace-item 0 price precision (1000 * price_h2) 2 ;euro/tonnellata

    if co-product_scenario = "acetaldehyde" [
      let price_coproduct random-float one-of (range 3 10 0.1)
      set price replace-item 1 price precision (1000 * price_coproduct) 2
    ]

    if co-product_scenario = "acetic acid" [
      let price_coproduct random-float one-of (range 0.6 1.2 0.1)
      set price replace-item 1 price precision (1000 * price_coproduct) 2
    ]

    if co-product_scenario = "acetal" [
      let price_coproduct random-float one-of (range 0.8 1.25 0.1)
      set price replace-item 1 price precision (1000 * price_coproduct) 2

    ]
  ]

  if breed = F_T [ ; https://revista.ipecege.org.br/Revista/article/view/123/79
    set ton_transport_rate random-float one-of (range 0.17 0.23 0.01) ;euro a tonnellata a km
    set price replace-item 0 price ton_transport_rate
  ]
  if breed = S_T [
    set ton_transport_rate random-float one-of (range 44.02 62.23 0.01) ;euro a tonnellata a km
    let ton_transport_rate_km (ton_transport_rate / Dis-C1-C2)
    set price replace-item 0 price ton_transport_rate_km
  ]
end 

to set_prod_cost

  if breed = farmers [
        set cost-ton ifelse-value t-factor = 0.5 [ ;https://www.agrifarming.in/sugarcane-farming-in-brazil-exploring-varieties-cultivation-production-costs-and-profit#google_vignette
    random-float (12.55 - 10.79) + 10.79 ;costo di produzione euro/tonnellata
  ][
    random-float (10.02 - 8.36) + 8.36]
  ]


  if breed = FPP [
      ifelse t-factor = 0.5 [
      set cost-ton precision (random-float (335.56 - 279.63) + 279.63) 2
    ] [
      set cost-ton precision (random-float (279.63 - 223.7) + 223.7) 2
      ]
    ]


  if breed = SPP [
  let pc prod_capacity
  let mean-cost 0
  let std-dev 500 ; €/ton, equivalente a σ = 0.5 €/kg

  if pc <= (50 * lab-scale)  [
    set mean-cost 9000 ; €/ton (μ = 9 €/kg)
  ]
  if (pc > 50 * lab-scale ) and (pc <= 57 * lab-scale )[
    set mean-cost 7000 ; €/ton (μ = 7 €/kg)
  ]
  if (pc > 57 * lab-scale ) and (pc <= 64 * lab-scale )[
    set mean-cost 5000 ; €/ton (μ = 5 €/kg)
  ]
  if (pc >= 64 * lab-scale ) and (pc <= 71 * lab-scale ) [
    set mean-cost 3000 ; €/ton (μ = 3 €/kg)
  ]

  set cost-ton random-normal mean-cost std-dev
]
end 

to visual ;disposizione nell'interfaccia

  ask patches [
    if (pxcor = 0 and pycor < 0) or (pycor = 0 and pxcor > 0) [
      set pcolor sky
    ]
  ]
  set-default-shape links "small-arrow-link"
  ask turtles [
    set size 0.8
    if breed = farmers [
      set shape "flower"
      set color green
      setup-random-position
    ]
    if breed = FPP [
      set shape "first prod"
      set color red
      setup-random-position
    ]
    if breed = SPP [
      set shape "second prod"
      set color pink
      let a one-of (range 13 15 1)
      let c one-of (range -15 -13 1)
      set xcor a
      set ycor c
    ]
    if breed = F_T [
      set shape "truck"
      set color cyan
      setup-random-position
    ]
    if breed = S_T [
      set shape "bot"
      set color blue
      ifelse random-float 1.0 < 0.5 [
        setxy 0 (random -15)
      ] [
        setxy random 15 0
      ]
    ]

    if breed = regulators [
      set shape "person business"
      set color yellow
      set size 0.9
      setxy random-xcor random-ycor
    ]
  ]
end 

to  move
  right random 360
  forward 1
end 

to setup-random-position
  let x random-xcor
  let y random-ycor
  if not (x > 0 and y < 0) [
    setxy x y
  ]
end 

to move-ft-gradually [target]
  let steps 3
  let dx_1 (([xcor] of target - xcor) / steps)
  let dy_1 (([ycor] of target - ycor) / steps)
  repeat steps [
    set xcor xcor + dx_1
    set ycor ycor + dy_1
    display
  ]
end 

to go

  if not simulation-running [ stop ]
  if not any? farmers [ print (word "No more farmers ") stop]
  if not any? FPP [ print (word "No more FPP ") stop]
  if not any? SPP [ print (word "No more SPP ") stop]

  ask turtles [
    if breed = farmers or breed = FPP or breed = SPP [ check_exit ]
    calculate_my_demand
    create-list-of-clients
    if breed = farmers [ production_farmers ]
    if breed = FPP or breed = SPP [ need_suppliers ]
    update-my-partners
    gate_1

  ]

  if (ticks mod mean_time_production = 0) and (ticks > 0) [
    ask turtles [
      calculate_CO2_emissions
      calculate_energy_consumption
      calculate_water_consumption
      gate_2
      expansion
      if alternative-green-market [
      enter-alternative-market
      ]
      if breed = farmers or breed = FPP or breed = SPP [ check_employee_resignation ]
    ]

    ask links with [ color = red ] [
      ask both-ends [ set green-certificates 0 ]
    ]

    ask links with [certified = true] [ set color green ]
    adjust_prices
    update_my_score
    reset_global_metrics

    ask turtles with [ (capital > R&D_cost) and (breed = farmers or breed = FPP) and  (my-partner = [] or (gate1 = 1) )
    ] [ R&Dinvestment ]
  ]

  if total-spp-production >= Gh2_demand [
    let f ticks / mean_time_production
    print (word "SPP production has met the GH2 demand of " Gh2_demand " Ton in " f " years")
    set simulation-running false
  ]

  display
  tick
end 

to identify_your_strategy

  let w daily-working-hours
  let t technology-level

  let quadrant "unknown"

  if (innovativeness > 50 and sustainability_attitude > 50) [
    set quadrant "Alta Innovazione, Alta Sostenibilità"
    set w 8
    set t 1
  ]

  if (innovativeness > 50 and sustainability_attitude <= 50) [
    set quadrant "Alta Innovazione, Bassa Sostenibilità"
    set w 8 + random 9
    set t 1
  ]

  if (innovativeness <= 50 and sustainability_attitude > 50) [
    set quadrant "Bassa Innovazione, Alta Sostenibilità"
    set w 8
    set t 0.5
  ]

  if (innovativeness <= 50 and sustainability_attitude <= 50) [
    set quadrant "Bassa Innovazione, Bassa Sostenibilità"
    set w 8 + random 9
    set t 0.5
  ]

  set w-factor sqrt ( w / 8 )
  set t-factor t
  if initial-employee != 0 [
  set employee-factor employee / initial-employee
  ]
end 

to reset_global_metrics

  set total-spp-production precision (total-spp-production + sum ([prod_level] of SPP)) 0
  set total-Co2-emissions precision (total-Co2-emissions + sum ([CO2_emissions] of turtles)) 0
  set total_energy_consumption precision (total_energy_consumption + sum [energy_consumption] of turtles) 0
  set total_water_consumption precision (total_water_consumption + sum [water_consumption] of turtles) 0
  set total_initial_employees sum [initial-employee] of turtles with [breed = farmers or breed = FPP or breed = SPP]

  ;ECONOMICO: turnover  -> la somma in un grafico
  set Far_turnover_ec sum [my_turnover_ec ] of farmers
  set FPP_turnover_ec sum [my_turnover_ec ] of FPP
  set SPP_turnover_ec sum [my_turnover_ec ] of SPP

  ;ECONOMICO: Costi in R&D
  set Far_R&D_cost sum [my_R&D_cost] of farmers
  set FPP_R&D_cost sum [my_R&D_cost] of FPP
  ; set SPP_R&D_cost sum [my_R&D_cost] of SPP NON FANNO RICERCA E SVILUPPO

  ;ECONOMICO: Ricavi dei certificati verdi
  ; set Far_green_certificates_revenue sum [my_green_certificates_revenue] of farmers NON VENDONO I CERTIFICATI VERDI
  set FPP_green_certificates_revenue sum [my_green_certificates_revenue] of FPP
  set SPP_green_certificates_revenue sum [my_green_certificates_revenue] of SPP

  ;SOCIALE: Educational
  set Far-diff-innovativeness sum [my-diff-innovativeness] of farmers
  set FPP-diff-innovativeness sum [my-diff-innovativeness] of FPP
  set SPP-diff-innovativeness sum [my-diff-innovativeness] of SPP
  set Far-diff-sustainability sum [my-diff-sustainability] of farmers
  set FPP-diff-sustainability sum [my-diff-sustainability] of FPP
  set SPP-diff-sustainability sum [my-diff-sustainability] of SPP

  ;SOCIALE: Dipendenti dimessi
  set Far_dismissed_employees sum [my_dismissed_employees] of farmers
  set FPP_my_dismissed_employees sum [my_dismissed_employees] of FPP
  set SPP_my_dismissed_employees sum [my_dismissed_employees] of SPP


  ;AMBIENTALE: Livello di Emissioni
  set Far_CO2_emissions sum [CO2_emissions] of farmers
  set FPP_CO2_emissions sum [CO2_emissions] of FPP
  set SPP_CO2_emissions sum [CO2_emissions] of SPP

  ;AMBIENTALE: Consumo energetico
  set Far_energy_consumption sum [energy_consumption] of farmers
  set FPP_energy_consumption sum [energy_consumption] of FPP
  set SPP_energy_consumption sum [energy_consumption] of SPP

  ;AMBIENTALE: Consumo Idrico
  set Far_water_consumption sum [water_consumption] of farmers
  set FPP_water_consumption sum [water_consumption] of FPP
  set SPP_water_consumption sum [water_consumption] of SPP

  ask turtles [
  ;  conventional-market
    ;exprocedura reset_production
    set my-dem 0
    set prod_level 0.1

  ]
end 

to calculate_my_demand
  ifelse capital > 0 [

    let monthly_capacity (prod_capacity - prod_level)
    ;set demand precision (monthly_capacity / 12) 2 ;tonnellate
    set demand (prod_capacity - prod_level)
    if breed = FPP [
     ; set my-dem demand * 18.0505
           set my-dem demand
    ]

    if breed = SPP [
 ;     show (word " demand "   demand )
     set my-dem demand

    ;  if co-product_scenario = "acetaldehyde" [ set my-dem demand * (1 / 0.0433213) ]
    ;  if co-product_scenario = "acetic acid" [ set my-dem demand * (1 / 0.086642599) ]
    ;  if co-product_scenario = "acetal" [ set my-dem demand * (1 / 0.014440433) ]
  ;    show (word " my-dem "  my-dem )
    ]
  ][
    set my-dem 0
  ]
end 

to create-list-of-clients
  ;se esistono dei potenziali clienti con una domanda > 0 allora riordinali punteggio, distanza, prezzo di vendita

  if breed = farmers [
    let potential-clients FPP with [my-dem > 0]
    set ordered-clients sort-by [[w q] -> ([my_score] of w - [mydis] of w - [item 0 price] of w) > ([my_score] of q - [mydis] of q - [item 0 price] of q)] potential-clients
    if length ordered-clients > radius [set ordered-clients sublist ordered-clients 0 radius]
    if empty? ordered-clients [set ordered-clients []]
  ]

  if breed = FPP [
    let potential-clients SPP with [my-dem > 0]
    set ordered-clients sort-by [[w q] -> ([my_score] of w - [mydis] of w - [item 0 price] of w) > ([my_score] of q - [mydis] of q - [item 0 price] of q)] potential-clients
    if length ordered-clients > radius [set ordered-clients sublist ordered-clients 0 radius]
  ]
end 

to update-my-partners
  set my-partner [other-end] of supplier-links with [end1 = myself or end2 = myself]
end 

to-report calculate_dis [partner]
  if [breed] of partner = farmers [
    report random-normal Max-Dis 3
  ]
  if [breed] of partner = FPP [
    report random-normal Dis-C1-C2 3
  ]

  if [breed] of partner = SPP [
    report random-normal Dis-C1-C2 3
  ]
end 

to need_suppliers
  if breed = FPP  [
    if my-dem > 0 and any? farmers with [prod_offer > 0] and (not empty? ordered-clients)[
      find_suppliers
      find_transporters

      if ( suppliers_found = true )  and ( transported_found = true ) [
        execute_purchase
        production_FPP_SPP
      ]
    ]
  ]

  if breed = SPP [
    if my-dem > 0 and any? FPP with [prod_offer > 0]  [
      find_suppliers
      find_transporters

      if ( suppliers_found = true ) and ( transported_found = true ) [
        execute_purchase
        production_FPP_SPP
      ]
    ]
  ]
end 

to production_farmers
  ; Produzione per i farmer senza necessità di acquisto materie prime
  identify_your_strategy

   let increment precision ((prod_capacity / 12) * w-factor * t-factor * employee-factor) 2
   let operational-cost precision (increment * cost-ton) 2

    if (capital > operational-cost) and (prod_level + increment < prod_capacity) and (not empty? ordered-clients) [
      set prod_level precision (prod_level + increment) 2
      set portfolio replace-item 0 portfolio prod_level
      set prod_offer (%offer) * (item 0 portfolio)
      set capital capital - operational-cost
    ]
end 

to find_suppliers
  set suppliers_found false

  if breed = FPP [
    let potential-suppliers farmers with [prod_offer > 0]
    let sorted-suppliers sort-by [[w q] ->
      ([my_score] of w - [mydis] of w - [item 0 price] of w + [prod_offer] of w) >
      ([my_score] of q - [mydis] of q - [item 0 price] of q + [prod_offer] of q)
    ] potential-suppliers

    if length sorted-suppliers > 0 [
      set ordered-suppliers sorted-suppliers
      set suppliers_found true
    ]
  ]

  if breed = SPP [
    let potential-suppliers FPP with [prod_offer > 0]
    let sorted-suppliers sort-by [[w q] ->
      ([my_score] of w - [mydis] of w - [item 0 price] of w + [prod_offer] of w) >
      ([my_score] of q - [mydis] of q - [item 0 price] of q + [prod_offer] of q)
    ] potential-suppliers


    if length sorted-suppliers > 0 [
      set ordered-suppliers sorted-suppliers
      set suppliers_found true
    ]
  ]
end 

to find_transporters
  set transported_found false

  if breed = FPP [
    let potential-transport F_T with [prod_capacity > 0]

    let sorted-transport sort-by [[w q] ->
      ([my_score] of w - [mydis] of w - [item 0 price] of w) >
      ([my_score] of q - [mydis] of q - [item 0 price] of q)
    ] potential-transport

    if length sorted-transport > 0 [
      set ordered-transport sorted-transport
      set transported_found true
    ]
  ]

  if breed = SPP [
    let potential-transport S_T with [prod_capacity > 0]

    let sorted-transport sort-by [[w q] ->
      ([my_score] of w - [mydis] of w - [item 0 price] of w) >
      ([my_score] of q - [mydis] of q - [item 0 price] of q)
    ] potential-transport

    if length sorted-transport > 0 [
      set ordered-transport sorted-transport
      set transported_found true
    ]
  ]
end 

to execute_purchase
  if (capital <= social_capital) [ stop ]

  ifelse (not empty? ordered-suppliers and not empty? ordered-transport) [
  let s first ordered-suppliers
  let transporter first ordered-transport

  ; Se esiste già un link tra s e me stesso allora prendi la distanza (dis) già memorizzata nel link. Altrimenti, calcola adesso una nuova distanza chiamando calculate_dis s.

  let link-sup one-of supplier-links with [end1 = s and end2 = self]
  let d ifelse-value link-sup != nobody [ [dis] of link-sup ] [calculate_dis s]

  let unit_price [item 0 price] of s ;euro/tonnellata

    if breed = FPP [
      let total_cost my-dem * (unit_price + ([item 0 price] of transporter) * d + cost-ton)

  ;; Se ho abbastanza capitale per coprire tutto l'acquisto
  ifelse ( capital >= total_cost )[
    ifelse my-dem <= [prod_offer] of s [
      ;; Acquisto tutta la disponibilità del fornitore
      create_or_update_link s
      execute_transaction s self transporter my-dem unit_price d
    ][
      ;; Acquisto tutto ciò che il fornitore può offrire
      create_or_update_link s
      execute_transaction s self transporter ([prod_offer] of s) unit_price d
    ]
  ] [
    ;; Capitale insufficiente → acquisto parziale
    let affordable_qty (( ( capital  ) / (unit_price + ([item 0 price] of transporter) * d + cost-ton )))
    if affordable_qty > 0 [
      let max_available min (list affordable_qty [prod_offer] of s)
      create_or_update_link s
      execute_transaction s self transporter max_available unit_price d
    ]
    ]]

        if breed = SPP [
  let total_cost ( my-dem * (unit_price + ([item 0 price] of transporter) * d) + cost-ton)

  ;; Se ho abbastanza capitale per coprire tutto l'acquisto
  ifelse ( capital >= total_cost )[
    ifelse my-dem <= [prod_offer] of s [
      ;; Acquisto tutta la disponibilità del fornitore
      create_or_update_link s
      execute_transaction s self transporter my-dem unit_price d
    ][
      ;; Acquisto tutto ciò che il fornitore può offrire
      create_or_update_link s
      execute_transaction s self transporter ([prod_offer] of s) unit_price d
    ]
  ] [
    ;; Capitale insufficiente → acquisto parziale
    let affordable_qty (( ( capital  ) / (unit_price + ([item 0 price] of transporter) * d + cost-ton )))
    if affordable_qty > 0 [
      let max_available min (list affordable_qty [prod_offer] of s)
      create_or_update_link s
      execute_transaction s self transporter max_available unit_price d
    ]
    ]]

  ][ stop ] ;se non c'è il supplier e non c'è il trasportatore
end 

to create_or_update_link [supplier]
  let existing-link one-of supplier-links with [end1 = supplier and end2 = myself]

  if not member? self [ordered-clients] of supplier [
    stop ; esce se il buyer non è tra gli ordered-clients
  ]

  ifelse existing-link != nobody [
    ; Link già esistente → aggiorna counter
    ask existing-link [
      set link-counter link-counter + 1
    ]
  ]
  [
    ; Link nuovo → crea il link e calcola la distanza dis
    ask supplier [
      create-supplier-link-to myself [
        set dis calculate_dis supplier
        set link-counter 1
        set certified false

        if breed = farmers and [breed] of end2 = FPP [ set type-link "F_F" ]
        if breed = FPP and [breed] of end2 = SPP [ set type-link "S_F" ]
      ]
    ]
  ]
end 

to execute_transaction [seller buyer transporter quantity price_per_unit d1]
  if (prod_level <= 0) or (prod_offer <= 0) [ stop ]

  let transport_cost precision (quantity * ([item 0 price] of transporter) * d1) 2
  let revenue_cost precision (quantity * price_per_unit) 2

  if quantity <= 0 [ stop ]

  ask seller [

    if breed = farmers [
    set capital capital + revenue_cost
    set revenue revenue + revenue_cost
    set my_turnover_ec precision (my_turnover_ec + revenue / capital ) 2
    set prod_offer prod_offer - quantity
    set CO2_emissions CO2_emissions + ((1000 * [emission-factor] of transporter * mydis * quantity) / 2 )
    ]

    if breed = FPP [
    set capital capital + revenue_cost
    set revenue revenue + revenue_cost
    set my_turnover_ec precision (my_turnover_ec + revenue / capital ) 2
    set prod_offer prod_offer - quantity
    set CO2_emissions CO2_emissions + ((1000 * [emission-factor] of transporter * mydis * quantity) / 2 )

    let operational-cost precision (quantity * cost-ton) 2
    set capital capital - operational-cost
    ]
    conventional-market
  ]

  ask buyer [

    if breed = FPP [
    set capital capital - revenue_cost - transport_cost
    set raw-material raw-material + quantity
    set CO2_emissions CO2_emissions + ((1000 * [emission-factor] of transporter * mydis * quantity) / 2 )
    ]

    if breed = SPP [
      conventional-market
      set capital capital - revenue_cost
      set raw-material raw-material + quantity
      set CO2_emissions CO2_emissions + ((1000 * [emission-factor] of transporter * mydis * quantity) / 2 )
      set capital capital - cost-ton - transport_cost

    ]

  ]

  ask transporter [
    set capital capital + transport_cost
    set revenue revenue + transport_cost
    move-ft-gradually seller
    move-ft-gradually buyer
  ]


  let link-sup one-of supplier-links with [end1 = seller and end2 = buyer]
  if link-sup != nobody [
    ask link-sup [
      set label precision ( quantity ) 0
    ]
  ]
end 

to conventional-market

  ; aggiorna il capitale degli FPP e SPP considerando i ricavi  dalla vendita dei loro co-prodotti sul mercato convenzionale.
  if breed = FPP [
    let r1 (item 1 price * item 1 portfolio)
    let r2 (item 2 price * item 2 portfolio)
    set capital capital + r1 + r2
    set revenue-conventional-market revenue-conventional-market + r1 + r2
  ]

  if breed = SPP [
    let r0 (item 0 price * item 0 portfolio )
    let r1 (item 1 price * item 1 portfolio)
    set capital capital + r0 + r1
    set revenue-conventional-market revenue-conventional-market + r1

    ;vendita dell'idrogeno avviene sempre
    set revenue revenue + ( item 0 price * item 0 portfolio )
    set my_turnover_ec precision (my_turnover_ec + revenue / capital ) 2
  ]


  ; Se parte della produzione non viene venduta tramite la rete di fornitori diretti, viene comunquue
  ; monetizzata attraverso questa vendita alternativa
  if prod_offer > 0 [

    let a random 100
    let b random 5

    if a > b [

      if breed = farmers [
      let r1 ((1 -  %offer ) * prod_offer * item 0 price)
      set capital capital + r1
      set revenue-conventional-market revenue-conventional-market + r1
      ]

      if breed = FPP [
      let r1 ((1 -  %offer ) * prod_offer * item 0 price)
      set capital capital + r1
      set revenue-conventional-market revenue-conventional-market + r1
      ]


      set portfolio [0 0 0] ;  ;svuota il portfolio dopo la vendita sul mercato convenzionale
    ]
  ]
end 

to adjust_prices
ask turtles [
; I prezzi agricoli sono più sensibili agli squilibri di mercato per via della stagionalità,
; scarsità delle scorte e volatilità. Al contrario, i prezzi industriali tendono ad essere
; più stabili grazie a economie di scala,
; contratti fissi e margini di assorbimento dei costi

  let margine_minimo 0.05 ; margine di guadagno minimo sul costo di produzione
  let a random 100
  let b random 100

  if a > b [
  if breed = farmers [
    let alpha 0.05

    set fpp_total_demand sum [my-dem] of fpp
    set far_total_supply sum [prod_offer] of farmers

    if far_total_supply > 0 and prod_offer > 0 [
      let excess-demand (fpp_total_demand - far_total_supply) / far_total_supply
      let delta-p ( item 0 price * alpha * excess-demand )


      let prezzo_minimo cost-ton * (1 + margine_minimo) ;al minimo del costo di produzione
      let nuovo_prezzo max list (item 0 price + delta-p) prezzo_minimo
      set price replace-item 0 price precision nuovo_prezzo 2

            if item 0 price > 100 [ set price replace-item 0 price 100 ]
      if item 0 price < 70 [ set price replace-item 0 price 70 ]
          set mean-price-farmers mean [item 0 price] of farmers

    ]
  ]

  if breed = FPP [
    let alpha 0.000000005

    set spp_total_demand sum [my-dem] of spp
    set fpp_total_supply sum [prod_offer] of fpp

    if fpp_total_supply > 0 and prod_offer > 0 [
      let excess-demand (spp_total_demand - fpp_total_supply) / fpp_total_supply
      let delta-p ( item 0 price * alpha * excess-demand )

      let prezzo_minimo cost-ton * (1 + margine_minimo)
      let nuovo_prezzo max list (item 0 price + delta-p) prezzo_minimo
      set price replace-item 0 price precision nuovo_prezzo 2


      if item 0 price > 950 [ set price replace-item 0 price 950 ]
      if item 0 price < 500 [ set price replace-item 0 price 500 ]
                    set mean-price-FPP mean [item 0 price] of FPP
    ]
  ]
  ]
  ]
end 

to production_FPP_SPP

  let input raw-material
  identify_your_strategy
  let x ifelse-value employee-factor >= 1 [ 1 ] [employee-factor]
  let eff ifelse-value (w-factor * t-factor * employee-factor) > 0.8 [1] [0.8]

  if breed = FPP [
    let output precision (input * 0.0554 * eff) 2
    set prod_level prod_level + output
    set portfolio replace-item 0 portfolio prod_level
    set portfolio replace-item 1 portfolio (item 1 portfolio + 0.0514 * input)
    set portfolio replace-item 2 portfolio (item 2 portfolio + 0.113 * input)
    set prod_offer (%offer) * (item 0 portfolio)
  ]

  if breed = SPP [
    if co-product_scenario = "acetaldehyde" [
      let output precision (input * 0.044 * eff) 2
      set prod_level prod_level + output
    ;        show (word "prod_level" prod_level)
      set portfolio replace-item 0 portfolio prod_level
      set portfolio replace-item 1 portfolio (item 1 portfolio + 0.9566787 * input)
    ]
    if co-product_scenario = "acetic acid" [
      let output precision (input * 0.088 * eff) 2
      set prod_level prod_level + output
     ;       show (word "prod_level" prod_level)
      set portfolio replace-item 0 portfolio prod_level
      set portfolio replace-item 1 portfolio (item 1 portfolio + 1.303249097 * input)
    ]
    if co-product_scenario = "acetal" [
      let output precision (input * 0.015 * eff) 2
      set prod_level prod_level + output
        ;    show (word "prod_level" prod_level)
      set portfolio replace-item 0 portfolio prod_level
      set portfolio replace-item 1 portfolio (item 1 portfolio + 0.855595668 * input)
      set portfolio replace-item 2 portfolio (item 2 portfolio + 0.129963899 * input)
    ]
    set prod_offer (item 0 portfolio)
  ]
  ; rappresenta quanto è stato acquistato e non ancora trasformato. Dopo ogni produzione questo materiale viene convertito in output
  set raw-material 0
end 

to update_my_score
  ask turtles with [ any? my-supplier-links ]
  [ let a turtle-set [other-end] of my-supplier-links
    set avg-innovativeness mean [innovativeness] of a
    set avg-sustainability mean [sustainability_attitude] of a
    ifelse  avg-innovativeness <  avg-sustainability [
      let deltai precision ( innovativeness -  avg-innovativeness ) 0
      ifelse deltai < 0 [
        set innovativeness precision ( innovativeness + ( abs (deltai) /  avg-innovativeness )  ) 0
        set my-diff-innovativeness my-diff-innovativeness + ( abs (deltai) /  avg-innovativeness )
      ] [
        set innovativeness precision (innovativeness) 0
      ]
    ]
    [  let deltas precision ( sustainability_attitude -  avg-sustainability ) 0
      ifelse deltas < 0 [

        set sustainability_attitude precision ( sustainability_attitude + ( abs (deltas) /  avg-sustainability )  ) 0
        set my-diff-sustainability my-diff-sustainability + ( abs(deltas) / avg-sustainability)

      ] [
        set sustainability_attitude precision ( sustainability_attitude ) 0
      ]
    ]
  ]
end 

to R&Dinvestment

  let r random 100
  let f random 100

  ifelse r > f [
    set prod_capacity prod_capacity * 1.1

    set R&D_cost precision (capital * %R&D_cost ) 2
    set capital capital - R&D_cost
    set my_R&D_cost my_R&D_cost + R&D_cost

    let diff-sustainability abs(sustainability_attitude - avg-sustainability)
    let diff-innovativeness abs(innovativeness - avg-innovativeness)

    set my-diff-sustainability my-diff-sustainability + diff-sustainability
    set my-diff-innovativeness my-diff-innovativeness + diff-innovativeness

    ifelse diff-sustainability > diff-innovativeness [
      set innovativeness precision ( innovativeness + (diff-innovativeness) ) 0
      set color blue
      set R&D_count R&D_count + 1
    ]
    [
      set sustainability_attitude precision ( sustainability_attitude + (diff-sustainability) ) 0
      set color white
      set R&D_count R&D_count + 1
    ]

    stop ][
    stop
  ]
end 

to check_employee_resignation
  ;Se l’azienda ha pochi o nessun partner attivo, può simulare un ambiente di lavoro incerto → dimissioni
  let r (list length [my-partner] of farmers )
  let s (list length [my-partner] of FPP )
  let t (list length [my-partner] of SPP )


  if employee > 0 [

    if breed = farmers [
      let a mean r
      if length my-partner < a [
        set employee employee - 1
        set my_dismissed_employees my_dismissed_employees + 1
        set total_dismissed_employees total_dismissed_employees + 1

      ]
    ]


    if breed = FPP [
      let b mean s
      if length my-partner < b [
        set employee employee - 1
        set my_dismissed_employees my_dismissed_employees + 1
        set total_dismissed_employees total_dismissed_employees + 1

      ]
    ]

    if breed = SPP [
      let c mean t
      if length my-partner < c [
        set employee employee - 1
        set my_dismissed_employees my_dismissed_employees + 1
        set total_dismissed_employees total_dismissed_employees + 1

      ]
    ]

  ]
end 

to check_exit
  if ticks > 2 [
    if (employee = 0) or (capital = 0) [

      if breed = farmers [
        set Far-dead-agents Far-dead-agents + 1
      ]

      if breed = FPP [
        set FPP-dead-agents FPP-dead-agents + 1
      ]

      if breed = SPP [
        set SPP-dead-agents SPP-dead-agents + 1
      ]
      die ]
  ]
end 

to gate_1
  ask FPP [
    if any? supplier-links with [end1 = myself] [
      ask my-supplier-links [ set color yellow ]
      foreach [end2] of my-supplier-links [ x ->
        ask x [ set gate1 1 ]
      ]
    ]
  ]
end 

to calculate_CO2_emissions
  ;fattore di emissioni kgC02/kgH2 = tonn CO2/ton H2 quindi consideriamo tonnellate su tonnellate
  ;prod level ton
  if prod_level > 0 [
    ;per 1000 per convertire in tonnellate
    if breed = farmers [ ;diviso 100 per tenere conto del dimensionamento dei farmers
    set CO2_emissions precision ( 10 * prod_level * emission-factor ) 0 ;ton di CO2
    ]

    if breed = FPP [ ;diviso 10 per tenere conto del dimensionamento dei farmers
    set CO2_emissions precision ( 100 * prod_level * emission-factor ) 0 ;ton di CO2
    ]

    if breed = SPP [
    set CO2_emissions precision ( 1000 * prod_level * emission-factor ) 0 ;ton di CO2
    ]

    if breed = F_T or breed = S_T [
    set CO2_emissions precision ( 1000 * prod_level * emission-factor ) 0 ;ton di CO2
    ]

  ]
end 

to calculate_energy_consumption ;per tonnellata
  if prod_level > 0 [
    let consumption_factor 0
    ;kWh/kg di H2 (o litro) * 1000 = kWh/ton di H2

    if breed = farmers [ set consumption_factor 0.4 * 1000 ] ; 0,4 kWh per ogni chilogrammo di canna da zucchero prodotto https://www.iea.org/reports/world-energy-outlook-2022/executive-summary?language=it
    if breed = FPP [ set consumption_factor 0.7 * 1000 ] ; 0,7 kWh per litro di bioetanolo prodotto https://iris.uniroma1.it/bitstream/11573/1689626/1/Rispoli_Sustainable-production-hydrogen_2023.pdf
    if breed = SPP [ set consumption_factor 50 * 1000] ; 50 kWh per Kg di idrogeno prodotto https://mocada.it/blog/quanto-costa-produrre-idrogeno/

    set energy_consumption precision ( energy_consumption + prod_level * consumption_factor ) 0 ;kWh

  ]
end 

to calculate_water_consumption ;per tonnellata

  if prod_level > 0 [
    if breed = farmers [
      let water_conversion_factor 2.7 * 1000 ; litri per ogni Kg di canna da zucchero prodotto - Water Footprint Network https://tools.waterfootprint.org/product-gallery/
      set water_consumption water_consumption + prod_level * water_conversion_factor ;litri (a tonnellata (perché è stato moltiplicato per mille))

    ]

    if breed = FPP [
      let water_conversion_factor 6 * 1000
      set water_consumption water_consumption + prod_level * water_conversion_factor

    ]

    if breed = SPP [
      let water_conversion_factor 9 * 1000 ; la produzione di 1 kg di idrogeno richiede circa 9 litri di acqua https://mocada.it/blog/quanto-costa-produrre-idrogeno/?accettato=1
      set water_consumption precision ( water_consumption + prod_level * water_conversion_factor ) 0 ; litri / tonnellata
    ]
  ]
end 

to gate_2
  ask FPP [

    let ff-links supplier-links with [
      end2 = myself and link-counter >= link-required
    ]

    let sf-links supplier-links with [
      end1 = myself and link-counter >= link-required
    ]

    if any? ff-links and any? sf-links [
      ask ff-links [ set color red ]
      ask sf-links [ set color red ]
    ]
  ]


  if any? my-supplier-links with [ color = red ][

    let a  my-supplier-links with [ color = red ]
    foreach sort a [x ->
      ask [both-ends] of x [

        set gate2_p true
        set gate2_pp true
  ]]]
end 

to expansion
  ;l'espansione può avvenire solo se c'è stabilità nella value chain
  ;quindi solo se i link sono rossi
  ask turtles with [gate2_p = true  and employee > 0 ][
    ; if breed = farmers or breed = FPP or breed = SPP [
    let b random 100
    let c random 100
    let expansion-cost 10000


    ifelse b > c  [ ;probabilità simula il rischio o l'incertezza dell'investimento
      if (capital > expansion-cost) and (capital > social_capital) [
        let a t-factor * w-factor
        set prod_capacity prod_capacity + prod_capacity * a / employee
        set employee employee + 1
        set capital capital - expansion-cost
        set expansion-count expansion-count + 1
        set gate2_p false
        stop

    ] ][stop  ]

  ]
end 

to enter-alternative-market
  ;la CO2 emessa dal trasportatore metà va a chi compra e metà a chi acquista

  ask turtles with [gate2_pp = true][

    if breed = farmers [
      let a mean [sustainability_attitude] of farmers
      if sustainability_attitude >= a [
        set bonsucro-certificates bonsucro-certificates + 1
        set sustainability_attitude precision (sustainability_attitude * 1.1 ) 0
        set green-certificates green-certificates + 1
        set shape "star"
        set color green

        ask my-supplier-links [
          set certified true
          set color green
        ]
      ]
    ]

    if breed = FPP [
      let emission_factor_fossil_fuel NTER_F * 1000
      let C02_baseline (emission_factor_fossil_fuel * prod_level)/ 10
      let CO2_avoided (C02_baseline - CO2_emissions)
      let price-CBIO 14.48 ;Fonte: https://www.researchgate.net/figure/Estimated-price-of-each-CBIO-from-2021-to-2029_fig17_357242140

      ifelse CO2_avoided > 0 [
        set rewarded-CBIO precision ( rewarded-CBIO + floor ( CO2_avoided / 1000 ) ) 0
        ifelse capital >= 5 * ( rewarded-CBIO * price-CBIO )[

          set green-certificates green-certificates + rewarded-CBIO
          set capital capital - ( price-CBIO  * rewarded-CBIO )
          set sustainability_attitude precision (sustainability_attitude * 1.1 ) 0
          set shape "star"
          set color green

          ask my-supplier-links [ set certified true ]
        ][
          let affordable-CBIO capital / ( 5 * price-CBIO )
          set rewarded-CBIO rewarded-CBIO - affordable-CBIO
          set green-certificates green-certificates + affordable-CBIO
          set capital capital - ( price-CBIO  * affordable-CBIO )
          set sustainability_attitude precision (sustainability_attitude * 1.1 ) 0
          set shape "star"
          set color green

          ask my-supplier-links [ set certified true ]
        ]
      ][
        if capital > social_capital [
          set missing_CBIO round (abs CO2_avoided / 1000)
          buy_CBIO
        ]
      ]
    ]

    if breed = SPP and hydrogen_type = "Grey Hydrogen" [
      let emission_factor_gray_hydrogen 10.92 * 1000
      set total-green-emissions CO2_emissions
      set total-gray-emissions prod_level * emission_factor_gray_hydrogen
      let reduction-percentage precision ( (1 - (total-green-emissions / total-gray-emissions)) * 100 ) 3

      ifelse reduction-percentage >= required-percentage [
        set rewarded-certificates rewarded-certificates + ceiling ((reduction-percentage - required-percentage) / 10)
        set green-certificates green-certificates + rewarded-certificates
        set capital capital - ( 500 + ( 0.30 * rewarded-certificates ) ) ; euro - Fonte: https://www.certifhy.eu/eu-rfnbo-scheme-documents/
        set sustainability_attitude precision (sustainability_attitude * 1.1 ) 0
        set shape "star"
        set color green

        ask my-supplier-links [ set certified true
          set color green
          set color red  ]
      ] [
        if capital > social_capital [
          buy_green_certificates reduction-percentage total-gray-emissions total-green-emissions
        ]
      ]
    ]
    set gate2_pp false
  ]
end 

to buy_CBIO
  let buyers turtles with [breed = FPP and missing_CBIO > 0 and capital > 0]
  let sellers turtles with [breed = FPP and rewarded-CBIO > 0]

  ask buyers [
    let buyer self
    ;  show (word "⟹ Buyer: " buyer " | missing_CBIO: " missing_CBIO " | capitale: " capital)

    while [missing_CBIO > 0 and any? sellers] [
      let seller one-of sellers with [rewarded-CBIO > 0]
      if seller = nobody [ stop ]

      ;   show (word "   ↳ Trovato seller: " seller " | CBIO disponibili: " [rewarded-CBIO] of seller "|Capital seller " [capital] of seller )

      let to-buy min (list missing_CBIO [rewarded-CBIO] of seller)
      let CBIOcost to-buy * CBIO-price

      ;   show (word "     Tentativo acquisto: " to-buy " CBIO al costo di: " CBIOcost)

      ifelse capital >= CBIOcost [
        ; Esegue lo scambio
        ask seller [
          set rewarded-CBIO rewarded-CBIO - to-buy
          set capital capital + CBIOcost
          set green_certificate_revenue green_certificate_revenue + CBIOcost
          set my_green_certificates_revenue my_green_certificates_revenue + CBIOcost
          ;     show (word " Seller: " self " ha venduto " to-buy " CBIO | Rimasti: " rewarded-CBIO " | Capitale ora: " capital)
        ;  if rewarded-CBIO > 0 [
          conventional-alternative-market
         ; ]
        ]

        set capital capital - CBIOcost
        set CBIO-acquired CBIO-acquired + to-buy
        set missing_CBIO missing_CBIO - to-buy

        ;    show (word "   Buyer: " self " ha acquistato " to-buy " CBIO | Rimanenti: " missing_CBIO " | Capitale ora: " capital)
      ]  [

      let total-fine missing_CBIO * fine-per-ton
      set capital capital - total-fine
      if capital < 0 [set capital 0 ]
      set missing_CBIO 0
      ]
    ]

  ]
end 

to buy_green_certificates [percentage tgray-emissions tgreen-emissions]

  set potential-certificates ceiling ((100 - percentage) / 10) ; certificati richiesti
  let buyerself self
  let sellers turtles with [breed = SPP and rewarded-certificates > 0]
  set certificate-price precision (Certifhy-certificate-price + random 0.7 ) 2
  let sorted-sellers sort-on [certificate-price] sellers

  if not empty? sorted-sellers [
    let best-seller item 0 sorted-sellers
    let unit-price [certificate-price] of best-seller
    let available-certs [rewarded-certificates] of best-seller
    let certs-to-buy min (list available-certs potential-certificates)
    let total-price ( 500 + unit-price * certs-to-buy )

    ifelse capital >= total-price [
      ask best-seller [
        set rewarded-certificates rewarded-certificates - certs-to-buy
        set capital capital + total-price
        set green_certificate_revenue green_certificate_revenue + total-price
        set my_green_certificates_revenue my_green_certificates_revenue + total-price
      ;  if rewarded-certificates > 0 [
        conventional-alternative-market
      ;  ]
      ]
      set capital capital - total-price
      set certificates-acquired certificates-acquired + certs-to-buy
      set potential-certificates potential-certificates - certs-to-buy
    ] [
      ;; non può permettersi i certificati → multa https://en.wikipedia.org/wiki/EU_Allowance?utm 100 euro * tonnellata non evitata
      let emissions-to-be-offset tgreen-emissions - tgray-emissions
      let total-fine emissions-to-be-offset * fine-per-ton
      set capital capital - total-fine
      if capital < 0 [set capital 0 ]
      set potential-certificates 0
    ]
  ]
end 

to conventional-alternative-market


    if breed = FPP [
      if rewarded-CBIO > 0 [
      set capital capital + ( rewarded-CBIO * CBIO-price)
      set green_certificate_revenue green_certificate_revenue + ( rewarded-CBIO * CBIO-price)
      set my_green_certificates_revenue my_green_certificates_revenue + ( rewarded-CBIO * CBIO-price)
    ]
  ]


    if breed = SPP [
      if rewarded-certificates > 0 [
      set capital capital +  ( 500 + rewarded-certificates *  Certifhy-certificate-price )
      set green_certificate_revenue green_certificate_revenue + ( 500 + rewarded-certificates * Certifhy-certificate-price )
      set my_green_certificates_revenue my_green_certificates_revenue + ( 500 + rewarded-certificates * Certifhy-certificate-price )
    ]
  ]
end 

There is only one version of this model, created 13 days ago by Simonetta Primario.

Attached files

File Type Description Last updated
GH2-ABM_UNINA.png preview Preview for 'GH2-ABM_UNINA' 13 days ago, by Simonetta Primario Download

This model does not have any ancestors.

This model does not have any descendants.