【问题标题】:Trying to determine a link with specific nodes试图确定与特定节点的链接
【发布时间】:2020-08-08 07:36:40
【问题描述】:

我正在尝试调用现有链接但具有特定节点。请记住,此命令位于 foreach 中。所以现在我有这个:

foreach max-links
[
the-links -> ask the-links
show [label] of [one-of my-out-links] of [end2] of the-links with [other-end = [end1] of the-links]
]

“with”命令不起作用,因为它需要一个代理集。我还用“and”命令尝试了这个,它不起作用,因为它需要一个真或假。 谁能告诉我如何添加:

[other-end = [end1] of the-links]

代码部分?

【问题讨论】:

    标签: netlogo


    【解决方案1】:

    这是您的代码,间距略有不同

    foreach max-links
    [ the-links ->
      ask the-links
      show [label] of [one-of my-out-links] of [end2] of the-links with [other-end = [end1] of the-links]
    ]
    

    问题 1:您需要在“链接”被要求做的事情周围加上括号

    问题 2:您在一行代码中有太多复杂的逻辑 - 没有括号可以提供帮助。如果你想调试,把它分成几个步骤,然后只有在它工作时才组合。另外,我怀疑“链接”是单个链接(因为它位于 foreach 中)而不是链接集,因此您应该给它一个单数名称以帮助您保持思路清晰。

    所以:show [label] of [one-of my-out-links] of [end2] of the-links with [other-end = [end1] of the-links]

    变成

    let chosen-turtle [end2] of the-link with [other-end = [end1] of the-link]
    let chosen-link [one-of my-out-links] of chosen-turtle
    show [label] of chosen-turtle
    

    把它分解成这样的步骤,很明显第一行没有意义。如果链接的other-end[end1] of the-link,那么您只是要求[end2] of the-link

    发现(可能的)问题后,固定代码是:

    foreach max-links
    [ the-link ->
      ask the-link
      [ let chosen-turtle [end2] of the-link
        let chosen-link [one-of my-out-links] of chosen-turtle
        show [label] of chosen-turtle
      ]
    ]
    

    而且,如果这有效(我无法测试它),那么您可以根据需要将其放回一行。但是以多行开头,因为 NetLogo 会指向有问题的行,从而更容易调试。

    foreach max-links
    [ the-link ->
      ask the-link
      [ show [label] of [one-of my-out-links] of [end2] of the-link
      ]
    ]
    

    【讨论】:

      猜你喜欢
      • 2017-01-28
      • 2012-07-17
      • 1970-01-01
      • 1970-01-01
      • 2018-09-18
      • 2019-02-23
      • 1970-01-01
      • 2018-05-16
      • 2019-03-29
      相关资源
      最近更新 更多