Is It Possible to. have 2 similar patch variables?

49 views
Skip to first unread message

Emily W

unread,
Dec 3, 2020, 11:47:03 AM12/3/20
to netlogo-users

I am trying to set up pheromone, a patch variable, in addition to the existing patch-variable chemical. This is based off the chemical in the original Ants model by Uri Wilensky. I get this error in setting up: Expected command

to recolor-patch ;; patch procedure [ set pcolor scale-color green chemical 0.1 5 ] [ set pcolor scale-color gray pheromone 0.1 5 ] end

Can you help me figure out how to have both variables?

Chemical currently functions by being released by both leaders and followers, diffusing/evaporating, and controlling behavior of followers and foragers through uphill-chemical. I want pheromone to be similar, but released by leaders only and responded to be followers only.

to go ask followers [if any? leaders [uphill-chemical fd 3 pickup-food]] diffuse chemical (diffusion-rate / 100) ask patches [ set chemical chemical * (100 - evaporation-rate) / 100 ;; slowly evaporate chemical recolor-patch ] tick end to pickup-food if color = violet [facexy nest-x nest-y jump 2 set chemical chemical + 60] end

Thanks!!

Michael Tamillow

unread,
Dec 3, 2020, 12:51:57 PM12/3/20
to Emily W, netlogo-users
Hi Emily,

It looks like you are not setting the patch variable but you are setting the color of the patch based on the variable. It seems like this would be conflicting since you can’t have two colors for one patch.

You can diffuse the variables identically, but visualizing it might be difficult. Maybe a switch that determines which variables diffusion is visually displayed?

Hope that helps.

Sent from my iPhone

On Dec 3, 2020, at 10:47 AM, Emily W <liftu...@gmail.com> wrote:


--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/e6edd678-36a1-4cd2-8969-01e081ae0eean%40googlegroups.com.

Aaron Andre Brandes

unread,
Dec 8, 2020, 9:48:50 AM12/8/20
to Michael Tamillow, Emily W, netlogo-users

Micheal has the correct diagnosis of your problem.

You can visualize a second variable by using the view2.5d extension.

I have attached an example that demonstrates the use of patch height to show a second variable.

The Models Library has an example 2.5d Patch View Example that  uses diffusion, but bases the height on the pcolor, not a second variable.

 

I hope this is helpful, and let the list know if you have further questions.

Aaron

 

-- 

Aaron Brandes, Software Developer

Center for Connected Learning and Computer-Based Modeling

2.5d PatchView

John Chen

unread,
Dec 8, 2020, 9:52:27 AM12/8/20
to Aaron Andre Brandes, Emily W, Michael Tamillow, netlogo-users
Colors have potentialities to express two dimensional data, if view2.5d is somehow not being used. You may use brightness/contrast for one variable and hue for another, though the variation is limited.

James Steiner

unread,
Dec 10, 2020, 10:27:02 AM12/10/20
to netlogo-users
You can visualize up to three variables on the same patch if you blend the colors yourself and use the RBG primitive reporter.

For example, pheromone can be a shade of red, and chemical can be a shade of green. You can use SCALE-COLOR and some math to scale the values to the ranges needed by the RBG reporter. Then use that to set the PCOLOR. Then your chemicals will be visualized as overlapping fields of red, blue, and green, blending toward white where they overlap.

Below is a sample model that demonstrates this idea. Paste the code into the code pane of a new model, Add a setup and go / forever button.

Further manipulating the calculated RGB values can be used to highlight certain values. If all the values are high, the display is not as useful, as it blurs into a solid white field. 

I hope it is clear enough that it helps you.

~~James

;; START OF CODE
patches-own
[ pvariable1
  pvariable2
  pvariable3
]

breed [ emitters emitter ]

emitters-own
[ tvariable1
  tvariable2
  tvariable3
  tconsume1
  tconsume2
  tconsume3
]

globals
[ max-pvariable1
  max-pvariable2
  max-pvariable3
  to-RGB
  edges
]

to setup
  clear-all
  reset-ticks
  setup-emitters
  setup-environment
  color-patches
  display
end

to go
  emitters-move
  emitters-emit
  emitters-consume
  diffuse-chemicals
  color-patches
  tick
end

to setup-emitters
  ;; create three different kinds of chemical emitters
  create-emitters 10
  [ setxy random-pxcor random-pycor
    set tvariable1 2
    set tconsume2 2
  ]
  create-emitters 10
  [ setxy random-pxcor random-pycor
    set tvariable2 2
    set tconsume3 2
  ]
  create-emitters 10
  [ setxy random-pxcor random-pycor
    set tvariable3 2
    set tconsume1 2
  ]
end

to setup-environment
  set edges patches with
  [
    pxcor = min-pxcor or
    pxcor = max-pxcor or
    pycor = min-pycor or
    pycor = max-pycor
  ]
 
  set to-RGB 255 / white
 
  set max-pvariable1 10
  set max-pvariable2 10
  set max-pvariable3 10
end

to emitters-move
  ask emitters
  [ move-to one-of neighbors
  ]
end

to emitters-emit
  ask emitters
  [
    set pvariable1 pvariable1 + tvariable1
    set pvariable2 pvariable2 + tvariable2
    set pvariable3 pvariable3 + tvariable3

  ]
end

to emitters-consume
  ask emitters
  [
    set pvariable1 pvariable1 - tconsume1
    set pvariable2 pvariable2 - tconsume2
    set pvariable3 pvariable3 - tconsume3

  ]
end

to diffuse-chemicals
    ;; simulate chemicals diffusing off the edge of the world
    ask edges [ set pvariable1 0 set pvariable2 0 set pvariable3 0]
    ;; diffuse chemicals  in world
    diffuse pvariable1 .25
    diffuse pvariable2 .25
    diffuse pvariable3 .25  
end

to color-patches
 
  ;; color the patches
  ask patches
  [
    ;; we use gray gives us value from 0 to 9.9
    let pcolor-1 to-RGB * SCALE-COLOR GRAY pvariable1 0 max-pvariable1
    let pcolor-2 to-RGB * SCALE-COLOR GRAY pvariable2 0 max-pvariable2
    let pcolor-3 to-RGB * SCALE-COLOR GRAY pvariable3 0 max-pvariable3
    set pcolor RGB pcolor-1 pcolor-2 pcolor-3
  ]
end

;; END OF CODE


 

--

Michael Tamillow

unread,
Dec 10, 2020, 10:39:51 AM12/10/20
to James Steiner, netlogo-users
This poses the question: is purple qualitatively different than the blue and red that compose it?

I would say in the human mind it is.

Sent from my iPhone

On Dec 10, 2020, at 9:27 AM, James Steiner <grego...@gmail.com> wrote:



James Steiner

unread,
Dec 28, 2020, 10:30:43 AM12/28/20
to Emily Warsavage, netlogo-users

You need to provide all the required parameters. 

Since it requires three parameters (red, green blue) and you are are only using two colors, just set the third color to 0.

Set pcolor rgb p1 p2 0

You could put the 0 in any position to leave that color out. 

Set pcolor rgb 0 p1 p2

~~James


On Tue, Dec 15, 2020 at 10:28 AM Emily Warsavage <liftu...@gmail.com> wrote:
What do you suggest I do? 

On Tue, Dec 15, 2020 at 8:27 AM Emily Warsavage <liftu...@gmail.com> wrote:
Thanks! In trying the code in my model, I'm getting an error message for set pcolor RG pcolor-1 pcolor-2, since the original code had set pcolor RGB pcolor-1-pcolor-2 pcolor-3. 

Emily W

You received this message because you are subscribed to a topic in the Google Groups "netlogo-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/netlogo-users/gjchsUi-PnY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/CADiHOG60oqH7r%2BGm2RuTH8uFGyAP8YcgBL0JBYYjdsCLDji0uw%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages