- 抱歉,我还是 Netlogo 编程的初学者,我正在尝试根据优先级在机器上安排作业。
- 目前只有 product1 乌龟被一只机器乌龟处理。而其他产品海龟没有在空闲的机器上运行,例如 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
问问题
765 次
1 回答
1
将呼叫tick
从您的个人go-product
程序中取出。在整个模型中调用一次才有意义tick
,而且那是在主程序的最后go
。
while
从您的go
过程中删除使用。时间会在您的模型中流逝,因为go
在永久按钮中一遍又一遍地调用 - 不是因为您的go
过程中有循环。永远的按钮已经足够循环了。
目标是构建您的模型,以便每次通过go
(也就是说一个滴答声),只发生一个工作单元或动作或动作。然后,随着go
一遍又一遍地运行,更长的工作单元,需要多个滴答来完成,似乎会同时发生。
示例模型中的几乎每个模型,包括教程 3 模型,都是以这种方式构建的。只有当您完全确定自己知道自己在做什么以及为什么这样做时,您才应该使用不同的结构。
于 2015-09-17T12:37:17.597 回答