Netlogoで四角形をより小さなランダムな長方形に分割する方法はありますか?Netlogoで正方形を小さな正方形に無作為に分割します
私は通常の長方形で構成Netlogoにロードされた農地のSHPファイルを持っている、としたいので、この質問は次のとおりです。細分化し、細分化が黒く塗られている6つの長方形、1と次の画像のようにそれらがどのように細分化され、都市開発によって占有されているかをシミュレートします。小区画のサイズは、総平方の1/3から1/8までの範囲とすることができる。ありがとう。
Netlogoで四角形をより小さなランダムな長方形に分割する方法はありますか?Netlogoで正方形を小さな正方形に無作為に分割します
私は通常の長方形で構成Netlogoにロードされた農地のSHPファイルを持っている、としたいので、この質問は次のとおりです。細分化し、細分化が黒く塗られている6つの長方形、1と次の画像のようにそれらがどのように細分化され、都市開発によって占有されているかをシミュレートします。小区画のサイズは、総平方の1/3から1/8までの範囲とすることができる。ありがとう。
私はこれがかなり難しいと思っています。特に、特定の最小寸法が必要な場合は特にそうです。たぶん下のコードを試してみてください。これは基本的に矩形の入力(潜在的に農場のプロット)をとり、オーバーラップする長方形の全体を生成します。ランダムなビットの問題は、オーバーラップするので、あなたの1/8よりも狭いか、または大きいセクションを得ることができるということです。カウンターで遊んで長方形の数を増やしたり減らしたりすることは、パッチ全体を細分できないことを意味し、実行時間が長くなり、細分化がより小さくなる可能性があります。
patches-own [ id ]
to setup
ca
resize-world -50 50 -50 50
set-patch-size 4
ask patches [ set id -1 ]
ask rectangle -20 20 -40 40 [
set pcolor red
]
reset-ticks
end
to go
rectangle-sub -20 20 40 -40
tick
end
to rectangle-sub [ x0 x1 y0 y1 ]
; Make sure the x0 x1/y0 y1 order is correct
let xp0 min (list x0 x1)
let xp1 max (list x0 x1)
let yp0 min (list y0 y1)
let yp1 max (list y0 y1)
; Define the rectangle to subdivide
let main_rect rectangle xp0 xp1 yp0 yp1
; Define width and height
let width xp1 - xp0
let height yp1 - yp0
let w3 round (width/3)
let w8 round (width/8)
let h3 round (height/3)
let h8 round (height/8)
; Set a while loop to make mini rectangles, with
; a counter to stop the loop after too many tries
let counter 0
while [ counter < 100 and any? main_rect with [id = -1 ] ] [
let newx0 xp0 + (random width)
let newx1 newx0 + (ceiling width/(random 6 + 3))
let newy0 yp0 + (random height)
let newy1 newy0 + (ceiling height/(random 6 + 3))
; define a sub rectangle
let newrect rectangle newx0 newx1 newy0 newy1
; remove any patches from the sub rectangle that are not
; also part of the main rectangle
set newrect newrect with [ member? self main_rect ]
if any? newrect [
; Make sure the dimensions aren't too small or big
let nwidth (max [pxcor] of newrect - min [pxcor] of newrect)
let nheight (max [pycor] of newrect - min [pycor] of newrect)
if nwidth < w3 and nwidth > w8 and nheight < h3 and nheight > h8 [
; Choose a random patch and assign its id to all others
; in the same newrect patch-set
let groupid random 10000
ask newrect [
set id groupid
set pcolor id/100
]
]
]
set counter counter + 1
]
print counter
end
to-report rectangle [ x0 x1 y0 y1 ]
; reports a patch-set bounded by
; the coordinate arguments passed
report patches with [
pxcor > x0 and pxcor < x1 and
pycor > y0 and pycor < y1
]
end
EDITS:
OK-私はここで少し船外に行っているかもしれませんが、私はこの問題が好き。ここでは、亀の矩形を描く代わりの解決方法があります。つまり、重なりがないようにします。さらに、矩形は外側または以前のid-d矩形を構築する必要があります。したがって、ランダムに切り離された矩形を取得することはありません。しかし、それは矩形内にIDなしの1パッチの四角形を残すことができるので、好きなようにそれらを並べ替える必要があります。
どのように動作するかを確認するには、ディスプレイを連続して置き、スローダウンします。本質的に、イカがないパッチにはカメがはじまり、同じ方向を向いて前方に移動してある距離を移動する前にある距離を離れて移動するパートナーをハッチします。各コーナーパッチのx座標とy座標はリストに格納され、定義されている矩形にIDを割り当てます。
patches-own [ id ]
to setup
ca
resize-world -50 50 -50 50
set-patch-size 5
ask patches [ set id -1 ]
ask rectangle -20 20 -40 40 [
set pcolor red
]
reset-ticks
end
to go
turtle-define-rect -20 20 40 -40
tick
end
to turtle-define-rect [ x0 x1 y0 y1 ]
; Make sure the x0 x1/y0 y1 order is correct
let xp0 min (list x0 x1)
let xp1 max (list x0 x1)
let yp0 min (list y0 y1)
let yp1 max (list y0 y1)
; Define the rectangle to subdivide
let main_rect rectangle xp0 xp1 yp0 yp1
let xlist []
let ylist []
let possible_area one-of main_rect with [
id = -1 and
any? neighbors4 with [id = -1] and
any? neighbors4 with [not member? self main_rect or id != -1]
]
if possible_area != nobody [
ask possible_area [
let w random 5 + 5
let h random 10 + 10
sprout 1 [
set color blue
set size 3
let start-patch patch-here
let id_temp [id] of patch-here
face one-of neighbors4 with [not member? self main_rect or id != -1]
rt 180
hatch 1 [
create-link-with one-of other turtles-here
repeat w [
if ([id] of patch-ahead 1 = -1) and ([ member? self main_rect] of patch-ahead 1) [
fd 1
]
]
]
set xlist lput xcor xlist
set ylist lput ycor ylist
ask link-neighbors [
set xlist lput xcor xlist
set ylist lput ycor ylist
]
let turn one-of [ 90 -90 ]
rt turn
ask link-neighbors [
rt turn
]
ask my-links [
tie
]
repeat h [
if (
([id] of patch-ahead 1 = -1) and
([ member? self main_rect] of patch-ahead 1) and
([ [id] of patch-ahead 1 = -1 ] of link-neighbors = [true]) and
([ [ member? self main_rect] of patch-ahead 1 ] of link-neighbors = [true])
)
[
fd 1
]
]
set xlist lput xcor xlist
set ylist lput ycor ylist
ask link-neighbors [
set xlist lput xcor xlist
set ylist lput ycor ylist
]
ask link-neighbors [ die ]
die
]
]
let xt0 min xlist
let xt1 max xlist
let yt0 min ylist
let yt1 max ylist
let new_id random 10000
ask rectangle xt0 xt1 yt0 yt1 [
set id new_id
]
]
ask main_rect with [ id != -1 ] [
set pcolor id/100
]
end
to-report rectangle [ x0 x1 y0 y1 ]
; reports a patch-set bounded by
; the coordinate arguments passed
report patches with [
pxcor >= x0 and pxcor <= x1 and
pycor >= y0 and pycor <= y1
]
end
出力は次のようになります。
赤以外の色が異なるIDを持つ長方形を示すを。
ルーク、ありがとう、あなたの答えは本当に助けている。 1/8は単なる提案に過ぎず、本当に重要なことは長方形が重ならないことです。実際の生活では、それは同じ空間を占める2つの都市開発を意味する。新しい長方形がid = -1のパッチでのみ形成できるというコードを記述するとできますか? –
@JavierSandoval - ちょっとハビエル - それを手に入れました。同時にすべての開発を定義していても、新しいものを作成したいのであれば、それは問題ありません。私は編集された答えに別のアプローチを加えました。 –
もう一度ルークに感謝します。もう一つのこと:細分化の数を制御する方法はありますか?実際の生活では、私が勉強している農地の区画は、より少ない数に細分されています。 –