我想在netlogo中的节点之间创建条件流。使用扩散模型中的代码,我试图设置如果乌龟1的值大于x(例如1),来自乌龟1的当前流量将停止流入乌龟2.任何帮助都非常感激。
这是我目前的代码。
`directed-link-breed [active-links active-link]
undirected-link-breed [inactive-links inactive-link]
turtles-own [ val new-val ] ; a node's past and current quantity, represented as size
links-own [ current-flow ] ; the amount of quantity that has passed through a link
; in a given step
globals [
total-val ; total quantity in the system
max-val ; maximum quantity held by a single node in the system
max-flow ; maximum quantity that has passed through a link in the system
mean-flow ; average quantity that is passing through an arbitrary
; link in the system
]
;;;;;;;;;;;;;;;;;;;;;;;;
;;; Setup Procedures ;;;
;;;;;;;;;;;;;;;;;;;;;;;;
to setup
clear-all
set-default-shape turtles "circle"
create-turtles 3 [set color blue]
ask turtle 0 [setxy -11 16]
ask turtle 1 [setxy -12 8]
ask turtle 2 [setxy -9 12]
ask turtle 0 [
set val 1
create-active-link-to turtle 2
[set current-flow 1]
]
ask turtle 1 [
set val 1
create-active-link-to turtle 2
[set current-flow 1]
]
ask turtle 2 [
set val 1
create-active-link-to turtle 0
[set current-flow 1]
]
ask turtle 2[
set val 1
create-active-link-to turtle 1
[set current-flow 1]
]
update-globals
update-visuals
reset-ticks
end
;;;;;;;;;;;;;;;;;;;;;;;
;;; Main Procedure ;;;
;;;;;;;;;;;;;;;;;;;;;;;
to go
ask turtles [ set new-val 0 ]
ask turtles [
let recipients out-active-link-neighbors
ifelse any? recipients [
let val-to-keep val * (1 - diffusion-rate / 100)
; we keep some amount of our value from one turn to the next
set new-val new-val + val-to-keep
; What we don't keep for ourselves, we divide evenly among our out-link-neighbors.
let val-increment ((val - val-to-keep) / count recipients)
ask recipients [
set new-val new-val + val-increment
ask in-active-link-from myself [ set current-flow val-increment ]
]
] [
set new-val new-val + val
]
]
ask turtles [ set val new-val ]
update-globals
update-visuals
tick
end
;;;;;;;;;;;;;;;;;;;;;;;
;;; Updates ;;;
;;;;;;;;;;;;;;;;;;;;;;;
to update-globals
set total-val sum [ val ] of turtles
set max-val max [ val ] of turtles
if any? active-links [
set max-flow max [current-flow] of active-links
set mean-flow mean [current-flow] of active-links
]
end
to update-visuals
ask turtles [ update-node-appearance ]
ask active-links [ update-link-appearance ]
end
to update-node-appearance ; node procedure
; scale the size to be between 0.1 and 5.0
set size 0.1 + 5 * sqrt (val / total-val)
end
to update-link-appearance ; link procedure
; scale color to be brighter when more value is flowing through it
set color scale-color gray (current-flow / (2 * mean-flow + 0.00001)) -0.4 1
end
`