2017-03-21 6 views
1

Ich modelliere die Gebietsauswahl in NetLogo, wo Schildkröten ein Gebietszentrum auswählen ("Start-Patch") und dann basierend auf dem Wert der Patches ein Territorium daraus erstellen. Turtles kehren immer zum Start-Patch zurück, nachdem sie einen neuen Patch angefordert haben, wählen dann, bewegen sich zu ihm und beanspruchen den nächst-wertvollsten Patch. Nach der Auswahl eines Territoriums weiß die Schildkröte, welche Patches sie besitzt und Patches kennen ihren Besitzer.NetLogo: geographische Mitte des Patch-Sets berechnen

Letztendlich kann der Startbereich eines Territoriums nicht wirklich das geografische Zentrum sein. Nachdem eine Schildkröte ihr Territorium ausgewählt hat, wie könnte ich sie bitten, das Gebiet zu bewerten, das geographische Zentrum zu identifizieren und die Nähe des Start-Patches zum wahren Zentrum des Territoriums zu berechnen? (Anmerkung: Ich möchte Schildkröten nicht zwingen, den Start-Patch im geographischen Zentrum zu behalten - sie können frei wählen, welche Patches sie wollen. Aber ich kann Schildkröten zwingen, ein Territorium neu zu wählen, wenn es kein gibt Enge Übereinstimmung - diese Gebiete sind ansonsten nicht sehr effizient.)

Hier ist ein Beispiel dafür, wie Territory-Start-Patches (schwarze Sterne) geografischen Zentren nicht gleich sind. Ein Beispielcode ist unten. Irgendwelche Vorschläge? Danke im Voraus! Visual: example of resulting territories and how the "center" doesn't usually end up in the geographic center of a territory.

patches-own [ 
    benefit ;; ranges 0.1-1 and represents food available in the patch 
    owner ] ;; patches are owned once selected for a territory 

turtles-own [ 
    start-patch  ;; the selected center of the territory 
    sum-value  ;; sum of values of patches in my territory 
    territory-list ;; list of patches I've selected 
    territory  ;; agentset of patches I've selected 
    established ] ;; true/false, true when has settled in a final territory after assessing geographic center 

globals [threshold = 25] 

to setup 
    ask patches [ set owner nobody ] 
end 

to go 
    ask turtles [ 
     pick-center 
     build-territory] 
    tick 
end 

to pick-center 
    if start-patch = 0 
    [move-to best-center ;; (calculated by a reporter elsewhere as moving windows for a cluster of high-benefit patches) 
    set start-patch patch-here 
    set owner self 
    set territory-list (list patch-here) 
    set territory (patches with [owner = myself]) 
    ] 

to build-territory 
    ifelse sum-value < threshold 
    [ pick-patch ] ;; keeps picking patches for territory until I've met my threshold 
    [ assess-geographic-center] ;; once met threshold, assess real center of patch-set 
end 

to pick-patch 
    let _destination highest-value ;; (this is calculated by reporters elsewhere based on benefit/travel costs to a patch) 
    face _destination forward 1 
     if patch-here = _destination 
     [ claim-patch _destination ] 

end 

to claim-patch [_patch] 
    ask _patch [set owner myself] 
    set sum-value sum-value + (benefit/(distance start-patch)) 
    set territory-list lput patch-here territory-list 
    set territory (patch-set territory _patch) 
    move-to start-patch 
end 

to assess-geographic-center 
    ;; Once the territory is built, the turtle should identify the actual 
    ;; geographic center of the patch-set it has selected...how to do this? 
    ;; Once it knows the center, the turtle should compare the distance to the original start-patch. 
    ;; If >10 patches away, it will move to that start-patch and start over with selecting a territory.... 
end 
+0

Nehmen Sie den durchschnittlichen pxcor und durchschnittliche Pycor der Patches in dem Satz? –

Antwort

2

Können Sie entkommen mit nur dem Mittelwert pxcor und pycor aller Patches? Etwas wie:

to setup 

    ca 
    reset-ticks 
    let n 70 

    ask one-of patches [ 
    set pcolor red 
    ] 

    while [ (count patches with [pcolor = red ]) < n ] [ 
    ask one-of patches with [ pcolor = red ] [ 
     ask one-of neighbors4 [set pcolor red ] 

    ] 
    ] 

    let xmean mean [pxcor] of patches with [ pcolor = red ] 
    print xmean 
    let ymean mean [pycor] of patches with [ pcolor = red ] 
    print ymean 

    ask patch xmean ymean [ set pcolor blue 
    ] 

end 
1

Nach der vorherigen Antwort, hier ist, was ich gefunden habe. Dies geht in der letzten Prozedur in meinem ursprünglichen Code:

to assess-geographic-center 
    let xmean mean [pxcor] of patches with [ owner = myself ] 
    let ymean mean [pycor] of patches with [ owner = myself ] 
    ask patch xmean ymean [ set pcolor black ] ;; make the geographic center visible 
    let geographic-center patch xmean ymean 
    let distance-away distance geographic-center ;; the turtle is on its start-patch when assessing this distance 
    ifelse distance-away <= 5 
     [ set established true ] ;; turtle is happy if start-patch and geographic-center are approximately equal, territory "established" 
     [ move-to geographic-center ;; otherwise, turtle moves to geographic-center, 
      reposition ] ;; and follows a procedure "reposition" to makes this the new start-patch and repick the territory 
end