I am trying to make farmer agents move their loads (herds) to selected target locations. Each farmers may own random number of loads ranging between 1 -10. The farmers select number of targets same as their number of loads. Loads originate from farmer's home and move to target sites that farmers have chosen. Each load has a variable distance-travelled and each farmer has a variable
total-distance-travelled. My aim is to calculate sum of distance-travelled by each load of individual farmers under total-distance-travelled and patch coordinates for visited patches.
Breed [ loads load ]
breed [ farmers farmer]
farmers-own [visited-list my-loads num-loads my-targets my-home total-distance-travelled ]
loads-own [load-id origin current-destination distance-travelled]
patches-own [ my-targets? target-cell? resource my-agent ]
to setup
ca
;;;;;;;;;;;;;;;;;;; setup farmers ;;;;;;;;;;;;;;;;;;;;;;;;;;;
create-farmers num-farmer ; crt agents based on slider
[
set shape "person"
set color random 50
set size 1.5
set my-targets no-patches ; no targets initially
setxy random-xcor random-ycor
set my-home patch-here ; agent sets current-patch as my-home
set num-loads random 10 + 1 ; number of loads starting from one instead of zero
set total-distance-travelled 0 ; initial travel distance is zero
set visited-list [ ]
pen-down
;;;;;;;;;;;;;;;;;; setup loads ;;;;;;;;;;;;;;;;;;;;;;;
hatch-loads num-loads ; farmers create loads same as their value of num-loads variable
[ set load-id [ who ] of myself ] ; load variable that identify load-owner
set my-loads loads with [ load-id = who ] ; farmer variable that identify farmer's loads
ask loads [
pen-down
set shape "box" set size 1
set origin [ my-home] of farmers with [ who = [load-id] of myself] ; setting origin patch as farmer's home patch
]
]
;;;;;;;;;;;;;;;;;; setup patches ;;;;;;;;;;;;;;;;;;;;;;;
Ask patches [
set resource random 9
set my-agent nobody
ifelse resource = 0
[ set target-cell? false ]
[ set target-cell? true ]
]
reset-ticks
end
to go
if ticks > 365 [ stop ]
ask farmers [
find-my-targets
move-myloads
calculate-total-distance-travelled
]
tick
end
to find-my-targets ;; turtle procedure
ask farmers [
set my-targets up-to-n-of num-loads patches with [target-cell? ]
set visited-list fput my-targets visited-list
move-myloads
]
end
to move-myloads
ask my-loads [
let old-xcor xcor
let old-ycor ycor
move-to my-targets
set current-destination my-targets
set distance-travelled distance origin
]
end
to calculate-total-distance-travelled
end
It does work but it stores my-targets and visited-sites as number of patches e.g.
[[(agentset, 5 patches) (agentset, 5 patches)] [(agentset, 3 patches) (agentset, 3 patches)]]