I'm always trying to optimize my crops and stockpiles so that there's a path cut through them with the path designated as high-traffic while the crop/stockpile area is designated as low-traffic.
I've written a program to take an X by X area of tiles, denote some of them as being used, then attempt to optimize this setup through further randomly generated patterns or simply flipping some tiles from on to off or vice-versa. Because of the way I typically dig out my rooms, a tile is only considered to be usable if there is a path from a certain square (either on the side if there's a door on that side of the room, or in the middle if there are stairs.) It is set up where I could easily denote multiple entryways.
As a simple example, here's what is spits out for the optimum 3x3, 4x4, 5x5, and 6x6 configurations:
Score: 108.69
X X X 1 1 2
X 0 1 2
X X X 1 1 2
Score: 42.18
X X X X 1 1 3 3
X X 0 1 2 3
X X X 1 1 2 3
X X X X 2 2 2 -
Score: 26.93
X X X X X 2 2 2 4 4
X X X 1 1 2 3 4
X X X 0 1 2 3 4
X X X 1 1 2 3 4
X X X X X 2 2 2 4 4
Score: 17.36
X X X X X X 2 2 2 3 5 5
X X X 1 1 2 3 4 5
X X X X 0 1 2 3 4 5
X X X X X 1 1 2 3 4 5
X X X X 2 2 2 3 4 5
X X X X X - 3 3 3 4 5
Here's the gist of the scoring equations:
reachableUsedTiles = getReachableUsedTiles(distanceArray)
totalTiles = width * height
reachableUsedTilesRatio = reachableUsedTiles / totalTiles
totalDistanceToReachableUsedTiles = getTotalDistanceToReachableUsedTiles(distanceArray)
averageDistanceToReachableUsedTiles = *totalDistanceToReachableUsedTiles / reachableUsedTiles
tileConfigurationScore = 100.0 * reachableUsedTilesRatio ^ 3 / averageDistanceToReachableUsedTiles
Here's a 7x7, 8x8, 9x9 and a different 9x9 generation, although its ability to find elegant solutions seems to begin to fall off here:
Score: 12.03
X X X X X - 3 3 3 4 5 -
X X X X X 2 2 2 3 4 5 6
X X X X X 1 1 2 3 5 5 6
X X X X X X 0 1 2 3 5 5 6
X X X 1 1 2 3 4 5 6
X X X X 2 2 2 3 4 5 6
X X X X X X X 3 3 4 4 4 7 7
Score: 7.91
X X X X X X X 3 3 - 7 6 6 6 7
X X X X X 2 2 2 5 5 5 6 7
X X X X X X 1 1 2 3 4 5 6 7
X X X X X 0 1 2 3 4 5 7 7
X X X X X 1 1 2 3 4 5 6 7
X X X X X X 2 2 2 3 4 5 6 7
X X X X X X X - 3 3 3 4 6 6 -
X X X X X X X - - 4 4 4 - - -
Score: 5.88
X X X X X X X - - 4 4 4 5 A 9 9
X X X X X X - 3 3 3 4 5 8 8 8
X X X X X X 2 2 2 3 4 5 6 7 8
X X X X X X 1 1 2 3 5 5 6 7 8
X X X X X X X X 0 1 2 4 4 5 6 7 -
X X X X 1 1 2 3 4 5 6 7 -
X X X X X X X 2 2 2 3 4 5 6 7 -
X X X X X X - 3 3 3 4 7 7 7 -
X X X X X X X X - - 4 4 4 8 8 - -
Score: 11.08
X X X X X X X 4 4 4 - 5 4 4 4 4
X X X X X X 4 3 3 3 5 3 3 3 4
X X X X X X X 4 3 2 2 2 2 2 3 4
X X X X 5 3 2 1 1 1 2 3 4
X X X X X X 4 4 2 1 0 1 2 3 4
X X X X X X 4 3 2 1 1 1 2 3 4
X X X X X 4 3 2 2 2 2 2 3 4
X X X X X X X X - 3 3 3 3 3 3 3 4
X X X X X X X - - - - 4 4 4 - -
If anyone has any ideas for improving this I'd love to hear them. I'm also interested in any questions or setups you'd like me to run through the program.