Netlogo 海龟需要在两个不同的目标位置同时移动
Netlogo turtles need to move same time at two different target location
- 抱歉,我是 Netlogo 编程的初学者,我正在尝试
根据优先级在机器上安排作业。
- 目前只有product1 turtle 由一个machine turtle 处理。
而其他产品 turtles 没有被 运行 放在机器上
空闲,例如 machine2 和 machine3。目前他们正在等待
另一个循环完成以处理下一个。
我想实现的是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
从您的个人 go-product
程序中取出对 tick
的调用。在整个模型中只调用一次 tick
才有意义,那是在主 go
过程的末尾。
从您的 go
过程中删除对 while
的使用。时间会在你的模型中流逝,因为 go
在一个永远的按钮中被一遍又一遍地调用——而不是因为你的 go
过程中有循环。永远的按钮已经足够循环了。
我们的目标是构建您的模型,以便每次 go
(也就是说一次滴答),只发生一个工作单元或动作或运动。然后,随着 go
一遍又一遍地运行,需要多个滴答才能完成的更长的工作单元似乎会同时发生。
示例模型中的几乎每个模型,包括教程 3 模型,都是以这种方式构建的。只有当您绝对确定自己知道自己在做什么以及为什么这样做时,您才应该有不同的结构。
- 抱歉,我是 Netlogo 编程的初学者,我正在尝试 根据优先级在机器上安排作业。
- 目前只有product1 turtle 由一个machine turtle 处理。 而其他产品 turtles 没有被 运行 放在机器上 空闲,例如 machine2 和 machine3。目前他们正在等待 另一个循环完成以处理下一个。
我想实现的是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
从您的个人 go-product
程序中取出对 tick
的调用。在整个模型中只调用一次 tick
才有意义,那是在主 go
过程的末尾。
从您的 go
过程中删除对 while
的使用。时间会在你的模型中流逝,因为 go
在一个永远的按钮中被一遍又一遍地调用——而不是因为你的 go
过程中有循环。永远的按钮已经足够循环了。
我们的目标是构建您的模型,以便每次 go
(也就是说一次滴答),只发生一个工作单元或动作或运动。然后,随着 go
一遍又一遍地运行,需要多个滴答才能完成的更长的工作单元似乎会同时发生。
示例模型中的几乎每个模型,包括教程 3 模型,都是以这种方式构建的。只有当您绝对确定自己知道自己在做什么以及为什么这样做时,您才应该有不同的结构。