删除一个完整的海龟有向加权图中的几个链接
Deleting several links in a complete directed weighted graph of turtles
我有 n 只海龟,它们彼此都有 link。这意味着我拥有一个完整的有向加权图。我已经设法找到每只海龟具有最大值的 links,但现在我想删除所有其他没有最大值的 links,再次针对每只海龟。
我正在使用 [die] 函数,但为了区分每个海龟的 links 集合,然后从每个集合中清除 links
这是我正在使用的代码行:
> ask turtles
[
> ask my-in-links with [trust < max [trust] of links with [other-end] = ] [die]
]
但是,我想除了使用另一端函数我还可以使用这行代码
> ask turtles [
ask my-in-links with [trust < max [trust] of links with [out-link-to] = ] [die]
]
我最初的想法是通过使用两个函数之一(另一端/输出-link-到),我可以在 link 的集合之间创建一个公共属性。
我的主要问题是
- 我不确定函数(other-end/out-link-to)是否正确
- 我不知道在“=”表达式后面写什么
- 我不知道 ask 海龟函数开始与哪只海龟一起工作
这是一个完整的模型,可以实现您想要实现的目标。
links-own [trust]
to testme
clear-all
; create complete directed network
create-turtles 10
ask turtles
[ create-links-to other turtles
[ set trust random 50
]
]
; display complete network briefly
layout-circle turtles 10
type "average trust value is: " print mean [trust] of links
wait 5
; delete all except highest trust for each turtle
ask turtles
[ let keeper my-in-links with-max [trust]
ask my-in-links with [not member? self keeper][die]
]
type "average trust value is: " print mean [trust] of links
end
我让它显示初始网络并打印平均信任值,以便您了解发生了什么。
这里的重要概念是 my-links
是一个代理集(特别是,它是一个链接集,因为集合中的代理是链接)。因为你要做的只是查看连接到一只海龟的链接,那么哪只海龟在另一端并不重要,你根本不需要参考另一端。
您可以简单地查看附加到特定海龟的链接集(my-in-links
或 my-links
或 my-out-links
),然后查看这些链接的信任值.我已使用 with-max
找到具有最高值的那个,然后使用集合成员资格。但你也可以使用
ask turtles
[ let upper max [trust] of my-in-links
ask my-in-links with [trust < upper] [die]
]
最接近您在问题中编写的代码。
我有 n 只海龟,它们彼此都有 link。这意味着我拥有一个完整的有向加权图。我已经设法找到每只海龟具有最大值的 links,但现在我想删除所有其他没有最大值的 links,再次针对每只海龟。 我正在使用 [die] 函数,但为了区分每个海龟的 links 集合,然后从每个集合中清除 links 这是我正在使用的代码行:
> ask turtles
[
> ask my-in-links with [trust < max [trust] of links with [other-end] = ] [die]
]
但是,我想除了使用另一端函数我还可以使用这行代码
> ask turtles [
ask my-in-links with [trust < max [trust] of links with [out-link-to] = ] [die]
]
我最初的想法是通过使用两个函数之一(另一端/输出-link-到),我可以在 link 的集合之间创建一个公共属性。 我的主要问题是
- 我不确定函数(other-end/out-link-to)是否正确
- 我不知道在“=”表达式后面写什么
- 我不知道 ask 海龟函数开始与哪只海龟一起工作
这是一个完整的模型,可以实现您想要实现的目标。
links-own [trust]
to testme
clear-all
; create complete directed network
create-turtles 10
ask turtles
[ create-links-to other turtles
[ set trust random 50
]
]
; display complete network briefly
layout-circle turtles 10
type "average trust value is: " print mean [trust] of links
wait 5
; delete all except highest trust for each turtle
ask turtles
[ let keeper my-in-links with-max [trust]
ask my-in-links with [not member? self keeper][die]
]
type "average trust value is: " print mean [trust] of links
end
我让它显示初始网络并打印平均信任值,以便您了解发生了什么。
这里的重要概念是 my-links
是一个代理集(特别是,它是一个链接集,因为集合中的代理是链接)。因为你要做的只是查看连接到一只海龟的链接,那么哪只海龟在另一端并不重要,你根本不需要参考另一端。
您可以简单地查看附加到特定海龟的链接集(my-in-links
或 my-links
或 my-out-links
),然后查看这些链接的信任值.我已使用 with-max
找到具有最高值的那个,然后使用集合成员资格。但你也可以使用
ask turtles
[ let upper max [trust] of my-in-links
ask my-in-links with [trust < upper] [die]
]
最接近您在问题中编写的代码。