GH2_V0

No 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 6.3.0 • Viewed 76 times • Downloaded 1 time • Run 0 times
Download the 'GH2_V0' 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 demonstrates diffusion of a quantity through a directed network. The quantity moves among nodes in the network only along established, directed links between two nodes.

The simple rules that drive this diffusion lead to interesting patterns related to the topology, density, and stability of the network. Furthermore, the model may be useful in understanding the basic properties of dynamic processes on networks, and provides a useful starting point for designing more complex and realistic network-based models.

HOW IT WORKS

In each tick, each node shares some percentage (defined by the DIFFUSION-RATE slider) of its "value" quantity with its neighbors in the network. Specifically, the amount of shared value is divided equally and sent along each of the outgoing links from each node to each other node. If a node has no outgoing links, then it doesn't share any of it's value; it just accumulates any that its neighbors have provided via incoming links.

Note that because it is a directed network, node B may give value to node A even if node A doesn't give back.

The size of each node shows how much "value" that node has, where the area of the node is proportional to its value. The brightness of a link represents how much value just flowed through that edge.

HOW TO USE IT

Choose the size of network that you want to model using the GRID-SIZE slider. Choose the expected density of links in the network using the LINK-CHANCE slider.

To create the network with these properties, press SETUP.

The DIFFUSION-RATE slider controls how much "value" each node shares with its neighbors during a given time step.

Press the GO button to run the model.

The REWIRE-A-LINK button causes one link to disappear, and a new one to appear elsewhere in the grid.

The KEEP-REWIRING button causes a continual rewiring of links to occur.

The histogram displays the number of nodes whose values fall into certain ranges. For instance, you might see that there are many nodes with nearly zero value, while there are just a few nodes with very large value.

THINGS TO NOTICE

As time passes, the network tends toward an equilibrium state. (Is that always the case, or is it possible for a network to never settle down?)

However, if you run both the GO and KEEP-REWIRING buttons at the same time, then the network will never completely settle down. If you ran the model in this way for a long long time, would the distribution of value across the nodes in the network be uniform, if you averaged across time? Or would nodes near the edges of the grid tend to have more or less value?

THINGS TO TRY

Try running the model with a small 3x3 grid. How many nodes end up with positive value (not approaching zero) after running the model for a while? Sometimes just a single node ends up with all of the value, while other times every node in the network can sustain a positive value. What properties of the network are necessary in order for every node to sustain a positive value? Are these properties more or less likely to occur with large networks?

EXTENDING THE MODEL

Imagine you are modeling a business economy, where each node is a business, and it has suppliers and customers (represented by directed links from that node). Is it reasonable to assume that as a business accumulates more profit from sales, it will in turn purchase more from its suppliers? In order to more accurately match this economic model, change the model into a supply chain model where each node also has an inventory level, and a price they are charging per unit. Try to come up with reasonable rules for how many units each business decides to buy or sell.

How would you change this model to more accurately represent water flowing (or being pumped) through pipes? Should the links be directed or undirected? What if water is continually flowing in or out of the system at certain locations?

NETLOGO FEATURES

This model works in a manner analogous to NetLogo's diffuse command, which causes patches to all share with their neighbors portions of the value of some variable. However, whereas the neighbor relationship in patches is symmetric, this model uses directed links, which can be used to create asymmetric relationships between agents. If you used undirected links, the behavior of this model would more closely resemble the diffuse command, where the value of all the nodes would eventually become the same.

In this model, there are two link-breeds: one for active links (which are shown in the view) and another for inactive links (which are invisible). This makes "rewiring" of links easier, because rather than killing a link and creating a new link, we can just change the breed of a link and hide or show it.

Though it is not used in this model, there exists a network extension for NetLogo that you can download at: https://github.com/NetLogo/NW-Extension.

RELATED MODELS

Virus on a Network

HOW TO CITE

If you mention this model or the NetLogo software in a publication, we ask that you include the citations below.

For the model itself:

Please cite the NetLogo software as:

COPYRIGHT AND LICENSE

Copyright 2008 Uri Wilensky.

CC BY-NC-SA 3.0

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit https://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Commercial licenses are also available. To inquire about commercial licenses, please contact Uri Wilensky at uri@northwestern.edu.

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]

turtles-own [
  prod_capacity
  prod_level
  sustainability_attitude
  innovativeness
  capital
  revenue
  cost
  profit
  demand
  prod_offer
  price
  my_score
max-score
max-score-turtle
  ordered-clients
  ordered-suppliers
ordered-transport
   target-FPP
  target-farmers
  portfolio
  demander
  supplier
  p
  my_self
  my-sup
  my-co2-prod
]

Farmers-own [

]
FPP-own[
  sugare_cane_prod
  bioethanol_prod

]
SPP-own[

]

F_T-own [
]

links-own [ flow n_flow active]

globals [
yellow-linked-agents
avg-sustainability
  avg-innovativeness
  total-spp-production
  simulation-running
  CO2_Emissions
]

;;;;;;;;;;;;;;;;;;;;;;;;
;;; Setup Procedures ;;;
;;;;;;;;;;;;;;;;;;;;;;;;

to setup
  clear-all
  set CO2_Emissions 0
  set simulation-running true
  set total-spp-production 0

  ; create the 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

  visual

  ask turtles[
    set portfolio [0 0 0]

  ]

capacity
  set avg-sustainability 0
  set avg-innovativeness 0

  reset-ticks
end 

to go

  ask turtles [
  create-list-of-suppliers
  create-list-of-clients
  if breed = farmers [farmer_production]
  valuate_demand_and_offer
  build_a_supply_chain
  ;if breed = FPP [highlight-complete-supply-chain]
  ]

  ask links with [active = false] [die]
  calculate_av_score
  if not simulation-running [ stop ]

  ; Reset production level every 12 ticks and gradually increase it to reach near production capacity
  ifelse (ticks mod 12 = 0) [
    CO2_Emission_Count
    reset_production
    R&Dinvestment

  ]
  [colors]


  eq_stop

  display
  tick
end 

to  build_a_supply_chain

    if demand > 0
    [choose_a_partner]
end 

to CO2_Emission_Count
  ask turtles [
if breed = farmers [
      set my-co2-prod my-co2-prod + (prod_level * CO2-Emission-For-Sugarcane-production)
    set  CO2_Emissions  CO2_Emissions + my-co2-prod]
  if breed = FPP [
    set my-co2-prod my-co2-prod + (item 0 portfolio *  CO2-Emission-For-Bioethanol-production)
    set  CO2_Emissions  CO2_Emissions + my-co2-prod]

  ]
end 

to create-list-of-suppliers

  if breed =  FPP [
    ; Valuta Farmers come fornitori
    let potential-suppliers farmers with [prod_offer > 0]
    set ordered-suppliers sort-by [[w q] -> ([my_score] of w - distance w - [item 0 price] of w + [prod_offer] of w) > ([my_score] of q - distance q - [item 0 price] of q + [prod_offer] of q)] potential-suppliers
    if length ordered-suppliers > radius [
      set ordered-suppliers sublist ordered-suppliers 0 radius]
  ]

  if breed =  SPP [
    let potential-suppliers FPP with [prod_offer > 0]
    set ordered-suppliers sort-by [[w q] -> ([my_score] of w - distance w - [item 0 price] of w + [prod_offer] of w) > ([my_score] of q - distance q - [item 0 price] of q + [prod_offer] of q)] potential-suppliers
    if length ordered-suppliers > radius [
      set ordered-suppliers sublist ordered-suppliers 0 radius]

    let potential-transport F_T
    set ordered-transport sort-by [[w q] -> ([my_score] of w - distance w - [item 0 price] of w) > ([my_score] of q - distance q - [item 0 price] of q)] potential-transport
  ]
end 

to create-list-of-clients
  if breed = farmers [
    let potential-clients FPP with [demand > 0]
    set ordered-clients sort-by [[w q] -> ([my_score] of w - distance w - [item 0 price] of w) > ([my_score] of q - distance q - [item 0 price] of q)] potential-clients
    if length ordered-clients > radius [set ordered-clients sublist ordered-clients 0 radius]
  ]

  if breed = FPP[
    let potential-clients SPP with [demand > 0]
    set ordered-clients sort-by [[w q] -> ([my_score] of w - distance w - [item 0 price] of w) > ([my_score] of q - distance q - [item 0 price] of q)] potential-clients
    if length ordered-clients > radius [set ordered-clients sublist ordered-clients 0 radius]
    ; Valuta F_T come channels
    let potential-transport F_T with [prod_offer < [demand] of myself]
    set ordered-transport sort-by [[w q] -> ([my_score] of w - distance w - [item 0 price] of w) > ([my_score] of q - distance q - [item 0 price] of q)] potential-transport
  ]

  if breed = F_T [
    let potential-clients FPP with [demand > 0] ; FT che hanno bisogno di più produzione
    set ordered-clients sort-by [[w q] -> ([my_score] of w - distance w - [item 0 price] of w) > ([my_score] of q - distance q - [item 0 price] of q)] potential-clients
    if length ordered-clients > radius [set ordered-clients sublist ordered-clients 0 radius]
  ]
end 

to reset_production

  set total-spp-production precision (total-spp-production + sum ([prod_level] of SPP)) 0

  ask turtles[
      set prod_offer prod_offer + prod_level
      set prod_level 0.1
]
end 

to valuate_demand_and_offer

    if breed = FPP[
    let dem prod_capacity - prod_level
    set demand dem * 18.0505
      ]
  if breed = SPP [
    let dem prod_capacity - prod_level
    set demand dem * 23.0833]
if (demand > 0)  [set demander true]
if (prod_offer > 0) [set supplier true]
end 

to farmer_production

   let increment min(list ((prod_capacity - prod_level) / (12 - (ticks mod 12))) prod_capacity)
   set prod_level precision (prod_level + increment) 2
  set prod_offer prod_level
  set portfolio replace-item 0 portfolio prod_level
end 

to calculate_av_score

  if any? links with [color = yellow] [
     set yellow-linked-agents (turtle-set [end1] of links with [color = yellow] [end2] of links with [color = yellow])

  set avg-sustainability mean [sustainability_attitude] of yellow-linked-agents
    set avg-innovativeness mean [innovativeness] of yellow-linked-agents]
end 

to R&Dinvestment

  ask turtles with [(breed = FPP or breed = SPP or breed = farmers) and my-sup = 0][
    ifelse  (capital > R&D_cost) and (ticks != 0)[


      ; Calculate the difference between the agent's and the averages
      let diff-sustainability abs(sustainability_attitude - avg-sustainability)
      let diff-innovativeness abs(innovativeness - avg-innovativeness)

      ; Deduct the R&D cost
      set capital capital - R&D_cost

      ; Decide in which field to invest based on the greater difference
      ifelse diff-sustainability > diff-innovativeness [
        ; Invest in sustainability
        set sustainability_attitude sustainability_attitude + (diff-sustainability) ; Adjust the multiplier as needed
      ]
      [; Otherwise Invest in innovation
        set innovativeness innovativeness + (diff-innovativeness ) ; Adjust the multiplier as needed
      ]

      set prod_capacity prod_capacity + 10000
      set my_score innovativeness + sustainability_attitude

      set color pink



  ][]]
end 

to capacity

  ask turtles[

  set prod_level 0.1
  set sustainability_attitude random 100 + 1
  set innovativeness random 100 + 1
  set my_score innovativeness + sustainability_attitude

  if breed = farmers
  [set prod_capacity random (9E+06 - 5E+06 + 1) + 5E+06
   set capital random 1E+10
  ]

  if breed = FPP
  [set prod_capacity random (2.22E+08 - 1E+08 + 1) + 1E+08
   set capital random 1E+10
  ]

  if breed = SPP
  [set prod_capacity random (1E+07 - 5E+06 + 1) + 5E+06
   set capital random 1E+010
  ]


  ]

   ask n-of %Big_farmers farmers [
    set size 1.1
    set prod_capacity random (8.58E+08 - 9E+06 + 1) + 9E+06
    set capital random (1E+09 - 1E+06 + 1) + 1E+06
 ]
end 

to production [ff]

  if breed = FPP [
      let r1 item 0 portfolio
      let r2 item 1 portfolio
      let r3 item 2 portfolio
      ; Crea la lista portfolio con i valori calcolati
      set portfolio replace-item 0 portfolio (r1 + 0.0554 * ff)
      set portfolio replace-item 1 portfolio (r2 + 0.0514 * ff)
      set portfolio replace-item 2 portfolio (r3 + 0.113 * ff)

  ]

  if breed = SPP [
      if co-product_scenario = "acetaldehyde" [
        let r1 item 0 portfolio
        let r2 item 1 portfolio
        ; Crea la lista portfolio con i valori calcolati
        set portfolio replace-item 0 portfolio (r1 + 0.0438 * ff)
      set portfolio replace-item 1 portfolio (r2 + 0.9562 * ff)]


        if co-product_scenario = "acetic acid" [
          let c1 item 0 portfolio
          let c2 item 1 portfolio
          ; Crea la lista portfolio con i valori calcolati
          set portfolio replace-item 0 portfolio (c1 + 0.0875 * ff)
          set portfolio replace-item 1 portfolio (c2 + 1.3036 * ff)]

          if co-product_scenario = "acetal" [
            let w1 item 0 portfolio
            let w2 item 1 portfolio
            let w3 item 2 portfolio
            ; Crea la lista portfolio con i valori calcolati
            set portfolio replace-item 0 portfolio (w1 + 0.0146 * ff)
            set portfolio replace-item 1 portfolio (w2 + 0.8551 * ff)
            set portfolio replace-item 2 portfolio (w3 + 0.1303 * ff)]
  ]
end 

to choose_a_partner

; for agents with demand > 0
let u random 100
let z random 100
  ifelse u > z [
  if breed = FPP or (breed = SPP) [
    let dem demand
    ; Cerca tra i fornitori (Farmers)
    foreach ordered-suppliers [supp ->

      if (dem > 0) and ([prod_offer] of supp > 0.1) and (capital > (dem * [item 0 price] of supp)) and (member? self [ordered-clients] of supp) [
        let tt min list dem [prod_offer] of supp
        if breed = FPP [
          create-supplier-link-from supp  ; Creazione del link di fornitura
          [ set n_flow n_flow + 1
            set active true
            activate_link]
          set dem dem - tt

        ]

        if breed = SPP [
          create-supplier-link-from supp  ; Creazione del link di fornitura
          [ set n_flow n_flow + 1
            set active true
            activate_link]
          set dem dem - tt

        ]
  ]]]][stop]
end 

to find_transport [flow_material supplie clien]
  ; Identifica un F_T adatto per il trasporto
 if breed = FPP [
  let available-FTs F_T with [capital >= (flow_material * item 0 price)] ; Semplice filtro di esempio
  if any? available-FTs [
    let selected-FT one-of available-FTs
    ; Supponiamo che il FPP conosca già i suoi farmer collegati
   ask selected-FT [
      set color white
  move-ft-gradually supplie ; Sostituisci move-to con move-ft-gradually
  move-ft-gradually clien ; Ripeti per il movimento verso il FPP
  ]]]
  if breed = SPP[
let available-STs S_T with [capital >= (flow_material * item 0 price)] ; Semplice filtro di esempio
  if any? available-STs [
    let selected-ST one-of available-STs
    ; Supponiamo che il FPP conosca già i suoi farmer collegati
   ask selected-ST [
      set color white
  move-ft-gradually supplie ; Sostituisci move-to con move-ft-gradually
  move-ft-gradually clien ; Ripeti per il movimento verso il FPP
  ]]]
end 

to activate_link

  set flow min (list [prod_offer] of end1 [demand] of end2)
  set label precision (flow) 1
  let z end1
  let y end2
  ask end1[
    set my-sup my-sup + 1
    let rev (item 0 price * [flow] of myself)
    set prod_offer prod_offer - [flow] of myself
    let j (item 0 portfolio) * (item 0 price)
    let k (item 1 portfolio) * (item 1 price)
    let l (item 2 portfolio) * (item 2 price)
    set capital capital + rev
    ; Aumenta la sostenibilità e l'innovazione ricevendo conoscenza
    ;set sustainability_attitude sustainability_attitude + (0.05 * [flow] of myself)
    ;set innovativeness innovativeness + (0.05 * [flow] of myself)

  ]
  ask end2[
    set my-sup my-sup + 1
    if breed = FPP
    [set prod_level precision (prod_level + (0.0554 * [flow] of myself))2
      set capital capital - ([item 0 price] of z * [flow] of myself)
    ]
    ;per gli SPP il mercato non è simulato per cui il capital viene aggiornato qui hp che tutto l'idrogeno verde prodotto trovi mercato
    if breed = SPP and co-product_scenario = "acetaldehyde"
    [set prod_level precision (prod_level + (0.0433 * [flow] of myself))2
    set capital capital - ([item 0 price] of z * [flow] of myself)
    ]

    if breed = SPP and co-product_scenario = "acetic acid"
    [set prod_level precision (prod_level + (0.0875 * [flow] of myself))2
    set capital capital - ([item 0 price] of z * [flow] of myself)
         ]

    if breed = SPP and co-product_scenario = "acetal"
    [set prod_level precision (prod_level + (0.0146 * [flow] of myself))2
    set capital capital - ([item 0 price] of z * [flow] of myself)

   ]
     market  z y
    let ff [flow] of myself
    production ff

    ; Aumenta la sostenibilità e l'innovazione ricevendo conoscenza
    set sustainability_attitude sustainability_attitude + (0.05 * [flow] of myself)
    set innovativeness innovativeness + (0.05 * [flow] of myself)
   find_transport [flow] of myself y z


  ]

  set flow 0
  set active false
end 

to market [sup cli]
  if breed = SPP[
     if co-product_scenario = "acetaldehyde"[
     set capital capital + (([item 0 price] of self * (0.0433 * [flow] of myself)) + ([item 1 price] of self * (0.9567 * [flow] of myself)))

    ]

    if co-product_scenario = "acetic acid"[
    set capital capital + (([item 0 price] of self * (0.0875 * [flow] of myself)) + ([item 1 price] of self * (1.3036 * [flow] of myself)))]


    if co-product_scenario = "acetal" [
      set capital capital + (([item 0 price] of self * (0.0146 * [flow] of myself)) + ([item 1 price] of self * (0.8551 * [flow] of myself)))  ]]

  if breed = FPP [
    set capital capital + (([item 1 price] of self * (0.0514 * [flow] of myself)) + ([item 2 price] of self * ( 0.113 * [flow] of myself)))]
end 

to eq_stop
  if total-spp-production >= Gh2_demand [
    let f ticks / 12
    print (word "SPP production has met the GH2 demand of " Gh2_demand " Kg in " f "years")
    set simulation-running false  ; Use this to signal the simulation to stop
  ]
end 

to visual
  ask patches [
    if (pxcor = 0 and pycor < 0) or (pycor = 0 and pxcor > 0) [
      set pcolor sky  ; Usiamo il colore "sky" per l'azzurro
    ]
  ]
  set-default-shape links "small-arrow-link"

  ask turtles [
    set size 0.8
    set price [0 0 0]
set demander false
    set supplier false
    if breed = farmers [
    set ordered-clients []
    set shape "flower"
    set color green
    let price_sugarcane random-float one-of (range 0.022 0.026 0.001)
    set price replace-item 0 price price_sugarcane
      setup-random-position]

    if breed = FPP [
    set ordered-clients []
    set ordered-suppliers []
    set shape "first prod"
    set color red
    let price_bioethanol random-float one-of (range 0.8 0.9 0.001)
    let price_sugar random-float one-of (range 0.3 0.4 0.001)
    let price_bioeletr random-float one-of (range 0.07 0.085 0.001)
    set price replace-item 0 price price_bioethanol
    set price replace-item 1 price price_sugar
    set price replace-item 2 price price_bioeletr

    setup-random-position
  ]

  if breed = SPP [
    set ordered-suppliers []
    set shape "second prod"
    set color 116
 let price_h2 random-float one-of (range 4 5 0.01)
      set price replace-item 0 price price_h2

       if co-product_scenario = "acetaldehyde" [let price_coproduct random-float one-of (range 3 10 1)
      set price replace-item 1 price price_coproduct
      ]
        if co-product_scenario = "acetic acid" [ let price_coproduct random-float one-of (range 0.8 0.9 0.001)
      set price replace-item 1 price price_coproduct]
          if co-product_scenario = "acetal"[ let price_coproduct random-float one-of (range 0.8 1.25 0.01)
        set price replace-item 1 price price_coproduct ]

    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 yellow
    setup-random-position]

     if breed = S_T[
    set shape "bot"
    set color white
    ifelse random-float 1.0 < 0.5 [
    ; Posizione lungo l'asse y (pxcor = 0, pycor < 0)
    setxy 0 (random -15)
  ] [
    ; Posizione lungo l'asse x (pycor = 0, pxcor > 0)
    setxy random 15 0 ]
  ]]
end 

; Funzione per impostare la posizione in uno dei quadranti 1, 3, 4

to setup-random-position
  ; Continua a scegliere una posizione finché non ne trova una valida
    let x random-xcor
    let y random-ycor
    ; Controlla se la posizione è valida (non nel quadrante 2)
    if not (x > 0 and y < 0) [
      setxy x y
    ]
end 

to move-ft-gradually [target]
  let steps 3 ; Numero di passi per raggiungere la destinazione
  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 ; Aggiorna l'interfaccia grafica ad ogni passo
    ; Puoi inserire un wait qui se vuoi rallentare visivamente il movimento, es: wait 0.05
  ]
end 

to colors
  ask turtles[
    if breed = farmers [
      set color green]

    if breed = FPP [
      set color red]

    if breed = SPP [
      set color violet]]
end 
;to highlight-complete-supply-chain
;
;  ; Iterate over FPP agents
;
;    ; Check if there are incoming links from Farmers
;    let has-farmer-link? any? in-link-neighbors with [breed = farmers]
;    ; Check if there are outgoing links to SPPs
;    let has-SPP-link? any? out-link-neighbors with [breed = SPP]
;
;    ; If both conditions are met, highlight all related links in yellow
;    if has-farmer-link? and has-SPP-link? [
;      ; Highlight incoming links from Farmers
;      ask my-in-links with [[breed] of end1 = farmers] [
;        set color yellow
;      ]
;      ; Highlight outgoing links to SPPs
;      ask my-out-links with [[breed] of end2 = SPP] [
;        set color yellow
;      ]
;    ]
;
;end

There is only one version of this model, created 6 months ago by Simonetta Primario.

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.