Rdb
Rdb

Reputation: 21

"Can't use XXX in an observer context because patch only"

I am havig some diffuculties with a part of my code. Netlogo reort "Can't use GO in an observer context because patch only"

My guess is that this is because in the go part I ask for a procedure (CACULATEWILANDATRAC) that does not begin with "ask Patches". However the (CACULATEWILANDATRAC) produce is to calculate one of the patches own-variables, so ask patches does not seem fit here.

I still tried to solve it with putting ask patches before the procure but then I get another error when running the model : " only the observer can ASK the set of all patches. error while patch 1079 509 running ASK called by (anonymous command: [ [the-Land-use the-Senario] -> ask patches [ if count patches with [ the-Land-use ] > the-Senario [ set Willingstochange True ] ] ]) called by procedure CACULATEWILANDATRAC"

The problem thus lies with where to call for the CACULATEWILANDATRAC procedure? It is now part of the go procedure but this thus gives the error "Can't use XXX in an observer context because turtle only".

My entire code:

> extensions [gis]
globals
[
  land-use-map
   Senario1N               ;; the count of patches senario 1 describes
   Senario1L
   Senario1A
   Senario1B
   Senario1I
   Senario1R
   Senario1W
  %landusetypeN           ;; the amount patches
  %landusetypeL
  %landusetypeA
  %landusetypeB
  %landusetypeI
  Willingstochange        ;; If true a patch would like to change (if true the count of patches has a surplus comparing to the sneario, if false they have a shortage)
  atractiveness           ;; if a patch type is attractive to change in <1 = yess
  Atractiveneighbor

]

patches-own
  [   Land-use                ;; Wat kind og landusetype a patch has
    ]



to setup
  clear-all
  load-gis   ;;load the maps
  setup-constants
  update-global-variables
  update-display
  reset-ticks
end



to load-gis  ;;load the maps

  set land-use-map gis:load-dataset "a_LANDUSE_cellsize5.asc"     ;;loads the land use map
  gis:set-world-envelope-ds gis:envelope-of land-use-map          ;;sets the envelope of the world to match that of the GIS dataset
  gis:apply-raster land-use-map Land-use                          ;;patches in the land-use-map have a specific land-use now

  ask patches [
    if Land-use = 1 [ set pcolor Green ] ; Green = Nature         ;; patches have a certain color now
    if Land-use = 2 [ set pcolor red ] ; Dark red = Leisure
    if Land-use = 3 [ set pcolor Yellow ] ; Yellow = Agriculture
    if Land-use = 4 [ set pcolor brown ] ; brouwn = Buildup
    if Land-use = 5 [ set pcolor grey ] ; grey = roads
    if Land-use = 6 [ set pcolor pink ] ; pink = industry
    if Land-use = 7 [ set pcolor blue ] ; Blue = water
  ]


    resize-world 0 1633 0 780
    set-patch-size 1

end

to setup-constants
  set Senario1N 49174        ;; the count of patches senario 1 describes
  set Senario1L 17871
  set Senario1A 569970
  set Senario1B 34202
  set Senario1I 5540
  set Senario1R 34968
  set Senario1W 65594

end



to go ;; this asks the model to caculate certain variables defined below
  givecountlansusetypes
  askforchange
  caculateWILandAtrac
  tick
end

to givecountlansusetypes ;; here the cuurent amount of patches is shown
  show count patches with [Land-use = 1]
  show count patches with [Land-use = 2]
  show count patches with [Land-use = 3]
  show count patches with [Land-use = 4]
  show count patches with [Land-use = 5]
  show count patches with [Land-use = 6]
  show count patches with [Land-use = 7]
end

to update-display
  ask patches
  [
    if Land-use = 1 [ set pcolor Green ]   ;; Green = Nature           ;; patches have a certain color now
    if Land-use = 2 [ set pcolor red ]     ;; Dark red = Leisure
    if Land-use = 3 [ set pcolor yellow ]  ;; Yellow = Agriculture
    if Land-use = 4 [ set pcolor brown ]   ;; brouwn = Buildup
    if Land-use = 5 [ set pcolor grey ]    ;; grey = roads
    if Land-use = 6 [ set pcolor pink ]    ;; pink = industry
    if Land-use = 7 [ set pcolor blue ]    ;; Blue = water
    ]
end

to update-global-variables
  if count patches > 0
    [ set %landusetypeN (count patches with [ Land-use = 1 ] / count patches) * 100
      set %landusetypeL (count patches with [ Land-use = 2 ] / count patches) * 100
      set %landusetypeA (count patches with [ Land-use = 3 ] / count patches) * 100
      set %landusetypeB (count patches with [ Land-use = 4 ] / count patches) * 100
      set %landusetypeI (count patches with [ Land-use = 6 ] / count patches) * 100
    ]

end



to caculateWILandAtrac
  ;; Sets Willingness to change true if patches are with more fellowpatches than the senario decribes
  (foreach list (Land-use = 1) (Land-use = 2)[49174 17871]
  [ [the-Land-use the-Senario] ->  ask patches [if count patches with [the-Land-use] > the-Senario [ set Willingstochange True ] ] ])
  ;; gives score to the patches attractiveness based on the ratio patches/senario

  (foreach list (Land-use = 1) (Land-use = 2)[49174 17871]
  [ [the-Land-use the-Senario] ->  ask patches  [ set atractiveness (count patches with [the-Land-use]/ the-Senario) ]  ])

end


to askforchange
  ask patches [
    if Willingstochange = true [change]    ;; this ask the patches that are willing to change (have a surpuls) to go and change
  ]
end


to change
  ask neighbors with [Willingstochange = false ]                   ;; this asks if the patch had neigbors with a shortage
  [set Atractiveneighbor min-one-of patches [atractiveness]]       ;; this asks to give the neigbor with the lowest patchcount/senario ratio
  ask patches [set Land-use ([Land-use] of Atractiveneighbor)]     ;; this asks the patches to change their land-use to the land-use of neigbor with the lowest patchcount/senario ratio

end

Upvotes: 0

Views: 1516

Answers (1)

Bwpietzsch
Bwpietzsch

Reputation: 66

In your last line of code the current asked patch (asked in askforchange) asks all patches to set their Land-use accordingly. I think that there lies your problem.

Maybe it solves your problem, if you replace the last line with the following:

set Land-use ([Land-use] of Atractiveneighbor)

With this, the currently asked patch changes its land-use accordingly. But I am not quite sure, if that is what you want the procedure to do there?

Upvotes: 1

Related Questions