Hmm... xKiv, I think this is what you're saying in your first sentence but... my question on Winterbay's knapsack comparison and best item per size... does that only go for aftercore, or can you use that method for in-run as well? I've done a moderate amount of work to make EatDrink actually aware of what it can make at any specific time in the queueing, and so it picks the single best item based on its average cost that will fit into size... then the next best item that's still available that will fit into size, and repeat until no size is left. However, it eliminates invalid options (or should) at each consideration, keeping all other valid options because you never know how many other 'best' options will be eliminated at each step.
Solving it as a knapsack should work always, as long as you consider each *unit* of food as a separate item (i.e. "hi mein #1, cost 100 (on sale!)", "hi mein #2, cost 5000", ...). This will probably take a very long time to solve, even if you only keep 35 units of the best size-1 items (like, say, 15 knob pasties on sale and 20 urinal cakes or something), 18 units of the best size-2 items, 12 units of the best size-3 items and so on.
Probably faster in run, because then your options are limited.
But that approach requires prior knowledge of availability and real costs. You don't know if that 6th whatever will cost the same as the 5th or much more. You don't even know if the 1st one costs much less. This already makes the whole thing questionable - and then approximate solutions seem more acceptable.
I believe what ED currently does is an acceptable approximation, given all the other constraints it has.
Is there any good way to avoid needing to recalculate up to 35 'best' choices for food during stomach runs? Or the much more common 30 'best' choices during Boris runs... Seems like calculating 35 'best' options on down during a run for a total of 1.0333147966386144929666651337523e+40 options (factorial 35) would be a whole lot slower than our current calculations... though 35 total best options might be faster during aftercore.
Well, the current algorithm takes how much time? (let's talk about stomach only here, otherwise it's just times 3 or some other constant)
If N is the amount of all food .... as understand it: you pick a diet (at worst 35*N steps to find 35 optimal size-1 things to eat), but after eating the first one you discover you need to recompute, which is then 34*N, and again (33*N), ... for a total worst case of (35+34+...+2+1)*N=N*35*36/2=N*630 steps.
If you simply take what I propose above and used that instead at each calculation/recalculation, preparation for first step (finding best foods for sizes 1 to 35) will take 35*N time, then constructing a diet from that will take 1 (only 1 possible diet of size 1) + 2 (2 possibilities to find the best diet of size 2) + 3 (...) + 4 + ... + 35 = 630 steps.
(it's actually about half that, because of the removed duplicates, but let's not math *that* out)
That's (N+1)*35*36/2
Then you eat the first one discover you have to recompute, this time for only 34 hunger ... which will take (N+1)*34*35/2 time.
And the next one (N+1)*33*34/2 time.
And so on, until the last one should'n take more than N+1 time.
(again, I am overestimating the times because I don't want to math any better)
Which is somewhat more difficult to sum, but it will definitely be less than (N+1)*35*630=(N+1)*22050,
which is "only" about 35 times slower than current ED. That might still be dominated by getting all the mall prices, but I am not sure if it would be worth it in improvements.
It's *theoretically* better (as long as my version isn't flawed, which I can't guarantee) - it can find better diets that ED wouldn't even consider, in some situations, but I am not sure if those situations actually happen [1].
If the best possible diet is 3 chow meins (or 5 lasagna), both methods will find it, and the simple method will find it faster.
There's enough foods of various sizes in the e-kol-nomy that the "simpler" result shouldn't be significantly worse, I think.
Trying all permutations in a knapsack solution would be .... inadvisable.
This is the main problem I see with making ED more 'efficient' overall.
Calculating multiple 'best' choices quickly spirals into a lengthy morass of math that leaves the end user sitting staring at a non-updating (or overly spammy) screen in frustration.
AFAIK, eleron does this, and his javascript returns results almost instantly (I remember people saying his results are actually optimal, as opposed to EatDrink's results - but I don't know if the javascript version does the same algorithm as the site used back then). It also has some optimized recalculation, but I haven't decrypted it enough to actually understand what it does.
[1] here's a contrived situation:
assume VoA=1000, eating to 15, no value from anything but adventures, and only these types of food exist:
a 10-fulness yum-yum, costing 1000 and generating 50 adventures (that's 50000-1000=49000 profit, and value (when choosing next food) 49000/10=4900)
a 7-fullness nom-nom, costing 1000 and generating 30 adventures (30000-1000=29000 profit, value 29000/7=4142.857...)
a 4-fulness yuck-yuck, costing 10 and generating 4 adventures (4000-10=3990 profit, value 3990/4=997.5)
a 1-fullness fortune cookie, costing 40 and generating 1 adventure (1000-40=960 profit, value 960)
If I understand current ED correctly, these are listed in the order ED will try to pick them. So ED will get to pick this diet:
yum-yum, yuck-yuck, fortune cookie (the nom-nom won't fit after eating a yum-yum), for total profit 49000+3990+960=53950 (and "value" 3596.666666...)
What I wrote should do this
size 1: [fortune cookie]
size 2: [fortune cookie, fortune cookie]
...
size 6: [six fortune cookies]
size 7: compare [seven fortune cookies] (6720 profit) with [nom-nom] (29000 profit), [nom-nom] wins
// you don't have to divide by fullness here, because you always compare things that take the same fullness
size 8: [nom-nom, fortune cookie]
size 9: [nom-nom, 2 fortune cookies]
size 10: compare [nom-nom, 3 fortune cookies] (profit 29000+31880) with [yum-yum] (profit 49000), [yum-yum] wins
size 11: [yum-yum, fortune cookie]
...
size 13: [yum-yum, 3 fortune cookies]
size 14: compare [2 nom-nom] (58000) with [yum-yum, 4 fortune cookies] (52840), [2 nom-nom] wins
size 15: for once, let's review everything that is compared at this step:
[fortune cookie] (size 1) + [2 nom-nom] (size 14)
[2 fortune cookies] (size 2) + [yum-yum, 3 fortune cookies] (size 13)
[3 fc] + [yum, 2 fc]
[4 fc] + [yum, 1 fc]
[5 fc] + [yum]
[6 fc] + [nom, 2 fc]
[nom] + [nom, fc]
(stop here, because the rest of the sequence would be just the same thing backwards)
some of these are duplicate (or more), so in the end the comparison is between
[1 fc, 2 nom] (profit 960 +2*29000 = 58960, "value" 3930.666...)
[5 fc, yum]
[8 fc, nom]
You can guess which wins ...
[2 nom-nom, fortune cookie]
That's 34% better profit (in real situation, the improvement won't be nearly as drastic, I suspect)
----
and now I should run before they won't let me out of the building >_>