vendredi 28 décembre 2018

random-poisson value for entire list in netlogo

I have agents called 'orders' Within these agents there is a number of devices as an attribute. Depending on the age of each of the devices, a certain number of devices will break in accordance with a random-poisson process. For example:

Orders have attributes:

  • Number of installed devices (amount-installed)
  • Number of broken devices (amount-broken)
  • Number of devices broken this timestep (broken-this-year)
  • Age of the devices in this order (order-age)
  • Average lifespan of the order (average-lifespan)

I have found a few ways on how to implement this using a filter in a list approach:

ask orders [
    let broken-list n-values amount-installed [random-poisson order-age]
    set broken-list filter [s -> s >= average-lifespan] broken-list
    set broken-this-year length broken-list
    set amount-installed amount-installed - broken-this-year
    set amount-broken amount-broken + broken-this-year
]

Another way I have found to implement this is using a while-loop approach:

 ask orders [
    while [amount-checked < amount-installed] [
      if random-poisson order-age >= average-lifespan [
        set broken-this-year broken-this-year + 1
      ]
      set amount-checked amount-checked + 1
    ]
    set amount-installed amount-installed - broken-this-year
    set amount-broken amount-broken + broken-this-year
]

There should therefore be a number of the installed devices that break, while a number of devices still remain working. However, each order consists of several thousands of devices, and there are hundreds of orders in my model. This process therefore takes an extremely long time to the point that the computer freezes. There must be a way to attain the same results without using a loop method. Does anyone know a better way to approach this?




Aucun commentaire:

Enregistrer un commentaire