Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Algorithm to minimize vertex distances - Dwarf Fortress

I play Dwarf Fortress game. And the main challenge for me is to design layout of the fortress efficiently. Meaning, that each industry flow should be as dense as possible, to minimize the travel distances.

An example could be food industry Food Industry. Each grey ellipse represents a single building. Each white rectangle represents product from the building.

My goal is to find algorithm which would distribute the buildings on 2D grid in such manner that distance between those building is minimal in the sense how they are connected. Meaning that fishery and loom can be far apart, but loom and farmer's should be as close as possible.

At the moment I have considered using some ready software, to simulate the layout, but some tips for algorithm would be fine.

Currently I'm considering some force-directed algorithm, but I'm not sure about the discrete grid requirement.

Formalization of question: Is there a Force Draw Graph algorithm which works in discrete coordinates?

UPDATE: I have found implementation of the Force draw algorithm in AS3 (the web contains JS version too). I will try to convert it to discrete version. But I have some doubts it will work...

UPDATE2: Some further restrictions were requested in comments. Here they are: Each building occupy single cell on virtual grid. Buildings can be on adjacent cells. Buildings cannot stack/overlap. (PS: In game, each building has deifned size, usually 3x3, but I want to keep the problem more general, to allow for more approaches).

like image 478
jnovacho Avatar asked Jan 23 '14 14:01

jnovacho


1 Answers

So I've managed to do some code which aproximates solution of this problem. It's not a top class product but it's working. I plan to do some updates over time, but I don't have any time frame set.

The source code is here: https://github.com/sutr90/DF-Layout

My code uses Simulated Annealing approach. Where cost function is based on total area, total length of edges and overlap. To measure distance, I use taxi-cab metric, but that is a subject to change.

like image 90
jnovacho Avatar answered Sep 19 '22 14:09

jnovacho