Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Crop/Stockpile Optimization  (Read 1228 times)

jakeb89

  • Bay Watcher
    • View Profile
Crop/Stockpile Optimization
« on: May 11, 2010, 02:53:20 am »

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.
Logged

ItchyBeard

  • Bay Watcher
    • View Profile
Re: Crop/Stockpile Optimization
« Reply #1 on: May 11, 2010, 04:35:04 am »

If anyone has any ideas for improving this I'd love to hear them.
I'm not clear on the utility of what you're doing in terms of practical fort building, but you're obviously having fun :).

What would be more practical, and perhaps garner more interest, would be crunching some numbers for optimal layout of production industry chains.

e.g. For a full cloth industry it would need to take into account at least:
  • Crops - rope reed for thread, blade weed for dye
  • Workshops - mill, farmer's workshop, loom, dyers, clothier
  • Stockpiles - plants, seeds, empty bags, dye bags, thread, cloth, finished goods

...with the goal of minimising walking distances at the individual steps of the production chain (ideally utilising vertical travel as well). I think it would be insufficient to minimise the sum of the walk distances for the entire chain as that might lead to one step taking much longer than the others (and thus stalling production). If you wanted to get really fancy you could also take into account the position of blocking tiles in each workshop and the impact that would have on pathing to the stockpiles...
Logged

Dave Mongoose

  • Bay Watcher
    • View Profile
Re: Crop/Stockpile Optimization
« Reply #2 on: May 11, 2010, 09:23:49 am »

Sounds pretty cool: Are you using a genetic algorithm for this?

The problem with having a single path is that only one dwarf can use it at once, and it's only efficient when approaching from one side.

I assume the idea is to reduce wear on the objects in the stockpile from dwarves walking over them? I'm not sure what other benefits this would have...
Logged

Hyperturtle

  • Bay Watcher
    • View Profile
Re: Crop/Stockpile Optimization
« Reply #3 on: May 11, 2010, 06:01:15 pm »

Generally speaking, I put a food stockpile designated for plant matter only, within a screen away or directly underneath the farm, with a pathway leading indoors.  I allow for all food types in the kitchen area, so barrels are moved automatically from the plant only stockpile into the kitchen (or, in some cases, placed directly into the kitchen first).
Logged
igless

Kazang

  • Bay Watcher
    • View Profile
Re: Crop/Stockpile Optimization
« Reply #4 on: May 11, 2010, 06:30:49 pm »

Does waking over food/crops cause wear to the goods or slower movement speed?  Since they do not block the tile I always assumed it was treated as empty for the purpose of pathfinding/movement.

I normally arrange stock piles for food above or below the main farm area with a central core of stockpiles with the various workshops using those goods around the outside of stockpiles, with 1 or 2 tile wide paths through the piles just make organization easier.   
Logged

Pierre Monteux

  • Bay Watcher
    • View Profile
Re: Crop/Stockpile Optimization
« Reply #5 on: May 11, 2010, 06:51:30 pm »

Same question.  I didn't know that things could "wear".  Well other than clothing.
Logged
I've had Dorf's wh ohave pulled a Monty Python's Black Knight. They've had limbs chopped off and just keep coming. Although most of those are my patented "Spartan Dwarfs."
except in DF, the "I'll bit your legs off" threat is serious.

jseah

  • Bay Watcher
    • View Profile
Re: Crop/Stockpile Optimization
« Reply #6 on: May 12, 2010, 02:48:39 am »

What would be more practical, and perhaps garner more interest, would be crunching some numbers for optimal layout of production industry chains.

e.g. For a full cloth industry it would need to take into account at least:
  • Crops - rope reed for thread, blade weed for dye
  • Workshops - mill, farmer's workshop, loom, dyers, clothier
  • Stockpiles - plants, seeds, empty bags, dye bags, thread, cloth, finished goods

...with the goal of minimising walking distances at the individual steps of the production chain (ideally utilising vertical travel as well). I think it would be insufficient to minimise the sum of the walk distances for the entire chain as that might lead to one step taking much longer than the others (and thus stalling production). If you wanted to get really fancy you could also take into account the position of blocking tiles in each workshop and the impact that would have on pathing to the stockpiles...
How about the layout I use for this?
Farm -> adjacent 3x9 stockpile with hole in the 3,5 position for a millstone -> 1x3 farmer's workshop -> 1x3 loom -> 1x3 clothier
With stockpile only set to accept unprocessed crops and no stockpiles in the fort for thread or cloth. 

The idea is that any clogs in the system would slow down the production of that step and you can monitor which is the problem area (say due to skill level differences) by looking at the average workshop clutter. 
Of course, it does mean that you can't turn off the chain since there's no storage, so I find I usually have to shut down farming after year 3 because it churns out too much clothing to use/trade/tribute. 
Logged