0

I have 200 turtles which represent producers. Each turtle, has 2 variables (sales of 2 prodcuts) and they are compared to let the prodcuer know which product was the most popular, so the turtle's color changes to the color representing that product. I defined this loop :

    while [counter < 201][
      ask n-of 1 producers [
        if  (product1sales > product2sales) 
       [
       set color  green
    ]
if  (product2sales > product1sales) 
       [
       set color  red
    ]
;
  set counter counter + 1]

  ]

I assumed each time n-of is called, one turtle is chosen, but this specific turtle will not be chosen again. I also assumed that by running the code, all the turtles must be either green or red, but some are neither green nor red since n-of is not working as I assumed. one-of is not doing what I want either. Any ideas?

Thanks

user710
  • 161
  • 2
  • 12
  • `one-of` and `n-of` select 1 and n random agents respectively, but that has no implications for future selection, just the number of agents to be asked. In NetLogo, it is very unlikely you would ever need to loop through agents because that's what `ask` does. The `ask []` primitive is not simultaneous, it iterates through the agents being asked and each one (in random order) does whatever is in the []. – JenB Jun 23 '17 at 09:03
  • Thanks. I tested this code to understand what n-of does to better decide what to do about accessing a csv file. 200 producers' information is stored in a csv that I imported and put them in a matrix, each row contains things related to a producer. What I need to be done that I suppose ask does not is that for each producer, a row of marix gets selected. The sum of the two first columns be stored in one variable, and the other 3 columns are also summed in another variable. Then that comparison is done. Do you think I'd better ask it as a new question? – user710 Jun 23 '17 at 19:13
  • definitely ask a new question if you can't make it work. But look in the Models Library, Code section, there is an example of importing a csv file and assigning values to agent properties – JenB Jun 24 '17 at 08:33
  • Thanks. The code in the library is helpful :) – user710 Jun 25 '17 at 01:19

1 Answers1

0

If you just ask producers it will ask all of the producers in a random order, but without repeating- if you just want all of them to make a choice between the two choices you wouldn't even need the counter.

If either product1sales or product2salesis always higher, you could also trim a little by using ifelse. See if the example below would give you what you need:

breed [ producers producer ]

producers-own [ product1sales product2sales ]

to setup
  ca
  reset-ticks
  create-producers 200 [
    setxy random 30 - 15 random 30 - 15
    set product1sales random-float 11
    set product2sales random-float 11
    set color white
  ]

end

to choose

  ask producers [
    ifelse  product1sales > product2sales [
      set color green
    ]
    [ 
      set color red
    ]
  ]      

end
Luke C
  • 10,081
  • 1
  • 14
  • 21