How do I report distance from patch to turtle in behavior space?

101 Views Asked by At

I have patches in a circle that represent something that the turtles go into. In the end when running Behavior Space experiments I want to be able to measure the distance from each turtle to the edge of that circle, and I want to report the net value of it. I keep getting errors and I do not know properly how to do it.

I've tried setting final coordinates and initial coordinates to "patch-here". But I keep getting problems that say "You can't use INITIAL-COORD in an observer context, because INITIAL-COORD is turtle-only".

;my code ends at 350 ticks, this is in the go function...

if ticks = 350
    [ask rbc [ set final-coord patch-here ]
    ask initial-coord [set dist dist + distance final-coord]
    set dist dist / (count rbc)]

;and then when I try to make a file from my data...

to makeOutputFile
    set fileCounter 0
    let date date-and-time
    repeat 16 [set date remove-item 0 date]

    set output_folder (word "Experiments/")

    while [file-exists? (word output_folder"run_"fileCounter"_"date"_output.txt")][set fileCounter fileCounter + 1]
    let output_file(word output_folder"run_"fileCounter"_"date"_output.txt")

    file-close-all
    file-open output_file
    file-write ( "dist:")
    file-write (dist)

end
1

There are 1 best solutions below

0
StephenGuerin On

try replacing:

[ask rbc [ set final-coord patch-here ]
    ask initial-coord [set dist dist + distance final-coord]
    set dist dist / (count rbc)]

with:

set dist mean [distance initial-coord] of rbc

This should work if inital-coord is a global or turtle property

Also, you might calculate this in the "measure runs using these reporters" area in the BehaviorSpace window instead of writing to files manually.