我想要实现的是Product1只需要Machine1进行操作。 P2需要M2和M3,P3需要M1,M2和M3。所以当Product1 海龟在M1上,其他海龟应该移动到相应的 目标和安排自己
breed [product1 productA]
breed [product3 productB]
breed [product2 productC]
breed [machine1 machineA]
breed [machine2 machineB]
breed [machine3 machineC]
breed [schedulers scheduler]
globals [Priority]
product1-own
[
productID
productLength
arriveTime
startTime
finishTime
]
product2-own
[
productID
productLength
arriveTime
startTime
finishTime
waitTime
]
product3-own
[
productID
productLength
arriveTime
startTime
finishTime
]
schedulers-own
[
numJobArrive
numJobStart
numJobFinish
numJobWait
currentmachineID
]
machine-own
[
machineID
numJobStart
numJobFinish
waitTimeM
idleTimeM
nextAvailTime
currentproductID
utilization
]
to setup
clear-all
ask patches [set pcolor 8]
ask patch -3 6 [set pcolor 125]
ask patch -3 2 [set pcolor 125]
ask patch 1 4 [set pcolor black]
setup-products1
setup-products2
setup-products3
setup-machines
reset-ticks
end
to setup-machines
create-machine1 1 [setxy -3 6
set shape "computer server"]
create-machine2 1[setxy -3 2
set shape "computer server"]
create-machine3 1[setxy 1 4
set shape "computer server"]
end
to setup-products1
create-product1 Job1-products [
set shape "hexagonal prism"
set color red
set size 1.25
set xcor -14
set ycor 6
set heading 90
separate-products
]
end
to setup-products2
create-product2 Job2-products [
set shape "die 4"
set color blue
set xcor -14
set ycor 4
set size 1.25
set heading 90
separate-products
]
end
to setup-products3
create-product3 Job3-products [
set shape "box"
set color brown
set size 1.25
set xcor -14
set ycor 2
set heading 90
separate-products
]
end
; this procedure is needed so when we click "Setup" we
; don't end up with any two Products on the same patch
to separate-products ;; turtle procedure
if any? other turtles-here
[ fd 1.5
separate-products ]
end
to go-product3
let totalprod (turtle-set product1 product2 product3)
let targetmachine1 patch -3 6
let targetmachine2 patch -3 2
let targetmachine3 patch 1 4
if count product3 > 0
[
ask one-of product3 [
if not any? product1-on machine1 or not any? product2-on machine1
[
move-to targetmachine1
]
if not any? product1-on machine2 or not any? product2-on machine2
[
face targetmachine2
move-to targetmachine2
]
if not any? product1-on machine3 or not any? product2-on machine3
[
face targetmachine3
move-to targetmachine3
die
]
]]
tick
end
to go-product2
let targetmachine1 patch -3 2
let targetmachine2 patch 1 4
if count product2 > 0
[
ask one-of product2 [
if not any? product1-on machine2 or not any? product3-on machine2
[
face targetmachine1
move-to targetmachine1
]
if not any? product1-on machine3 or not any? product3-on machine3
[
face targetmachine2
move-to targetmachine2
die
]
]]
tick
end
to go-product1
let targetmachine patch 1 4
if count product1 > 0
[
ask one-of product1
[
if not any? product2-on machine3 or not any? product3-on machine3
[
face targetmachine
move-to targetmachine
die
]
]]
tick
end
to go
let totalprod (turtle-set product1 product2 product3)
while [count totalprod > 0] [
if Priority = "0" [
go-product1
go-product2
go-product3
]
if Priority = "1" [
while [count product1 > 0][
go-product1 ]
go-product2
go-product3
]
if Priority = "2" [
while [count product2 > 0][
go-product2 ]
go-product1
go-product3
]
if Priority = "3" [
while [count product3 > 0][
go-product3 ]
go-product1
go-product2
]
]
tick
end
答案 0 :(得分:1)
从您的个人tick
程序中接听go-product
来电。在您的整个模型中调用tick
一次,并且在主go
过程结束时调用它是唯一有意义的。
从while
程序中删除go
的使用。时间会传递到您的模型中,因为go
在永久按钮中反复调用 - 不是因为您在go
过程中有循环。永远的按钮循环足够。
目标是构建模型,以便每次通过go
(也就是说一个勾号)时,只会发生一个工作单元或动作或动作。然后,当go
一遍又一遍地运行时,那么需要多次完成工作的较长工作单元似乎会同时发生。
样本模型中几乎每个模型,包括Tutorial 3模型,都是以这种方式构建的。如果您完全确定自己知道自己在做什么以及为什么要这样做,那么您应该只有不同的结构。