user710
user710

Reputation: 161

Not to use breed but deal with two types of turtles

I have two sets of agents: retailerA and retailerB. Previously, I used breed to create them, but as I wanted to create a random network in which it was asking all the turtles and randomly choosing some to be connected, I decided it is better to keep turtles in the random network code (in the library) and do this change:

create-turtles 130 ; 100 of which are retailerA and 30 are retialerB.

Now I want each set of agents to have a different display. RetailerA will be scattered randomly while retailerB should be shown in a circle. However, the following code does not do what I want.

to A
create-turtles 100
set retailerA? true
set shape "person"
setxy random-xcor random-ycor
end

to B
  create-turtles 30 [
    set retailerB? true
    set shape "person"
    set color gray

  ]
  ask turtles with [retailerB?] [
    layout-circle turtles with [retailerB?] (max-pxcor - 5)
    ]
end

This treats all the turtles to have a circle display.

Thanks,

Upvotes: 0

Views: 459

Answers (1)

Luke C
Luke C

Reputation: 10336

When you create a turtles-own variable, the default value is 0. So, if you do

  create-turtles 100 [
    set retailerA? true
    set shape "person"
    setxy random-xcor random-ycor
  ]

You have correctly set retailerA? to true, but since you did not set retailerB? for this agentset, they will all have a value of 0 for retailerB?. So, if you try to evaluate a true/false expression using with (eg turtles with [retailerB?]...) but some of the turtles return a value of 0 instead of either true or false, NetLogo doesn't know what to do. To fix this, you could either explicitly set those variables in the setup procedure, like this:

to spawn-a
  create-turtles 100 [
    set retailerA? true
    set retailerB? false
    set shape "person"
    setxy random-xcor random-ycor
  ]
end

or you could explicitly say with [retailerB? = true].

Additionally, check out the syntax for layout-circle- you don't need to ask turtles with that primitive. To fix your issues, then, you'd need something like:

turtles-own [ retailerA? retailerB? ]

to setup
  ca
  spawn-a
  spawn-b
  reset-ticks
end

to spawn-a
  create-turtles 100 [
    set retailerA? true
    set shape "person"
    setxy random-xcor random-ycor
  ]
end

to spawn-b
  create-turtles 30 [
    set retailerB? true
    set shape "person"
    set color gray

  ]  
  layout-circle turtles with [retailerB? = true] (max-pxcor - 5)
end

Upvotes: 2

Related Questions