删除不同品种的海龟之间的链接
Delete links between turtles with different breeds
如果满足条件,我想在一只乌龟和另一只不同品种的乌龟之间放置 links。
我正在使用以下代码来执行此操作:
ask one-of turtle1 [
if any? my-out-links with [breed = turtle2]
[ask one-of out-link-neighbors with [breed = turtle2 and value < 0.7] ;; value should refer to a neighbour's characteristics and it represents my condition
[die]
]
]
但是 links 似乎被保留了下来。没有 link 被删除。
你能告诉我我的代码有什么问题以及如何相应地修复它吗?
我假设 turtle1
和 turtle2
是两种海龟。如果是这样,
if any? my-out-links with [breed = turtle2]
将永远不会发现任何这样的异常 link,因为您正在检查 my-out-links
是否属于品种 turtle2
,当然没有 links 属于那个品种。您想要知道 link 另一端的乌龟是否属于 turtle2
品种。由于这些是定向的 links,因此您要检查的海龟位于 end2
.
if any? my-out-links with [[breed] of end2 = turtle2]
会让您知道 my-out-links
另一端的海龟是否属于 turtle2
.
品种
行
ask one-of out-link-neighbors with [breed = turtle2 and value < 0.7] [die]
可能会做的比您预期的要多。它要求品种 turtle2
和 value < 0.7
的 link-邻居 turtle 死去。这确实也会杀死 link(因为它失去了 end2
),但是如果你想杀死 link 而不是另一端的乌龟,你可以做所有这些在一行中
ask one-of turtle1 [
ask one-of my-out-links with [[breed = turtle2 and value < 0.7] of end2] [die]
]
如果没有这样的 out-link,那么您将询问 nobody
而询问将不会执行任何操作。
如果满足条件,我想在一只乌龟和另一只不同品种的乌龟之间放置 links。 我正在使用以下代码来执行此操作:
ask one-of turtle1 [
if any? my-out-links with [breed = turtle2]
[ask one-of out-link-neighbors with [breed = turtle2 and value < 0.7] ;; value should refer to a neighbour's characteristics and it represents my condition
[die]
]
]
但是 links 似乎被保留了下来。没有 link 被删除。
你能告诉我我的代码有什么问题以及如何相应地修复它吗?
我假设 turtle1
和 turtle2
是两种海龟。如果是这样,
if any? my-out-links with [breed = turtle2]
将永远不会发现任何这样的异常 link,因为您正在检查 my-out-links
是否属于品种 turtle2
,当然没有 links 属于那个品种。您想要知道 link 另一端的乌龟是否属于 turtle2
品种。由于这些是定向的 links,因此您要检查的海龟位于 end2
.
if any? my-out-links with [[breed] of end2 = turtle2]
会让您知道 my-out-links
另一端的海龟是否属于 turtle2
.
行
ask one-of out-link-neighbors with [breed = turtle2 and value < 0.7] [die]
可能会做的比您预期的要多。它要求品种 turtle2
和 value < 0.7
的 link-邻居 turtle 死去。这确实也会杀死 link(因为它失去了 end2
),但是如果你想杀死 link 而不是另一端的乌龟,你可以做所有这些在一行中
ask one-of turtle1 [
ask one-of my-out-links with [[breed = turtle2 and value < 0.7] of end2] [die]
]
如果没有这样的 out-link,那么您将询问 nobody
而询问将不会执行任何操作。