commands run too many times?

9 views
Skip to first unread message

Unruh Lee

unread,
Jun 21, 2022, 5:20:44 PM6/21/22
to netlogo-users
I can't figure out why this code is executing multiple times per "highlanders with [ cacao-grower = true ]". It is cumulatively adding up the values for "exchange-value-wealth" for ALL such agents, once per agent. So when there is only one such agent, it is correct, according to what I want the code to do. But when there are two such agents, it does it two times for each agent, instead of the two times I'd expect, and also incorrectly adds results from the first tick AGAIN. And when there are three such agents, it does it three times more and again adds the former cumulative sum incorrectly. 

to harvest-cacao
  ask highlanders with [ cacao-grower = true ] [
    let owner-id who
    let max-res-of-owned-patches [ max-resource-here ] of patches with [ owner = owner-id ] 
    show word "max-resource-here values of each patch owned: "  max-res-of-owned-patches
    let cacao-values [] ; an empty list, to start, of the cacao crop values
    foreach max-res-of-owned-patches [ x -> set cacao-values lput (x * 2) cacao-values ] ; sets the cacao crop values list as product of max-resource-here * 2, just for simplicity / testing.
    show word "cacao crop values: " cacao-values
    let cacao-total sum cacao-values ; total value of all cacao crops owned by each grower
    set exchange-value-wealth exchange-value-wealth + cacao-total 
    print word "exchange-value-wealth: " exchange-value-wealth 
  ]
end


The full model code is attached in case that's handy. It is slightly different than the above, for simplicity. 

Thanks in advance for any help!
Lee

resourceharvest_altered_6_21_22.nlogo

Unruh Lee

unread,
Jun 21, 2022, 6:17:08 PM6/21/22
to netlogo-users
PS. I just realized part of what I said was behaving wrong about this code, is actually behaving correctly. When I said, "and also incorrectly adds results from the first tick AGAIN.." , that was incorrect; it should be adding cumulatively in this way. 

But the other part is still problematic: "...cumulatively adding up the values for "exchange-value-wealth" for ALL such agents, once per agent." That is the part I want to fix. 

--
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/2vb7Cj7eC2M/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/ebbae193-cc0c-44f5-aa3b-1be87555f3a6n%40googlegroups.com.

James Steiner

unread,
Jun 21, 2022, 7:46:35 PM6/21/22
to Unruh Lee, netlogo-users
I can't download the model on mobile, but is it possible that this procedure is being called from inside another ASK? Like "ask highlanders [ harvest-cacao ]"

That would explain what you describe

Also, just as an idiomatic netlogo  style note: rather than store who in owner, store the turtle, so you can use: 

 Patches with [ owner = myself ] 










--
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.

James Steiner

unread,
Jun 21, 2022, 7:57:58 PM6/21/22
to Unruh Lee, netlogo-users
Yeah, it looks like you're running that procedure inside another procedure 


Ps. You can turn who into a color like so:

Set color red + 10 * ( who mod 13) 

If you need more than that, I have some fancy math that will produce more shades. Up to like, 52 total. 


Reply all
Reply to author
Forward
0 new messages