Search code examples
constraintssimulationnetlogoagent-based-modeling

Trying to find a way to keep agents to specific patches in net logo


I have created a world that has a blue side and green side with a border in the middle in which I have created two sets of agents one being blue-population and other being green-population, however I cant seem to keep the blue-population in the blue side and like wise with the green, this is the code I am working with:

    to setup_world
  clear-all
  reset-ticks
  ask patches with [pxcor <  0] [ set pcolor blue ]
  ask patches with [pxcor >  0] [ set pcolor green ]

  set border patches with [(pxcor =  0 and abs (pycor) >= 0)]
  ask border [ set pcolor white]

end
to setup_agents

  clear-turtles create-humans blue_population [
    setxy random-xcor random-ycor 
 ifelse xcor >= 0
    [set continent 1]
    [set continent 2]
    set virus? false
    set dead false
    set antibodies 0
    set color yellow
    set size 10
    set shape "blue person"
    ]

   create-humans green_population [
    setxy random-xcor random-ycor
     ifelse xcor >= 0
    [set continent 1]
    [set continent 2]
    set color yellow
    set size 10
    set shape "green person"
    set shape "person"
    set virus? false
    set dead false
    set antibodies 0

  ;]
end

I was hoping by creating continents I was able to keep them to a specific side but does not seem to work, I feel as I am not using the right constraints, anyone can provide me any insight on how this can be resolved ?


Solution

  • Your logic is a little confused, I suspect you changed how you were planning to do it in the middle. Look at the blue population procedure - you make them all blue people, but you have created them in any random location and then assigned the continent based on where they are located. At no point have you actually said the equivalent of 'if I am on the blue side, I am a blue person' or 'only create the blue people on the blue side'.

    What you really want is something more like:

    setxy abs random-xcor random-ycor for the blue people

    and

    setxy abs random-xcor * -1 random-ycor for the green people

    abs makes the number positive so this is an easy way to randomly select a positive number (which you can make negative by multiplying by -1)