Taliesin 发表于 2008-3-14 16:14:39

关于turtle的使用问题

我将customer设为 turtles-own,初始值赋为-1,为的是当turtle遇到同伴时就将其中的一个turtle认为自己的customer,然后进行交易,如下:
to do-business
rt random 360
fd 1
ifelse(other turtles-here != nobody)[
   set customer one-of other turtles-here ;;这样一来,customer不代表了一个turtle吗?但在运行时出现了问题.
   set of self item (( of customer) - 1)of self   
   set of customer item (( of self) - 1)of customer
   set of self length of self
   set trade-record-current( list (timer) (random money-upper-limit))

问题的提示如下:

error while turtle 50 running OF in procedure DO-BUSINESS
called by procedure GO
OF expected input to be a turtle agentset or turtle but got NOBODY instead.
(halted running of go)

这是为什么呢?我看到一些netlogo中自带的例子也是用这种方法来找turtle的同伴的啊?期待高手解答~~
另外,我用( of customer)来获取turtle的编号的方法对的吗?如set of self item (( of customer) - 1)of self    中.

wjcpcahu 发表于 2008-3-17 17:34:20

资料不全

你把你的所有程序传上来我看一下,估计不是大问题。(南京大学)

Taliesin 发表于 2008-3-18 13:10:54

你好,这是我现在正在写着的程序,以上问题就在其中,请多指教
globals[
xmax
ymax
global-reputation-list

;;每一个turtle的全局声誉都存在此LIST中
credibility-list
;;每一个turtle的评价可信度
honest-service
unhonest-service
oscillation
rand-dynamic
]

turtles-own[
trade-record-all
;;a list of lists,由trade-record-one组成
trade-record-one
;;list,trade-record-all 中的一个list,作为暂存用,记录两个turtles的交易记录

;;[对方turtle的编号,交易总次数,交易总金额,[本次交易的时间,交易金额,得到的评价,给出的评价,评价时间,此次交易后相对于对方turtle的局部声誉]]
trade-record-current;;list,trade-record-one中的这个list,作为暂存用,[本次交易的时间,交易金额,得到的评价,给出的评价,评价时间,此次交易后相对于对方turtle的局部声誉]
credibility-receive ;;list,他每个turtle还需要有一个存储其他turtle对其评价质量进行评价的list
neighbor-total
;;记录该turtle的邻居节点的数目
trade-time
;;当前发生交易的turtle的交易时间
appraise-give
;;当前发生交易时给出的评价
appraise-receive
;;当前发生交易时收到的评价
appraise-time
;;当前发生交易时的评价时间
local-reputation-now;;此次交易后相对于对方turtle的局部声誉
trade-times-total
;;与当前turtle的交易总次数
trade-money-total
;;与当前turtle的交易总金额
local-reputation
global-reputation
credibility
;;评价可信度,每次交易后都需要更新
credibility-all
;;a list of lists,由credibility-one组成。[对j的评价质量的评价]对j的评价质量的评价]……对j的评价质量的评价]……],其中一共有people项,根据

;;turtle的编号对号入座,对于其自身的编号,在计算用到的时候再进行剔减,初始值均为0.5
credibility-one
;;a list 对j给1的评价的质量评价,i对j给2的评价的质量评价……],其中一共有people项
global-proportion
customer
customer-no
trust-ok
trade-record-one-len;;trade-record-one的长度
]

;;setup procedure

to setup

ca

initialize-settings

crt people

reset-timer

poll-class

setup-plots

do-plots
end

to initialize-settings

set global-reputation-list []

set credibility-list n-values people

set honest-service 0

set unhonest-service 0

set oscillation 0

set rand-dynamic 0
end

to setup-turtles
set shape "person"
setxy random-xcor random-ycor
set trade-record-one []

set trade-record-all n-values people [(list (? + 1) 0 0)]

set trade-record-current []
set credibility-receive []
set local-reputation 0.5
set neighbor-total 0
set trade-times-total 0
set trade-money-total 0
set customer nobody
set credibility-all n-values people
set credibility n-values people [-1]
get-color

end

to-report creat-credibility
report n-values people
end

to setup-plots

set xmax 30

set ymax 1.0

clear-all-plots

setup-plot1

setup-plot2

setup-plot3
end

;;run time procedures

to go

ask turtles
end

to do-business


rt random 360

fd 1

ifelse(other turtles-here != nobody)[

set customer one-of other turtles-here

;; set of customer myself

set of self item (( of customer) - 1)
of self
;;filter of customer] of self

set of customer item (( of self) - 1)
of customer

set of self length of self

set trade-record-current( list (timer) (random money-upper-limit))

ask self
;;先求i对j的信任度

if ( of self)
;;根据i对j的信任度来决定是否与j进行交易[
ask customer if ( of customer);;这里可能会用到myself

[

do-trade

update-credibility-ijl

update-credibility-list


update-global-reputation-list

poll-class

get-color

]]

;;如果所得的信任度满足条件,则进行交易

[

rt random 360

fd 1

]

end

to do-trust
set trust-ok False


let max-trade-times 0
foreach of customer ]
let max-trade-money 0
foreach of customer ]
let local-proportion sqrt((item 1 of myself * item 2 of myself) /( max-trade-times * max-trade-money))


get-global-proportion
let trust-value
local-proportion * (item 5 (last (item ( of customer - 1) of customer))) + global-proportion *(item ( of customer - 1) global-reputation-list)
if(trust-value > trade-trust-value)

end

to get-global-proportion
ifelse(of customer = 1) and (trade-record-one-len > 3)


let sum-money 0
while[ i < people]
[
if( length (item i
of customer) > 3 )
[
set sum-money (sum-money + item 2(item i of myself))
]
]
let j 0
let note 0
while[ j < people]
[
if( length (item i
of customer) > 3 )
[
ifelse(item (of myself - 1) of turtle j != -1)
of myself - 1) of turtle j )* item 2(item i of myself)/ sum-money)]
of myself)/ sum-money)]
]
]
set global-proportion note
]
end

to do-trade
;;这个过程实际上是给双方作出评价的过程
set trade-record-current lput( random-float 1) trade-record-current ;;本turtle 得到的评价
set trade-record-current lput( random-float 1) trade-record-current ;;本turtle 给出的评价
set trade-record-current lput(timer) trade-record-current
;;评价时间
ask myself [
update-local-reputation
set trade-record-current lput( of myself) trade-record-current
]
set of myself lput(trade-record-current) of myself
;;将此次交易的记录加入到trade-record-one中
set of myself (replace-item ( of customer - 1 ) of myself of myself)
let note (item 2 trade-record-current )
set trade-record-current
(replace-item 2 trade-record-current (item 3 trade-record-current))
set trade-record-current
(replace-item 3 trade-record-current note)


ask customer [
update-local-reputation
set trade-record-current
(replace-item 4 trade-record-current ([ of myself]of customer))
]


set of customer lput(trade-record-current) of customer

set of customer (replace-item ( of myself - 1) ( of customer)( of customer))
;;将此次交易的记录加入到customer的trade-record-all中
end

to update-local-reputation
set of myself length of myself


;;if of myself > 3
update-neighbor-total
;;更新邻居节点的数目,在此进行
let i 3
let sum-time 0
while of myself]
[
set sum-time ( sum-time + item 0(item i of myself) )
set i
( i + 1)
]
let j 3
let sum-money 0
while of myself]
[
set sum-money ( sum-money + (item 1(item j of myself)) * (item 0(item j of myself) ) / sum-time)
set j
( j + 1)
]
let k 3
let power 0
let local 0
while of myself]
[
set local (local + (item 0 (item k of myself)) * (item 1 (item k of myself)) * (item 2 (item k of myself)) / sum-time / sum-money)
set k (k + 1)
]
set of myself (local)
end

to update-neighbor-total

if( of myself = 3)


end

to update-credibility-ijl

;;思路:每一次,当一个turtle发和另一个turtle成功发生交易作出了评价之后,就去搜索本次交易对象的邻居节点,对这些邻居节点的评价质量作出评价。
let l 0
while[ l < people ]
;;对j的邻居节点的trade-record进行扫描,以对j的邻居节点的评价质量进行评价
[
let trade-record-one-j-l-len length item l ( of customer)
if (trade-record-one-j-l-len > 3)
of customer);;暂存那个评价质量正在被评价的turtle j的与l的trade-record-one
let i 3
let sum-time 0
while
[
set sum-time ( sum-time + item 4(item i of myself) )
set i
( i + 1)
]
let credibility-i-j-l 0
;;i评价(j对jl的评价)
let j 3
let k 4
while
[
while [((item 4(item j of myself)) - item 4(item k trade-record-one-j-l)) > 0];;首先要寻找在i第k次给l评价的这一时刻,l相对于j的局部声誉
set credibility-i-j-l ( credibility-i-j-l + (item 4(item j of myself)) * (1 - abs ((item 3(item j of myself)) - item 5 (item k trade-record-one-j-l) ) )/ sum-time)
set j
( j + 1)
]
set of turtle l (replace-item ( of myself - 1)( of turtle l)(replace-item ( of customer - 1) (item ( of myself - 1) of turtle l) credibility-i-j-l ))


let note ((sum (item ( of myself - 1)( of turtle l)) - 1 ) / (people - 2))
;;及时更新i对l的评价质量的评价
set of turtle l (replace-item ( of myself - 1) of turtle l note) ]
set l (l + 1)
]
end

to update-credibility-list
let i 0
while
[
let j 0
let note 0
let k 0
;;计作出过评价的邻居节点的数目
while
[
if (item j( of turtle (i + 1)) != -1)
;;判断是否给本turtle的评价质量做出过评价的节点
of turtle (i + 1)))
;;*(exp (-(people - 2)))/(people - 2))]
set k (k + 1)
]
set j (j + 1)
]
set note (note *(exp (- (1 / k)))/ k)
set credibility-list (replace-item i credibility-list note)
set i (i + 1)
]
end

to update-global-reputation-list
let j 0
while
[
let new 0
;;暂存新的一个全局声誉
let i 0
let sum-money 0
let credibility-money 0
while
[
set sum-money (sum-money + item 2(item i of turtle (j + 1)))
set credibility-money (credibility-money + (item 2(item i of turtle (j + 1))) * (item j credibility-list))
set i (i + 1)
]
let k 0
let new1 0
while
[
set new1 (new1 + (item k credibility-list)* item 2(item k of turtle (j + 1))* (item 5 (last (item k of turtle(j + 1)))) / credibility-money)
set k (k + 1)
]
set new ((exp( -(1 /(sum-money * of turtle (j + 1))))) * new1)
set global-reputation-list (replace-item j global-reputation-list new)
set j (j + 1)
]
end



to get-color

set color blue
end

to poll-class
end

to setup-plot1

set-current-plot "Trends-of-Local-reputation"

set-plot-x-range 0 xmax

set-plot-y-range 0.0 ymax
end

to setup-plot2

set-current-plot "Trends-of-global-reputation"

set-plot-x-range 0 xmax

set-plot-y-range 0.0 ymax
end

to setup-plot3

set-current-plot "Trends-of-credibility"

set-plot-x-range 0 xmax

set-plot-y-range 0.0 ymax
end

to do-plots
set-current-plot "Trends-of-Local-reputation"
set-current-plot-pen "Honest service"
end

[ 本帖最后由 Taliesin 于 2008-3-19 12:45 编辑 ]

wjcpcahu 发表于 2008-3-19 11:33:07

有点困难

没想到挺复杂的,我去问问师兄们,不知道你是自己建构的模型还是其它模型的改进,我试了一下好像setup都有问题,别着急啊,呵呵 。

wjcpcahu 发表于 2008-3-19 11:34:29

还有啊

wjcpcahu 发表于 2008-3-19 11:35:59

还有啊

能不能传nlogo附件上来,一个一个敲太累了,好长的程序啊。:L :L :L

Taliesin 发表于 2008-3-19 12:47:57

嘻嘻,不好意思啊,现在把附件加上了.

这是我自己编的,估计有不少错误,对netlogo了解不是很深,请多指教,谢谢!

wjcpcahu 发表于 2008-3-22 16:55:16

程序公式

我问了一下,只是从程序角度来分析,是跑不起来的。如果参照你建的模型(公式),可能会有帮助,我的邮箱是wjcpcahu@126.com.方便的话,看看能不能进一步探讨。

cronie 发表于 2008-5-19 18:02:44

运行不了

提示custom无值,这是怎么回事?

dcjmmm 发表于 2011-4-10 14:42:01

好高深

ANQINGHU 发表于 2011-11-7 11:36:13

为什么大部分的帖子的交流都止步于2008年,从08年到现在好像已经很长时间没有更新过了啊,为什么呢?
页: [1]
查看完整版本: 关于turtle的使用问题