Bay 12 Games Forum

Dwarf Fortress => DF Suggestions => Topic started by: NW_Kohaku on February 26, 2011, 10:16:01 pm

Title: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on February 26, 2011, 10:16:01 pm
Right, so this topic is the single biggest winner of the ESV, and yet it doesn't have its own dedicated thread.  I did a quick search of "stacking" and "hauling", and found only a couple of threads from two or three years ago, which mostly devolved into fighting, anyway, so I figure a new thread probably won't hurt. 

This is a topic I'm extracting out of the ESV thread (http://www.bay12forums.com/smf/index.php?topic=24818.msg2019024#msg2019024), since this is straying pretty far off-topic to seriously discuss this one item in the ESV thread.

I'm not entirely sure this is going to be a "suggestion" so much as a discussion about what is and is not feasable, and how to make the coding as optimized as possible.  But maybe we can put our heads together, and come up with some sort of way of handling all this code that Toady hasn't thought about, which would be great.

First up, the Devpage items we are talking about:

Quote from: The Devpage
Hauling Improvements  
  • Being able to haul multiple small objects
  • Having multiple dwarves involved with item hauling for a job
  • Being able to move multiple objects with roughly the same destination at once
  • Wheelbarrows to haul more objects than can be carried
  • Minecarts
  • Wooden, stone-carved and metal tracks
  • Can be filled like stockpiles and moved between destinations
  • Work animals to tow carts and haul objects

I don't think people really disagree with what needs to happen in the game - people want dwarves who can more rationally do things like pick up more than one object in the same tile that is going to the same stockpile.  We want a dwarf to be able to see 5 plump helmets in a stockpile, and have a stack of 5 plump helmets in his/her hands, and figure that he/she can consolidate them together into a stack of 10 plump helmets, rather than having stacks that can only be divided, never consolidated back together again.  In fact, people really, really agree on this, since it was the big winner of the ESV by a mile.

The problem here is the tradeoff of performance for dwarven sanity. 

Thus, the conversation in progress:

It is not "the FPS drops by half", it is "the FPS drops to 1/n of old FPS" where n is quantify of dwarves. (or even "the FPS drops to 1/(n*n) of old FPS")

I'm going to have to ask you to explain where you came up with those numbers.  The only way that sort of complexity would make sense is if the entire pathfinding routine would have to take place per every other pathfinding creature in the entire map, which makes absolutely no sense.
We have route from A to B. [for example single sock moved from A [battlefield] to B [trade depot]]

We want to detect routes likes A->X->Y->B, without huge additional cost.
To find routes like this it is required to make pathfinding A->B and A->X->Y->B for every possible pair of X->Y. [sock moved from X1 [battlefield] to Y1 [trade depot], sock moved from X2 [battlefield] to Y2 [trade depot], seed moved from X3 table to Y3 stockpile etc]

So with n jobs, single planned results in pathfinder running n times instead of one check.
Result: pathfinding running n^2 times for n jobs, instead of n times.
[I assumed that number of jobs is liner vs number of dwarves, but "where n is quantify of dwarves" can be changed to "where n is quantify of jobs"]

So, let's start...

To a certain extent, I think a part of this problem is that Stacking and Hauling constitute more than one topic and set of code, and what I really want to see (stacking) is something that should be not terribly difficult, at least for certain types of items. 



Stacking

I did a little digging to find a Toady quote about how stacking works, as well...

Coins have their coin batch index (year for dwarves) and the material, but there's also ownership, contaminants, temperature, damage, age, storage information, maker id, flags based on if your fort owns/made it, melt/dump/forbid/hide designations, job information...  and probably more.  Some of it can be scrapped or otherwise dealt with, but it's not a triviality if you want to keep track of things.  Even if it checks all of these things and consolidates equal stacks (which would be rare -- or with age+maker id, virtually impossible), seeing it happen in some cases and not others with identically named objects would lead to false bug reports, I think.  Probably more profitable is addressing the main concerns in other ways -- getting dwarves to grab all the bolt stacks they need when they go to get a one bolt stack or making coins work in a sensible fashion don't really depend on stacking so much.  Increased CPU drag from broken stacks is probably the main thing that can't be dodged without some direct handling, and I'm leaning toward not suppressing the information by using some extra objects (could use the same ones as the interface would I guess, though there are all sorts of ways to think about it).
Can't you just create a new "stack" container that would be created by stacking two objects of the same types (bolts, coins, ...) and destroyed when it contains only one object?

This is roughly what I meant by "extra objects", except for the "just" part.  The main point is that it's not only an interface problem.  If items are potentially contained in fake stack items, all the job handling needs to be revised to support that.  It's a bit less of a pain if you restrict to only coins or bolts say, but there are still things to be considered.  Take bolts for example.  Your guy wants to equip some.  First it needs to recognize the container as a valid ammo object.  Depending on exactly what you choose to stack, some members might not be as eligible as others -- what if some in the stack were forbidden, or tasked for a job, prior to stack formation, for example?  Those cases would need to be disallowed or handled.  Then the equipment checker needs to realize he's got the bolts when he places the container in his quiver.  Not so bad, possibly handled by current code, but something to check.  Now he wants to fire a bolt -- shooting needs to be rewritten to support bolts in the fake objects.  Sort of a piece of the quiver code already, maybe nothing needs to be touched at all, but takes some checking and testing.  There are side issues like valuations and stocks screen stuff, which might be handled already, and other thises and thats (environmental functions would need to be taught about fake containers -- rain for example should get the bolts wet, but currently there's no mechanism for jumping through a container on the ground to get the inside stuff wet, I think, since containers are generally real -- not hard, but yet another issue), as well as any applicable storage jobs, which run into some of the first problems I mentioned.  As you get to other objects, like food, you inherit more difficulties (vermin need to see and realize that they can eat food in stacks for free, etc. etc.).  As far as I can tell, the problem is not super difficult, and a lot of the issues just need a nudge one way or the other, or no nudge at all, but there are a Lot of issues that turn this into a tedious and long haul.  There's generally more to do and check than people expect.

Items like iron bars are not distinct from one another - you can stack as many iron bars in one location as you arbitrarily will decide the limit is for a given tile.  You only have to keep wood distinct by the type of tree it came from.  You can have as little as .1 liters of wood, (or whatever your smallest unit size is,) and up to 100 liters of wood, (or whatever the limit for volume in a given tile is,) and as long as dwarves just actively try to consolidate their items of the exact same type together, there's not really much problem in coding this, here.  Basically, all you need is a "is this particular stack full?" check performed when a dwarf is trying to pathfind to the stockpiles.  They already sort of do this in the form of a "is something on this tile?" check, and a check to put similar items into barrels, so you can't tell me that doing an additional check to see if there's a not-quite-full stack of identical material will cause a terrible strain in coding or FPS.  (At least, this is assuming that iron bars and wooden logs don't have to carry around "maker data" or anything like that.)

As for other things...

Well, most of the detail could be exported to a single pointer on the actual coin, and if you rewrite stacks to be pointer counts, that helps.  (Exported detail is everything on the coin when it's made, date manufacturer, material, etc)

The problem is contaminants...

Thing is, I think we could probably do some sort of bastardized system. 

Some goods that are never going to be in stacks (statues, for example) can just continue being what they are.

This means that stackable manufactured items would need to have two data sections, a "manufacture data", and a "status data".  Manufacture data is the data about what the stack actually is made of, who made it, when it was made, etc., all the stuff that doesn't change once the item has bene manufactured, unless it is consumed somehow. Status data is the information on contaminants, ownership, designations, job data, and other things that have to do with how something is being moved around and used.

For the stackable manufactured type of thing, a "stack" would just need a pointer to a master table of manufactured goods from your fortress for the "manufacture data", plus maybe something that gets imported to that list from the outside when the merchants are visiting, could work, similar to what Granite was talking about.  It would need occasional garbage collection, as well, to see that the last of the 120 units in the masterwork quarry bush leaf roast stack had finally either been consumed or rotted, and that production data was not necessary any longer. 

The rest of the "stack" would need to have status data on the specific items.

The "stack" would be what you see in the 'k' look menu, there, if you are looking specifically at a stack of cow bone bolts or something. 

On top of this, we would want to have a more fungible "container" stack, where you could say that you grab 15 individual bone bolts that are all made at different times, but which you don't particularly care about the details, you just want a stack of 15 bone bolts.

To a certain extent, you don't really need to have individual status information on each bolt in the stack - if one bolt is spattered in mud, and you lump them all together in a container stack, it's not too big a deal if those lumped together bolts are now all spattered with mud, and all the same temperature, and all designated the same, since you want to treat those as a group of functionally similar items, anyway.  Hence, container stacks can just have a list of pointers to that manufacture data, and then a single status data for everything in the "container" stack.

(Yes, this is the sort of thing that Toady said would take rewriting job data to get around, but... well, we're talking about rewriting how jobs get handled, anyway, so that's pretty much a sunk cost at this point, anyway.)



Hauling

OK, here, we're talking about the problem where, let's say a dwarf or a goblin dies out in the battlefield on the surface of your fort.  Now you have to go collect all those precious, precious socks.  Thing is, each goblin or dwarf generates about 10-20 hauling jobs when he dies.  Each individual piece of clothing needs to be individually hauled to the nearest stockpile that accepts the particular crap piece of clothing you're dealing with.  This means it takes 10-20 trips from the battlefield to the stockpiles per dead dwarf or goblin.  Typically, this means 10-20 haulers all swarm a single goblin at a time after a siege like some sort of bearded ant colony picking the meat from a set of dead critters.  Since each trip only takes one stupid wooden ring at a time, it's frustratingly inefficient.  In fact, most of the time, I just leave the non-iron crap out there for the kobolds and racoons to just take off my hands for me.  (Oh no, the kobolds stole some worthless leather mittens and wooden rings from the goblin corpses!)

Now, this is where the job assignment for things like hauling needs to be much more sane.  In the case of hauling clothing off of corpses, I think I can assume that what happens is that each item that isn't in a stockpile generates a "job" that says the item needs to go from where it is to the stockpile that it targets, and the item puts its job up into the job queue for dwarves who are idle and looking for a job with the hauling labor enabled to pick off the list. 

What needs to happen in a rational sense is that jobs need to check for other jobs to get bundled into a complex job.  In the case of a dead goblin with 20 articles of clothing, this should be fairly easy to do, because odds are, all the clothing items are all in the same tile, and need to go to the same stockpile as their task.  Hence, if they are basically the same job repeated 20 times (carry item from point A to point B, and all of those point A are the same point A, and all those point B are the same point B), then there isn't going to be a problem in the "haul multiple items of different types" pathfinding task, because all you need to do is search for jobs that go from the same place to the same destination.

So long as we are dealing with same exact starting and ending points, then it's not going to be any problem at all to code this, the problem is when we are dealing with "nearby" tasks.  This gets split into two ways of thinking about the task - "nearby" in terms of mutiple at least vaguely nearby starting points with only one destination stockpile, and "nearby" in terms of multiple densly nearby objects that have more than one destination.

After a miner has gone by and excavated a mining shaft, and there's a whole mess of stones just lying around for haulers to get around to doing something with.  They're all in different tiles, but they all probably need to go to the same point.  Either they're all getting dumped, or they're probably going to be slated for hauling jobs en masse to a large stockpile.  This means that when the jobs are created, they're going to need to look in their own immediate vicinity for similar objects with a job to be hauled to the same spot that they need to be hauled.  This way, they can line themselves up in a "related job set" or something so that hauler dwarves who have a wheelbarrow or something to carry that many stones can decide to declare they are taking more than one of these hauling jobs at the same time.  I'll call this "Type A Nearby Hauling". 

The other thing is if, in the goblin example, the iron breastplate and the elf leather socks need to go to different stockpiles.  The iron breastplate, for example, needs to go to the stockpile near the furnaces to get melted down, while the socks are slated for dumping directly into the magma pit.  Let's call this "Type B Nearby Hauling".

Now, here's the thing about how these get processed... It's the items themselves, in lining up the job queue that declares whether they are related to one another, not the dwarves who are taking the jobs, and it does this at the job task's creation.  Dwarves who decide to take up the task will then have to declare how many of those jobs they can actually complete (based upon their hauling capacity), and then mark those jobs as "taken".  The remaining jobs will then have to decide how to reform themselves on the jobs queue as priorities and how related they are to one another.

I'm not even really being specific in what "nearby" means, at that, since we don't want to call any more pathfinding than is really necessary.  This means "nearby" can be a fairly problematic concept.  We don't want to declare anything within 5 tiles to be "nearby", since maybe there's a wall in the way, and "nearby" will be declared to be something that actually takes 120 steps to even reach.  The best thing I can say without actually declaring a real pathfinding search is that the game should be able to draw a direct line between all the objects without hitting an obstruction and without running a "real" pathfinding task to search from one to the other.

Even more problematic is that every time a task is created, it will then need to have to search for what other jobs are nearby.

One solution is searching the entire jobs list, and then looking at the "starting from" location to find the "nearby" ones. This causes problems when the jobs list becomes longer, because it means that every new job will have to make a search of every single job already put on the job queue to search its starting location. This basically has a complexity of O^2+O where O is the number of jobs being put into the jobs queue.  (Subgeometric complexity growth with number of tasks.)

Alternately, it can actually look at the physical map around it, and search every tile for objects, then search those objects for jobs that take that object someplace, and then test to see if they are going the same place, and THEN search to see if they are actually "nearby" and don't have an obstruction between them. This causes problems to start with, since you have to search a lot of tiles for items to even start with, and then, if you have something horribly complex like a dump zone/quantum stockpile with 5,000 items in one of those tiles.  Preventing quantum stockpiles or putting limits on the number of items that can physically enter a tile (meaning dumping an item into a pit which already has 100 items in it will simply create a "solid wall" that prevents more items from entering it) will put some sanity check into that, but it's still going to be a problem.  This has a complexity of R^3 (Op+Oq+Od), where R is the radius of tiles around the object that you consider "nearby" (Alternately, you can only search for "nearby" as being on the same z-level - this means that objects on different portions of a ramp will never be tasked with one another, but it can cut out a lot of false positives where you assume that anything on another z-level is probably going to be very difficult to path a direct line to.  This means you only need R^2 complexity.)  while Op are the number of items present in a given tile, Oq are the number of items with hauling jobs queued, and Od are objects with nearby enough destinations.

I can't say with utter certainty which one would be the most efficient.



Ugh, for something that was just some idle side-conversation, this sure spun out of control into another big rant...  Maybe I should stop thinking so much.

I probably forgot to complete a thought somewhere up there, but this is getting to the point where I just sort of want to post it and maybe revise it later...
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on February 26, 2011, 10:18:37 pm
Reserving a post just in case.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Granite26 on February 26, 2011, 10:22:32 pm
Code: [Select]
Results of a poll from '08

What is your most desired suggestion out of the collected top 10?
show levers / name levers / blink connected 35 (6.4%)
excavate - mine without stone production 32 (5.9%)
stop dwarven entrance dance when ordered inside 73 (13.4%)
forbidden area designation 20 (3.7%)more raw files 50 (9.2%)
job priorities 55 (10.1%)
combine stacks / better stack handling 65 (11.9%)
more underground diversity 93 (17%)
improved sieges 48 (8.8%)
framerate improvements 75 (13.7%)
two things to notice:  Most of this is fixed or unrecognizably different, and the big vote from 3 years ago had about 450 people involved.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Granite26 on February 26, 2011, 10:29:26 pm
Responding directly to the OP: your stacking ideas won't work.  If there's a max size for stacks, it has to be item-dependent for small items like coins and bolts.  Items spilling into adjacent tiles is an interesting idea, but there needs to be some distinction between deliberately stacked items (don't spill) and carelessly dropped items (do spill).

Restacking also has some complexities that you might not have considered -- Toady had some posts about it a while back.

Quote
combine stacks / better stack handling
-- this has been a problem since before the first public release, and the two ideas were basically to actually do it and to fake doing it via interface presentation of item lists etc.  Actually combining items would virtually require losing information, or you'd almost never do it (most items carry a lot of info), so I've grown to dislike this option.  The other option is to make the player think its happening more or less, and that's fairly easy in the interface lists.  The problem comes with jobs -- dwarves need to learn how to use multiple item stacks and consider it in all of their thoughts, which makes it sort of a pervasive rewrite.  As with job priorities, just something I haven't jumped into, but definitely there to be done.

Quote
Coins have their coin batch index (year for dwarves) and the material, but there's also ownership, contaminants, temperature, damage, age, storage information, maker id, flags based on if your fort owns/made it, melt/dump/forbid/hide designations, job information...  and probably more.  Some of it can be scrapped or otherwise dealt with, but it's not a triviality if you want to keep track of things.  Even if it checks all of these things and consolidates equal stacks (which would be rare -- or with age+maker id, virtually impossible), seeing it happen in some cases and not others with identically named objects would lead to false bug reports, I think.  Probably more profitable is addressing the main concerns in other ways -- getting dwarves to grab all the bolt stacks they need when they go to get a one bolt stack or making coins work in a sensible fashion don't really depend on stacking so much.  Increased CPU drag from broken stacks is probably the main thing that can't be dodged without some direct handling, and I'm leaning toward not suppressing the information by using some extra objects (could use the same ones as the interface would I guess, though there are all sorts of ways to think about it).

Quote
This is roughly what I meant by "extra objects", except for the "just" part.  The main point is that it's not only an interface problem.  If items are potentially contained in fake stack items, all the job handling needs to be revised to support that.  It's a bit less of a pain if you restrict to only coins or bolts say, but there are still things to be considered.  Take bolts for example.  Your guy wants to equip some.  First it needs to recognize the container as a valid ammo object.  Depending on exactly what you choose to stack, some members might not be as eligible as others -- what if some in the stack were forbidden, or tasked for a job, prior to stack formation, for example?  Those cases would need to be disallowed or handled.  Then the equipment checker needs to realize he's got the bolts when he places the container in his quiver.  Not so bad, possibly handled by current code, but something to check.  Now he wants to fire a bolt -- shooting needs to be rewritten to support bolts in the fake objects.  Sort of a piece of the quiver code already, maybe nothing needs to be touched at all, but takes some checking and testing.  There are side issues like valuations and stocks screen stuff, which might be handled already, and other thises and thats (environmental functions would need to be taught about fake containers -- rain for example should get the bolts wet, but currently there's no mechanism for jumping through a container on the ground to get the inside stuff wet, I think, since containers are generally real -- not hard, but yet another issue), as well as any applicable storage jobs, which run into some of the first problems I mentioned.  As you get to other objects, like food, you inherit more difficulties (vermin need to see and realize that they can eat food in stacks for free, etc. etc.).  As far as I can tell, the problem is not super difficult, and a lot of the issues just need a nudge one way or the other, or no nudge at all, but there are a Lot of issues that turn this into a tedious and long haul.  There's generally more to do and check than people expect.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on February 26, 2011, 10:37:39 pm
Holy wall of text

Part of the problem is all the old forum posts didn't copy over.  A lot of this was fleshed out.  I'm pretty sure Toady knows what he wants to do with this, at least in general, it's just that it doesn't meet the effort/reward ratio yet.  I mean yeah, it's a pain in the ass, but it works, and 'fixing' it isn't going to be an order of magnitude improvement, but it'd take a lot of really in depth work to produce something that's liable to be buggy, and doesn't increase the feature set of the game.

Well, this was just an extremely long-winded response to Kogut at its root that I figured should have its own thread since it was really going to derail the ESV thread.  (But it took so long to write there were 4 different posts in the meantime :P )

Anyway, like I said, I'm not sure if it's going to actually be something that Toady didn't think about, but maybe we can put together an actually optimized suggestion that Toady hasn't thought of yet. 

Besides, any time that I try to write out a suggestion, except for maybe Class Warfare, I always seem to have to say "but we need stacking improvements, first".  Stacking is a crippling feature of the game right now, since it means that we have to use these huge "it takes a whole tree to do even the smallest action that consumes wood" types of tasks. 

What's the advantage in making a ceramic pot that takes a tree of fuel to bake in the kiln when you can just make a barrel out of a tree of wood?  If you have to glaze it afterwards, with a block of ash...

We need to have much smaller units and tasks that take more than single digit integer amounts of items to be able to deal with industry in this game in a sane way, and none of the things I really want to see happen to industry in this game can happen until this happens first.  So maybe that's selfish, I don't know, but any way I see the game developing to become much more interesting in the ways that I find interesting, it takes this as a prerequsite.  (Although I'm hardly the only one who wants to see the ability to haul large amounts of stone from mining handled in a sane manner...)

Quasi-EDIT:  Reading the second Granite post after writing this...

Actual EDIT:  No, I think I managed to entail all of that in the post that I started this thread with, especially since I actually quoted the last two of those Toady quotes in the body of the text.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Granite26 on February 26, 2011, 10:47:30 pm
awesome... my mouse sucks.  I did say what's in the quotes, put the poll numbers in, and wiped the original.  Still meant it.

I'd just suggest that you edit the post to be more bullet pointy, and put all the text in the second post.

Topic for discussion: 
Quote
Coins have their coin batch index (year for dwarves) and the material, but there's also ownership, contaminants, temperature, damage, age, storage information, maker id, flags based on if your fort owns/made it, melt/dump/forbid/hide designations, job information.

What would you say can be offloaded, converted to the stack info, or dumped.  Every one of those has to be one of the three.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on February 26, 2011, 11:02:53 pm
awesome... my mouse sucks.  I did say what's in the quotes, put the poll numbers in, and wiped the original.  Still meant it.

I'd just suggest that you edit the post to be more bullet pointy, and put all the text in the second post.

... maybe tommorow morning, my brain's a little fried right now from doing nothing but sitting in a chair thinking for the past 5 hours, and I'm getting into my bedtime stare zone of mental activity.

Topic for discussion: 
Quote
Coins have their coin batch index (year for dwarves) and the material, but there's also ownership, contaminants, temperature, damage, age, storage information, maker id, flags based on if your fort owns/made it, melt/dump/forbid/hide designations, job information.

What would you say can be offloaded, converted to the stack info, or dumped.  Every one of those has to be one of the three.

Well, assuming I am correct in interpreting that "offloaded" means "it's got a pointer to manufacturing data" and "stack info" is "the stack applies this data to everything in the same stack", and "dumped" means "Screw it, we don't need to track this at all", then...


*** Damage is the only problematic one.  Items in the same stack with one another should probably be damaged the same, but the problem is that they will all start with different damage values.  Probably, the best way to really handle this is to make every individual item in the stack have its pointer to the offloaded data, the number of items exactly like that, and also a damage value.



Edit from a long time later:
Actually, you could track item wear or damage more abstractly, if you don't mind a loss of granularity over some types of items.  (If you are stacking them, anyway, then you shouldn't be all that concerned with granular details.)

Simply track an abstract "Average" wear or damage number, and then a "Standard Deviation" number, and bell-curve the results abstractly.  Hence, throwing a badly damaged item into a stack of reasonably well-maintained items will result in not just a drop in the average wear, but also a spike in the standard deviation, so the bell-curve will be spread out, and abstractly include plenty of low-wear items as well as a few outlier damaged items.

Dwarves could simply draw at random or puposefully pick the most damaged or most repaired ones as specified (so that if they are looking for socks in a sock pile, they would probably want to pick the least threadbare socks to own for themselves).
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Granite26 on February 26, 2011, 11:08:57 pm
you interpreted correctly.

Contaminents is the interesting one.  One arrow has the dried poison blood of a basilisk on it.  Stack with similar arrows and they all do?  How does that play with poison, or sympathetic magic, or evidence?

Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on February 26, 2011, 11:17:38 pm
you interpreted correctly.

Contaminents is the interesting one.  One arrow has the dried poison blood of a basilisk on it.  Stack with similar arrows and they all do?  How does that play with poison, or sympathetic magic, or evidence?

Well, dried blood might be a little illogical, but I was thinking of contaminants as generally being liquid in nature, like mud. 

Pack all your bolts together, and if one of them was muddy, then all of them are going to be at least a little muddy.  The stuff can be averaged out on consolidation to say that each bolt is only 1/15th as muddy if you have 1 muddy bolt and 14 clean bolts put together, although I'm not sure about how much data there is on how muddy an object is. 

Even if it's dried blood, you're going to knock a little bit of dried blood off of one bolt onto another. 

"Evidence" isn't really something I think about.  I'm not particularly excited by "CSI: Fortress", and think it's fairly silly and far more micromanagement than it's worth, but I guess if you really, positively have to track everything individually, it can be *special* like damage is, and have extra data per item in the stack to track exactly which bolts get mud rubbed on them... but that takes up extra processor cycles checking everything's contact with everything else's contaminants in contact with one another, and I think it's just plain simpler to say "all these bolts have trace amounts of blood on them".
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Granite26 on February 26, 2011, 11:29:45 pm
Temperature:  Everything has it's own temperature.  Everything.  EVERY THING.

Anywho, what about an object with an innate temperature  (magic arrow).  What if you put a fire arrow and an ice arrow in the same stack?  What if you pull the shuriken out of the lava a stick it in the pile.  Should it instantly cool off?  Should everything instantly average?  Should they all get burning hot?  Each item also has a specific heat, so the math for avg isn't just sigma temp / items...
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on February 26, 2011, 11:49:45 pm
Temperature:  Everything has it's own temperature.  Everything.  EVERY THING.

Yes, and this is exactly why temperature code is so horribly obtuse and processor-consuming, in spite of not really even doing much.

Anywho, what about an object with an innate temperature  (magic arrow).  What if you put a fire arrow and an ice arrow in the same stack?  What if you pull the shuriken out of the lava a stick it in the pile.  Should it instantly cool off?  Should everything instantly average?  Should they all get burning hot?  Each item also has a specific heat, so the math for avg isn't just sigma temp / items...

Well, as far as I know, nether cap wood items (basically, magic ice wood without being declared as "magic" expressly) actually keep the entire area around it cool.  They prevent anything in the same tile that they occupy from being melted by magma, although I haven't tested this myself. 

Anyway, as far as application goes, there needs to be some logical safeguards.  A fire arrow and an ice arrow shouldn't be allowed in the same stack at all, since you aren't going to want to just randomly start firing either one without looking - those things are special arrows used for special tasks.  You only want to stack functionally identical arrows - all bone arrows, barring some special magical bone, are functionally identical, so you could just go by material property matching (they use the same material template, so they're functionally identical).  This may mean not being able to stack iron arrows with steel arrows, but that's a loss that we may just have to suck up.  The benefits of being able to stack iron arrows with other iron arrows alone are great enough that we might just be able to pass that up.

As for pulling a metal item out of magma, and trying to put it in a stack with other similar items, then realistically speaking, you have to actually pick it up, and hold it, then transfer it to the stack of other items.  Hence, first, you'd have one hand on the metal item that is transferring heat onto your hand for a while, then you could toss it on the stack, where it could start trying to average out that temperature, and eventually, that temperature would average out...

Of course, with that said, I really don't know what sort of code this game already has for convection, and I highly suspect it doesn't have any at all, considering the silliness it produces, so having to handle gradual convection through a stack is a moot point, anyway. 

I think it would be satisfactory if you just had to get a dwarf to "handle" the object, first, at which point bad stuff can happen to the hand that picks up something hot.  Hopefully, at some point, dwarves will actually get to the point where they can have a thought that goes "FIRE! HOT!" and drop something before they catch fire.  After that, you can just do instant convection, unless the temperature is being handled by contaminant, anyway.  (I think I remember someone talking about how they were killed in adventure mode because they picked up a shield with dragon blood contaminant on it, and it set them on fire, because the contaminant sets the temperature of the entire object to a specific temperature, the way that Nether Caps already do very wierd things to area temperature.)  Contaminants might just ignore all sanity for temperature, anyway, as far as I can tell.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Granite26 on February 27, 2011, 12:14:53 am
(http://t2.gstatic.com/images?q=tbn:ANd9GcTpM12PGlBNTouZMKdq92cnMT6Ag3fsG5nFJLCucbkPb-BcS0yg4w)
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on February 27, 2011, 12:18:51 am
Spoiler (click to show/hide)

I have no idea what that means...
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Granite26 on February 27, 2011, 12:20:09 am
for starters, it means your fantasy education is lacking
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on February 27, 2011, 12:25:06 am
for starters, it means your fantasy education is lacking

That's not helping.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Kogut on February 27, 2011, 04:32:18 am
You're pretending that you can't look at the map when trying to determine if something is "5 squares away."

Lets say this is our map.  * are the path, T is a Task Object.

.*......
.*......
.*..#...
.*..#T..
.*..#...
.*..#...
.*......
.*......


If we count diagonals as 1 space, then T is 5 away from the path (go around the wall on the top).  So we want this to be included, but we don't want to run an A* check on it (and by definition, every other task on the map).

What can we do?

Well, we do this: find every square adjacent to the path, and every square adjacent to that, etc. until we have 5 deep and note every task that falls inside that area.  Essentially we're doing a limited distance flood-fill.


1*12345.
1*12345.
1*12#45.
1*12#5..
1*12#5..
1*12#45.
1*12345.
1*12345.


Voila.  And if the object is in another room not direclty accessible, then the item isn't categorized:


1*12345.
1*12345.
1*12####
1*12#T..
1*12#...
1*12####
1*12345.
1*12345.


Now you have a list of every task that is inside some boundary distance of the dwarf's desired path.  Some tasks have a starting point and an ending point ("fetch quests" and for those you need to check the starting point and the ending point with the requirement that the start location is closer to the dwarf's starting location (and vice versa) which you can do through normal distance calculations (no need to do a path-find distance, as we already know that both points are within 5 of the existing path).
It is L*x, where L is length of path and x is maximum distance to find job (it is in fact BFS with found path as starting points with limited path length). It also will annihilate FPS.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Kogut on February 27, 2011, 04:48:23 am
Alternately, it can actually look at the physical map around it, and search every tile for objects, then search those objects for jobs that take that object someplace, and then test to see if they are going the same place, and THEN search to see if they are actually "nearby" and don't have an obstruction between them. This causes problems to start with, since you have to search a lot of tiles for items to even start with, and then, if you have something horribly complex like a dump zone/quantum stockpile with 5,000 items in one of those tiles.  Preventing quantum stockpiles or putting limits on the number of items that can physically enter a tile (meaning dumping an item into a pit which already has 100 items in it will simply create a "solid wall" that prevents more items from entering it) will put some sanity check into that, but it's still going to be a problem.  This has a complexity of R^3 (Op+Oq+Od), where R is the radius of tiles around the object that you consider "nearby" (Alternately, you can only search for "nearby" as being on the same z-level - this means that objects on different portions of a ramp will never be tasked with one another, but it can cut out a lot of false positives where you assume that anything on another z-level is probably going to be very difficult to path a direct line to.  This means you only need R^2 complexity.)  while Op are the number of items present in a given tile, Oq are the number of items with hauling jobs queued, and Od are objects with nearby enough destinations.
Complexity is rather: n+m*pf, where:
n: number of items nearby start
m: number of items nearby start with nearby end
pf:cost of pathfinding from end to additional possible end

Problem is that worst case is sth like this:
{pile of dumped objects and sock}++++++++++++++corridor 1+++++++++++++++++++{socks stockpile}
+
++++++++++++++++++++++++++++++++++++++++corridor 2+++++++++++++++++++++{quantum dump}
In result every single dump-marked object must be processed before picking up sock to check is it possible to consolidate them in single job (with result: bad idea, pick only sock).

It would result in effects similar with ghosts (100 FPS - 0 FPS - 100 FPS). So without limiting number of objects on tile it is completely impossible.
@10 jobs for one dead dwarf. Better solution is to replace 2 shoes, 2 socks etc with single object "typical civilian clothing"
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on February 27, 2011, 09:25:43 am
Complexity is rather: n+m*pf, where:
n: number of items nearby start
m: number of items nearby start with nearby end
pf:cost of pathfinding from end to additional possible end

Problem is that worst case is sth like this:
{pile of dumped objects and sock}++++++++++++++corridor 1+++++++++++++++++++{socks stockpile}
+
++++++++++++++++++++++++++++++++++++++++corridor 2+++++++++++++++++++++{quantum dump}
In result every single dump-marked object must be processed before picking up sock to check is it possible to consolidate them in single job (with result: bad idea, pick only sock).

It would result in effects similar with ghosts (100 FPS - 0 FPS - 100 FPS). So without limiting number of objects on tile it is completely impossible.
@10 jobs for one dead dwarf. Better solution is to replace 2 shoes, 2 socks etc with single object "typical civilian clothing"

That doesn't make sense to me...

First off, if a stockpile is full, you don't have to pathfind to it to see if it's full beforehand, the job itself can see whether or not the stockpile is full before it posts itself to see which stockpile the job wants the item in question to go to.

Secondly, you don't have to fully pathfind from the starting location to each destination to see whether they are going to the same place - you can do that by just having the job post is destination stockpile, and comparing coordinates.  You can do a quick and dirty calculation of distances by absolute distance from the starting location to each stockpile and from stockpile to other stockpile to get a very rough idea of which would be most efficient, and then stick with it, whether it was actually more efficient or not.  (Which is very similar to how dwarves choose the "closest" stockpile to pull stones from when they are choosing materials for workshops.)

Hence, the only way you'd reject a pathfinding to a stockpile would be if it turns out you can't pathfind to the stockpile at all.  The game should take a bias towards claiming jobs just to get them out of the way, even if that involves using the not quite most efficient way of hauling goods.  Remember, you would have to pathfind from where the dwarf starts to the goblin corpse to the stockpile back to the corpse back to the stockpile back to the corpse back to the stockpile already.  Consolidating this down to one big pathfinding crunch where you calculate from dwarf to corpse to stockpile A to stockpile B to stockpile C wouldn't actually cause that much of an average FPS dip.

You can combine this with some of the more advanced pahtfinding ideas, like storying paths from one stockpile or workshop to other stockpiles or workshops that are commonly used, and get a more accurate (less dirty, but still quick) pathfinding cost to use when deciding the closest distances.

Thirdly, I hate to think of any condition other than claiming a quantum stockpile where you would actually have a hundred or so jobs activate on top of a single tile that need to go to completely different stockpiles, but even if there were, so long as you aren't checking for a path to a blocked-off stockpile, those jobs should still be claimed by most dwarves who even bother to pathfind, anyway, unless they literally cannot pathfind from the quantum stockpile to the stockpile they want to go to, in which case that stockpile should just have some sort of "inaccessable" marking for a certain number of frames.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Silverionmox on February 27, 2011, 09:32:24 am
Let's try out where a more naturalistic approach gets us.

- As a reminder, dwarves have a limited carrying capacity. They can only carry so much goblin shoes, depending on their force and containers. This will naturally limit the items we have to consider.

- Grouping jobs: instead of striving for maximum time and resource efficiency (every free dwarf must haul if there's an item to be hauled), strive for organizational efficiency: all hauling jobs for a group of items are grouped, and assigned to a dwarf. That dwarf goes over there, takes what he can carry (preferring items for the same stockpile(s)), goes to stockpile it (visiting several stockpiles in a row and dropping of items, if necessary), and returns to pick up more. When he goes to sleep somebody else can be assigned to continue the group of jobs.

- Ad hoc: a dwarf goes to an item to be hauled, picks it up and checks for a similar nearby item (using a limited floodfill like Draco suggested; the distance of the floodfill should be larger if the trip to the stockpile is longer (people think twice whether they have everything before leaving the store and driving back home, but if you're taking food out of the pantry it's not important if you have to return one more time)), if he finds one he picks it up and checks for more until his backpack is full and goes to the stockpile, if he doesn't he goes to the stockpile.

- Central depot stockpiles: for large quantities of diverse items (eg. battlefield remains) it makes sense to haul everything to a central location (inside your fortress, presumably) and sort it out later.
The way it could work is to flag a stockpile as central/depot: this stockpile would then get priority as a destination for non-stockpiled items. However, it would also be emptied ASAP by moving stuff to normal stockpiles. That way you could set up a central stockpile for everything to start, and later diversify with other central stockpiles when you don't want corpses to be brought into your central hall, or set up the ore processing facilities elsewhere.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: ikkonoishi on February 27, 2011, 09:38:50 am
One solution is searching the entire jobs list, and then looking at the "starting from" location to find the "nearby" ones. This causes problems when the jobs list becomes longer, because it means that every new job will have to make a search of every single job already put on the job queue to search its starting location. This basically has a complexity of O^2+O where O is the number of jobs being put into the jobs queue.  (Subgeometric complexity growth with number of tasks.)

I don't think it would be near that complex. You don't need to check the existing jobs at all. The empty slots in the stockpile generate the jobs after all. When the stockpile goes through the item list grabbing items to fill its slots it could create bundled item gather jobs instead of tons of single hauling jobs.

So instead of having
Code: [Select]
Item myitem
for each emptyslot in stockpile.emptyslots
{
   myitem = getUnstockpiledItem(stockpile.acceptableItems)
   CreateJob(Haul,myitem,emptyslot)
}
You would have
Code: [Select]
bulkhaulingjob[] myjobs
item myitem
for each emptyslot in stockpile.emptyslots
{
   myitem = getUnstockpiledItem(stockpile.acceptableItems)
   for each job in myjobs
   {
      if (job.items[0].location.getXYDist(myitem.location) < 2 && job.items < MAXBUNDLEDITEMS)
      {
         job.addHaul(myitem,emptyslot)
         break
      }
      elseif (job == myjobs.lastjob)
      {
         myjobs.add(CreateJob(BulkHaul,myitem,emptyslot))
         break
       }
    }
}
The code for the job itself would be.
Code: [Select]
goTo(items[0].location)
for each item in items

   if item.location.getXYDist(dwarf.location) < 2
   {
      pickup(item)
   }
   else
   {
      dwarf.complainAboutItemBeingMisplacedAndGoGetABeerOrSomething()
   }
}
for each destination in destinations
{
   goTo(destination)
   drop(items.firstitem)
}


With MAXBUNDLEDITEMS at 2 this would double hauling efficiency for 90% of the jobs that occur. Workshops are always full of items most of which will end up in the same place. Crafting, butchering, brewing, plant processing, elf murdering, ect... Forging usually needs metal and fuel both of which come from the bar stockpile, and could very well be in the same bin.

It considers only directly adjacent tiles to be acceptable for bundling which removes the need for additional path-finding at the pickup end. So long as the items are close enough you just teleport them to the dwarf's inventory. They don't even have to move.

The jobs are all generated by the same stockpile so any additional pathing on the delivery end is up to the player.


Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Lungfish on February 27, 2011, 09:47:22 am
Most of the crap my dwarves swarm to pick up and carry back to the hoard can fit in bins, and the dwarves can carry bins full of stuff. Why, oh why, can't they just bring a bin with them? It could be automated - when 10+ binnable things are a certain distance from their target stockpile and in the same region, a dwarf on their way to haul them can pick up an empty bin and put the stuff in it like they would put bolts in a quiver. Or if they HAVE to put down a bin before putting something in it, maybe a spot could be designated just for bins - a temporary "anything" stockpile that accepts only items on adjacent tiles. Picking things up one at a time and putting it into a nearby bin wouldn't be as bad as having to go all the way to hell and back for every sock, helm, and amulet.

Or maybe it's a Dwarven Culture thing? Maybe they just love racing through battlefields in a great and infrequent Trinket Relay. Running in a crowd of 60 dwarves accross the map to scavenge an elven caravan that didn't survive a goblin ambush could generate invisible happy thoughts, and finding a more efficient way to haul things could make them sad without them even knowing about it!
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Granite26 on February 27, 2011, 09:49:25 am
Nice, ikinoishi....

Krull has the main character reach into a stream of 'lava' to retrieve the magic shuriken needed to kill the final boss.  Basically it was a use case derived from a movie.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on February 27, 2011, 09:54:27 am
- As a reminder, dwarves have a limited carrying capacity. They can only carry so much goblin shoes, depending on their force and containers. This will naturally limit the items we have to consider.

Oh, did I forget to mention that?  I meant to.  If you are only pathfinding once you have actually decided to try carrying something, then you don't need to pathfind any more items than you can actually carry.

- Grouping jobs: instead of striving for maximum time and resource efficiency (every free dwarf must haul if there's an item to be hauled), strive for organizational efficiency: all hauling jobs for a group of items are grouped, and assigned to a dwarf. That dwarf goes over there, takes what he can carry (preferring items for the same stockpile(s)), goes to stockpile it (visiting several stockpiles in a row and dropping of items, if necessary), and returns to pick up more. When he goes to sleep somebody else can be assigned to continue the group of jobs.

I was going to try to address Draco's post with this, but... I'm not sure if looking for things "on the way" is worth the pathfinding cost, actually.  Basically, we could just go by absolute job starting and ending point definitions of "nearby".  It means that maybe the haulers will go to a distant site, pick up half a wheelbarrow's worth of socks, and roll right over a sock on the way to the sock stockpile, but that at least prevents additional limited-range flood pathfinding along an already pathfound route. 

Basically, I'd think it would come down to how likely it is that you would save trips and jobs and extra full pathfinding tasks by doing so compared to the costs of doing so.  You'd have to test this with plenty of live forts to really get a sense of the average number of jobs you'd save for doing this.

If a goblin dies, and the stockpile for metal armor are clearly in another part of the map than the stockpile for fabric and leather clothing, then there should probably be completely different tasks for dwarves to jump for.  If there are a large enough number of items that the dwarf cannot claim all the hauling jobs for that pile of crap, then the jobs that he/she cannot claim should still be left up on the jobs queue for other haulers to try to take.

- Ad hoc: a dwarf goes to an item to be hauled, picks it up and checks for a similar nearby item (using a limited floodfill like Draco suggested; the distance of the floodfill should be larger if the trip to the stockpile is longer (people think twice whether they have everything before leaving the store and driving back home, but if you're taking food out of the pantry it's not important if you have to return one more time)), if he finds one he picks it up and checks for more until his backpack is full and goes to the stockpile, if he doesn't he goes to the stockpile.

Actually, if we're dealing with wheelbarrows or even mine carts that are "mobile stockpiles", then wheelbarrow-hauler dwarves should have a much larger "nearby" definition, so that a single guy with a wheelbarrow might try to take up every single goblin-corpse-clothing-looting job that he can physically cram into his wheelbarrow.  Provided that the siege goblins all died relatively near one another, you could set a ten or twenty-tile "nearby" radius or something similarly large, and use flood filling around the corpses to see a decent path between which corpses to visit.  The flood-fill would be costly, but it should only take one or two dwarves to even do the entire task, as opposed to the hundreds of trips you'd be saving in the long run.

- Central depot stockpiles: for large quantities of diverse items (eg. battlefield remains) it makes sense to haul everything to a central location (inside your fortress, presumably) and sort it out later.
The way it could work is to flag a stockpile as central/depot: this stockpile would then get priority as a destination for non-stockpiled items. However, it would also be emptied ASAP by moving stuff to normal stockpiles. That way you could set up a central stockpile for everything to start, and later diversify with other central stockpiles when you don't want corpses to be brought into your central hall, or set up the ore processing facilities elsewhere.

This makes a lot of sense, but may be tricky to get coded. 

Of course, this pretty much describes what the minecarts are supposed to be and do, anyway.  You make a minecart track to near where the hauling jobs are getting created (battlefield, mining quarry, farm, underground tree factory), and then shove the mining cart back to the central distribution area, where it can be distributed to the workshop resource stockpiles.



Ah, three ninja attacks... I'll post and sort that out later.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on February 27, 2011, 10:07:11 am
I don't think it would be near that complex. You don't need to check the existing jobs at all. The empty slots in the stockpile generate the jobs after all. When the stockpile goes through the item list grabbing items to fill its slots it could create bundled item gather jobs instead of tons of single hauling jobs.

With MAXBUNDLEDITEMS at 2 this would double hauling efficiency for 90% of the jobs that occur. Workshops are always full of items most of which will end up in the same place. Crafting, butchering, brewing, plant processing, elf murdering, ect... Forging usually needs metal and fuel both of which come from the bar stockpile, and could very well be in the same bin.

It considers only directly adjacent tiles to be acceptable for bundling which removes the need for additional path-finding at the pickup end. So long as the items are close enough you just teleport them to the dwarf's inventory. They don't even have to move.

OK, I didn't know that the stockpile creates the job, not the item.  That changes how I have to consider the hauling jobs, then, although I have yet to think through all the ramifications... give me a bit. 

The limited attempt to go out of your way to collect more items unless it's a really easy calculation can make some sense, so I guess it's a matter of just trying to playtest this until it comes out being the best overall balance.  (Maybe some sort of init option for "nearby" definition so that the players can test this out, since we players can carry a lot more of the playtesting weight than Toady can?) 

We also need to have a way to use wheelbarrows, however, which would presumably be able to carry more items at once, so that you could stuff all the crap a goblin drops into the wheelbarrow if it's all going to the same stockpile, anyway.

Most of the crap my dwarves swarm to pick up and carry back to the hoard can fit in bins, and the dwarves can carry bins full of stuff. Why, oh why, can't they just bring a bin with them? It could be automated - when 10+ binnable things are a certain distance from their target stockpile and in the same region, a dwarf on their way to haul them can pick up an empty bin and put the stuff in it like they would put bolts in a quiver. Or if they HAVE to put down a bin before putting something in it, maybe a spot could be designated just for bins - a temporary "anything" stockpile that accepts only items on adjacent tiles. Picking things up one at a time and putting it into a nearby bin wouldn't be as bad as having to go all the way to hell and back for every sock, helm, and amulet.

This is exactly what wheelbarrows are for - they're just bins on a wheel and don't even weigh dwarves down.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Granite26 on February 27, 2011, 10:13:51 am
NW, check out the job priorities thread in my sig.  It's got a lot of job info in it.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Silverionmox on February 27, 2011, 10:24:00 am
- Grouping jobs: instead of striving for maximum time and resource efficiency (every free dwarf must haul if there's an item to be hauled), strive for organizational efficiency: all hauling jobs for a group of items are grouped, and assigned to a dwarf. That dwarf goes over there, takes what he can carry (preferring items for the same stockpile(s)), goes to stockpile it (visiting several stockpiles in a row and dropping of items, if necessary), and returns to pick up more. When he goes to sleep somebody else can be assigned to continue the group of jobs.

I was going to try to address Draco's post with this, but... I'm not sure if looking for things "on the way" is worth the pathfinding cost, actually.  Basically, we could just go by absolute job starting and ending point definitions of "nearby".  It means that maybe the haulers will go to a distant site, pick up half a wheelbarrow's worth of socks, and roll right over a sock on the way to the sock stockpile, but that at least prevents additional limited-range flood pathfinding along an already pathfound route. 

Basically, I'd think it would come down to how likely it is that you would save trips and jobs and extra full pathfinding tasks by doing so compared to the costs of doing so.  You'd have to test this with plenty of live forts to really get a sense of the average number of jobs you'd save for doing this.

If a goblin dies, and the stockpile for metal armor are clearly in another part of the map than the stockpile for fabric and leather clothing, then there should probably be completely different tasks for dwarves to jump for.  If there are a large enough number of items that the dwarf cannot claim all the hauling jobs for that pile of crap, then the jobs that he/she cannot claim should still be left up on the jobs queue for other haulers to try to take.
Indeed, jobs on the way shouldn't be considered, because that inevitably requires computing "the way", i.e. pathfinding, adapting the path etc. What I meant was grouping jobs that are close together.

After his load is full, the dwarf is simply emptying his load. So he just needs to pathfind to the nearest stockpile, drop off what he can, and then he'll look for the closest stockpile out of all the stockpiles he needs to visit. Repeat until empty. Trying to find the ideal route between the stockpiles is not worth it, IMO. I don't care if the haulers are a bit dumb. They're normally safely inside the fortress at that point anyway.

a decent path between which corpses to visit
That's a travelling salesman problem. Might be tricky. What I meant was floodfilling until a hit, then picking that up, then floodfilling again from that position.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: ikkonoishi on February 27, 2011, 10:29:01 am
We also need to have a way to use wheelbarrows, however, which would presumably be able to carry more items at once, so that you could stuff all the crap a goblin drops into the wheelbarrow if it's all going to the same stockpile, anyway.

Just add a check to my pseudocode in the job section. If the number of items in the job is higher than, lets say, 5 the dwarves will grab a wheelbarrow or empty bin. If they can't find one then they can grab what they can, and maybe split the bulk haul job so another dwarf can help.

Or wheelbarrows could be creatures that can't move on their own. They have their own AI that looks for clusters of hauling tasks when they are idle, and claims them. Then they create a job for a dwarf to come move them to their destination and load them. If you don't have wheelbarrows then there would not be any extra checks for wheelbarrow usage. This would also allow for other creatures to be haulers with dwarven assistance and proper training. Train a bunch of hauling kangaroos, fill their pouches with items, and drag them around the fort!

Edit: After testing with stone stockpiles it seems that the stockpiles as a whole don't create the jobs because when I created 3 stone stockpiles instead of claiming items in the order of their creation they claimed them in a jumbled order. I think therefore that the individual stockpile tiles claim the items. More testing could determine the exact order, but I have to go to bed in 30 minutes so I won't be doing it anytime soon.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on February 27, 2011, 11:00:05 am
NW, check out the job priorities thread in my sig.  It's got a lot of job info in it.

I did, it's actually got a lot in common with the dwarfbot discussion and some of my previous talks about job priorities.

That's a travelling salesman problem. Might be tricky. What I meant was floodfilling until a hit, then picking that up, then floodfilling again from that position.

If we do it that way, we can wind up "following a trail of breadcrumbs" away from a task we should be lumping in as a nearby task.  If there's a single item on the floor that by chance creates the first task on the job board, then there is another single item a single tile away to the north, but a pile of goods that needs to go to the stockpile two tiles to the south, and then when the flood search takes place from the single item that was to the north, it finds another item 2 more tiles to the north of that, then another item 4 more tiles to the north of that, then another 8 tiles to the north of that, then you've gone out of detection range for the whole pile of items to the south.

Depending on how many items a dwarf might be able to haul at once (with something like a wheelbarrow), then it might be useful to perform a full flood on the first item, then stop-on-hit floods for every successive item, with a full flood exception every 5 items or so if we have a really large hauling capacity.  Then, we could do a relatively quick and dirty absolute distance traveling salesman calculation, where we try to find the two items that are the furthest apart from one another to set start and end points in the collection task.

After his load is full, the dwarf is simply emptying his load. So he just needs to pathfind to the nearest stockpile, drop off what he can, and then he'll look for the closest stockpile out of all the stockpiles he needs to visit. Repeat until empty. Trying to find the ideal route between the stockpiles is not worth it, IMO. I don't care if the haulers are a bit dumb. They're normally safely inside the fortress at that point anyway.

Yes, it's going to be a really odd way of trying to balance performance with stupidity in terms of dwarfy pathfinding :P

Just add a check to my pseudocode in the job section. If the number of items in the job is higher than, lets say, 5 the dwarves will grab a wheelbarrow or empty bin. If they can't find one then they can grab what they can, and maybe split the bulk haul job so another dwarf can help.

Or wheelbarrows could be creatures that can't move on their own. They have their own AI that looks for clusters of hauling tasks when they are idle, and claims them. Then they create a job for a dwarf to come move them to their destination and load them. If you don't have wheelbarrows then there would not be any extra checks for wheelbarrow usage. This would also allow for other creatures to be haulers with dwarven assistance and proper training. Train a bunch of hauling kangaroos, fill their pouches with items, and drag them around the fort!

Edit: After testing with stone stockpiles it seems that the stockpiles as a whole don't create the jobs because when I created 3 stone stockpiles instead of claiming items in the order of their creation they claimed them in a jumbled order. I think therefore that the individual stockpile tiles claim the items. More testing could determine the exact order, but I have to go to bed in 30 minutes so I won't be doing it anytime soon.

Well, the wheelbarrow as a creature might make more sense when talking about minecarts, which are supposed to be mobile stockpiles.  Wheelbarrows I've seen as more just being backpacks or extra hands for a dwarf that they carry as "equipment" and up their maximum inventory hauling space.

Actually, having backpacks as some sort of hauling harness might be an amusing idea.  Haulers will become more specialized dwarves that have their own desirability based upon their ability to carry more items at once if this goes all the way.  You must protect your legendary haulers as they are precious resources necessary for maintaining the working order of your fortress. :P

As for stockpiles, I don't know if individual tiles claim stones, since they always seem to fill from the top left horizontally and then downward, which seems like it's just a "capacity" check.  Maybe your stockpiles were simply taking turns declaring jobs, or they were set to claim different kinds of stone, or distance calculations made different stockpiles become declared closer on a very odd basis.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: blizzerd on February 27, 2011, 11:04:46 am
add in this or something like it, because i feel its related:

http://www.bay12forums.com/smf/index.php?topic=78340.0

basically "demand when needed" in stead of "reserve until use" for constructions and the objects used to make them

basically in short, when you build a bed and select -tower cap bed- or [SPECIFIC ARTEFACT NAME HERE] as the object used to build it, df will not reserve any -tower cap bed- or [SPECIFIC ARTEFACT NAME HERE] until a dwarf has prepared the site for construction and is about to walk over to the reserved object to fetch it, this will prevent any constructions from suspending because a reserved object is placed on its location for construction even if the specified objects construction is also suspended and will also make it so the dwarves ALWAYS pick the closest object that fits the requirement from the moment they need it, meaning more will have to be worked with stockpiles but this would also enable one to for example build a giant structure with chalk blocks and start designating the walls and everything even if this person's fort has only have 1 actual block in stores at this moment, while the masons construct more and move it to the stockpile next to the construction

because the latter is far more inefficient when it comes to dwarven fortress mechanics
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Draco18s on February 27, 2011, 11:15:42 am
It is L*x, where L is length of path and x is maximum distance to find job (it is in fact BFS with found path as starting points with limited path length). It also will annihilate FPS.

So rather than countering the idea with a better idea all you did is tell me why it wouldn't be efficient enough.

And how efficient does the algorithm need to be in order to be good enough for you?
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on February 27, 2011, 11:20:25 am
OK, I can see that...

That's applying the same code to other tasks that have similar requirements, which can makes sense, provided the task is indeed similar.  A job from a furnace that requires coke and flux and iron to make some pig iron is something that can use the same code as what we are talking about, although you would have to do something like search for the coke first, then find the absolute nearest flux and absolute nearest iron from both the coke and flux items, and do that dirty salesman calculation to find the low-pathfinding quickest way to collect all three items and bring them to the forge in one trip.

You can just hold off on setting which stones are tasked for being built into a wall until a dwarf actually starts the decision tree to pick up stones to bring them to the wall.  Of course a "10 granite stones will be needed for this task, and there are only 15 granite stones are in the fort, so don't assign more than 5 more granite to any other tasks" type of message will need to be placed into the game's material-allocation logic in the meantime.

You would also need to make some sort of fancy extra step of temporary stockpile type of code, as well.  For example, the dwarf may pick up three stones that were nearby on his way to the wall he is going to build, and then set those three stones down in the places where they are going to be turned into their respective wall tiles, so that they are nearby and out of the way of the current building task.  If setting the stone down on the tile where the stone will be built into a wall is a problem for some reason, it has to be pretty fancy in choosing a "nearby" tile that isn't going to have a task on it (like another wall building), either.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Granite26 on February 27, 2011, 11:26:28 am
It is L*x, where L is length of path and x is maximum distance to find job (it is in fact BFS with found path as starting points with limited path length). It also will annihilate FPS.

So rather than countering the idea with a better idea all you did is tell me why it wouldn't be efficient enough.

And how efficient does the algorithm need to be in order to be good enough for you?
It's just a cost benefit thing.  Anticipated cost >> Anticipated benefit.

From my perspective, any change would need to pay for itself.  Since haulers are effectively free, doubling up would need to be at least as efficient (processor wise) as taking two trips.  Right now, I don't think it is (I mean sure, when they DO take two things, it's more efficient, but the overhead is added to ALL hauling jobs).
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on February 27, 2011, 11:56:20 am
So rather than countering the idea with a better idea all you did is tell me why it wouldn't be efficient enough.

And how efficient does the algorithm need to be in order to be good enough for you?

It's just a cost benefit thing.  Anticipated cost >> Anticipated benefit.

From my perspective, any change would need to pay for itself.  Since haulers are effectively free, doubling up would need to be at least as efficient (processor wise) as taking two trips.  Right now, I don't think it is (I mean sure, when they DO take two things, it's more efficient, but the overhead is added to ALL hauling jobs).

Well, as an alternative, what about the "nearby" from only the specific site of the job, rather than the length of the pathfinding?  You could potentially alter the definition of "nearby" based upon a quick and dirty absolute length of the path to the stockpile or something, so that you could say that you will try harder to collect more items in a single trip if you know that the stockpile will be further away, and take longer pathfinding back.

That way, the amount of time you spend consolidating jobs by pathfinding just from one nearby item to the next nearby item, and then do the big and difficult pathfinding task of going from the last item to the stockpile all at once, saving in overall pathfinding time.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Granite26 on February 27, 2011, 12:17:40 pm
that makes a lot of sense.  What are the cases for massive amounts of A -> B hauling? 

1:  To/From Depot  (check)
2:  To stockpile from workshop (check)
3:  To stockpile from corpse (check)
4:  To workshop from stockpile (check), (think 'needs 5 steel bars)

Slightly more difficult:

4:  To stockpile from mining area
5:  To stockpile from battlefield

What other use cases for massive hauling are there?

I think wheelbarrows are still a mess, though.  Should I use one?  Where's the closest one?  How far do I actually have to go?  Do I pass close to one?
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Kogut on February 27, 2011, 12:49:40 pm
It is L*x, where L is length of path and x is maximum distance to find job (it is in fact BFS with found path as starting points with limited path length). It also will annihilate FPS.
So rather than countering the idea with a better idea all you did is tell me why it wouldn't be efficient enough.

And how efficient does the algorithm need to be in order to be good enough for you?
I see that 'on your way' may be nice but I have no idea how to make efficient algorithm (n log n or better) to solve it.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Silverionmox on February 27, 2011, 01:01:48 pm
If we do it that way, we can wind up "following a trail of breadcrumbs" away from a task we should be lumping in as a nearby task.  If there's a single item on the floor that by chance creates the first task on the job board, then there is another single item a single tile away to the north, but a pile of goods that needs to go to the stockpile two tiles to the south, and then when the flood search takes place from the single item that was to the north, it finds another item 2 more tiles to the north of that, then another item 4 more tiles to the north of that, then another 8 tiles to the north of that, then you've gone out of detection range for the whole pile of items to the south.
Hey, I like that. That's how children get lost in forests and stories start. I seriously think there is room for dumbness here. We want to save the player's time by improving processor usage, not save the hauler's time by improving his GPS.

It is just one hauling strategy: if there's a big pile of items, it should be grouped as one set of jobs and assigned to one or more dwarves). The items that are not eligible for that treatment because they are not concentrated enough will inevitably have to picked up that way.

I think wheelbarrows are still a mess, though.  Should I use one?  Where's the closest one?  How far do I actually have to go?  Do I pass close to one?

Another big problem with wheelbarrows: stairs. Giving each dwarf a backpack (or basket, bag, etc. depending on available materials and crafters) should be sufficient to do most hauling. Wheelbarrows can then be thought of as a tool to move heavy loads faster, rather than a container. Gravel, ore, sand, clay and other bulk goods should be put in bins for transport anyway: those can then be carried up the stairs as necessary.

Wheelbarrows would be the most useful for a group of identical jobs, eg. 35 pieces of bituminous coal to stockpile: the dwarf would fill a bin, put it on the wheelbarrow, deliver it to the stockpile, get a new bin and go back to fill it - keeping the wheelbarrow with him all the time. Otherwise the decision to get an empty wheelbarrow (probably somewhere near a stockpile) will be a calculation in itself (requiring pathfinding as well, wheels don't walk and the terrain needs to be checked).
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Draco18s on February 27, 2011, 01:30:39 pm
It is L*x, where L is length of path and x is maximum distance to find job (it is in fact BFS with found path as starting points with limited path length). It also will annihilate FPS.
So rather than countering the idea with a better idea all you did is tell me why it wouldn't be efficient enough.

And how efficient does the algorithm need to be in order to be good enough for you?
I see that 'on your way' may be nice but I have no idea how to make efficient algorithm (n log n or better) to solve it.

If you have no idea how efficient an algorithm is, then you can't comment on its efficiency.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Granite26 on February 27, 2011, 02:07:18 pm
It is L*x, where L is length of path and x is maximum distance to find job (it is in fact BFS with found path as starting points with limited path length). It also will annihilate FPS.
So rather than countering the idea with a better idea all you did is tell me why it wouldn't be efficient enough.

And how efficient does the algorithm need to be in order to be good enough for you?
I see that 'on your way' may be nice but I have no idea how to make efficient algorithm (n log n or better) to solve it.

If you have no idea how efficient an algorithm is, then you can't comment on its efficiency.

He said it wasn't n log n and he didn't know a way to make it n log n, not that he didn't know how efficient it was.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on February 27, 2011, 04:53:05 pm
Hey, I like that. That's how children get lost in forests and stories start. I seriously think there is room for dumbness here. We want to save the player's time by improving processor usage, not save the hauler's time by improving his GPS.

It is just one hauling strategy: if there's a big pile of items, it should be grouped as one set of jobs and assigned to one or more dwarves). The items that are not eligible for that treatment because they are not concentrated enough will inevitably have to picked up that way.

OK, fair enough, I guess having dumb dwarves as a flavor choice may be OK, so long as it isn't so stupid you pull your hair out or have to babysit them. 

Another big problem with wheelbarrows: stairs. Giving each dwarf a backpack (or basket, bag, etc. depending on available materials and crafters) should be sufficient to do most hauling. Wheelbarrows can then be thought of as a tool to move heavy loads faster, rather than a container. Gravel, ore, sand, clay and other bulk goods should be put in bins for transport anyway: those can then be carried up the stairs as necessary.

Wheelbarrows would be the most useful for a group of identical jobs, eg. 35 pieces of bituminous coal to stockpile: the dwarf would fill a bin, put it on the wheelbarrow, deliver it to the stockpile, get a new bin and go back to fill it - keeping the wheelbarrow with him all the time. Otherwise the decision to get an empty wheelbarrow (probably somewhere near a stockpile) will be a calculation in itself (requiring pathfinding as well, wheels don't walk and the terrain needs to be checked).

Well, cows can go up tight flights of stairs that apparently spin in place, so it might just be that for now, wheelbarrows go up stairs, too.  Alternately, wheelbarrows would have to be treated with code more similar to the caravan wagon code, which is massively problematic for Toady.  It would probably make ramps much more popular than stairs in fortress design, though.

Wheelbarrows are something I think might just become "hauler equipment" at a certain point just to make the game easier - a woodcutter grabs an axe so that he/she can cut down the trees, and a hauler might grab the first available wheelbarrow or backpack to be able to better haul goods, and just pathfinds and hauls as best they can with the equipment they have.  It might be wierd from the current game perspective, but if we cut down on the number of trips haulers have to do by giving them wheelbarrows, haulers shouldn't take up such a percentage of the fortress population.  Alternately, there might be some sort of toggle we can put on a flag in the labors menu that says they're a "wheelbarrower" labor acive that should be carrying around a wheelbarrow because we have determined they are performing hauling so frequently that they need a wheelbarrow, and it won't be wasted on them to push it.

There may need to be something in the job "relation" code that will make jobs try to group with each other and count how big a group of jobs they can make.  Wheelbarrowers and minecart pushers should try to go for the larger job groups, while backpackers might leave very large grouped jobs for wheelbarrowers and aim for mid-sized jobs as a priority, while standard haulers will go for individual outlier items that don't have many nearby items to group tasks.  (This means that the job order itself decides how to group themselves, before the dwarves even decide to take the job and try to pathfind.)

that makes a lot of sense.  What are the cases for massive amounts of A -> B hauling? 

1:  To/From Depot  (check)
2:  To stockpile from workshop (check)
3:  To stockpile from corpse (check)
4:  To workshop from stockpile (check), (think 'needs 5 steel bars)

Slightly more difficult:

4:  To stockpile from mining area
5:  To stockpile from battlefield

What other use cases for massive hauling are there?

Dump zones that are un-forbidden.  That can be a very large concentration of items.

Butcher's shops, too, but that's already a workshop to stockpile job. 

I actually think the "central distribution area" based upon minecarts would have to be the single most difficult decision tree to build.  Even if pathfinding is easy, since you have a set track to follow, you have a major set of decisions to make if you want this to be automated.

You have to decide when there are enough hauling jobs that a minecart is worth sending out, where to send it back, what to lump onto the cart, and what to haul by hand to stockpiles that are far enough away, when to haul back (if the only remaining items are "too far"), and then decide how to distribute the goods in the cart.

Plus, if we have draft animals pulling the minecart, we need jobs for attaching the mule or horse or ox to the cart, and then making sure to let it go before it starves to death.

A "central distribution area" that might look like some kind of Grand Central Station might be a good way of handling some of the "where does it go" coding.  It would also be amusingly bustling.  But a distribution area that has all your carts dump their cargo (maybe even keeping carts on a single track), and maybe load up their cargo to get shipped off to distant workshops or stockpiles, or else leaving the goods to be loaded from unloading bay to some of the nearby stockpiles.  This kind of setup would make industrial areas of the fortress much more centralized.

Oh, and what it you move the minecart up to the workshops?  Can you just haul a whole bunch or coal and flux and iron into a cart and shove it down to the furnaces?
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Granite26 on February 27, 2011, 05:18:14 pm
I don't like the idea of institutionalizing the quantum dumps.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on February 27, 2011, 05:24:08 pm
I don't like the idea of institutionalizing the quantum dumps.

I'm not talking about institutionalizing quantum dumps, I was just talking about dump zones (which forbid items that go into them) that you unforbid.  There are reasons to use dump zones other than creating quantum stockpiles.  For example, dumping wood from the surface down a long pit to the magma forges, then unforbidding them at the bottom from time to time to save transit time on woodcutting.  (Besides, it's not a quantum stockpile if you're taking it to a real stockpile.)

More generally, any sort of mass-unforbid action will probably cause a big push to stockpile a huge number of items. 
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Draco18s on February 27, 2011, 05:25:26 pm
He said it wasn't n log n and he didn't know a way to make it n log n, not that he didn't know how efficient it was.

So because he doesn't know how to make it efficient, therefore its not efficient, therefore its bad?
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Kogut on February 27, 2011, 05:28:44 pm
He said it wasn't n log n and he didn't know a way to make it n log n, not that he didn't know how efficient it was.
So because he doesn't know how to make it efficient, therefore its not efficient, therefore its bad?
I only said that I have absolutely no idea how to do it and that it is probably very hard to do it in FPS-friendly way (harder than normal pathfinding that is too slow already).
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Granite26 on February 27, 2011, 05:30:39 pm
He said it wasn't n log n and he didn't know a way to make it n log n, not that he didn't know how efficient it was.

So because he doesn't know how to make it efficient, therefore its not efficient, therefore its bad?
Well, again speaking for me, bad to do unless a way to make it efficient is found.  It may not be possible.

Honestly, DF appears to be chasing Moore's Law for new features.  :)
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on February 27, 2011, 05:46:54 pm
Could we please stick to actually discussing the topic, instead of who's being unconstructive or not?

Is there any sort of response to how to most efficiently use wheelbarrows and backpacks, for example?  What about the minecarts and central distribution areas?
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Granite26 on February 27, 2011, 05:50:48 pm
I don't like the idea of institutionalizing the quantum dumps.

I'm not talking about institutionalizing quantum dumps, I was just talking about dump zones (which forbid items that go into them) that you unforbid.  There are reasons to use dump zones other than creating quantum stockpiles.  For example, dumping wood from the surface down a long pit to the magma forges, then unforbidding them at the bottom from time to time to save transit time on woodcutting.  (Besides, it's not a quantum stockpile if you're taking it to a real stockpile.)

More generally, any sort of mass-unforbid action will probably cause a big push to stockpile a huge number of items.

good points.

Just add 'stockpile to stockpile' to the list
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: blizzerd on February 27, 2011, 06:29:44 pm
what about making wheelbarrows something a bucket is to a water pond or a soap is to a hospital?

only if an item is coming or going from a certain stockpile and to another certain stockpile the dwarf will pick up the wheelbarrow at the stockpile that he needs to pick up the item from to pick up the items and transport it to the second stockpile, then he does the next transport task until he becomes hungry or the end stockpile is full

so wheelbarrows only work for stockpiles, and using them intensively would increase speeds tremendously with moving stuff about
would that work?
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on February 27, 2011, 06:36:36 pm
what about making wheelbarrows something a bucket is to a water pond or a soap is to a hospital?

only if an item is coming or going from a certain stockpile and to another certain stockpile the dwarf will pick up the wheelbarrow at the stockpile that he needs to pick up the item from to pick up the items and transport it to the second stockpile, then he does the next transport task until he becomes hungry or the end stockpile is full

The problem with that is that you'd have the dwarves dropping the wheelbarrow after every job, then needing to go pick it up again each time they need to use it again. 

If a dwarf is going to be a dedicated hauler, it makes sense for them to use the wheelbarrow any time they aren't going on break to eat or whatever.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Granite26 on February 27, 2011, 06:43:00 pm
Or, have it an equip setting for dwarves under the hauling screen.  HAUL (Odds, Ends, Wheelbarrow)
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Silverionmox on February 27, 2011, 06:55:13 pm
We could also let wheelbarrows (and minecarts) be associated with stockpiles like bins and barrels are. They would then only be used for jobs relevant to that stockpile (or possibly workshop). Useful for furnaces, that need a lot of coal, carpenters that need wood etc.

If that's too limited assigning them to burrows might work.

Assigning them to either places, persons or jobs will be necessary in order not too complicate the decision when and whether to use them too much.

In any case wheelbarrows need to be used only for many items, because they automatically generate an extra hauling job: bringing the wheelbarrow to where it is needed.

IRL, wheelbarrows are typically used for repeating, predictable large amounts of stuff. Like minecarts, but those require industrial amounts of stuff to be useful. I know a case of 16th-17th century quarrymen that quarried blocks of stone in underground tunnels. They used horses and carts to get the stone out, driving along the same route all the time. (The tunnels were later used to grow mushrooms...)
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Granite26 on February 27, 2011, 07:03:35 pm
We could also let wheelbarrows (and minecarts) be associated with stockpiles like bins and barrels are. They would then only be used for jobs relevant to that stockpile (or possibly workshop). Useful for furnaces, that need a lot of coal, carpenters that need wood etc.
How do they get back to the stockpile?
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Silverionmox on February 27, 2011, 07:28:04 pm
We could also let wheelbarrows (and minecarts) be associated with stockpiles like bins and barrels are. They would then only be used for jobs relevant to that stockpile (or possibly workshop). Useful for furnaces, that need a lot of coal, carpenters that need wood etc.
How do they get back to the stockpile?
Finishing the hauling job would include bringing back the wheelbarrow. Or rather, the wheelbarrows would be at the furnace, and the haulers would got there to get instructions and equipment, do their jobs and when they're done a wheelbarrow full of coal is at the furnace, and the hauler free to take another job.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Maklak on February 27, 2011, 07:35:48 pm
Even consolidating multiple jobs "haul goblinite armor from square A to stockpile B" would be a big improvement, and is simpler than checking proximity. This would also give us a workaround: Make a quantum dump in the middle of goblinite, dump everything, and then reclaim, so it gets hauled to stockpiles efficiently. There wouldn't be a need to create "haul many items" type jobs in job list, as long as Dwarf could TSK many jobs at once (but this approach is probably suboptimal). 

I'd also like to see an improvement to stockpiles: one pointer for taking items from another stockpile and one for giving to another stockpile. While not a true n:m relationship, it would still be more versatile than the current system, where a stockpile can be given items by many stockpiles, but one stockpile can give items to only one stockpile. With my suggestion giving and taking are functionally similar, but distinct. Any stockpile could give items to one stockpile and take items from one stockpile. That way you could have 1:n and n:1 in various combinations, and m:n would require a "relay" stockpile in the middle (m:n could be formed by m:1 and 1:n). It would ofc require coding various borderline cases (Can stockpile A take from B, while B gives to A? etc)

On Floodfill: you can do it only once for point A, and list enough items to fill wheelbarrow, and even do it as a breadth-first search, but ONLY PROVIDED you have information on items stored in tiles. AFAIK, tile doesn't know, what items are there, it it items, that know where they are. A pretty good way to quickly access information about nearby items would be to use Z-addresses. A Z-address is in short an integer generated from coordinates in such a way, that nearby Z-addresses usually mean that items are close, and for any given distance from initial point you can calculate minimum and maximum Z-addresses worth looking at. This property plus indexing points in space by their Z-addresses greatly speeds up dbscan clustering algorithm (from O(n^2) to O(eps*n^2 + n*log(n))).
http://en.wikipedia.org/wiki/Z-order_%28curve%29
http://en.wikipedia.org/wiki/UB-tree
http://en.wikipedia.org/wiki/Quadtree

NW Kohaku, please clarify, weather you want to optimize FPS time or Dwarf walking time.

As for wheelbarrows, I see them as backpacks / bins on wheels, and anything in them weights less for the purpose of carrying speed.
If Dwarf could store items in wheelbarrow driven by another dwarf, it could lead to rather amusing spam of "hauler cancels store item in wheelbarrow, wheelbarrow misplaced", and other bugs  :D

I remember another suggestion about improved hauling: workshops having miniature input stockpiles, that generate hauling jobs for materials for queued items, so crafters don't need to go themselves to nearby quantum dumps. Do the same for building walls.

I have another suggestion about improving proximity(A) to B type hauling: Mass melting. Melting would be more efficient if multiple items made of the same material were hauled to smelter before actual smelting. It seems more realistic to collect a whole batch of scrap metal before smelting, than burn all that coal to melt 1 bolt or cup or something, and get almost nothing from it.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on February 27, 2011, 08:17:01 pm
I'd also like to see an improvement to stockpiles: one pointer for taking items from another stockpile and one for giving to another stockpile. While not a true n:m relationship, it would still be more versatile than the current system, where a stockpile can be given items by many stockpiles, but one stockpile can give items to only one stockpile. With my suggestion giving and taking are functionally similar, but distinct. Any stockpile could give items to one stockpile and take items from one stockpile. That way you could have 1:n and n:1 in various combinations, and m:n would require a "relay" stockpile in the middle (m:n could be formed by m:1 and 1:n). It would ofc require coding various borderline cases (Can stockpile A take from B, while B gives to A? etc)

I'm not sure I follow you on this one...

NW Kohaku, please clarify, weather you want to optimize FPS time or Dwarf walking time.

Either both or one or the other at different times. 

The entire purpose of stacking and hauling is to make dwarf times better to a certain extent, but at the same time, you can't completely ignore FPS time.  It's something that you have to balance.  I'm fine with slightly slower FPS in return for slightly saner dwarf behavior, especially if it makes many of the other things I really want to see from dwarven AI advances possible.

I remember another suggestion about improved hauling: workshops having miniature input stockpiles, that generate hauling jobs for materials for queued items, so crafters don't need to go themselves to nearby quantum dumps. Do the same for building walls.

Actually, I remember making an Improved Mechanisms suggestion where conveyor belts could be built that take items from an "output" tile directly to the stockpiles or "input" tiles of another workshop.  If it's something like the loom and dyer and clothier's shops, then threads can go from one shop to the next without requiring a hauling task at all on their way down the assembly line.

I have another suggestion about improving proximity(A) to B type hauling: Mass melting. Melting would be more efficient if multiple items made of the same material were hauled to smelter before actual smelting. It seems more realistic to collect a whole batch of scrap metal before smelting, than burn all that coal to melt 1 bolt or cup or something, and get almost nothing from it.

I'd like this, too.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Granite26 on February 27, 2011, 08:44:10 pm
We could also let wheelbarrows (and minecarts) be associated with stockpiles like bins and barrels are. They would then only be used for jobs relevant to that stockpile (or possibly workshop). Useful for furnaces, that need a lot of coal, carpenters that need wood etc.
How do they get back to the stockpile?
Finishing the hauling job would include bringing back the wheelbarrow. Or rather, the wheelbarrows would be at the furnace, and the haulers would got there to get instructions and equipment, do their jobs and when they're done a wheelbarrow full of coal is at the furnace, and the hauler free to take another job.
So an extra trip...  (not that that's horrible, it just needs to be explicit.  You don't start saving time until you're bringing three things at a time.

Bonus for wheelbarrow as a Labour setting:  Jobs pick dwarves, so if wheelbarrow is a labour, the job to haul stuff in a wheelbarrow can be created ahead of time.  The job knows it's a group job, the dwarf doesn't have to check.  That means they are bundled from the get go.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: ikkonoishi on February 27, 2011, 09:51:42 pm
Another thought on wheelbarrows.

Wheelbarrows are buildings. You place them, make a room out of them, and then choose a destination. You then choose whether this is a one time run or a continuing order. You can choose how many items will make a trip worthwhile, and what items the wheelbarrow should grab using the stockpile interface. If the destination is a stockpile then the wheelbarrow picks up what it takes automatically.

Dwarves run up, and fill the wheelbarrow with all loose items in that room. Then the dwarves take the wheelbarrow to the destination, and either dump it all on the floor or transfer it into the stockpile. If the building is set to a one time haul the building is deconstructed, or if it is set to repeat the dwarves rebuild it by taking the wheelbarrow back to it.

Wheelbarrow wrangling could be a skill with low skill dwarves moving slower or spilling items out along the way, and having to stop to put them back in. You could have multipliers for stair tiles making this more likely.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Uristocrat on February 27, 2011, 09:55:36 pm
It butchered your link.  You wanted to link to http://en.wikipedia.org/wiki/Z-order_%28curve%29 (http://en.wikipedia.org/wiki/Z-order_%28curve%29)
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on February 27, 2011, 10:00:25 pm
Another thought on wheelbarrows.

Wheelbarrows are buildings. You place them, make a room out of them, and then choose a destination. You then choose whether this is a one time run or a continuing order. You can choose how many items will make a trip worthwhile, and what items the wheelbarrow should grab using the stockpile interface. If the destination is a stockpile then the wheelbarrow picks up what it takes automatically.

Dwarves run up, and fill the wheelbarrow with all loose items in that room. Then the dwarves take the wheelbarrow to the destination, and either dump it all on the floor or transfer it into the stockpile. If the building is set to a one time haul the building is deconstructed, or if it is set to repeat the dwarves rebuild it by taking the wheelbarrow back to it.

Wheelbarrow wrangling could be a skill with low skill dwarves moving slower or spilling items out along the way, and having to stop to put them back in. You could have multipliers for stair tiles making this more likely.

This sounds like way more micromanagement than it needs to be.  This sounds like more micromanagement than even the minecarts need to have.  You should be able to allow minecarts, which work as stockpiles, to run automatically.

I rather prefer wheelbarrows as just backpacks with bigger carrying capacities and which heavily reduce the penalties for carrying and reduce fatigue.  You don't have to do anything special besides allocate the wheelbarrow to a single dwarf, who carries it with him everywhere he goes when he is picking up multiple items.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Granite26 on February 27, 2011, 10:23:28 pm
Dunno, I could see some merit to that...  dwarfs treat the wheelbarrow as part of the stockpile?


It's micro, but not horrid micro, esp for mining...

I don't think it could.work for a repeat...

More like...  build it in the shaft, say 'fill' as a stockpile, then when you are done, say 'dump here' which sgould be close to where you want it...  i.e. your dump, or where you plan to build a stockpile....  makes a good addition to other options.

New stockpile setting:  max distance stockpile will pull an item from.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: ikkonoishi on February 28, 2011, 01:31:00 am
No micro unless you set it up for a one time haul.
You build the wheelbarrow up next to a craft shop, and increase the room size to include the craft shop.
Set the destination for the craft stockpile next to the depot.
Dwarves fill the wheelbarrow up with crafts till it is full, and then dump it at the destination. If it is set to repeat they then take it back to where it was before.

It basically acts as a one tile stockpile, but when it gets full it is emptied at another place.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Kogut on February 28, 2011, 02:33:42 am
I posted my own idea here: http://www.bay12forums.com/smf/index.php?topic=78517.msg2028383#msg2028383
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: ikkonoishi on February 28, 2011, 02:36:58 am
I posted my own idea here: http://www.bay12forums.com/smf/index.php?topic=78517.msg2028383#msg2028383
So you started a new thread to post something after reading a thread discussing that topic? This thread is only 4 pages long. There isn't any need to try to split it yet.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Kogut on February 28, 2011, 02:38:41 am
Because it contains many, many various ideas how to do it. And mine is not going to fix everything and add multiple pointless objects (top suggestion from ESV) but to fix small part of it.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: ikkonoishi on February 28, 2011, 03:09:48 am
Because it contains many, many various ideas how to do it. And mine is not going to fix everything and add multiple pointless objects (top suggestion from ESV) but to fix small part of it.

That is the entire purpose of the megathread concept. Everything related to a topic in one place. So we don't end up flooding the entire forum with discussions on one subject.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Granite26 on February 28, 2011, 07:58:41 am
And so that new playeers don't have to read 40 billion threads on the same subject, most covering the same ground, before being able to add something actually new to the discussion.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on February 28, 2011, 10:09:35 am
Dunno, I could see some merit to that...  dwarfs treat the wheelbarrow as part of the stockpile?


It's micro, but not horrid micro, esp for mining...

I don't think it could.work for a repeat...

More like...  build it in the shaft, say 'fill' as a stockpile, then when you are done, say 'dump here' which sgould be close to where you want it...  i.e. your dump, or where you plan to build a stockpile....  makes a good addition to other options.

New stockpile setting:  max distance stockpile will pull an item from.
No micro unless you set it up for a one time haul.
You build the wheelbarrow up next to a craft shop, and increase the room size to include the craft shop.
Set the destination for the craft stockpile next to the depot.
Dwarves fill the wheelbarrow up with crafts till it is full, and then dump it at the destination. If it is set to repeat they then take it back to where it was before.

It basically acts as a one tile stockpile, but when it gets full it is emptied at another place.

The thing is, the "makes a mobile stockpile" role is basically the exact purpose of a minecart - wheelbarrows are meant to be just for normal hauling.  If you want to set up minecarts manually, that's one thing, but wheelbarrows should be different from minecarts if we are going to have both of them, especially if we already have to set down tracks for minecarts to follow.

I'd also say that it's better to just talk about how to give dwarves the AI capacity to realize when they need the minecart returned.  You can just set the little stations for the minecarts on the tracks, and let dwarves decide when they need a cart in that station. 

If you want to have a dedicated cargo route, you can set a minecart track from the furnaces to a central storage area or for raw materials to be shipped from the mines to the furnaces.

If you can do all this with wheelbarrows, what is the purpose of having a minecart at all, when minecarts involve tracks, and possibly even draft animals, which are a much greater material and logistical upfront capital cost, when you already put all the practical advantages of minecarts on wheelbarrows?  Even if you say that minecarts can carry more, it's not likely to be so much more that you can't just put in a fleet of wheelbarrows to compensate for the lack of hauling capacity.

Also, the objective should always be to reduce micromanagement of functions wherever it is even remotely possible.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Granite26 on February 28, 2011, 10:18:38 am
What IS the difference between a mine cart and a wheelbarrow?  Cart holds more and is on tracks. That's it.

The point is allowing micro of certain mass hquling jobs.  Everything else is implimentation details.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on February 28, 2011, 10:27:16 am
Again, I don't think there's a reason to make wheelbarrows micromanagement of certain mass hauling jobs.  You shouldn't want micromanagement of certain mass hauling jobs, but if you're going to want it, the fact that you're laying down tracks for a minecart, anyway, makes that a much better place to put the micromanagement.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Granite26 on February 28, 2011, 10:47:19 am
Honestly, I think carts are a bad fit for DF.  No way to lay tracks that is at all efficient.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on February 28, 2011, 11:58:40 am
Honestly, I think carts are a bad fit for DF.  No way to lay tracks that is at all efficient.

*sigh*

If you want to argue for why we shouldn't have minecarts, you shouldn't set up a front that you want to make wheelbarrows take their place beforehand, and just talk about why you don't want minecarts.  I still don't see why we can't have wheelbarrows performing the job of a backpack that carries multiple heavy items easily, since that's what the game most desperately needs, and having a fancy mobile stockpile is less useful than a backpack with a wheel.

Minecarts can handle those big repeat mass hauling jobs, since that's what minecarts are meant for.  Wheelbarrows are for carrying heavy things while being fairly mobile to respond to shifting needs to be in different areas.

Now then, as for minecarts in particular:

Quote from: The Devpage
Hauling Improvements  
  • Being able to haul multiple small objects
  • Having multiple dwarves involved with item hauling for a job
  • Being able to move multiple objects with roughly the same destination at once
  • Wheelbarrows to haul more objects than can be carried
  • Minecarts
  • Wooden, stone-carved and metal tracks
  • Can be filled like stockpiles and moved between destinations
  • Work animals to tow carts and haul objects

While I don't want to read too much into this, that at least means that Toady implicitly agrees that minecarts should go into the game, and require the ability to make tracks to make them run.  I'm no huge proponent of minecarts, but they're on the list, and so I felt like it was worth talking about how to make them more efficiently codable.

Now then, can you explain what you mean by "efficient"?  Efficient for what, exactly?
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Symmetry on February 28, 2011, 12:19:37 pm
If we look elsewhere on that list we see lifts (elevators in american?).  I can see lifts working quite like minecarts in some respects, being useful for moving lots of items from one place to another.  In any case the mechanics of this kind of thing might be worth wondering about as it looks like there will be multiple applications.

It does seem that minecarts and other kinds of mass item movement would only really be useful if mining was changed to require rock to be hauled out as well as mined.  eg.  mining creates "broken rock" that can't be pathed through and has to be hauled away one bit at a time.
 
Otherwise the best use would be building a minecart in the middle of the battlefield to help dump socks, which is a little wrong.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on February 28, 2011, 12:28:42 pm
Well, I've lobbied for slower mining and  a need to remove slag and mullock, and consolidate them as a type of wall if you cram enough into a single tile to remove them from the game's item tracking model. 

Eventually, a fortress would look like an anthill, with all the materials they dig out winding up in piles on the surface.  (Solves the quantum dumping issue by making a certain number of stones consolidate into a wall when the last stone is added into a tile.  To prevent extra checks, it only happens on the enterance of an item into the tile.)

We could wind up with something where minecarts dump mullock off a cliff, and it just piles up on the ground in a giant mound.

Eventually, though, you'd want to start backfilling all the holes in the earth you create, and just stuff your extra mullock in the empty mining shafts.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Draco18s on February 28, 2011, 12:30:15 pm
Eventually, a fortress would look like an anthill, with all the materials they dig out winding up in piles on the surface.  (Solves the quantum dumping issue by making a certain number of stones consolidate into a wall when the last stone is added into a tile.  To prevent extra checks, it only happens on the enterance of an item into the tile.)

Hilarious exploit:
If 7 stones become a "wall tile" that wall tile can then be dug out dropping.... 1 stone.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on February 28, 2011, 12:48:44 pm
Hilarious exploit:
If 7 stones become a "wall tile" that wall tile can then be dug out dropping.... 1 stone.

Part of the point of it is to make a sort of conservation of mass system in mining that weighs the entire "you can clear-cut a mountain with one pick in two years" thing down with having to actually move the stone instead of just walking through it.

Basically, the idea is that you "break" a wall by mining it into 7/7 mullock items or else maybe 6/7 mullock and 1 stone or rough gem or ore that is useful.  The mullock would sort of spill out to prevent reconsolidation, and prevent mining if there wasn't room to prevent consolidation.

(Note, I am not actually proposing a 7/7 system, which I see as just an artifact of previous map coding compression that should probably be phased out at some future point.)

If you throw mullock into a pile and it consolidates into a "consolidated mullock wall", then break that wall by mining it, it will just turn into 7 units of mullock again.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Draco18s on February 28, 2011, 01:20:08 pm
(Note, I am not actually proposing a 7/7 system, which I see as just an artifact of previous map coding compression that should probably be phased out at some future point.)

(Just as a note: Neither am I, it was a hypothetical number)

Anyway, thanks for the clarification.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Granite26 on February 28, 2011, 01:35:57 pm
Im a big fan of slower mining, and reforming walls makes a lot of sense(not as living stone, but maybe as 'granite conglomerate' that is looks the same as living granite.), esp. For processor speed.

I don't think 1 walls worth of granite should make one walls worth of G.C. though.

Also,  makes for more interesting veins if a square can contain 1-7 units of ore.  Makes them easier to follow too.

_________
As for carts, I know they are planned, I know they are popular, I just think they are a bad idea.  I wasn't trting to 'replace carts function with barrrows', because I didn't think thqt was carts job to begin with.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Symmetry on February 28, 2011, 03:34:29 pm
I completely agree they're a bad idea with the way the game works right now.  About the most use I'd get out of them is running over goblins in some kind of nightmare frogger clone.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on February 28, 2011, 03:43:13 pm
Well, lifts might be either a positively fantastic masterstroke of coding that Toady performs that allows for extremely brilliant automation of logistics, or it will simply be another manually-operated thing that requires very careful construction of pressure plate mechanisms to be able to move large pieces of fortress around in a big steampunky way.

If dwarves know how to use lifts themselves without your input, you can make those minecarts become something very special, with multiple floors of tracks and the lift acting as a sort of terminal.  You can ferry out minecarts to the mining veins, dump all the slag and worthless stone in one cart that gets automatically ferried off into the dumping grounds, while the useful ores and gems and stones get put into the other cart that goes to the central distribution center.

If I can actually design and manage a fully automated minecart logistics model in future DF, I would be beside myself in euphoria. 

Unfortunately, I don't think this is going to be coming very soon if at all, and I doubt heavily the "coming at all" part, as well.  I think we're more likely to see the "you have to move the lifts by manually ordering the pulling of a lever" type of mechanics.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Symmetry on February 28, 2011, 04:05:45 pm
If they're both manually operated then they're going to need to carry a huge amount of rock to justify the overhead of operating them, let alone the overhead of building them and their tracks.  (sidenote, I think some mines used grooves carved in the floor which might work better)
Moving water or magma around might possibly be another use?  If you can move large amounts at once it would help stop evaporation problems, and it would be worth the overhead compared to building a pump network in some cases.

I am looking forward to sections of the fortress moving though, if only for a "Transformers: Fortresses in Disguise" thread.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Granite26 on February 28, 2011, 05:01:08 pm
If they're both manually operated then they're going to need to carry a huge amount of rock to justify the overhead of operating them, let alone the overhead of building them and their tracks.  (sidenote, I think some mines used grooves carved in the floor which might work better)
Moving water or magma around might possibly be another use?  If you can move large amounts at once it would help stop evaporation problems, and it would be worth the overhead compared to building a pump network in some cases.

Wow, nice... grooves could make the whole shebang work.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on February 28, 2011, 05:03:57 pm
If they're both manually operated then they're going to need to carry a huge amount of rock to justify the overhead of operating them, let alone the overhead of building them and their tracks.  (sidenote, I think some mines used grooves carved in the floor which might work better)
Moving water or magma around might possibly be another use?  If you can move large amounts at once it would help stop evaporation problems, and it would be worth the overhead compared to building a pump network in some cases.

I am looking forward to sections of the fortress moving though, if only for a "Transformers: Fortresses in Disguise" thread.

Yes, I have no doubt that the first thing everyone will do upon the instant a version of DF with moving fortress parts is released is to build a horde of giant spider walkers that vomit magma at attacking goblins.  I look forward to the arms race.  (I also wonder if "improved sieging" will include goblin spider walkers with magma, just as part of that arms race - SURPRISE, SUCKERS! Remember that child the goblins kidnapped 4 years ago?  Now goblins have the secrets of magma-spewing spider-walkers, too!)

Anyway, I think that stone tracks would be by far the most preferred method of running a minecart, and could probably just be designated to be carved into the floor as you go.  Maybe it would be slower than a metal track, but it's a world less annoying than actually using a metal bar to extend a minecart track to the next set of iron ore that you are going to convert into the steel that you will only use extending the mine cart tracks.  Even if one steel bar made 10 tiles of track, you're asking a lot, and I expect it would only be really useful in the truly important areas where additional speed in movement would be worth almost any material price.

Shipping magma by minecart seems both crazy and dwarfy, if not quite as dwarfy as the utterly insane magma piston.  I can't wait for mechanics that include making a minecart going down a ramp speed the cart up, and make turns along the track "slosh out" some of the magma onto unsuspecting dwarves, or runaway minecarts create Frogger-style !!Fun!! for your miners or maybe some goblins.  OK, so maybe not a big utility to the average player, but it is some sadistic fun.  Plus, I still have fond memories of designing roller coasters in some old theme park simulator games, where you had to keep the actual physics of how fast your roller coaster was going in mind.  That seems like the sort of fun and/or Fun that DF is made for.

... with all that said, I think we've sailed waaaay off topic in the past couple pages.  Weren't we talking about ways to optimize pathfinding before?

Or is there nothing left to talk about regarding how to make gathering as many items as possible into the most efficient task processor-wise possible?


Darn my lengthy posts and tendency to get ninjad for it...

Wow, nice... grooves could make the whole shebang work.

Yeah, I think the best way to handle carts would be just designating mining tracks as you carve through the rock, and designating certain "stops" by hand if need be, although just having the dwarves automatically know where best to place their minecart would be the ideal solution, if one that might take some fancy (if fortunately infrequent) pathfinding decisions.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Silverionmox on February 28, 2011, 06:15:16 pm
Mine carts on rails would really only be justified for the continuous mining of huge deposits of ore and coal. While I'm not against crossing the tech border in specific cases, there's a reason mine carts didn't really turn up before the industrial revolution and mass production: too much trouble for those relatively small quantities of goods. So I suspect that mine carts will only see much use for the future huge, concentrated deposits that will be mined for years: only there the distance from the items to the mine cart will always be small.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on February 28, 2011, 06:52:26 pm
Mine carts on rails would really only be justified for the continuous mining of huge deposits of ore and coal. While I'm not against crossing the tech border in specific cases, there's a reason mine carts didn't really turn up before the industrial revolution and mass production: too much trouble for those relatively small quantities of goods. So I suspect that mine carts will only see much use for the future huge, concentrated deposits that will be mined for years: only there the distance from the items to the mine cart will always be small.

There are several cases I can think of for routine bulk hauling jobs in DF, though - first is wood dumping down a pit to the furnaces for conversion to charcoal.  The wood would have to be collected manually, but the central pit could be de-forbidden routinely by the player, and have a minecart pick up large loads of wood to carry it to the furnaces.  In an ideal world, you could have that dump site just dump wood directly into the minecart waiting at the bottom, and that whole process would be automated.

Next is sending a minecart up to your "killzone" to carry down all the goblin armor for melting.  Preferably protecting the cart's pathway with a drawbridge that has a rail track on it.

Finally, a path from a central "finished goods" stockpile to the trading depot.  Just shove it all on the cart, and dump the cart onto the depot.

There's also just designating the stone rails to be built along the mine veins instead of simply creating normal floors, which would mean that as you dig, the minecart's reach extends along with the vein.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Granite26 on February 28, 2011, 07:10:35 pm

Yes, I have no doubt that the first thing everyone will do upon the instant a version of DF with moving fortress parts is released is to build a horde of giant spider walkers that vomit magma at attacking goblins.  I look forward to the arms race.  (I also wonder if "improved sieging" will include goblin spider walkers with magma, just as part of that arms race - SURPRISE, SUCKERS! Remember that child the goblins kidnapped 4 years ago?  Now goblins have the secrets of magma-spewing spider-walkers, too!)


spat coke....
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on February 28, 2011, 07:29:25 pm
I'm already concieving of ways to build a "spider walker" - assuming they cannot rotate, they would need two sets of legs, one to move north/south, and another to move east/west, and you could basically put a ring of fortifications at the top, and a ring of fortifications near the bottom, sticking out as a downward bubble, and have marksdwarves staff the walker. 

Then, if goblins come with walkers of their own, we could have marksdwarves launch bolts at the rival walkers, and then try to launch a gangplank to board the enemy walkers.

Basically, land-naval battles.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Symmetry on March 01, 2011, 12:54:47 pm
... with all that said, I think we've sailed waaaay off topic in the past couple pages.  Weren't we talking about ways to optimize pathfinding before?

Or is there nothing left to talk about regarding how to make gathering as many items as possible into the most efficient task processor-wise possible?

There is but it's hard to think of an efficient algorithm to solve a problem we don't understand.  If we accept that the only use of minecarts (And related lifts, etc.) is to move things from one or two specific locations or stockpiles, to a few other specific locations, and we think manual control is tolerable, then that sets some fairly easy limits on what the algorithm is actually expected to cope with.  In this case we don't really have to change the algorithm at all, we just have a minecart that create store jobs like a stockpile.

Similarly for multiple hauling problems we really care about cleaning out workshops, stacking rocks (possibly into minecarts) and perhaps one or two jobs that need two ingredients (brewing with a barrel and plump helmet for example). 
The cases where the items are next to each other, or in the same place, are the easiest here as already discussed.  Multiple ingredients is harder, though as we're only trying to improve on the time spent running around and calculating at the moment the dwarf could go for the lightest item first (obv.), then when they get it look for the other item it would get if it was at the workshop (normal rubbish 3D cartesian distance, which needs fixing too but that's a different problem), then path to the new item directly, and then back to the workshop.

This is three pathfinds rather than four, although in the worst case it's possible they will cover the same number of tiles as currently.

If Toady does try and fix the 3D cartesian distance item lookup too then there are a lot of possibilities, but they involve so much work I think it might be best left for him to deal with.  Too many tradeoffs based around what he's comfortable with coding and maintaining.

Also it seems to me the wheelbarrow problem discussed earlier is identical to the current situation with water buckets.  They do make a mess of my hospital.
I don't have anything more useful to say on that except people wearing wheelbarrows makes it much simpler :)
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Maklak on March 01, 2011, 03:46:08 pm
I'd also like to see an improvement to stockpiles: one pointer for taking items from another stockpile and one for giving to another stockpile. While not a true n:m relationship, it would still be more versatile than the current system, where a stockpile can be given items by many stockpiles, but one stockpile can give items to only one stockpile. With my suggestion giving and taking are functionally similar, but distinct. Any stockpile could give items to one stockpile and take items from one stockpile. That way you could have 1:n and n:1 in various combinations, and m:n would require a "relay" stockpile in the middle (m:n could be formed by m:1 and 1:n). It would ofc require coding various borderline cases (Can stockpile A take from B, while B gives to A? etc)

I'm not sure I follow you on this one...


Quote from: magmawiki
Each stockpile can take from any number of other stockpiles, but can only have one stockpile taking from it in turn. This limit applies even if the two stockpiles you want it to feed into don't share a single material that can be stored in both of them. Additionally, you can't make two stockpiles feed into each other, although larger loops (e.g. 3 stockpiles that feed into each other in a circle) are allowed.


I'm suggesting, that apart from "take from a pile" we get "give to a pile". Each workhop would only get one "take from a pile", and one "give to a pile", but a stockpile could have multiple stockpiles taking from it, and giving to it. It is kinda confusing, as taking and giving are not the same, yet work similar (items get moved).

"Give to a pile" could be used for making a central stockpile 'sink' items from other stockpiles, pretty much like we can do with the current system.

"Take from a pile" could be used to make multiple small stockpiles (workshops input, prison cell foodstores, etc) take from one central stockpile.

For this to work each stockpile would only need two pointers: one to from where it takes and one to where it gives items. At each iteration of stockpiles looking for items, these two pointers would be checked for each stockpile. Things like stockpile item count, and tasking items to be moved are already in the code, so it probaly wouldn't be difficult to implement (and easier than n stocpiles taking from m stockpiles), and it would geve players more options with logistisc, which this thread is about. 
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Draco18s on March 01, 2011, 03:54:47 pm
Just like to point out that both of those do the same thing.  I'm all in favor of adding another UI option, but mechanically those are identical.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Granite26 on March 01, 2011, 04:01:18 pm
I wrote up a proposal for stockpiles that didn't want to be filled (only craftsmen used them to save from walking.), Ones that did want to be filled(stocking multiple dining rooms) and ones thqt don't care.(warehouses).

If you get your restrictions right, everything works from there.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Maklak on March 01, 2011, 04:11:50 pm
Just like to point out that both of those do the same thing.  I'm all in favor of adding another UI option, but mechanically those are identical.
They are identical in that weather A takes from B or B gives to A, items get moved from A to B. They are not identical in how they are implemented, as "take from another stockpile" fills *this stockpile, and "give to another stockpile" empties *this stockpile. This suggestion is also different from what we have now in that multiple stockpiles could take from one stockpile as well as one stockpile could be given by many stockpiles. In the current system (unless wiki is wrong) a stockpile can take from multiple stockpiles, but any stockpiles can be taken from by only one stockpile.

If I still haven't made this celar, lets just drop it, faster hauling of multiple items is more important anyway.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Silverionmox on March 01, 2011, 04:22:32 pm
Saying "A gives to B" or "B takes from A" will have the same effect... You're just allowing two links instead of one. Multiple links would be useful though. For example, if you want to supply a carpenter, an ashery and a siege workshop with their own stockpiles from a central wood stockpile.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Draco18s on March 01, 2011, 04:39:05 pm
Saying "A gives to B" or "B takes from A" will have the same effect... You're just allowing two links instead of one.

Precisely.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Sowelu on March 01, 2011, 05:47:12 pm
Personally, I think that a major hauling improvement could be gained by letting dwarves poach jobs from other dwarves.  Once you're picking up five objects in one go, you start running into situations like the way that dwarves mine.  "I'll mine out all but one tile of this room, and leave it for the other dwarf who's hustling over from across the map!"

Let dwarves keep track of estimated time remaining that it will take to complete a goal.  If another dwarf is close enough that they can complete it a lot faster, let them poach it.  Hauling, mining, anything.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Granite26 on March 01, 2011, 05:49:55 pm
Personally, I think that a major hauling improvement could be gained by letting dwarves poach jobs from other dwarves.  Once you're picking up five objects in one go, you start running into situations like the way that dwarves mine.  "I'll mine out all but one tile of this room, and leave it for the other dwarf who's hustling over from across the map!"

Let dwarves keep track of estimated time remaining that it will take to complete a goal.  If another dwarf is close enough that they can complete it a lot faster, let them poach it.  Hauling, mining, anything.

You'd have to handle the serial theft case too.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Sowelu on March 01, 2011, 06:30:10 pm
Personally, I think that a major hauling improvement could be gained by letting dwarves poach jobs from other dwarves.  Once you're picking up five objects in one go, you start running into situations like the way that dwarves mine.  "I'll mine out all but one tile of this room, and leave it for the other dwarf who's hustling over from across the map!"

Let dwarves keep track of estimated time remaining that it will take to complete a goal.  If another dwarf is close enough that they can complete it a lot faster, let them poach it.  Hauling, mining, anything.

You'd have to handle the serial theft case too.

Seems easy enough.  Only take the job if you are significantly closer (say, will complete it in 50% the time), and don't take a job that's already far enough in progress (already holding item to be hauled, already mining the square, etc).
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on March 01, 2011, 06:50:14 pm
There is but it's hard to think of an efficient algorithm to solve a problem we don't understand.  If we accept that the only use of minecarts (And related lifts, etc.) is to move things from one or two specific locations or stockpiles, to a few other specific locations, and we think manual control is tolerable, then that sets some fairly easy limits on what the algorithm is actually expected to cope with.  In this case we don't really have to change the algorithm at all, we just have a minecart that create store jobs like a stockpile.

Well, if we don't understand it, it's time to think about it more until we do.   :P

There shouldn't be any more manual control than absolutely necessary.

OK, let's think logically about how a minecart should probably operate... Unless you want to have the carts pushed around manually waiting at one point or another, then what we need to do is have a way for dwarves to know when it is fine to use a cart as a stockpile, and what areas that cart has connections to when you want to use it as a bulk transport. 

Without having to make your dwarves do a really complicated pathfinding check to see when it is acceptable to try to use a minecart, the only thing I can think of is to make a minecart track create its own zone upon creation.  Presumably, this will be connected to every other piece of track, lest it be useless, so it basically forms a long, snaking zone throughout the areas you have built those tracks, connecting everything together. 

This minecart zone would spread some arbitrary (possibly player-togglable) number of tiles out from the tracks, and when a dwarf tries to take up a job involving hauling, it will check to see if the item to be hauled is within the zone of the tracks, and if the destination is within the zone of the tracks.  Pathfinding along tracks, barring some really kooky behavior on the part of the player, should be very easy, so you could probably do a count of how many tiles it takes to get from start to finish fairly fast, but you could have either a pathfinding check to see what a straight walk would be, anyway, to see how many more tiles one would have to travel by foot, and compare that against the minecart's pathing if you want to be really accurate and save as much dwarf travel time as possible.  (Again, this is a matter of CPU efficiency vs. Dwarf motion efficiency.)  This would have to include the time/tiles it takes a cart-hauling dwarf to actually move the cart into position.

Before using a minecart even makes sense, however, you need to have a set number of items in the area to even make it more useful than just hauling everything by hand. 

This is a possible calculation, of course, it's just a very wierd one, since it means that you have to get the dwarf to calculate how many trips it would take the dwarf back and forth without using the cart vs. how many trips it takes with a cart, plus the amount of time you have to spend getting the cart into position, plus the amount of time it takes to get the dwarf to the cart to start pushing it... and these might have to be done by quick-and-dirty calculations to save on pathfinding time, and prevent a dwarf from just sitting there and making a dozen pathfinding calculations and then winding up just doing the simple pick up the earrings all by himself since it was only very light items type of solution. 

The player might have some sort of ability to interfere with how the zones are set up - letting the player exclude some areas from being in zones, and include larger areas than the cart would normally allow to be in zones, if need be.  It might just be a separate part of the zones menu, or some special cart extension of the zones menu. 

Cart zone tiles would theoretically also be able to include areas that are still walls as part of the zones, so that the yet-to-be mined portions of the mines would already be included in the cart zone... but that causes problems because you don't want zones that are on other sides of walls to be included.  The other solution is to make any tile that is made into a floor with no blocking wall tile take another check when the pathfinding connectivity map is running to see if any adjacent tile is already in a minecart zone, and if so, check for cart tracks within a finite number of steps (flood style) to see if it should be connected to the minecart zone.  This would mean that a tile that was recently mined would declare itself part of a minecart zone, and then tell the stone hauling job of the stone the wall became to become a potential minecart hauling job if its destination is part of the minecart zone's sphere of influence, as well. 

... OK, that's all that a first-blush look at how to make a minecart path will tell me... so could someone blow this idea up for me so I can try to think of a better way to rebuild it?



Gah.. so many people posting in this thread...  7 replies... I need to stop reading books in the middle of posts.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Granite26 on March 01, 2011, 07:05:42 pm
Does the 'take from stockpile' command wait until there's a full bin?  That could be a very low hanging fruit
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Silverionmox on March 02, 2011, 01:45:24 pm
Personally, I think that a major hauling improvement could be gained by letting dwarves poach jobs from other dwarves.  Once you're picking up five objects in one go, you start running into situations like the way that dwarves mine.  "I'll mine out all but one tile of this room, and leave it for the other dwarf who's hustling over from across the map!"

Let dwarves keep track of estimated time remaining that it will take to complete a goal.  If another dwarf is close enough that they can complete it a lot faster, let them poach it.  Hauling, mining, anything.
That would possibly involve a lot of calculations to see whether and if a suitable dwarf is close, and then if he is close enough.

I think grouping jobs would be very useful: you'd have some parameters in the init, or an options screen in-game, that determines the size of the job groupings (eg. 250, 50, 5 or 1 (= free-for-all, like it is now)) for each type of job. Instead of a single job, a group of jobs would be assigned to a dwarf. Another dwarf can take over when the first is tired. (That would also serve as a kind of priority system: if the group sizes are large, there will be fewer dwarves working on them, and they'll take longer to be completed, keeping your other dwarves unoccupied.) All in all, it would reduce job assignment inefficiency, preventing logical job groupings to be splintered and dwarves run over to mine just a single square (which will reduce pathfinding needs as well, if the jobs of a particular dwarf are grouped in one place). Jobs are already sequentially grouped in workshops, so it's not far-fetched to apply it to other jobs, like hauling, woodcutting, dumping, mining etc. that are typically generated in large quantities at once.

Continuing in that vein, one could also group dwarves in teams much like and assign the job groups to them. That would also work nicely with a future apprentice system (they are all working on the same job, but use the skill of the master, while still allowing the apprentices to gain experience). It would be somewhat similar to squads, which is good because you'll want to determine their uniform/job clothing as well. Leather aprons for my smiths, helmets for my miners!
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Granite26 on March 02, 2011, 04:21:40 pm
Personally, I think that a major hauling improvement could be gained by letting dwarves poach jobs from other dwarves.  Once you're picking up five objects in one go, you start running into situations like the way that dwarves mine.  "I'll mine out all but one tile of this room, and leave it for the other dwarf who's hustling over from across the map!"

Let dwarves keep track of estimated time remaining that it will take to complete a goal.  If another dwarf is close enough that they can complete it a lot faster, let them poach it.  Hauling, mining, anything.

You'd have to handle the serial theft case too.

Seems easy enough.  Only take the job if you are significantly closer (say, will complete it in 50% the time), and don't take a job that's already far enough in progress (already holding item to be hauled, already mining the square, etc).

What I mean is, take a 3x3 room and (d) all the walls.   If you have 2 miners, one might take the other miners job all the way around the room.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Draco18s on March 02, 2011, 04:28:50 pm
What I mean is, take a 3x3 room and (d) all the walls.   If you have 2 miners, one might take the other miners job all the way around the room.

Explain further.

1) Why would miner 1 steal a job prior to his own being completed.
2) Why would miner 1 steal a job prior to completing every other available job in said 3x3 room.

E.g. prioritize untaken jobs that are at the same (or equivalent) distance.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Granite26 on March 02, 2011, 04:55:37 pm
I didn't mean it wouldn't work, just that it was a wrinkle.  Wrinkles are expensive.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Mike Mayday on April 01, 2012, 01:21:48 pm
I asked Draco to link the ESV item to this discussion, so let me also post a link the other thread with hauling+stockpile suggestions (just in case).
http://www.bay12forums.com/smf/index.php?topic=104479.0
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: zwei on April 01, 2012, 01:42:23 pm
I think "naive" implementation would be rather painless to implement and very effective.

Naive is that while dwarf is carrying item to stockpile he checks whether each tile he steps on contains item that can be also put to same stockpile and is not tasked already, we will add it to carried bundle.

No extra pathing needed, only one check per item on each tile of path. Should be effective for batlefield clean up, field harvesting and gathering ores/stones. Anywhere where dwarf is likely to walk over objects of same type.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on April 01, 2012, 03:01:05 pm
I just modified a post from the first page of this discussion, since I have been thinking more and more about abstraction lately.

It's from the post on how to handle the data of items put into stacks:

Edit from a long time later:
Actually, you could track item wear or damage more abstractly, if you don't mind a loss of granularity over some types of items.  (If you are stacking them, anyway, then you shouldn't be all that concerned with granular details.)

Simply track an abstract "Average" wear or damage number, and then a "Standard Deviation" number, and bell-curve the results abstractly.  Hence, throwing a badly damaged item into a stack of reasonably well-maintained items will result in not just a drop in the average wear, but also a spike in the standard deviation, so the bell-curve will be spread out, and abstractly include plenty of low-wear items as well as a few outlier damaged items.

Dwarves could simply draw at random or puposefully pick the most damaged or most repaired ones as specified (so that if they are looking for socks in a sock pile, they would probably want to pick the least threadbare socks to own for themselves).

This would mean that a stack of socks would have its "threadbareness" data blurred between each other, but still keep some granularity as to whether or not some socks are more worn down than others.

It wouldn't be useful in terms of items where you absolutely want to keep track of how good of a repair an item is, like a named sword with a hundred kills, but those sorts of things are the types of things that probably just shouldn't stack at all, anyway.

For iron bolts or pig tail fiber socks, which don't need that sort of tracking data, it's good enough.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Tirunus on April 01, 2012, 03:31:25 pm
Tldr I am a rageing Sissy and want things to not be horribly inefficient.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Kogut on April 04, 2012, 01:39:04 am
Please, RAWify stockpiles (p menu and settings of stockpiles), I hate disabling seeds, fat and extracts on every single food stockpile in every single game.

Reposted from http://www.bay12forums.com/smf/index.php?topic=104479.0 (as this thread is linked to ESV)
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on April 04, 2012, 05:01:59 pm
Please, RAWify stockpiles (p menu and settings of stockpiles), I hate disabling seeds, fat and extracts on every single food stockpile in every single game.

Reposted from http://www.bay12forums.com/smf/index.php?topic=104479.0 (as this thread is linked to ESV)

It is?  It is!  Wait, when did my thread get linked to the ESV?

Anyway, what I've always held is that we need not so much a "raw" as we need an "inport/export" function, similar to embark profiles or macros have now.  Functionally, these are somewhat similar in that they are basically just .txt scripts, but RAWs require actually leaving the game to modify, and I'd rather just have the ability to modify stockpiles in-game and then hit "save" and "load" as need be.

Of course, I should also point out that this isn't exactly what this thread is explicitly meant for...
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: King Mir on April 04, 2012, 05:20:02 pm
There is but it's hard to think of an efficient algorithm to solve a problem we don't understand.  If we accept that the only use of minecarts (And related lifts, etc.) is to move things from one or two specific locations or stockpiles, to a few other specific locations, and we think manual control is tolerable, then that sets some fairly easy limits on what the algorithm is actually expected to cope with.  In this case we don't really have to change the algorithm at all, we just have a minecart that create store jobs like a stockpile.

Well, if we don't understand it, it's time to think about it more until we do.   :P

... OK, that's all that a first-blush look at how to make a minecart path will tell me... so could someone blow this idea up for me so I can try to think of a better way to rebuild it?
If a minecart is an option, a dwarf should probably always choose the minecart. The trickier thing is keeping track of which goods can and cannot go on the cart. If a minecart acts like a stockpile, it needs to be connected to a stockpile to dump things in, and it needs to keep track of wich stockpiles the track is connected to.

I don't think you would necessarily have a single track that winds the full hight of the fortress. You might for mining purposes, but I imagine having issolated tracks carts for different industries, running side by side.

Quote
Gah.. so many people posting in this thread...  7 replies... I need to stop reading books in the middle of posts.
And writing them.  ;)
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on April 04, 2012, 06:32:55 pm
Quote
Gah.. so many people posting in this thread...  7 replies... I need to stop reading books in the middle of posts.
And writing them.  ;)

Are you kidding, I barely filled a page with that.  I obviously should have written something more comprehensive.

If a minecart is an option, a dwarf should probably always choose the minecart. The trickier thing is keeping track of which goods can and cannot go on the cart. If a minecart acts like a stockpile, it needs to be connected to a stockpile to dump things in, and it needs to keep track of wich stockpiles the track is connected to.

I don't think you would necessarily have a single track that winds the full hight of the fortress. You might for mining purposes, but I imagine having issolated tracks carts for different industries, running side by side.

Well, no, minecarts can't always be the option, because what if you are, say, looking to bring some food from a farm to a food stockpile, and the food stockpile is 5 tiles away, wheras the nearest mine cart is 100 tiles away, and the tracks don't even lead to anywhere within 60 tiles of the food stockpile, because you've only laid down tracks in the heavy mining segments.  You have to check to see if that's the case before making your decision, of course, but there are reasons not to go there.

As for the tracks and carts for different industries, I was thinking about this when I was talking about the "rollercoaster" aspects of the minecarts in some of the other threads, and an old idea I had about conveyor belts-

Spoiler: quoting myself (click to show/hide)

Basically, if you can create a way to "mechanize" minecart motion by throwing mechanisms under the tracks, and setting up roller-coaster style "acceleration wheels" that are simply wheels that turn due to the torque applied through mechanisms in order to push along a cart that is moving slowly enough through one of the tiles that is mechanized, it will be able to push those carts along a path, or push it up hills so that when it goes down the hills, it can just carry on its own momentum forward. 

If you build a full circuit of mechanized carts, however, you could recreate that conveyor belt approach. 

That is, if a workshop is attended, all "finished products" from a workshop could be offloaded from a workshop into a cart as it passes by, and all "raw materials" that it will need for the queued jobs can be input into the workshop without needing to have a hauling job performed - workers just automatically offload or take in whatever they need as long as they are at the workshop as the cart goes by.

Then, you can have supply chains like sending a cart track on a loop between a farm, the farmer's workshop, the dyer, the loom, the stockpile, and maybe the trade depot.  Minimize your need to actually haul things through automated movement of goods.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Mike Mayday on April 04, 2012, 06:38:33 pm
It is?  It is!  Wait, when did my thread get linked to the ESV?

I asked Draco to link the ESV item to this discussion

:P
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: King Mir on April 04, 2012, 07:30:37 pm
If a minecart is an option, a dwarf should probably always choose the minecart. The trickier thing is keeping track of which goods can and cannot go on the cart. If a minecart acts like a stockpile, it needs to be connected to a stockpile to dump things in, and it needs to keep track of wich stockpiles the track is connected to.

I don't think you would necessarily have a single track that winds the full hight of the fortress. You might for mining purposes, but I imagine having issolated tracks carts for different industries, running side by side.

Well, no, minecarts can't always be the option, because what if you are, say, looking to bring some food from a farm to a food stockpile, and the food stockpile is 5 tiles away, wheras the nearest mine cart is 100 tiles away, and the tracks don't even lead to anywhere within 60 tiles of the food stockpile, because you've only laid down tracks in the heavy mining segments.  You have to check to see if that's the case before making your decision, of course, but there are reasons not to go there.
Yeah, you still need the mine cart zones of influence. That can be a breadth first search for tiles within a certain walking distance. It could be displayed in a mannor simmilar to the depot wagon access.

Quote
As for the tracks and carts for different industries, I was thinking about this when I was talking about the "rollercoaster" aspects of the minecarts in some of the other threads, and an old idea I had about conveyor belts-

Spoiler: quoting myself (click to show/hide)

Basically, if you can create a way to "mechanize" minecart motion by throwing mechanisms under the tracks, and setting up roller-coaster style "acceleration wheels" that are simply wheels that turn due to the torque applied through mechanisms in order to push along a cart that is moving slowly enough through one of the tiles that is mechanized, it will be able to push those carts along a path, or push it up hills so that when it goes down the hills, it can just carry on its own momentum forward. 

If you build a full circuit of mechanized carts, however, you could recreate that conveyor belt approach. 

That is, if a workshop is attended, all "finished products" from a workshop could be offloaded from a workshop into a cart as it passes by, and all "raw materials" that it will need for the queued jobs can be input into the workshop without needing to have a hauling job performed - workers just automatically offload or take in whatever they need as long as they are at the workshop as the cart goes by.

Then, you can have supply chains like sending a cart track on a loop between a farm, the farmer's workshop, the dyer, the loom, the stockpile, and maybe the trade depot.  Minimize your need to actually haul things through automated movement of goods.
I'm a little weary of full on converyers in a pre-industrial setting. At some point one starts to ask "If dwarves know this much mechanics, why can't they harness steam already?". I'm not sure exactly where to draw the line, but conveyers are near it.

I'd rather have supplies moved to a nearby stockpile than dirrectly into a workshop. This avoids clutter. In addition it's more realistic and detailed. A workshop is not a building; it is perhalps a table and a few other machines that may eventually be split into individually placeable objects. The pile of raw materials doesn't need to be part of that; it can already be split off in a natual way. The ability to customize the size and raw contents of a stockpile realistically model how materials are stored near a workshop. This is not to say that job orders should not also specify material or that the take-from system does not need improvement. 

I'm not sure that I agree that hauling should be minimised as a rule. Hauling should be realistic, nothing more.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on April 04, 2012, 08:55:28 pm
Waterwheels turning belts that ran powered looms existed before steam did.  They were basically big wheels that had a long leather loop that ran between them, and that's basically all you need to make a conveyor belt. 

If you have all this mechanical power and drawbridges that raise up from water hitting a pressure plate, and mine carts that can be sent along, then just putting something on top of the leather belts running the power down the line in order to send it down the line for you is a simple task that takes no more technological progress than what we already are working with.

As for workshops, I'm simply picturing them as having some sort of bin or something next to the counter, where they store all the junk they've finished making but haven't sent off to the stockpile yet.  Workshops we have now get cluttered with all the stone doors and stuff we've built and are waiting for hauling.  This just lets the craftsdwarf toss that bin's contents into the minecart when it trundles by.

The important part is the bit about being able to set up a fortress that runs more-or-less on its own, with the ability to just tell the clothier at the loom to just keep weaving socks as long as dyed cloth keeps coming down the line.

It's also a thing about "look how cool my fortress is that it has this automated delivery system".  Sort of like the people who want to make minecart rides for "dwarven rollercoasters".
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Tierre on May 21, 2012, 08:21:07 am
Just wanted to reviwe a thread as it is in ESV. So it is here we need to discuss implemented carts and wheelbarrows and speak of what is left to do.

For hauling improvements - i think bin and barrel jobs have a lot of work in polishing to do. Like stuck dwarfes and taking barrel to get 1 plump helmet.

Wheelbarrows and minecarts are prety good (i don't have enough time to see if they have any major problems in them).

Also stacking is what everybody still wants (in my opinion at least).
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: therealmarauder on May 21, 2012, 10:15:14 am
I've been using minecarts as actual minecarts, moving heavy ores to my dump chute. I do that by making a stockpile over the ores and taking from that stockpile, so the dwarves don't do something dumb like walking to my ore dump location and taking the ores from there, hauling them up 60 flights of stairs and 200 tiles to my cart, then putting them in the cart that'll dump them down the shaft.

The problem I see is that it acts exactly like dumping. Instead of the sane thing to do, which is having one dwarf and ONLY one dwarf doing hauling tasks to or from a mine cart, five dwarves come down from the fortress into the mines and each hauls a single ore into the stockpile. This is horrible for me! It ties up six dwarves and they spend maybe 5% of time actually working.

Therefore, I'd like to see minecarts act more like workshops in this regard. I think it's reasonable for one dwarf to operate a minecart at a time. Dwarves do that with wheelbarrows, but not the carts. If only one dwarf were allowed to work on the cart at a time, then ores would be moved one at a time, slowly, from a distance of at most 20 steps, and this would happen five times, with all of that time spent working and none of it walking to and from the fortress. Then the single dwarf would be able to push the cart to the chute and back, which would be much faster.

Can we put a cap on the number of haulers? Maybe wheelbarrows can be added to cart stops. The sanest thing for dwarves to do would be to leave one wheelbarrow at the loading point, and have one dwarf move ores to the cart with the wheelbarrow, which would improve ore hauling efficiency at least 20x over the current method, but would not alter the power of minecarts.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: therealmarauder on May 22, 2012, 08:52:25 pm
I'm surprised this thread's buried.

It seems like mine carts could be integrated into pathing more strongly. This might belong to another post altogether, but pathing should allow for automation which is specified to dwarves. A dwarven highway could easily exist using rollers to quickly zip dwarves around the fortress, but those dwarves can't path using the highway. If dwarves can be allowed to path through mine cart systems, pathing to a mine cart then placing it on any route and using the route to move, dwarves could automatically use the mine cart system, especially if pathing with a rock cost more than pathing with a mine cart on a track. Using tools to reduce pathing costs would give an alternative to tying them to buildings or stockpiles, since dwarves could automatically use tools when they're beneficial.

Then again, simply modifying the mine carts to be used by one user at a time would make quite a difference in how effective they are. Many of the issues in hauling behavior lie in lack of job clustering, which is accomplished by workshops in other systems. No one washes one dish and then drives to work to reply to one email and then drives to the store five times to get five different things. Dwarves should grab tasks near where they are and they should grab small clusters of jobs when they grab a job. This applies generally to hauling, but also to lever-pulling and other jobs, like mining, where huge jumps are common when digging in multiple locations.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Sowelu on May 23, 2012, 04:08:28 pm
The highway idea might have issues if more than one dwarf wants to use the same highway.  Boom.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Andeerz on May 23, 2012, 05:24:55 pm
In response to NW_Kohaku and anyone else that might be interested, things akin to conveyor belts certainly existed way before 1400... chain pumps (http://en.wikipedia.org/wiki/Chain_pump) come to mind!
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Silverionmox on May 24, 2012, 05:29:08 pm
In response to NW_Kohaku and anyone else that might be interested, things akin to conveyor belts certainly existed way before 1400... chain pumps (http://en.wikipedia.org/wiki/Chain_pump) come to mind!
Well, something like a steam engine existed too, but it's mostly a matter of atmosphere. In addition, mass production would upset the economics of the world, and consequently everything else.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Andeerz on May 24, 2012, 06:05:07 pm
But keep in mind... mass production isn't as much about technology available as availability of labor, raw materials, and need for products (though, arguably, the "need" for products could be "invented" too!).

I say, go ahead with whatever tech before 1400 or whatever, even if it is something that would allow for mass production kind of stuff.  I think so long as time, labor, and raw material  requirements and the like are well modeled for whatever economic activity, the economics and medieval-esque fantasy setting will not be disturbed...

EDIT: Maybe steam engines should be out... unless something like a system of knowledge spread and technological development were implemented in a realistic way, though how that would be possible might require stuff way beyond what this game is intending to do or what computers are able to handle (though I just found a pretty neat branch of mathematical sciences dealing with technological progression and its modeling!!!  Perhaps more will come later...) 

Anyway, the reason I say this is that, yeah, the aelopile or whatever existed and all that, and it probably wouldn't have been beyond the comprehension of those ancient inventors to see the possibilities of steam power, but I believe that what probably kept people from developing effective steam engines before the 1700's or whatever was a slow rate of communication, sharing of ideas and designs, exacerbated by lack of literacy, social mobility, and a whole host of other factors... including availability of raw materials, sophistication of metalworking techniques, yadda yadda yadda... and they are all interconnected.  I really want to develop an idea for technological progression and/or knowledge spread and/or designs and stuff that would incorporate stuff like NW_Kohaku's Class Warfare ideas that I think would be absolutely key... and such a model would be necessary to have steam power have the possibility of making it into the game without it upsetting the economics of the world, the medieval fell, and whatever.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: kaenneth on May 24, 2012, 06:17:18 pm
Do you think it would be difficult to add a "Profile" setting to Stockpiles/Cart Stops like for Workshops, to be able to restrict who/how many haulers work of bringing items to it?
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Draco18s on May 25, 2012, 09:13:52 am
I believe that what probably kept people from developing effective steam engines before the 1700's or whatever was a slow rate of communication, sharing of ideas and designs, exacerbated by lack of literacy, social mobility, and a whole host of other factors...

Steam engines were known for thousands of years.  Ah la aeolipiles (http://en.wikipedia.org/wiki/Aeolipile), but no one could figure out how to harness the motion generated.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on May 25, 2012, 09:23:40 am
Actually, in my history of technology class I took, there was a pretty funny/sad and probably apocryphal story I was told about the first steam engines:

The first steam engines put to actual practical use were put into use in coal mines in England.  You see, they needed fuel for their steel industry, and they used to use charcoal for steel, but England had basically been cutting down all its trees because of increased steel production as it was expanding its empire, and needed more and more fuel for its steel.  So they went to mining coal as a last resort. 

All the easiest-to-reach coal was already burned, though, so they had to get the hard-to-reach stuff, instead.  And the hard-to-reach stuff was in flooded mines.

So they found a way to turn steam pressure into pnuematic pressure, where a fire was lit, steam built up pressure, and then a lever was pulled to have that pressure released, and push a piston that sucked water out of the mine.  This meant that they could start using coal to fire a machine that would help them mine more coal... However, the problem was that someone had to manually stand there pulling the lever only when the pressure was high enough, as measured by a pressure guage.

Because this was a ridiculously easy job, and it took no effort, and was boring as crap, they of course turned to that classic Industrial Revolution staple: Child labor!

So a boy was standing there all day watching a guage hit maximum before pulling the lever when he got an idea: He simply devised a system to tie the gauge by a string to the lever, so that when the gauge hit the pressure levels it took before he could pull the lever, the gauge would pull the lever for him.  Then he ran off and played. 

When the boss came back and realized that his child worker had just devised a labor-saving technique that eliminated the need for a human being to do stupid, repetitive labor, and vastly improved efficiency and safety, he did the only rational thing, and rewarded the child by firing him, because his position had now been eliminated.

And thus the modern age of industry was born.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Draco18s on May 25, 2012, 09:55:11 am
So a boy was standing there all day watching a guage hit maximum before pulling the lever when he got an idea: He simply devised a system to tie the gauge by a string to the lever, so that when the gauge hit the pressure levels it took before he could pull the lever, the gauge would pull the lever for him.  Then he ran off and played.

If you want something done efficiently, ask a lazy person to do it.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on May 25, 2012, 10:19:41 am
So a boy was standing there all day watching a guage hit maximum before pulling the lever when he got an idea: He simply devised a system to tie the gauge by a string to the lever, so that when the gauge hit the pressure levels it took before he could pull the lever, the gauge would pull the lever for him.  Then he ran off and played.

If you want something done efficiently, ask a lazy person to do it.

For that same class, I had to do research on the earliest times of computing (around the 1960s), and how people were reacting to it, and what their new expectations for computers were shaping up to be.

One guy, who I can't remember off the top of my head, said something that stuck with me, that went something like: "We all have these visions of a Jetsons future where man is so lazy that he will find a way for machines to do all his work for him until it reduces the work we do down to just pushing a single button.  These people have limited imaginations, for they don't understand that as soon as man has reduced all his work down to pushing a single button, the only thought that fills his head is how to make the machine press the button for him, too."

But really, that's how technology works: We have these crazy ideas of technological innovation coming from some single individual inventor like Alexander Bell inventing the telephone, but that's a total exception to the rule - Tesla and Bell and Edison all came at a time when a totally new basis upon which technology could be built was already developed.  True advancement doesn't come until long after the research is over, and the development is in play.  We had notions of electricity for centuries before that, but only when we started having the Industrial Revolution and machine tools to mass produce the means of transmitting electricity over long distances, and the machines to create the power that could create the electricity did that ever mean anything.  It's only when you had power plants that anyone could invent a lightbulb or telephone or electric motor. 

Real technological advancement comes from the kids you stick in the factory who have to push a button all day with nothing left to think about but how to find a way to make the machine push the stupid button for them, because there's no reason a human actually needs to be there to do something as boring and routine as button-pushing.  When you get the machine to push the button for you, you can run the whole factory with one guy who only has to walk by every now and again to make sure the whole thing isn't on fire, and the machine is still doing its job. 

That's how productivity per capita soars, and productivity per capita is how humanity advances.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Draco18s on May 25, 2012, 10:47:03 am
When you get the machine to push the button for you, you can run the whole factory with one guy who only has to walk by every now and again to make sure the whole thing isn't on fire, and the machine is still doing its job.

And even that you can outsource to a machine.

There's a 365T (http://365tomorrows.com/) on this topic somewhere, but I can't remember enough detail to know what to search for.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on May 25, 2012, 12:12:28 pm
When you get the machine to push the button for you, you can run the whole factory with one guy who only has to walk by every now and again to make sure the whole thing isn't on fire, and the machine is still doing its job.

And even that you can outsource to a machine.

There's a 365T (http://365tomorrows.com/) on this topic somewhere, but I can't remember enough detail to know what to search for.

Well, it's sort of the whole point of the arch of the history of technological progress.

I remember one argument I had about tech trees where I had a lot of trouble drilling this home to people, but it goes like this:

In the time before written histories, the typical peasant lived pretty much the same life they lived all the way up to the 17th century.  That is, one peasant worked a field of 5 acres.  Granted, earlier on, they only worked about 3 acres, until they could get slightly better tools that made working the farm easier, around the time of the ancient Egyptians, but basically, throughout all of history, around 90% of the population was doing just that: working 5 acres of farm.  (Exceptions of course to shepherd cultures, but those were even less changing with time than the farming cultures.) 

They could have improved agricultural yield with metal tools like steel plows, but steel was too expensive and rare to supply to most of the populace, so instead, they used wooden plows and oxes to plow the soil, and they could only work 5 acres.  This is because giving those average humans a greater share of the products of work was impossible - they just couldn't find a way to produce those metal goods for everyone unless they got everyone to do it themselves.  On the grand macroeconomic scale, it didn't matter if you were caveman, roman, dark ages peasant, middle ages peasant, Native American, or citizen of some great European empire during the age of exploration - the amount of goods in your life was always the same - what you and your family could produce for yourselves by hand, or maybe trade for from a little side business.

If you look at a graph of human productivity, it's basically a flat line all the way to the 18th century.  Why?  Because human productivity was directly tied to the number of humans and their animals alive to do work.  Both took food.  Food took arable land and people working that land - 90% of the people working that land.  Therefore, the amount of human productivity could never exceed the amount of arable land under the plow times the productive yield of that land. 

Therefore, human productivity could go up very, very slightly through techniques like the printing press where humans found a way to make their tools slightly better, but they still, fundamentally, were based upon human power.  And as long as it was based upon human power, it could never exceed human population. 

This only EVER[/b] changed with the introduction of steam power.  Now, you have the ability to make the machine do the work for the lazy human.  The lazy human can make the machine do the work for them, while they just pull the lever.  Then, they can make the machine pull the lever for them, and they just have to watch the machine.  Then, they can make another machine watch that machine, and you just have to have a human watch the machines watching the hundreds of other machines.  Now, one human is doing the work that once took tens of thousands of humans to do.

Now, you can produce ten thousand times as much product from ten thousand times as much work from a single human being. 

Now, on the grand macroeconomic scale, we have the actual capacity to produce far, far, more than we ever could per human, and that means we have the capacity to distribute to those humans not just enough food to ensure they aren't going to go hungry, but all sorts of wastefully unnecessary goods.  In fact, we produce so much we have to invent a culture of excess just to buy all the goods and then throw them away just to justify having all the productivity we do. 

We now have - for the ONLY time in human history - the utter fluke of a perspective that technology always inherently advances, and that is a good thing, instead of the classical fear of technology and knowledge.  This is because our economic model is based upon eternal growth of demand.  Therefore, we have to constantly innovate new ways to supply that demand and new ways to make people demand more things they don't really need. 

Now, we are approaching The Singularity.  The point where we have not just made the machine do the work for us, but the machine thinks for us, too.  The Singularity is the point where we make self-evolving AIs, which is to say, we make the machines so advanced that we make the machines make the machines better at pushing the button for us. 

It's called The Singularity because it is the point beyond which we cannot predict anything.  Once we have outsourced the job of finding better ways to be lazy to the machines, as well, it inherently means we are no longer going to understand the ways in which the machines are going to be becoming more advanced, and how they are figuring out faster ways to make other machines that make other machines that make other machines that watch the machines that press the buttons that make the machines do the work for the few redundant humans whose only job left remaining is trying to find a way to justify why they built all that crap in the first place. 

So I, for one, welcome our new AI overlords.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Draco18s on May 25, 2012, 12:25:19 pm
So I, for one, welcome our new AI overlords.

I don't, per say, but I will enjoy what comes with them.  Probably.  It depends on if we get a benevolent AI or not.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on May 25, 2012, 12:43:06 pm
So I, for one, welcome our new AI overlords.

I don't, per say, but I will enjoy what comes with them.  Probably.  It depends on if we get a benevolent AI or not.

Well, the only thing to really know about human history was that it was all just a lot of spinning of wheels, just waiting for a jump that took less than three centuries to complete.  That's only about 9 or 10 generations.  All the generations before that were just wasting their time.

Depending on whether or not the AI overlords are benevolent or not, our grandkids or great-grandkids may be the last humans to live.  Beyond that, one way or another, life extension and the fact that humans are totally unecessary for production may make reproduction functionally obsolete. 

In that timeframe, as well, we will be slamming into the Carrying Capacity of the Earth (http://en.wikipedia.org/wiki/Carrying_capacity), where humanity will have to destroy itself over the finite resources no longer being able to be stretched further, no matter how much more productivity we may have. 

It will be the end of our current consumerist society, one way or another. 

So smoke 'em if you got 'em, because we're hurtling headlong into the Singularity.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Draco18s on May 25, 2012, 12:46:13 pm
In that timeframe, as well, we will be slamming into the Carrying Capacity of the Earth (http://en.wikipedia.org/wiki/Carrying_capacity), where humanity will have to destroy itself over the finite resources no longer being able to be stretched further, no matter how much more productivity we may have. 

Aye-yup.  Azimov knew about that limit well and wrote several short stories on it.

Even worked out how many people would make the equasion "mass of all humans = mass of all animals."  Turns out you get a population density of Manhattan...over the entire surface area of the planet, including the oceans.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Itsdavyjones on May 25, 2012, 03:11:17 pm

In that timeframe, as well, we will be slamming into the Carrying Capacity of the Earth (http://en.wikipedia.org/wiki/Carrying_capacity), where humanity will have to destroy itself over the finite resources no longer being able to be stretched further, no matter how much more productivity we may have. 


http://www.space.com/15395-asteroid-mining-planetary-resources.html

This is a company that has just recently been formed that has plans on harvesting asteroids, so there may be a finite amount of material on Earth, but you can't forget the space based resources.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on May 25, 2012, 03:25:24 pm

In that timeframe, as well, we will be slamming into the Carrying Capacity of the Earth (http://en.wikipedia.org/wiki/Carrying_capacity), where humanity will have to destroy itself over the finite resources no longer being able to be stretched further, no matter how much more productivity we may have. 


http://www.space.com/15395-asteroid-mining-planetary-resources.html

This is a company that has just recently been formed that has plans on harvesting asteroids, so there may be a finite amount of material on Earth, but you can't forget the space based resources.

You don't mine for food.

The carrying capacity of the Earth is the amount of people we can feed if we convert every arable patch of land solely to the production of more food.

It is the functional wall into which our world will have to start killing each other over the scarcity of food as portions of humanity start to starve to death and tax our natural resources to the point where we will cause severe environmental degradation that will make our planet less capable of feeding even the few remaining humans.

This will only be averted by either severely limiting human population growth, invention of "superfoods" that take far less arable land to grow, or interplanetary colonization on a scale that allows us to just export excess humans into space. 

Bottom line, the next world war is probably going to be fought over water. 
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Heedicalking on May 25, 2012, 05:58:29 pm
I hope re-stacking bolts comes soon.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Tierre on May 28, 2012, 07:11:17 am
I hope re-stacking bolts comes soon.


LOL you tried to derail back derailed thread:) Yeah stacking is good but i doubt it will come soon - Toady likes all the info which is not important too much:) So he cannot stack different things together (very different - like 1 bolt is a bit more muddy than another... :( ).

To Kohaku - wow i saw you derail your own thread for the first time:)
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on May 28, 2012, 10:28:42 am
Enh, I could rerail it whenever it was important to do so.  Derails are no big deal, in spite of what everyone says. 

Anyway, part of the first page was specifically on how this information could be maintained in a stack.  It's entirely possible to maintain information on everything worth keeping track of in a stack of items.

Further, there is certainly room for making the tracking of information more abstract, anyway.  If a stack of 25 bolts made from one metalsmith is stacked with a stack of bolts from another metalsmith, you can just say 25 of the bolts was from the first metalsmith, and randomly choose which smith's bolts are being taken from the stack as they are removed.  You don't need to keep track of any specific bolt's creator, and realistically, you wouldn't.
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Tierre on May 30, 2012, 06:52:39 am
Well it's Toady's decision anyway:) I think a lot of info is unimportant to store but i am not a developer of dwarf fortress:)
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: NW_Kohaku on May 30, 2012, 10:31:13 am
Well it's Toady's decision anyway:) I think a lot of info is unimportant to store but i am not a developer of dwarf fortress:)

"Important" generally means "is used for something" (except for the engraving/improvement data, which is purely aesthetic, but still reasonably important, although I still don't think it's justified for coins,) so it's not likely to be changed.

Anyway, I've already said how you can keep every bit of data in a stack that could be held by items individually back in the front page, so there's no reason we can't stack.

Topic for discussion: 
Quote
Coins have their coin batch index (year for dwarves) and the material, but there's also ownership, contaminants, temperature, damage, age, storage information, maker id, flags based on if your fort owns/made it, melt/dump/forbid/hide designations, job information.

What would you say can be offloaded, converted to the stack info, or dumped.  Every one of those has to be one of the three.

Well, assuming I am correct in interpreting that "offloaded" means "it's got a pointer to manufacturing data" and "stack info" is "the stack applies this data to everything in the same stack", and "dumped" means "Screw it, we don't need to track this at all", then...

  • Coin batch index and material data - offload (Although possibly having some sort of generic "item type" data that would be stack data. That way, you don't have to search where the pointer points to see something very basic like "this is a bolt stack" when you're looking for something like iron bars.)
  • ownership - stack
  • contaminants - stack
  • temperature - stack (Actually, should this be by stack, or by tile, anyway?)
  • damage - ***
  • age - offload
  • storage information - stack
  • maker ID - offload
  • fortress or import flags - offload
  • melt/dump/forbid/hide designations - stack
  • job information - stack

*** Damage is the only problematic one.  Items in the same stack with one another should probably be damaged the same, but the problem is that they will all start with different damage values.  Probably, the best way to really handle this is to make every individual item in the stack have its pointer to the offloaded data, the number of items exactly like that, and also a damage value.



Edit from a long time later:
Actually, you could track item wear or damage more abstractly, if you don't mind a loss of granularity over some types of items.  (If you are stacking them, anyway, then you shouldn't be all that concerned with granular details.)

Simply track an abstract "Average" wear or damage number, and then a "Standard Deviation" number, and bell-curve the results abstractly.  Hence, throwing a badly damaged item into a stack of reasonably well-maintained items will result in not just a drop in the average wear, but also a spike in the standard deviation, so the bell-curve will be spread out, and abstractly include plenty of low-wear items as well as a few outlier damaged items.

Dwarves could simply draw at random or puposefully pick the most damaged or most repaired ones as specified (so that if they are looking for socks in a sock pile, they would probably want to pick the least threadbare socks to own for themselves).
Title: Re: Stacking and Hauling Improvements (optimization)
Post by: Kogut on June 02, 2012, 05:30:15 am

In that timeframe, as well, we will be slamming into the Carrying Capacity of the Earth (http://en.wikipedia.org/wiki/Carrying_capacity), where humanity will have to destroy itself over the finite resources no longer being able to be stretched further, no matter how much more productivity we may have. 


http://www.space.com/15395-asteroid-mining-planetary-resources.html

This is a company that has just recently been formed that has plans on harvesting asteroids, so there may be a finite amount of material on Earth, but you can't forget the space based resources.

You don't mine for food.

The carrying capacity of the Earth is the amount of people we can feed if we convert every arable patch of land solely to the production of more food.

It is the functional wall into which our world will have to start killing each other over the scarcity of food as portions of humanity start to starve to death and tax our natural resources to the point where we will cause severe environmental degradation that will make our planet less capable of feeding even the few remaining humans.

This will only be averted by either severely limiting human population growth, invention of "superfoods" that take far less arable land to grow, or interplanetary colonization on a scale that allows us to just export excess humans into space. 

Bottom line, the next world war is probably going to be fought over water.
World war over water is impractical - there is no reason why China would attack USA over water, but increasing number of local conflicts is very likely.