Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: How may I consider pathfinding efficiency against DF-style A* implementation...  (Read 1813 times)

Nameless Archon

  • Bay Watcher
    • View Profile

...without implementing the fort?

I have in mind a vertical (though not spherical) 31x31xM design with a 3x3 central stair and 1x1xM stairs in a double ring around the central stair in order to allow space for workshops to be built in a triple ring around the central stair while retaining good local vertical mobility. This will allow me to place stockpiles above/below workshops which can be built in groups, and so forth, feeds directly into bedrooms and such. I've laid it out in webfort with the intent to make this my current "standard" fort design, but the engineer in me is already trying to find the weaknesses of the design and optimize it for fear that this design may exacerbate pathfinding issues within DF.

However, I'm also trying to avoid having to implement then test multiple minor variations on this design to get better pathfinding performance. (Or to avoid implementing at all, if the design is going to be horribly broken.)

Is there a good way to vet a potential design against the A* engine in a performance sense without implementing it in DF? Are there general guidelines which might suggest ways in which the design spoilered below (in quickfort format) would perform suboptimally? There's no dead-ends, for example, and I'm assuming that DF will pathfind up/down levels before trying to pathfind N/S/E/W on the same level to find something on a different level. Dwarves should be able to pathfind through the local holes when making transit between worksops/stockpiles/beds, and through the central stair to pathfind into the few areas that don't have the standard layout (meeting hall, barracks/hospital/dorms, magma forges, etc.)

Basic 31x31 level design:
Spoiler (click to show/hide)
Logged

Jurph

  • Bay Watcher
  • Minister of Belt-fed Weaponry
    • View Profile

How may we consider your fort design without implementing it?  (Pics, please.)

That said, I read your description avidly because I've been pursuing a cylindrical design which uses a circular layout.  The central stairs are 3x3 but I clip the corners to make a plus shape.  I allow a single ring of empty tile for aesthetics and then place four 3x3 workshops in the cardinal spaces.  The circle's diameter is 15 tiles which leaves an extra two tiles of outer diameter for storage.  By placing two crossed 9x1 "high traffic" areas on each floor, we can link the center tile of each workshop to the stairwell; by surrounding the high traffic zone with single-tile perimeters of normal and low traffic, we can funnel dwarves onto the main walkways.  By restricting the two outer tiles we can reserve the outer areas for emergency storage.

I then propose stacking these circles with workshops and supporting storage as follows, from top to bottom:
  • Carpenter, Ashery, Wood Furnace, Soaper // Wood storage
  • Crafts, Tanner, Leatherworker // Bone & Leather storage
  • Butcher, Farmer's workshop // Pasture space
  • Loom, Clothier, Dyer, Mill // Thread & Cloth storage
  • Farmer's workshop, 3x3 farm // Large Harvest stockpiles
  • Still, Kitchen // Highest-value food inputs
  • Bin and barrel storage
  • Dining Room
  • Food & Drink storage, plumbing for well(s)
  • Trade Depot, Counting-house for noble // high-value Finished Goods storage
  • Additional Finished Goods storage
  • Masons, colored stone input piles // Masonry block storage
  • Mechanic, Crafts
  • Dining Room?
  • Danger Room, Barracks, Airlock to lower regions // weapon and armor storage

I'm still debating whether 3x3 bedrooms for the appropriate worker's area would be an improvement, or whether I want to reserve a deep-and-safe area with food, seeds, an emergency suit of armor, etc. as a Panic Room.  Consider that each dwarf could be assigned to a burrow encompassing only his workshop, his bedroom, the long vertical stairway, and a path to the important supplies for his job.

Since A* gets worse the longer your path length, condensing the fortress in this way minimizes the number of chances A* has to needlessly branch out.  For a good efficiency metric, estimate the ratio of haulers to valued contributors in your fortress -- in my fortress it's 4:1 or 5:1 -- and use that value as a multiplier on the value (or cost) of the skilled workers' contributions.  Now calculate the total hauling distance required to create (e.g.) a dyed cloth bag, a lavish meal, or a serrated copper disc.  Multiply the skilled workers' hauling steps by their value ratio.  You can compute a metric for wooden furniture, a metric for decorated stone crafts, a metric for bone bolts... whatever your fortress makes in bulk.  You could also create a value 'index' like a stock index, which says "in a given year I need a known qty of meals, drinks, and trade goods of these 3 types to get by... and the cost to my dwarves is X, which is my minimum overhead with this layout."

Note that in my 15-level cylinder, the maximum path-length is 30, and there's no reason to take that path; the maximum path length between an upstream workshop and its follow-on is probably the hike from the butcher's shop to the kitchen (9 tiles) or the run from the kitchen/still down to the food storage area, which could be as bad as 15 tiles.  By keeping everything 3 tiles from the main stairwell, I have cut the median path length very very far below what most users would expect.

...and yet I believe there is still room to further optimize this design.
Logged
Dreambrother has my original hammer-shaped Great Hall.  Towerweak has taken the idea to the next level.

Nameless Archon

  • Bay Watcher
    • View Profile

How may we consider your fort design without implementing it?  (Pics, please.)
Well, I provided the Quickfort layout, but that's probably not the best way to do it, since it assumes someone will fire up DF and designate it. Unfortunately, Webfort doesn't allow for an import from exported text, and I don't have a fort using it for stonesense. I'll try to put something together to better illustrate what I'm thinking - once I squash out most of the "aesthetic space" I think it will get smaller.

Quote
That said, I read your description avidly because I've been pursuing a cylindrical design which uses a circular layout.
Since I'm embarking on the use of Quickfort, I'm trying to figure out how best to test a design without multiple embarks and several years of game time to test each one. I haven't gone to a circle (and thus cylindrical design) yet, but I'm also trying to keep the number of z-levels somewhat closer to the default 5, which necessitates greater X-Y sprawl than your design.

Quote
I'm still debating whether 3x3 bedrooms for the appropriate worker's area would be an improvement
I've used 3x3 bedrooms in the design I'm considering, simply because it's convenient to modify the layout of the square to have 3x3 bedrooms centered on the staircases passing vertically through a series of bedrooms.

Quote
whether I want to reserve a deep-and-safe area with food, seeds, an emergency suit of armor, etc. as a Panic Room.
I intend to use my meeting area for this, using a longer entrance hallway that passes below a mist generator, over a dwarfbath, and then into the meeting hall across a drawbridge that can be sealed from the inside. This particular section of the floorplan will not conform to the standard design, since I need the extra path space to provide mist/wash/bridge.

Quote
Consider that each dwarf could be assigned to a burrow encompassing only his workshop, his bedroom, the long vertical stairway, and a path to the important supplies for his job.
I could do this, but I'll confess I balk at the inability to set this sort of micromanaged gameplay (yes, yes, DF, etc.) up as an automated function. The design I've been using is fairly vertical, but not particularly optimized (it's much larger X-Y than your cylinder design, which almost certainly translates to increased path space unless you get very creative with stockpile/burrow allocation).

Quote
(snip A* and cost calculations)
Whew. I guess here's where the !!SCIENCE!! starts. I'll tinker with some designs in webfort for a bit longer. I'm not sure I can touch your cylinder's efficiency, but I'm also not looking for a 15 z-level design, per se. (I know I CAN generate a world with this many levels above the caves, but I'm also trying to keep the number of z-levels down a bit closer to default.

Quote
...and yet I believe there is still room to further optimize this design.
I'm quite sure that this design is not optimized simply though designations. (I have some "aesthetic area" around the central stairs that could be eliminated to shrink the X-Y distances.) Creative burrow/traffic designations/stockpiles could probably improve it further, but I'll have to do some !!MATH!! first.

Thanks for the food for thought. I'll have to see what I can come up with.
Logged

Jurph

  • Bay Watcher
  • Minister of Belt-fed Weaponry
    • View Profile

Well, I provided the Quickfort layout, but that's probably not the best way to do it, since it assumes someone will fire up DF and designate it. Unfortunately, Webfort doesn't allow for an import from exported text, and I don't have a fort using it for stonesense. I'll try to put something together to better illustrate what I'm thinking - once I squash out most of the "aesthetic space" I think it will get smaller.
Perhaps sketch the concept in Webfort and post a screenshot of a single floor?

Quote
Since I'm embarking on the use of Quickfort, I'm trying to figure out how best to test a design without multiple embarks and several years of game time to test each one. I haven't gone to a circle (and thus cylindrical design) yet, but I'm also trying to keep the number of z-levels somewhat closer to the default 5, which necessitates greater X-Y sprawl than your design.
Which "default" is 5 levels?  Is that stone & soil levels above Cavern A?  As for non-circular design, dwarves take 1.4 times longer to move diagonally, so any design that tries to shorten paths and employs a central stairway will get driven towards a circle pretty quickly by geometry.

[/QUOTE]I intend to use my meeting area for this, using a longer entrance hallway that passes below a mist generator, over a dwarfbath, and then into the meeting hall across a drawbridge that can be sealed from the inside. This particular section of the floorplan will not conform to the standard design, since I need the extra path space to provide mist/wash/bridge.[/quote]
That's ambitious!  To conform to my cylinder design I'd almost have to build a three-or-four-level plumbing section -- probably around the same depth as the bottom of the first "wet" cavern -- which would mean there'd be a 10- to 15-level penalty just for traveling from zone to zone.  Given there's already going to be a large penalty for traveling down to the magma workshops, that doesn't bother me much for now.


Quote
I could do this, but I'll confess I balk at the inability to set this sort of micromanaged gameplay (yes, yes, DF, etc.) up as an automated function. The design I've been using is fairly vertical, but not particularly optimized (it's much larger X-Y than your cylinder design, which almost certainly translates to increased path space unless you get very creative with stockpile/burrow allocation).

I go waaaay down the rabbit hole on stockpiles in order to avoid having to actually do the burrow designation.  I, too, cringe at the micromanagement required to put my dwarves on burrow rails like that. 

Quote
(I have some "aesthetic area" around the central stairs that could be eliminated to shrink the X-Y distances.)
I use the buffer around my central stairs for commonly hauled goods -- empty barrels, bags, and bins -- to reduce the travel time for tedious hauling jobs.  As a bonus, the haulers keep it clean so it has that pleasant grey checkerboard aesthetic, even if there are six or seven different types of items allowed in the stockpile.

Quote
Thanks for the food for thought. I'll have to see what I can come up with.

No problem.  Looking forward to seeing your approach!
Logged
Dreambrother has my original hammer-shaped Great Hall.  Towerweak has taken the idea to the next level.

Nameless Archon

  • Bay Watcher
    • View Profile

Quote
Which "default" is 5 levels?  Is that stone & soil levels above Cavern A?
Yeah - I've been employing a larger number (15) simply to allow for a 10+ Z-level drop from the gatehouse bridge, but I've been thinking about the future of a larger fort (150+ dwarves) on my older (and dual core, sigh) PC, and so I'm trying to think ahead about how design could be used to minimize FPS death (or even just gross inefficiency) etc. This may be much less of a concern in the semi-near future - the new PC I'm planning to build will be faster per core than this one, so despite having more cores, I should still come out ahead of my present situation.

Quote
As for non-circular design, dwarves take 1.4 times longer to move diagonally
As my initial square design relied on staircases placed diagonally from the workshops, this is sort of a crucial piece of knowledge I didn't have. Is it actually hardcoded into their movement rate? I know that it's geometrically valid in the real world (square of hypotenuse, etc) but does DF actually treat diagonal motion this way, requiring dwarves to actually move more slowly when moving diagonally? Where did you find this info? (I checked the wiki, but I'm not sure where to even start to find an article on dwarven movement rates.)

If a tile is a tile regardless of the orientation of movement (eg. "game geometry" holds sway), then squares of diagonal X are no different than circles of diameter X with a few sections missing, and a square is easier to diagram/lay out for the player. If there's a 1.4*time movement penalty on diagonal movement, however, then circles make a lot more sense, and there's no need for me to start screenshotting squares that are by nature less efficient.

Quote
That's ambitious!
Ha! Not really. It's fairly easy to drop a single tile up-down staircase to any depth to provide water on any floor, but to be safe you end up having to take a supply line out a few squares on the desired "destination level" then carve a pipe that runs up one floor without a regulator (to allow for placing a shutoff hatch over the up ramp to prevent entry from below) then back down and straight into a pressure regulator (and then a reservoir) back on the desired level. Depending on caves, making the water source "problem free" poses much more of an issue. Since I'm running around with N levels of Z to play with above the first cavern, dropping a staircase of N levels connected to a passive source (like a river or brook) isn't hard at all. You just need to predict where you'll need the water in advance, because you need to have it 100% ready before it's filled (or build in a way to drain it, but that's usually a lot of water to drain off).

(...and consider that I always embark with 4+ miners and 2+ mechanics on a site with plenty of soil. I want the fort and water supply up fast so I can quickly get to a stage where I don't require the surface for anything.)

If fortifications worked 100% like they should, then it'd be easier, since you could sandwich a floodgate between fortifications safely right inside your regulator, but with the bug that allows submerged fortifications to be ignored, and bars/floodgates being subject to building destroyers, I have to have a plumbing "sink trap" to keep the water supply critter free by exploiting Z-level invulnerability of hatches 1-Z above.

Quote
To conform to my cylinder design I'd almost have to build a three-or-four-level plumbing section -- probably around the same depth as the bottom of the first "wet" cavern -- which would mean there'd be a 10- to 15-level penalty just for traveling from zone to zone.  Given there's already going to be a large penalty for traveling down to the magma workshops, that doesn't bother me much for now.
It's a lesser concern, but I've been considering just reversing my standard custom worldgen order, and just having everything down at the bottom of the world with a larger "levels above magma sea" value (layer 4?). Raise that to 15 or 20 and leave everything else default. (This often has the desirable side effect of having extra candy by stretching out the pillars.)

Quote
I go waaaay down the rabbit hole on stockpiles in order to avoid having to actually do the burrow designation.  I, too, cringe at the micromanagement required to put my dwarves on burrow rails like that.
I'm actually surprised that Quickfort hasn't (yet) started to go down this road - not that I'd enjoy creating the burrows for a default design even once, but... 

Quote
I use the buffer around my central stairs for commonly hauled goods -- empty barrels, bags, and bins -- to reduce the travel time for tedious hauling jobs.  As a bonus, the haulers keep it clean so it has that pleasant grey checkerboard aesthetic, even if there are six or seven different types of items allowed in the stockpile.
I haven't gone that route, but I have been keeping empty barrels (or bins, or ore) near the workshops where they serve as inputs.

Quote
No problem.  Looking forward to seeing your approach!
Well, judging from the replies, you've already spent a good deal more time thinking this through than I, so I've got quite a lot more thinking to do!
« Last Edit: April 15, 2011, 08:56:30 pm by Nameless Archon »
Logged