2016-07-12 7 views
-1

なぜこのエラーが発生するのか分かりません。私はget-earlywarnプロシージャに代理店を入れてみましたが、動作していないようです。それはask n-of nエージェントによって引き起こされますか?私はこれを別の手順に入れるべきですか?NetLogo 5.3.1エラー:カメだけの理由でGET-EARLYWARNをオブザーバコンテキストで使用することはできません

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
; FOR ALL MODELS 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 

; VARIABLES 

globals 
    [ 
    percent-agri 
    basin-area 
    agri-volume 
    yield-max 
    water-requirement 
    price-rice 
    agri-cost 
    month-rainfall 
    drought 
    month 
    d 
    n 
    p 
    total-income 
    ] 

breed [agents agent] 

agents-own 
    [ 
    agent-id-sw 
    agent-landarea-sw 
    agehh-sw 
    district-sw 
    pcons-sw 
    earlywarn-sw 
    pprob-sw 
    reach 
    agent-received 
    agent-demand 
    agent-volumestored 
    agent-volumeused 
    agent-yield-sw 
    agent-income-sw 
    y 
    store-capacity 
    ] 

; SETUP 

to setup 
    clear-all 
    define-month 
    set month-rainfall 848.5 ;; max rainfall from 2011 to 2014 in the river basin 
    define-agri-volume 
    set percent-agri 0.17  ;; assumes 17% of water from river basin is allocated for agriculture use 
    set basin-area 9.205e+15 ;; 9.205e+15 sq mm of surface area 
    set yield-max 6.15  ;; 6.15 tons of rice/ha 
    set water-requirement 528 ;; 528 cubic m/ton of rice 
    set price-rice 8963.10 ;; 8,963.10 VND per ton of rice 
    set agri-cost 500000  ;; 500,000 VND per cropping season 
end 

to define-month 
    if (ticks = 1) or (ticks = 13) or (ticks = 25) or (ticks = 37) or (ticks = 49) or (ticks = 61) or (ticks = 73) or (ticks = 85) or (ticks = 97) or (ticks = 109)  
    [ 
     set month "JANUARY" 
    ] 
    if (ticks = 2) or (ticks = 14) or (ticks = 26) or (ticks = 38) or (ticks = 50) or (ticks = 62) or (ticks = 74) or (ticks = 86) or (ticks = 98) or (ticks = 110) 
    [ 
     set month "FEBRUARY" 
    ] 
    if (ticks = 3) or (ticks = 15) or (ticks = 27) or (ticks = 39) or (ticks = 51) or (ticks = 63) or (ticks = 75) or (ticks = 87) or (ticks = 99) or (ticks = 111) 
    [ 
     set month "MARCH" 
    ] 
    if (ticks = 4) or (ticks = 16) or (ticks = 28) or (ticks = 40) or (ticks = 52) or (ticks = 64) or (ticks = 76) or (ticks = 88) or (ticks = 100) or (ticks = 112) 
    [ 
     set month "APRIL" 
    ] 
    if (ticks = 5) or (ticks = 17) or (ticks = 29) or (ticks = 41) or (ticks = 53) or (ticks = 65) or (ticks = 77) or (ticks = 89) or (ticks = 101) or (ticks = 113) 
    [ 
     set month "MAY" 
    ] 
    if (ticks = 6) or (ticks = 18) or (ticks = 30) or (ticks = 42) or (ticks = 54) or (ticks = 66) or (ticks = 78) or (ticks = 90) or (ticks = 102) or (ticks = 114) 
    [ 
     set month "JUNE" 
    ] 
    if (ticks = 7) or (ticks = 19) or (ticks = 31) or (ticks = 43) or (ticks = 55) or (ticks = 67) or (ticks = 79) or (ticks = 91) or (ticks = 103) or (ticks = 115) 
    [ 
     set month "JULY" 
    ] 
    if (ticks = 8) or (ticks = 20) or (ticks = 32) or (ticks = 44) or (ticks = 56) or (ticks = 68) or (ticks = 80) or (ticks = 92) or (ticks = 104) or (ticks = 116) 
    [ 
     set month "AUGUST" 
    ] 
    if (ticks = 9) or (ticks = 21) or (ticks = 33) or (ticks = 45) or (ticks = 57) or (ticks = 69) or (ticks = 81) or (ticks = 93) or (ticks = 105) or (ticks = 117) 
    [ 
     set month "SEPTEMBER" 
    ] 
    if (ticks = 10) or (ticks = 22) or (ticks = 34) or (ticks = 46) or (ticks = 58) or (ticks = 70) or (ticks = 82) or (ticks = 94) or (ticks = 106) or (ticks = 118) 
    [ 
     set month "OCTOBER" 
    ] 
    if (ticks = 11) or (ticks = 23) or (ticks = 35) or (ticks = 47) or (ticks = 59) or (ticks = 71) or (ticks = 83) or (ticks = 95) or (ticks = 107) or (ticks = 119) 
    [ 
     set month "NOVEMBER" 
    ] 
    if (ticks = 12) or (ticks = 24) or (ticks = 36) or (ticks = 48) or (ticks = 60) or (ticks = 72) or (ticks = 84) or (ticks = 96) or (ticks = 108) or (ticks = 120) 
    [ 
     set month "DECEMBER" 
    ] 
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
;STORE WATER MODEL 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 

; RUN MODEL 

to go-sw 
    tick 
    define-agents-sw 
    define-agri-volume 
    get-earlywarn 
    define-received 
    define-demand 
    store-water 
    use-storedwater 
    define-yield-sw 
    define-income-sw 
    define-total-income 
    if ticks = 121 [stop] 
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 

; INPUT DATA 

to define-agents-sw 

    create-agents 111 
    ask agents [hide-turtle] 

    random-seed new-seed 

    file-open "agent_id_sw.txt" 
    foreach sort agents [ask ? [set agent-id-sw file-read] ] 
    file-close 

    file-open "landarea_sw.txt" 
    foreach sort agents [ask ? [set agent-landarea-sw file-read] ] 
    file-close 

    file-open "agehh_sw.txt" 
    foreach sort agents [ask ? [set agehh-sw file-read] ] 
    file-close 

    file-open "district_sw.txt" 
    foreach sort agents [ask ? [set district-sw file-read] ] 
    file-close 

    file-open "pcons_sw.txt" 
    foreach sort agents [ask ? [set pcons-sw file-read] ] 
    file-close 

    file-open "earlywarn_sw.txt" 
    foreach sort agents [ask ? [set earlywarn-sw file-read] ] 
    file-close 

    file-open "pprob_sw.txt" 
    foreach sort agents [ask ? [set pprob-sw file-read] ] 
    file-close 

end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 

; STORE WATER PROCESS 

to define-agri-volume 
    set d random 0.9676  ;; or set d random 1 
    ifelse d >= 0.8998 
    [ 
    set agri-volume (month-rainfall * (1 - d) * basin-area * percent-agri) 
    set drought "DROUGHT" 
    ] 
    [ 
    set agri-volume (month-rainfall * (1 - d) * basin-area * percent-agri) 
    set drought "NODROUGHT" 
    ] 
end 

to get-earlywarn 
    if drought = "DROUGHT" 
    [ 
    ifelse (ticks = 1) or (ticks = 13) or (ticks = 25) or (ticks = 37) or (ticks = 49) or (ticks = 61) or (ticks = 73) or (ticks = 85)  or (ticks = 97) or (ticks = 109) or (ticks = 7) or (ticks = 19) or (ticks = 31) or (ticks = 43) or (ticks = 55) or (ticks = 67) or  (ticks = 79) or (ticks = 91) or (ticks = 103) or (ticks = 115) 
     [ 
     set n random 111 
     ;; n of agents reached by early warning system decided at the start of each cropping season 
     set p random 4 
     ] 
     [ 
     set n n 
     set p p 
     ] 
    ask n-of n agents 
     [ 
     set pprob-sw pprob-sw + p 
     set y (-0.591 * agehh-sw) + (-0.605 * district-sw) + (-0.249 * pcons-sw) + (2.223 * earlywarn-sw) + (-0.615 * pprob-sw)  ;; y is computed y-hat from logistic regression 
     ;; constant numbers are estimates from logistic regression 
     ] 
    ifelse agents = n-of n agents 
     [set reach "REACHED"] 
     [set reach "NOTREACHED"] 
    ifelse reach = "REACHED" 
     [ 
     ifelse y >= 0.5 
     [ 
     store-water 
     use-storedwater   
     ] 
     [ 
     ifelse agent-received > agent-demand 
      [set agent-volumeused agent-demand] 
      [set agent-volumeused agent-received] 
     set agent-volumestored 0 
     ] 
     ] 
     [ 
     ifelse agent-received > agent-demand 
     [set agent-volumeused agent-demand] 
     [set agent-volumeused agent-received] 
     set agent-volumestored 0 
     ] 
    ] 
    if drought = "NODROUGHT" 
    [ 
    ifelse agent-received > agent-demand 
     [set agent-volumeused agent-demand] 
     [set agent-volumeused agent-received] 
    set agent-volumestored 0 
    ] 
end 

to define-received 
     set agent-received agri-volume * agent-landarea-sw/sum [agent-landarea-sw] of agents 
end 

to define-demand 
     set agent-demand yield-max * water-requirement * agent-landarea-sw 
end 

to store-water 
    set store-capacity random 1000 
    ifelse agent-received > agent-demand 
    [ 
    let dif1 agent-received - agent-demand ;; assumes that stored water only comes from excess of received 
     ifelse dif1 >= store-capacity 
     [set agent-volumestored agent-volumestored + store-capacity] 
      [set agent-volumestored agent-volumestored + dif1] 
    ] 
     [set agent-volumestored agent-volumestored] 
end 

to use-storedwater 
    let dif2 agent-demand - agent-received 
    ifelse agent-received < agent-demand 
     [ 
    ifelse agent-volumestored > dif2 
     [ 
      set agent-volumeused agent-received + dif2 
    set agent-volumestored agent-volumestored - dif2 
    ] 
      [ 
    if agent-volumestored > 0 
       [ 
     set agent-volumeused agent-received + agent-volumestored 
      set agent-volumestored 0 
     ] 
    ] 
     ] 
     [ 
    set agent-volumeused agent-received 
    set agent-volumestored agent-volumestored - 0 
    ] 
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 

; GET OUTPUT 

to define-yield-sw 
    ask agents 
    [ 
    if (ticks = 6) or (ticks = 18) or (ticks = 30) or (ticks = 42) or (ticks = 54) or (ticks = 66) or (ticks = 78) or (ticks = 90) or (ticks = 102) or (ticks = 114) or (ticks = 12) or (ticks = 24) or (ticks = 36) or (ticks = 48) or (ticks = 60) or (ticks = 72) or (ticks = 84) or (ticks = 96) or (ticks = 108) or (ticks = 120)  ;; assumes 2 cropping seasons per year 
    [ifelse agent-volumeused >= agent-demand 
    [set agent-yield-sw agent-yield-sw + (yield-max * agent-landarea-sw)/6] 
    [ 
    set agent-yield-sw agent-yield-sw + 
    (6.15 * agent-landarea-sw * sum [agent-volumeused] of agents/sum [agent-demand] of agents)/6 
    ] 
    ] 
    ] 
end 

to define-income-sw 
    ask agents 
    [ 
    if (ticks = 6) or (ticks = 18) or (ticks = 30) or (ticks = 42) or (ticks = 54) or (ticks = 66) or (ticks = 78) or (ticks = 90) or (ticks = 102) or (ticks = 114) or (ticks = 12) or (ticks = 24) or (ticks = 36) or (ticks = 48) or (ticks = 60) or (ticks = 72) or (ticks = 84) or (ticks = 96) or (ticks = 108) or (ticks = 120) 
    [set agent-income-sw (agent-yield-sw * price-rice) - agri-cost] 
    ] 
end 

to define-total-income 
    if (ticks = 6) or (ticks = 18) or (ticks = 30) or (ticks = 42) or (ticks = 54) or (ticks = 66) or (ticks = 78) or (ticks = 90) or (ticks = 102) or (ticks = 114) or (ticks = 12) or (ticks = 24) or (ticks = 36) or (ticks = 48) or (ticks = 60) or (ticks = 72) or (ticks = 84) or (ticks = 96) or (ticks = 108) or (ticks = 120) 
    [set total-income sum [agent-income-sw] of agents] 
end 
+2

あなたの投稿を壊さないでください。 –

答えて

1

「亀は唯一のでオブザーバーコンテキストでXXXを使用することはできません」ので、どこかのコードで、あなただけのコマンド亀を求めているあなたは、エラーコードを取得している:ここで

コードです(例:X 前方または セット年齢年齢は亀が所有している)ではなく、直接カメへ。代わりの

to go 
    fd 1 
end 

を::私が言うgoコマンド作る場合と同様

to go 
    ask turtles [fd 1] 
end 

あなたのコードについては、何をどのようなグローバルがあるの所有者を見ずに、私は推測しているそのあなたは(GET-earlywarnて途中について)尋ねコードのビット:

ifelse reach = "REACHED" 
     [ 
     ifelse y >= 0.5 
     [ 
      store-water 
      use-storedwater   
     ].................... 

私はあなたがその時点でいずれかのエージェントにそれを求めていると思ういけません。手を差し伸べる前にエージェントに依頼すると助けになるはずです。

p.s.できるだけコード全体を渡す場合は、グローバル/ etcを含めてください。あるいは、問題を絞り込む方がはるかに優れています。

編集:はい。これでコード全体を入れました。間違いなく私が思った問題です。あなたはどんなカメにも尋ねることなく、もしかすると尋ねる。

関連する問題