3

I am fairly new to netlogo and modelling as a whole. I am now modelling the municipal solid waste system of the Netherlands and I need to be able to distribute a predetermined amount of waste-generated randomly among a breed (municipalities) within my model. I need to do the same for money among waste processors.

I have tried it with globals, with breeds-own and even creating a new breed for waste (which sort of worked but my solution needed way too much calculation power which I don't see how to simplify it.

thanks in advance

  • How long should the list be? Integers (whole numbers) or floats (decimal numbers)? What should the distribution of the random numbers be (I would guess uniform)? Would you give a few examples of the kind of output you'd like given certain inputs? – Bryan Head Oct 29 '14 at 01:08

1 Answers1

1
To share[waste]
While [waste > .1] ;; or some small number
[
Let r random-float 1
Set waste waste - r
Ask one-of patches[set pcolor pcolor + r
]
Ask one-of patches[set pcolor pcolor + waste ;; ditch the dregs
End

Doing it with integers would not be much different.

To make it a list

Let pots []
Ask patches[set pots lput pcolor pots]

Answer 2 uniform distribution

Ask n[set take random-float resource / count n]
Let fix (resource - sum [take] of p) / count n
Ask n[set take take + fix]
King-Ink
  • 2,096
  • 12
  • 18
  • It looks to me like the code might end up adding `r` in the same patch more than once. That may be what you intended. – Mars Oct 29 '14 at 02:38
  • Exactly right. That way it does't run out and produces a uniform distribution. – King-Ink Oct 29 '14 at 02:43
  • I was trying to figure out whether that would produce a uniform distribution, but have not succeeded. – Mars Oct 29 '14 at 02:45
  • I Threw it into a histogram it has a normal distribution... er.. not uniform. – King-Ink Oct 29 '14 at 02:55
  • King-Ink's algorithm seems like the right one to me, but I wonder if there's some formula that gives the same results without having to loop, and without having to approximate (by choosing an arbitrary small value for `waste`). As for getting a uniform distribution, I'm not sure that even makes sense to ask for. It seems to me that it can't _both_ be uniformly random _and_ add up to a fixed amount every time. – Seth Tisue Oct 29 '14 at 12:00
  • http://stackoverflow.com/a/16884017/86485 suggests "think of your sum as a number line, and rather than generating random numbers for the segments, generate n-1 numbers as points along the line, and subtract to get the segments" – Seth Tisue Oct 29 '14 at 12:03
  • http://stackoverflow.com/a/2640067/86485 suggests "generate N random numbers, compute their sum, divide each one by the sum" but this approach may be flawed; see discussion at the link – Seth Tisue Oct 29 '14 at 12:05
  • I have a flat solution. I will put it up as an answer – King-Ink Oct 29 '14 at 13:18