i'm working on a netlogo world with a certain number of supermarkets and distribution centers. Each supermarket has a single distribution centre that delivers goods once a week. But i don't know how to connect a single supermarket to a single distribution center.
with one of of min one of it always has double connections. This is my current code
globals [
households ; random kleur huizen, achtergrond grijs
supermarkets ;; blauw
distribution-centers ; roze autos, achtergrond rood
]
patches-own[ ]
turtles-own [visited target block ]
to setup
clear-all
setup-households
setup-supermarkets
setup-distribution-centers
reset-ticks
end
to setup-households
ask n-of N patches with [pcolor = black] [
set pcolor grey
sprout 1 [
set shape "house"
set color orange
]
]
set households patches with [pcolor = grey]
end
to setup-supermarkets
;; Blokje [groen] van 5x5 maken waar supermarkets inkunnen
ask patches with[
pxcor >= -2.5 and pxcor <= 2.5 and
pycor >= -2.5 and pycor <= 2.5
] [
set pcolor green
]
ask n-of M patches with [pcolor = green] [
set pcolor blue
]
set supermarkets patches with [pcolor = blue]
end
to setup-distribution-centers
;; als blokje zwart of groen is creer dan m aantal distrubution-centers
ask n-of M patches with [pcolor = black] [
set pcolor red
sprout 1 [
set visited false
set color pink
set shape "car"
set block patch-here
set target min-one-of supermarkets [distance myself]
]
]
set distribution-centers patches with [pcolor = red]
end
to go
ask turtles with [color = pink] [
if visited [
move-to-target
check-distribution-center
]
if not visited [
move-to-target
check-supermarkets
]
]
tick
stop
end
to move-to-target
if (color != green) [
face target
fd 1
]
end
to check-distribution-center
if patch-here = block [
set visited true
set color green
]
end
to check-supermarkets
if member? patch-here supermarkets [
set visited true
set target block
]
end
Since
min-one-of supermarkets [distance myself]returns the closest supermarket, chances are high that this is the same for two turtles. One way would be to track which supermarket is already a target of a turtle. Here is how you could do this (see lines 7, 63 & 64). Please be careful, this requires that there are always less or equal supermarkets compared to distribution-centers and that you only connect them once during one run.Btw. your code seems like it could benefit greatly from using breeds (for supermarkets, distribution-centers and housholds)!