2013-03-28 48 views
1

我遇到了我的netlogo程序問題。代碼如下:NetLogo許可怪異

globals[ 
growth-param 
money-size-ratio 

] 

turtles-own[ 
    location 
    tsize 
    bbalance 
] 

to setup 
    ca 
    reset-ticks 
    ask patches[set pcolor blue] 

    create-turtles initial-telemarketers [ 
    set size 1 
    set bbalance 0.0 
    setxy random-xcor random-ycor 
    set shape "circle" 
    ] 
    set growth-param 1000 
    set money-size-ratio 0.001 
end 

to go 
    ask patches[set pcolor blue] 
    sell 
    accounting 
    observer-updates 
    tick 
end 

to sell 

    let territory 10 * sqrt size 
    let maxcalls 100 * size 
    ask n-of maxcalls patches in-radius territory[ 
    if pcolor = blue [set pcolor black] 
    set bbalance bbalance + 2 
    ] 

end 

to accounting 
    let cost size * 50 
    ask turtles[ 
    set bbalance bbalance - cost 

    ifelse bbalance < 1 
    [die] 
    [set size bbalance * growth-param] 
    ] 

end 

to observer-updates 

end 

它應該是多少個電話營銷公司互動的簡單模型。這是來自Railsback &格林的建模書。

每次嘗試運行時,它都會提供兩個問題,我可以看到:在procedure sell中,它不希望將平衡設置爲新值,因爲它只是龜,而tick只是觀察者上下文。

感謝您的幫助!

回答

0

sell是一個龜程序(因爲它使用龜原始像,如sizein-radius)。但是go是一個觀察者程序。你不能直接從觀察者程序調用烏龜程序;你需要指定你想運行的龜。在go裏面,我想你可能打算寫ask turtles [ sell ]而不是sell

+0

好吧,如果有人試圖谷歌這一點,並不能找到別的,這裏是我的全部(工作!)代碼: – user2221135

1
globals[ 

    money-size-ratio 

] 

turtles-own[ 
    location 
    tsize 
    bbalance 
    maxsize 
] 

to setup 
    ca 
    reset-ticks 
    ask patches[set pcolor blue] 

    create-turtles initial-telemarketers [ 
    set size 1 
    set bbalance 0.0 
    setxy random-xcor random-ycor 
    set shape "circle" 
    set maxsize 0 
    ] 

    set money-size-ratio 0.001 
end 

to go 

    ask patches[set pcolor blue] 
    ask turtles [sell] 
    ask turtles [accounting] ;; let's ask the turtles to do this 
    observer-updates 
    tick 

end 

to sell 
    let territory 10 * sqrt size 
    let maxcalls 100 * size 
    if maxcalls > 40401[ 
    set maxcalls 40401;keeps maxcalls within acceptable bounds 
    ] 
    let coun 0 
    ask n-of maxcalls patches in-radius territory[ 
    if pcolor = blue[ 
     set pcolor black 
     set coun coun + 2 
    ] 
    ] 
    set bbalance bbalance + coun 


end 

to accounting 
    let cost size * 50 ;; size is a turtle variable so if you want to access it this way, let's make the whole thing 
        ;; a turtle procedure. That's what was confusing Netlogo about the tick command 

    set bbalance bbalance - cost 

    if bbalance > growth-param 
    [set size size + (bbalance - growth-param) * money-size-ratio 
     set bbalance growth-param 
     ] 
    if size > maxsize[ 
     set maxsize size 
    ] 


    if bbalance <= 0 
    [show (word "dead. Maximum size: " maxsize) 
     die 

     ] 

    if size = 0 
    [show (word "dead. Maximum size: " maxsize) 
     die 

     ] 



end 

to observer-updates 

end