[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

grid-based manhattan boxing

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 5
Thread images: 2

File: file.png (41KB, 957x418px) Image search: [Google]
file.png
41KB, 957x418px
maybe one of you anons has a good idea for this.

basically I want to separate a connected area in a 2d grid into the least amount of boxes as fast as possible. Are there any good algorithms lying around?

I came up with this pseudo code to illustrate what I want to do

field = [
[ 0, 0, 0, 0, 0 ],
[ 0, 1, 1, 0, 0 ],
[ 0, 1, 1, 1, 0 ],
[ 0, 1, 1, 1, 1 ],
[ 0, 0, 1, 0, 1 ],
[ 0, 0, 0, 0, 0 ],
]

func manhattan_boxing(field) {

// collect boxes
var boxes = [];

// array of point(x,y)
var open_cells = get_occupied_points(field);

while (!open_cells.empty()) {

// pick a point at random
var point = random(open_cells);

// Expansion count to N, E, S, W
var expansions = {0,0,0,0};

int n_expansions = 0;

// repeatedly try to expand in all 4 directions until nothing can be expanded anymore
do {
// try to expand north
if (can_expand_north(field, expansions, point)) {
expansions[0]++;
n_expansions++;
}

// try to expand east
if (can_expand_east(field, expansions, point)) {
expansions[1]++;
n_expansions++;
}

// try to expand south
if (can_expand_south(field, expansions, point)) {
expansions[2]++;
n_expansions++;
}

// try to expand west
if (can_expand_west(field, expansions, point)) {
expansions[3]++;
n_expansions++;
}

} until (n_expansions == 0);

box = get_box(point, expansions); // returns a box, which is defined by a minimum and maximum point of its spanning diagonal vectors

// add box to box collection
boxes.add(box);

// remove all open cells that are within the box
remove_open_cells(open_cells, box);

}

return boxes;
}

Any ideas?
>>
>>61769958
I won't do your highschool homework for you, but think about representing the area on grid in a different way. Hint: prefix is a powerful concept.
>>
>>61770315
I'm not the OP, but can you explain what you mean? Seems intriguing but I don't understand what you mean.
Even just a link to a concept/algorithm would be helpful.
>>
File: cases.png (1KB, 260x380px)
cases.png
1KB, 260x380px
A test case where a naive algorithm might produce bad results with more boxes than necessary.
>>
>>61769958
Based on a little research, it looks like finding the minimum set of boxes that represent the area may be a non-trivial computational geometry problem. Good luck.
Thread posts: 5
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.