If statement 如何在嵌套的ifelse语句中执行此操作

If statement 如何在嵌套的ifelse语句中执行此操作,if-statement,netlogo,If Statement,Netlogo,我目前正在从事一个项目,该项目需要以下内容:我希望端口(一个品种)询问存储位置(另一个品种)是否具有特定值。如果没有,则继续询问下一个存储位置等,直到他找到具有正确值的位置。如果是这样,那么它应该采取另一个行动(比如建造一些东西)。我现在拿到了这个,看起来很有效,但我觉得它太长太复杂了 to check-pipeline-26 ask storage 26 [ifelse pipeline < 1 [build-pipeline] [check-pipeline-2

我目前正在从事一个项目,该项目需要以下内容:我希望端口(一个品种)询问存储位置(另一个品种)是否具有特定值。如果没有,则继续询问下一个存储位置等,直到他找到具有正确值的位置。如果是这样,那么它应该采取另一个行动(比如建造一些东西)。我现在拿到了这个,看起来很有效,但我觉得它太长太复杂了

to check-pipeline-26
  ask storage 26
  [ifelse pipeline < 1
    [build-pipeline]
    [check-pipeline-27]
  ]
end

to check-pipeline-27
  ask storage 27
  [ifelse pipeline < 1
    [build-pipeline]
    [check-pipeline-28]
  ]
end

to check-pipeline-28
  ask storage 28
  [ifelse pipeline < 1
    [build-pipeline]
    [check-pipeline-29]
  ]
end

to check-pipeline-29
  ask storage 29
  [ifelse pipeline < 1
    [build-pipeline]
    [check-pipeline-30]
  ]
end
至check-pipeline-26
询问存储26
[ifelse管道<1
[建造管道]
[检查-27]
]
结束
检查-27号管道
询问存储27
[ifelse管道<1
[建造管道]
[检查-28]
]
结束
检查-28号管道
询问存储28
[ifelse管道<1
[建造管道]
[检查-29]
]
结束
检查-29号管道
询问存储29
[ifelse管道<1
[建造管道]
[检查-30]
]
结束
让我知道如果你有任何提示,使这更容易或简化。提前谢谢


Max

这里是一个递归解决方案,我将管道编号作为参数传入:

to check-pipeline [n]
    if n <= max [who] of storages
    ask storage n [ifelse pipeline < 1 
     [build-pipeline]
     [check-pipeline n + 1]
]
end
检查管道[n]
如果n询问astorage[如果管道<1[构建管道停止]]
]
结束

是否有需要按顺序执行的原因?如果
端口
最终将以正确的值到达
存储
,您是否可以使用类似
的方法使用[pipeline<1][build pipeline]
(未经测试,您可能需要修改以适应您的品种等)?这很有效,非常感谢!可能会导致以下问题,我对“build pipeline”也做了同样的操作,因此为每个管道指定了不同的变量。但让我看看我是否能解决这个问题!
 to check-pipeline
     foreach sort-on  [who] storages
      [astorage -> ask astorage[ if pipeline < 1 [build-pipeline stop]]]
    ]
 end