用链接值计算

发布于 2025-02-10 11:13:12 字数 1240 浏览 1 评论 0原文

我需要计算我自己和所有近亲之间的连接价值,这些连接价值使用链接的信任值。但是,获取所有链接的信任值并在计算中使用它们会减慢运行时间。我没有成功找到另一种方法来更有效地做到这一点。任何建议都将不胜感激!

breed [persons person]
undirected-link-breed [connections connection]
connections-own [trust]

persons-own 
[
  nearPersons
  familiarity
]
 
to setup
  clear-all
  setupPersons
  setupConnections
  updateConnections
  reset-ticks
end

setupPersons
  create-persons 1000
  [
    set color black
    set grouped false 
    setxy random-xcor random-ycor
  ]
end

to setupConnections
  ask persons [create-connections-with other persons]
  ask connections [ set trust 0.4]
end

to updateConnections
  while [(count persons with [grouped = false] / 1000) > 5]
  [
    let highlyTrusted n-of (2 + random 9) (persons with [grouped = false])
    ask highlyTrusted
    [
      ask my-out-connections with [member? other-end highlyTrusted] [set trust 0.6]
      set grouped true
    ]
  ]
end

to go
  getNearPersons
  calculateConnection
  forward 1
end

to getNearPersons
  ask persons [ set nearPersons other persons in-cone 3 360 ]
end

to calculateConnection
  ask persons with [nearPersons != nobody]
  [
    ask nearPersons
    [
      let degreeOfTrust [trust] of in-connection-from myself
     ]
   ]
end

I need to calculate a connection value between myself and all of my nearPersons which uses among others the trust value of the link. However, getting the trust values of all links and using these in the computation slows down the running time. I did not succeed to find another way to do it more efficiently. Any suggestions would be highly appreciated!

breed [persons person]
undirected-link-breed [connections connection]
connections-own [trust]

persons-own 
[
  nearPersons
  familiarity
]
 
to setup
  clear-all
  setupPersons
  setupConnections
  updateConnections
  reset-ticks
end

setupPersons
  create-persons 1000
  [
    set color black
    set grouped false 
    setxy random-xcor random-ycor
  ]
end

to setupConnections
  ask persons [create-connections-with other persons]
  ask connections [ set trust 0.4]
end

to updateConnections
  while [(count persons with [grouped = false] / 1000) > 5]
  [
    let highlyTrusted n-of (2 + random 9) (persons with [grouped = false])
    ask highlyTrusted
    [
      ask my-out-connections with [member? other-end highlyTrusted] [set trust 0.6]
      set grouped true
    ]
  ]
end

to go
  getNearPersons
  calculateConnection
  forward 1
end

to getNearPersons
  ask persons [ set nearPersons other persons in-cone 3 360 ]
end

to calculateConnection
  ask persons with [nearPersons != nobody]
  [
    ask nearPersons
    [
      let degreeOfTrust [trust] of in-connection-from myself
     ]
   ]
end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

强者自强 2025-02-17 11:13:12

这是使用信任代理而不是链接的模型。我认为,只要只有两个信任级别,它将为您提供相同的结果。我在代码中做了其他一些更改 - 特别是您的原始,而语句永远不会在编写时运行(商总是1)。大多数只是风格的问题。让我知道这是否不是您需要的。仍然不是一个速度恶魔,每滴1000人约5秒钟,但比链接版本快很多。请注意,Npersons是一个全球,因此我可以随身携带它。

查尔斯

globals [nPersons]

breed [persons person]

persons-own
[
  nearPersons
  Trusted
  unTrusted
  familiarity
  grouped
]

to setup
  clear-all
  set nPersons 1000
  ask patches [ set pcolor gray ]
  setupPersons
  updateConnections
  reset-ticks
end

to setupPersons
  create-persons nPersons
  [
    set color black
    set grouped false
    setxy random-xcor random-ycor
  ]
  ask persons [
    set Trusted no-turtles
    set unTrusted persons
    set familiarity 1
  ]
end

to updateConnections
  while [(count persons with [grouped = false] / nPersons) > 0.2]
  [
    let highlyTrusted n-of (2 + random 9) (persons)  
    ; so persons can be in more than one trust group and treat all trust groups equally?
    ask highlyTrusted
    [
      set Trusted other highlyTrusted
      set grouped true
    ]
  ]
end

to go
  ask persons [ getNearPersons ]
  calculateConnection
  ask persons [ forward 1 ]
  tick
end

to getNearPersons
  ask persons [ set nearPersons other persons in-radius 3 ]
end

to calculateConnection
  ask persons with [any? nearPersons]
  [
    let affiliation []
    ask nearPersons
    [
      let degreeOfTrust ifelse-value (member? myself Trusted) [0.6] [0.4]
;      let degreeOfTrust [trust] of in-connection-from myself ;;this line causes netlogo to run very slowly
      set affiliation lput (degreeOfTrust * familiarity) affiliation 
     ]
   ]
end

Here is the model using agentsets of trust rather than links. I think that it will give you identical results, as long as there are only those two trust levels. I made a few other changes in the code - in particular your original while statement would never run as it was written (the quotient was always 1). Most are simply matters of style. Let me know if this is not what you need. Still not a speed demon, about 5 seconds per tick with 1000 persons, but a lot faster than the link version. Note that nPersons is a global so that I could play around with it.

Charles

globals [nPersons]

breed [persons person]

persons-own
[
  nearPersons
  Trusted
  unTrusted
  familiarity
  grouped
]

to setup
  clear-all
  set nPersons 1000
  ask patches [ set pcolor gray ]
  setupPersons
  updateConnections
  reset-ticks
end

to setupPersons
  create-persons nPersons
  [
    set color black
    set grouped false
    setxy random-xcor random-ycor
  ]
  ask persons [
    set Trusted no-turtles
    set unTrusted persons
    set familiarity 1
  ]
end

to updateConnections
  while [(count persons with [grouped = false] / nPersons) > 0.2]
  [
    let highlyTrusted n-of (2 + random 9) (persons)  
    ; so persons can be in more than one trust group and treat all trust groups equally?
    ask highlyTrusted
    [
      set Trusted other highlyTrusted
      set grouped true
    ]
  ]
end

to go
  ask persons [ getNearPersons ]
  calculateConnection
  ask persons [ forward 1 ]
  tick
end

to getNearPersons
  ask persons [ set nearPersons other persons in-radius 3 ]
end

to calculateConnection
  ask persons with [any? nearPersons]
  [
    let affiliation []
    ask nearPersons
    [
      let degreeOfTrust ifelse-value (member? myself Trusted) [0.6] [0.4]
;      let degreeOfTrust [trust] of in-connection-from myself ;;this line causes netlogo to run very slowly
      set affiliation lput (degreeOfTrust * familiarity) affiliation 
     ]
   ]
end
影子是时光的心 2025-02-17 11:13:12

我必须对您的代码进行一些修改以使其运行,我在下面包括了它。但是我相信真正的问题只是您在做什么的规模。有了1000人,您反复进行了大约一百万个链接,并且鉴于您的世界大小,每个人的近人数量可能很大。您真的需要模型中的1000人吗?/或您真的需要每个人都与其他人建立联系?链接的数量与人数成倍增加。

breed [persons person]
undirected-link-breed [connections connection]
connections-own [trust]

persons-own
[
  nearPersons
  familiarity
  grouped
]

to setup
  clear-all
  setupPersons
  show "persons setup"
  setupConnections
  show "connections setup"
  updateConnections
  show "connections updated"
  reset-ticks
end

to setupPersons
  create-persons nPersons
  [
    set color black
    set grouped false
    setxy random-xcor random-ycor
  ]
end

to setupConnections
  ask persons [create-connections-with other persons]
  ask connections [ set trust 0.4]
end

to updateConnections
  while [(count persons with [grouped = false] / 1000) > 5]
  [
    let highlyTrusted n-of (2 + random 9) (persons)
    ask highlyTrusted
    [
      ask my-out-connections with [member? other-end highlyTrusted] [set trust 0.6]
      set grouped true
    ]
  ]
end

to go
  ask persons [ getNearPersons ]
  show mean [count nearPersons] of persons
  ask persons [ calculateConnection ]
  show "got Connections"
  ask persons [ forward 1 ]
  tick
end

to getNearPersons
  ask persons [ set nearPersons other persons in-cone 3 360 ]
end

to calculateConnection
  ask persons with [nearPersons != nobody]
  [
    let affiliation []
    let idx 0
    ask nearPersons
    [
      let degreeOfTrust [trust] of in-connection-from myself ;;this line causes netlogo to run very slowly
      set affiliation insert-item idx affiliation (degreeOfTrust * familiarity)
      set idx idx + 1
     ]
   ]
end

I had to make a few modifications of your code to make it run, I've included it below. But I believe the real problem is just the scale of what you are doing. With 1000 persons, there are approximately half a million links that you are repeatedly polling, and given the size of your world, the number of nearPersons for each person is likely quite large. Do you really need 1000 persons in your model, and/or do you really need every person to be connected to every other person? The number of links goes up exponentially with the number of persons.

breed [persons person]
undirected-link-breed [connections connection]
connections-own [trust]

persons-own
[
  nearPersons
  familiarity
  grouped
]

to setup
  clear-all
  setupPersons
  show "persons setup"
  setupConnections
  show "connections setup"
  updateConnections
  show "connections updated"
  reset-ticks
end

to setupPersons
  create-persons nPersons
  [
    set color black
    set grouped false
    setxy random-xcor random-ycor
  ]
end

to setupConnections
  ask persons [create-connections-with other persons]
  ask connections [ set trust 0.4]
end

to updateConnections
  while [(count persons with [grouped = false] / 1000) > 5]
  [
    let highlyTrusted n-of (2 + random 9) (persons)
    ask highlyTrusted
    [
      ask my-out-connections with [member? other-end highlyTrusted] [set trust 0.6]
      set grouped true
    ]
  ]
end

to go
  ask persons [ getNearPersons ]
  show mean [count nearPersons] of persons
  ask persons [ calculateConnection ]
  show "got Connections"
  ask persons [ forward 1 ]
  tick
end

to getNearPersons
  ask persons [ set nearPersons other persons in-cone 3 360 ]
end

to calculateConnection
  ask persons with [nearPersons != nobody]
  [
    let affiliation []
    let idx 0
    ask nearPersons
    [
      let degreeOfTrust [trust] of in-connection-from myself ;;this line causes netlogo to run very slowly
      set affiliation insert-item idx affiliation (degreeOfTrust * familiarity)
      set idx idx + 1
     ]
   ]
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文