【发布时间】:2015-08-11 17:07:59
【问题描述】:
请参阅下面的 Netlogo 文件。我希望海龟在来自“缓冲存储”的 WS3 处右转,而海龟在来自“QC 缓冲存储”的 WS5 处左转。但是,我收到一个错误。我在网上找到了附加代码,并没有100%理解它。有人可以帮帮我吗?
非常感谢, 约翰
globals [
IN-free-cabinet
IN-free-drum-a
IN-free-drum-b
new_directions
distance-to-jump
WM-output
WM-output-bad
drum-output
wip
mlt-aux
avg-mlt
]
patches-own[
directions
velocity
processing-time
is-processing?
malfunction
output
ID
bifurcation
]
breed [ machine ]
breed [ drum ]
machine-own [
birth-time
death-time
process-plan
processing
time-of-processing
QC-check
]
drum-own [
birth-time
process-plan
processing
time-of-processing
]
to create-WM [ machine-type ]
;********** Create Cabinet **********
set-default-shape machine "square"
ask patch -12 0 [
ifelse count machine-here = 0 [ set IN-free-cabinet TRUE ] [ set IN-free-cabinet FALSE ]
]
if IN-free-cabinet
[
create-machine 1 [
setxy -12 0
set size 1
set heading 90
set color Blue
set birth-time ticks
set process-plan ["WS1" "WS2" "WS3" "WS4" "WS5" "WS6" "OUT" ]
set processing FALSE
set QC-check "GOOD"
]
]
;********** Create Cabinet **********
;********** Create Drums **********
set-default-shape drum "drum"
ask patch -7 -3 [
ifelse count drum-here = 0 [ set IN-free-drum-a TRUE ] [ set IN-free-drum-a FALSE ]
]
ask patch -3 3 [
ifelse count drum-here = 0 [ set IN-free-drum-b TRUE ] [ set IN-free-drum-b FALSE ]
]
if IN-free-drum-a
[
create-drum 1 [
setxy -7 -3
set size 1
set heading 0
set color Pink
set birth-time ticks
set process-plan ["WS3"]
set processing FALSE
]
]
if IN-free-drum-b
[
create-drum 1 [
setxy -3 3
set size 1
set heading 180
set color Pink
set birth-time ticks
set process-plan ["WS5"]
set processing FALSE
]
]
;********** Create Drum **********
end
to setup
;; (for this model to work with NetLogo's new plotting features,
;; __clear-all-and-reset-ticks should be replaced with clear-all at
;; the beginning of your setup procedure and reset-ticks at the end
;; of the procedure.)
__clear-all-and-reset-ticks
set WM-output 0
set drum-output 0
set avg-mlt 0
set mlt-aux 0
set WM-output-bad 0
;********** Main line **********
ask patch -11 0 [
set pcolor White
set directions [-1 90 -1 -1]
set velocity 1
set processing-time WS1-Processing-Time
set is-processing? FALSE
set malfunction FALSE
set ID "WS1"
set bifurcation FALSE
]
ask patch -10 0 [
set pcolor Yellow
set directions [-1 90 -1 -1]
set velocity 1
set is-processing? FALSE
set malfunction FALSE
set bifurcation FALSE
]
ask patch -9 0 [
set pcolor White
set directions [-1 90 180 -1]
set velocity 1
set processing-time WS2-Processing-Time
set is-processing? FALSE
set malfunction FALSE
set ID "WS2"
set bifurcation FALSE
]
ask patch -8 0 [
set pcolor Yellow
set directions [-1 90 -1 -1]
set velocity 1
set is-processing? FALSE
set malfunction FALSE
set bifurcation FALSE
]
ask patch -7 0 [
set pcolor White
set directions [-1 90 -1 -1]
set velocity 1
set processing-time WS3-Processing-Time
set is-processing? FALSE
set malfunction FALSE
set ID "WS3"
set bifurcation FALSE
]
ask patch -6 0 [
set pcolor Yellow
set directions [-1 90 -1 -1]
set velocity 1
set is-processing? FALSE
set malfunction FALSE
set bifurcation FALSE
]
ask patch -5 0 [
set pcolor White
set directions [-1 90 -1 -1]
set velocity 1
set processing-time WS4-Processing-Time
set is-processing? FALSE
set malfunction FALSE
set ID "WS4"
set bifurcation FALSE
]
ask patch -4 0 [
set pcolor Yellow
set directions [-1 90 -1 -1]
set velocity 1
set is-processing? FALSE
set malfunction FALSE
set bifurcation FALSE
]
ask patch -3 0 [
set pcolor White
set directions [-1 90 -1 -1]
set velocity 1
set processing-time WS5-Processing-Time
set is-processing? FALSE
set malfunction FALSE
set ID "WS5"
set bifurcation FALSE
]
ask patch -2 0 [
set pcolor Yellow
set directions [-1 90 -1 -1]
set velocity 1
set is-processing? FALSE
set malfunction FALSE
set bifurcation FALSE
]
ask patch -1 0 [
set pcolor Yellow
set directions [-1 90 -1 -1]
set velocity 1
set processing-time 0
set is-processing? FALSE
set malfunction FALSE
set ID "WS6"
set bifurcation FALSE
]
ask patch 0 0 [
set pcolor Yellow
set directions [-1 90 180 -1]
set velocity 1
set is-processing? FALSE
set malfunction FALSE
set bifurcation TRUE
]
ask patch 1 0 [
set pcolor Yellow
set directions [-1 90 -1 -1]
set velocity 1
set is-processing? FALSE
set malfunction FALSE
set bifurcation FALSE
]
ask patch 2 0 [
set pcolor Yellow
set directions [-1 90 -1 -1]
set velocity 1
set processing-time 0
set is-processing? FALSE
set malfunction FALSE
set ID "WS7"
set bifurcation FALSE
]
ask patch 3 0 [
set pcolor Yellow
set directions [-1 90 -1 -1]
set velocity 1
set is-processing? FALSE
set malfunction FALSE
set bifurcation FALSE
]
ask patch 4 0 [
set pcolor Yellow
set directions [-1 90 -1 -1]
set velocity 1
set is-processing? FALSE
set malfunction FALSE
set bifurcation FALSE
]
ask patch 5 0 [
set pcolor Yellow
set directions [-1 90 -1 -1]
set velocity 1
set processing-time 0
set is-processing? FALSE
set malfunction FALSE
set ID "WS8"
set bifurcation FALSE
]
ask patch 6 0 [
set pcolor Yellow
set directions [-1 90 -1 -1]
set velocity 1
set is-processing? FALSE
set malfunction FALSE
set bifurcation FALSE
]
ask patch 7 0 [
set pcolor Yellow
set directions [-1 90 -1 -1]
set velocity 1
set processing-time 0
set is-processing? FALSE
set malfunction FALSE
set ID "WS9"
set bifurcation FALSE
]
ask patch 8 0 [
set pcolor Yellow
set directions [-1 90 -1 -1]
set velocity 1
set is-processing? FALSE
set malfunction FALSE
set bifurcation FALSE
]
ask patch 9 0 [
set pcolor Yellow
set directions [-1 90 -1 -1]
set velocity 1
set processing-time 0
set is-processing? FALSE
set malfunction FALSE
set ID "WS10"
set bifurcation FALSE
]
ask patch 10 0 [
set pcolor Yellow
set directions [-1 90 -1 -1]
set velocity 1
set is-processing? FALSE
set malfunction FALSE
set bifurcation FALSE
]
ask patch 11 0 [
set pcolor Green
set directions [-1 -1 -1 -1]
set velocity 1
set is-processing? FALSE
set malfunction FALSE
set output TRUE
set ID "OUT"
set bifurcation FALSE
]
;********** Main line **********
;********** Drum buffer **********
ask patch -3 1 [
set pcolor Yellow
set directions [180 -1 -1 -1]
set velocity 1
set is-processing? FALSE
set malfunction FALSE
set bifurcation FALSE
]
ask patch -3 2 [
set pcolor Yellow
set directions [180 -1 -1 -1]
set velocity 1
set is-processing? FALSE
set malfunction FALSE
set bifurcation FALSE
]
ask patch -3 3 [
set pcolor Green
set directions [180 -1 -1 -1]
set velocity 1
set is-processing? FALSE
set malfunction FALSE
set bifurcation FALSE
]
ask patch -7 -1 [
set pcolor Yellow
set directions [0 -1 -1 -1]
set velocity 1
set is-processing? FALSE
set malfunction FALSE
set bifurcation FALSE
]
ask patch -7 -2 [
set pcolor Yellow
set directions [0 -1 -1 -1]
set velocity 1
set is-processing? FALSE
set malfunction FALSE
set bifurcation FALSE
]
ask patch -7 -3 [
set pcolor Green
set directions [0 -1 -1 -1]
set velocity 1
set is-processing? FALSE
set malfunction FALSE
set bifurcation FALSE
]
;********** Drum buffer **********
;********** Alternative line **********
ask patch 0 -1 [
set pcolor Black
set directions [-1 -1 180 -1]
set velocity 1
set is-processing? FALSE
set malfunction FALSE
set bifurcation FALSE
]
ask patch 0 -2 [
set pcolor Black
set directions [-1 90 -1 -1]
set velocity 2
set is-processing? FALSE
set malfunction FALSE
set bifurcation FALSE
]
ask patch 1 -2 [
set pcolor Black
set directions [-1 90 -1 -1]
set velocity 1
set is-processing? FALSE
set malfunction FALSE
set bifurcation FALSE
]
ask patch 2 -2 [
set pcolor Black
set directions [-1 90 -1 -1]
set velocity 2
set processing-time 20
set is-processing? FALSE
set malfunction FALSE
set ID "WS11"
set bifurcation FALSE
]
ask patch 3 -2 [
set pcolor Black
set directions [-1 90 -1 -1]
set velocity 1
set is-processing? FALSE
set malfunction FALSE
set bifurcation FALSE
]
ask patch 4 -2 [
set pcolor Black
set directions [0 -1 -1 -1]
set velocity 2
set is-processing? FALSE
set malfunction FALSE
set bifurcation FALSE
]
ask patch 4 -1 [
set pcolor Black
set directions [0 -1 -1 -1]
set velocity 1
set is-processing? FALSE
set malfunction FALSE
set bifurcation FALSE
]
;********** Alternative line **********
;********** Line labels **********
ask patch -11 1 [
set plabel "WS1"
]
ask patch -9 1 [
set plabel "WS2"
]
ask patch -7 1 [
set plabel "WS3"
]
ask patch -5 1 [
set plabel "WS4"
]
ask patch -3 1 [
set plabel "WS5"
set plabel-color 25
]
; ask patch -1 1 [
; set plabel "WS6"
; ]
;; ask patch 2 1 [
; set plabel "WS7"
;]
; ask patch 5 1 [
; set plabel "WS8"
; ]
; ask patch 7 1 [
; set plabel "WS9"
; ]
; ask patch 9 1 [
; set plabel "WS10"
; ]
;; ask patch 2 -1 [
;; set plabel "WS11"
;; ]
ask patch 11 0 [
set plabel "OUT"
]
ask patch -6 0 [
set plabel "SCANNER"
set plabel-color 25
]
;********** Line labels ***********
;********** Input Buffer ***********
ask patch -12 0 [
set pcolor Green
set directions [-1 90 -1 -1]
set velocity 1
set is-processing? FALSE
set malfunction FALSE
set bifurcation FALSE
]
;********** Input Buffer ***********
end
to execute-random
;********** Machine movement ***********
ask machine [
ask patch-here[
set distance-to-jump velocity
set new_directions remove -1 directions ]
set heading first new_directions
ifelse not bifurcation [
if not processing and first process-plan != "WS3"[
if not any? machine-on patch-ahead distance-to-jump and not [malfunction] of patch-ahead distance-to-jump[ jump distance-to-jump ]
if first process-plan = ID [
set process-plan remove-item 0 process-plan
set processing TRUE
set is-processing? TRUE
set time-of-processing processing-time
]
]
if not processing and first process-plan = "WS3" and [ID] of patch-ahead distance-to-jump = "WS3" and
; not [malfunction] of patch-ahead distance-to-jump and
not any? machine-on patch-ahead distance-to-jump[
if any? drum-on patch-ahead distance-to-jump [
jump distance-to-jump
set process-plan remove-item 0 process-plan
set processing TRUE
set is-processing? TRUE
set time-of-processing processing-time
set shape "WM"
]
]
if not processing and first process-plan = "WS3" and [ID] of patch-ahead distance-to-jump != "WS3" and
; not [malfunction] of patch-ahead distance-to-jump and
not any? machine-on patch-ahead distance-to-jump[ jump distance-to-jump ]
][ ifelse not any? machine-on patch-ahead distance-to-jump and not [is-processing?] of patch-ahead 2 and not [malfunction] of patch-ahead distance-to-jump [ jump distance-to-jump
set process-plan remove-item 0 process-plan
set process-plan fput "WS7" process-plan
][
if not any? machine-on patch-right-and-ahead 90 2 and ([malfunction] of patch-ahead 2 or any? machine-on patch-ahead 2) [
; if use-W11 [
set heading 180
jump 2
set process-plan remove-item 0 process-plan
set process-plan fput "WS11" process-plan ] ] ]
]
; ]
;********** Machine movement ***********
;********** Drum movement ***********
ask drum [
if not processing and [ID] of patch-here != "WS3"[
ask patch-here[
set distance-to-jump velocity
set new_directions remove -1 directions ]
if not any? drum-on patch-ahead distance-to-jump and ID != "WS3" and not [is-processing?] of patch-ahead distance-to-jump [ jump distance-to-jump ]
]
if any? machine-on patch-here [ die ]
]
;********** Drum movement ***********
end
to resource-processing
ask patches [
if ID = "WS7" [ set processing-time 0 ]
if ID = "WS11" [ set processing-time 0 ]
]
ask machine [
if processing [
set time-of-processing time-of-processing - 1
ask patch-left-and-ahead 90 1 [ set plabel-color Green]
]
]
ask machine [
if processing [
if time-of-processing <= 0 [
ask patch-here [
set is-processing? FALSE
]
ask patch-left-and-ahead 90 1 [ set plabel-color White]
set processing FALSE
if [ID] of patch-here = "WS5" [ ifelse random-float 1 < 0.1 [ set QC-check "BAD" ] [ set QC-check "GOOD" ] ]
]
]
]
; ifelse malfunction-WS7 [ ask patch 2 0 [ set malfunction TRUE ] ]
; [ ask patch 2 0 [ set malfunction FALSE ] ]
end
to count-output
ask machine [
if plabel = "OUT" [
set death-time ticks
ifelse QC-check = "GOOD" [ set WM-output WM-output + 1 ] [ set WM-output-bad WM-output-bad + 1 ]
set mlt-aux (mlt-aux + (death-time - birth-time))
set avg-mlt (mlt-aux / (WM-output + WM-output-bad))
die ]
]
end
to count-drums
ask machine [
if plabel = "SCANNER"
[set drum-output drum-output + 1]
]
end
to resource-ocupation
ask patches [
ifelse any? machine-here [ set is-processing? TRUE ] [ set is-processing? FALSE ]
]
end
to statistics
set-current-plot-pen "WIP"
set wip count machine-on patches + count drum-on patches
plot wip
set-current-plot-pen "avg-mlt"
plot avg-mlt / 10
end
to execute
create-WM[]
resource-ocupation
resource-processing
execute-random
tick
count-drums
count-output
statistics
end
这是我的错误信息:
REMOVE expected input to be a string or list but got the number 0 instead.
error while patch -3 -1 running REMOVE
called by procedure EXECUTE-RANDOM
called by procedure EXECUTE
called by Button 'Run'
org.nlogo.nvm.ArgumentTypeException: REMOVE expected input to be a string or list but got the number 0 instead.
at org.nlogo.prim.etc._remove.report(_remove.java:57)
at org.nlogo.prim._asm_procedureexecuterandom_setobservervariable_61.perform()
at org.nlogo.nvm.Context.runExclusive(Context.java:119)
at org.nlogo.nvm.ExclusiveJob.run(ExclusiveJob.java:57)
at org.nlogo.nvm.Context.runExclusiveJob(Context.java:162)
at org.nlogo.prim._asm_procedureexecuterandom_ask_59.perform(:1)
at org.nlogo.nvm.Context.runExclusive(Context.java:119)
at org.nlogo.nvm.ExclusiveJob.run(ExclusiveJob.java:57)
at org.nlogo.nvm.Context.runExclusiveJob(Context.java:162)
at org.nlogo.prim._asm_procedureexecuterandom_ask_57.perform(:1)
at org.nlogo.nvm.Context.stepConcurrent(Context.java:91)
at org.nlogo.nvm.ConcurrentJob.step(ConcurrentJob.java:82)
at org.nlogo.job.JobThread.org$nlogo$job$JobThread$$runPrimaryJobs(JobThread.scala:143)
at org.nlogo.job.JobThread$$anonfun$run$1.apply$mcV$sp(JobThread.scala:78)
at org.nlogo.job.JobThread$$anonfun$run$1.apply(JobThread.scala:76)
at org.nlogo.job.JobThread$$anonfun$run$1.apply(JobThread.scala:76)
at scala.util.control.Exception$Catch.apply(Exception.scala:88)
at org.nlogo.util.Exceptions$.handling(Exceptions.scala:41)
at org.nlogo.job.JobThread.run(JobThread.scala:75)
NetLogo 5.2.0
main: org.nlogo.app.AppFrame
thread: JobThread
Java HotSpot(TM) 64-Bit Server VM 1.8.0_51 (Oracle Corporation; 1.8.0_51-b16)
operating system: Linux 3.13.0-24-generic (amd64 processor)
Scala version 2.9.2
JOGL: (3D View not initialized)
OpenGL Graphics: (3D View not initialized)
model: headsline
06:45:24.666 SwitchedTabsEvent (org.nlogo.app.Tabs) AWT-EventQueue-0
06:45:24.661 RuntimeErrorEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0
06:45:24.659 JobRemovedEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) JobThread
06:45:24.657 InterfaceGlobalEvent (org.nlogo.app.InterfacePanel$2 (org.nlogo.window.SliderWidget)) AWT-EventQueue-0
06:45:24.657 InterfaceGlobalEvent (org.nlogo.app.InterfacePanel$2 (org.nlogo.window.SliderWidget)) AWT-EventQueue-0
06:45:24.657 InterfaceGlobalEvent (org.nlogo.app.InterfacePanel$2 (org.nlogo.window.SliderWidget)) AWT-EventQueue-0
06:45:24.657 InterfaceGlobalEvent (org.nlogo.app.InterfacePanel$2 (org.nlogo.window.SliderWidget)) AWT-EventQueue-0
06:45:24.657 InterfaceGlobalEvent (org.nlogo.app.InterfacePanel$2 (org.nlogo.window.SliderWidget)) AWT-EventQueue-0
06:45:24.657 PeriodicUpdateEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0
06:45:24.549 AddJobEvent (org.nlogo.window.ButtonWidget) AWT-EventQueue-0
【问题讨论】:
-
这段代码太广泛了,没有实际模式无法理解,也许你可以上传.nlogo文件并分享它,以便我们看看发生了什么。另外,描述一下 WS3 和 WS5 对你意味着什么,我个人不太明白你遇到的问题。
标签: netlogo