根据其他 link-品种的存在创建(和更新计数)link-品种
Creating (& updating count) of link-breed based on presence of other link-breed
我有 6 名成员在两个团队中的一个(所以 2 x 3 个成员团队)。从每个团队中随机抽取两名团队成员来完成一项团队任务——这两名成员同时组成一个任务-link 与各自的团队任务。我的目标是创建并更新每个团队中两名成员互动次数 (interact-link) 的计数(links-自己的变量 n-interaction)。我曾尝试使用 ifelse 语句调用 who numbers 但无法更新 n-interaction。任何想法将不胜感激。
breed [members member]
breed [team-tasks team-task]
members-own [
teamID
tasklink?
teammembers
interactwith ]
team-tasks-own [
teamID
]
undirected-link-breed [team-links team-link]
undirected-link-breed [task-links task-link]
undirected-link-breed [interact-links interact-link]
interact-links-own [ n-interaction ]
to go
create-initialform-task
dyads-work-task
update-interaction
tick
clear-taskwork
end
to dyads-work-task
ask n-of 2 members with [teamID = 1]
[ create-task-link-with one-of team-tasks with [teamID = 1 and completed? = false]
set tasklink? true
]
ask n-of 2 members with [teamID = 2]
[ create-task-link-with one-of team-tasks with [teamID = 2 and completed? = false]
set tasklink? true
]
end
to update-interaction
ask members with [ teamID = 1 and tasklink? ]
[ let my-work-partner (other teammembers with [ teamID = 1 and tasklink? ])
set interactwith (sentence interactwith my-work-partner)
]
ask members with [ teamID = 2 and tasklink? ]
[
let my-work-partner (other teammembers with [ teamID = 2 and tasklink? ])
set interactwith (sentence interactwith [ who ] of my-work-partner)
]
end
to clear-taskwork
ask task-links [ die ]
ask members
[ set tasklink? false ]
end
如果没有 create-initialform-task
我无法让你的代码工作所以我使用简化代码创建了一个快速示例,我让两只海龟将它们的颜色设置为相同的随机颜色并询问 link 在它们之间将计数器更新 1 并设置为相同的颜色(颜色很容易快速可视化)。
go-1
首先选择将执行任务的两只海龟,然后使用 let
将它们放入局部变量中,因为我将不止一次调用它们。然后它执行任务(改变它们的颜色)。最后它要求其中一只海龟与另一只海龟检查它们的 link 并要求 link 更新它的颜色和计数器。我在 ask link-with one-of other actors
中使用的 one-of
感觉有点多余,但 link-with
只适用于一只海龟,而 other actors
是一个包含一只海龟的海龟集,这是不一样的。因此 one-of other actors
.
go-2
星从 link 的角度取而代之。对我来说,它感觉更优雅一些,但对您的目的可能用处不大。我没有选择两只海龟,而是随机选择一只 link 并让它更新两端海龟的颜色。
links-own [counter]
to setup
ca
crt 4 [
setxy random-xcor random-ycor
create-links-with other turtles [set counter 0]
]
end
to go-1
let random-color random 14 * 10 + 5
let actors n-of 2 turtles
ask actors [ set color random-color ]
ask one-of actors [
ask link-with one-of other actors [
set counter counter + 1
set color random-color
]
]
end
to go-2
let random-color random 14 * 10 + 5
ask one-of links [
set counter counter + 1
set color random-color
ask both-ends [
set color random-color
]
]
end
还有两件事我注意到:在你的 dyads-work-task
中,你让一个团队的两只海龟创建一个带有随机任务的 link,但你的代码中没有任何内容可以确保两者都创建一个 link 具有相同的随机任务。这就是局部变量派上用场的地方。
to dyads-work-task
let current-task one-of team-tasks with [teamID = 1 and completed? = false]
ask n-of 2 members with [teamID = 1]
[ create-task-link-with current-task
set tasklink? true
]
end
在 update-interaction
中,您以不同方式对待团队 1 和团队 2。第 1 队创建海龟列表,而第 2 队创建数字列表 (whos)。
最后,interact-link和team-link有必要吗?难道你不能只将交互计数器添加到 team-link 而不是因为你已经有了那个 link 吗?
我有 6 名成员在两个团队中的一个(所以 2 x 3 个成员团队)。从每个团队中随机抽取两名团队成员来完成一项团队任务——这两名成员同时组成一个任务-link 与各自的团队任务。我的目标是创建并更新每个团队中两名成员互动次数 (interact-link) 的计数(links-自己的变量 n-interaction)。我曾尝试使用 ifelse 语句调用 who numbers 但无法更新 n-interaction。任何想法将不胜感激。
breed [members member]
breed [team-tasks team-task]
members-own [
teamID
tasklink?
teammembers
interactwith ]
team-tasks-own [
teamID
]
undirected-link-breed [team-links team-link]
undirected-link-breed [task-links task-link]
undirected-link-breed [interact-links interact-link]
interact-links-own [ n-interaction ]
to go
create-initialform-task
dyads-work-task
update-interaction
tick
clear-taskwork
end
to dyads-work-task
ask n-of 2 members with [teamID = 1]
[ create-task-link-with one-of team-tasks with [teamID = 1 and completed? = false]
set tasklink? true
]
ask n-of 2 members with [teamID = 2]
[ create-task-link-with one-of team-tasks with [teamID = 2 and completed? = false]
set tasklink? true
]
end
to update-interaction
ask members with [ teamID = 1 and tasklink? ]
[ let my-work-partner (other teammembers with [ teamID = 1 and tasklink? ])
set interactwith (sentence interactwith my-work-partner)
]
ask members with [ teamID = 2 and tasklink? ]
[
let my-work-partner (other teammembers with [ teamID = 2 and tasklink? ])
set interactwith (sentence interactwith [ who ] of my-work-partner)
]
end
to clear-taskwork
ask task-links [ die ]
ask members
[ set tasklink? false ]
end
如果没有 create-initialform-task
我无法让你的代码工作所以我使用简化代码创建了一个快速示例,我让两只海龟将它们的颜色设置为相同的随机颜色并询问 link 在它们之间将计数器更新 1 并设置为相同的颜色(颜色很容易快速可视化)。
go-1
首先选择将执行任务的两只海龟,然后使用 let
将它们放入局部变量中,因为我将不止一次调用它们。然后它执行任务(改变它们的颜色)。最后它要求其中一只海龟与另一只海龟检查它们的 link 并要求 link 更新它的颜色和计数器。我在 ask link-with one-of other actors
中使用的 one-of
感觉有点多余,但 link-with
只适用于一只海龟,而 other actors
是一个包含一只海龟的海龟集,这是不一样的。因此 one-of other actors
.
go-2
星从 link 的角度取而代之。对我来说,它感觉更优雅一些,但对您的目的可能用处不大。我没有选择两只海龟,而是随机选择一只 link 并让它更新两端海龟的颜色。
links-own [counter]
to setup
ca
crt 4 [
setxy random-xcor random-ycor
create-links-with other turtles [set counter 0]
]
end
to go-1
let random-color random 14 * 10 + 5
let actors n-of 2 turtles
ask actors [ set color random-color ]
ask one-of actors [
ask link-with one-of other actors [
set counter counter + 1
set color random-color
]
]
end
to go-2
let random-color random 14 * 10 + 5
ask one-of links [
set counter counter + 1
set color random-color
ask both-ends [
set color random-color
]
]
end
还有两件事我注意到:在你的 dyads-work-task
中,你让一个团队的两只海龟创建一个带有随机任务的 link,但你的代码中没有任何内容可以确保两者都创建一个 link 具有相同的随机任务。这就是局部变量派上用场的地方。
to dyads-work-task
let current-task one-of team-tasks with [teamID = 1 and completed? = false]
ask n-of 2 members with [teamID = 1]
[ create-task-link-with current-task
set tasklink? true
]
end
在 update-interaction
中,您以不同方式对待团队 1 和团队 2。第 1 队创建海龟列表,而第 2 队创建数字列表 (whos)。
最后,interact-link和team-link有必要吗?难道你不能只将交互计数器添加到 team-link 而不是因为你已经有了那个 link 吗?