Latest Posts

Topic: productivity percentage of buildings is wrong

king_of_nowhere
Avatar
Topic Opener
Joined: 2014-09-15, 18:35
Posts: 1668
Ranking
One Elder of Players
Posted at: 2015-09-17, 19:34

I've noticed that the percentage that should represent the productivity oof a building ddoes not do so. In theory, it should tell how many times in the last 20 working cycles the building did actually work. In practice it doesn't at all. Fom what I could figure out, Whenever the building works, it adds 5%, and whenever the building skips a cycle it removes 5%, except if it skipped because economy does not need the ware, in which case it remains constant.

It is easy to see that it does not work. A building working one time every three should have a prooductivity of 33%, but with this counting mechanism it would have 0%. In fact, every building working less thhan half the times will eventually go to 0%, and every building working more than half will go to 100%. You may notice that most buildings, in fact, have those percentages; a building get an intermediate percentage only when its actualy work is variable.

To a first glance, this would look a mere cosmetical problem, but it is not. Messages like "no more resources" are based on those percentages. The program would suggest dismantling a woodcutter that works one time every two, because its percentage will be low. But that would still be only a minor annoyance.

No, the real problem is that strategies are based on those percentages.

I have three smelting works, all three working at 25%. I may reach the conclusion that I don't need them, that a single smelting works working at 75% would do the trick. Except I know for a fact that it doesn't. I'm not sure if two would suffice, but one for certain wouldn't handle my metal production. I have exhausted mines, because I'm playing that for a challenge, and they should have a productivity of 5% on average, since that's their chance to produce. But all 40 of them say 0%. I have 40-odd foresters and woodcutters to empower the smokeries; and I would like to know if I placed them well to optimize the production, if I placed the foresters too close or if I can cram them tighter. I cannot, because all the productivity tells me is that they work more than half the times.

Even worse, the AI bases its strategies on productivity. I read someone mentioning that the decision on whether to build more buildings of a certain type is based on the productivity of the existing ones. You can see how that doesn't work if the producctivity is not accurate.

The proper way to count produtivity would be to have a string of 20 bits, 0 or 1 depending on whether the building worked in that work cycle or not. At every work cycle, the program would shift all the numbers, remove the count for the older work cycle, and insert the number for the newer one. That would give an accurate count. i suppose it would require more calculations from the game engine, but it would be a pittance compared to what's needed to calculate the busyness of roads or the growth of trees. It should also be fairly simple to program, as far as I know (which, admittedly, isn't much). instruucting the buildings to make such a string shouldn't take much time. Instructing the game to save those strings with a savegame may be a bit more complex, but it should easily be doable.

I expect that such a fix would not only make the game a bit smoother for a human (in fact, few would realize it) but it would improve the performance of the AI


Top Quote
tuggyne

Joined: 2011-07-22, 00:27
Posts: 42
Ranking
Pry about Widelands
Location: TN
Posted at: 2015-09-17, 20:22

Actually tracking the bitstring as suggested is pretty trivial (three instructions — one to shift, one to mask, one to add the new bit). Summing the percentage from that isn't much harder — x86 has a dedicated instruction for that (?!?).

How are you thinking of handling no-product-needed skips, exactly? I suppose those could just leave the string unchanged.

Edited: 2015-09-17, 20:23

Top Quote
DragonAtma
Avatar
Joined: 2014-09-14, 01:54
Posts: 351
Ranking
Tribe Member
Posted at: 2015-09-17, 21:04

Not counting "no product needed" checks towards productivity is probably best. After all, thew two main reasons for a building to be idle (being so rich you're at the limit and being so poor you can't even make one) are polar opposites.


Top Quote
Tibor

Joined: 2009-03-23, 23:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2015-09-17, 21:12

in fact there is an circular buffer for 20 last results - but "skipped" is not pushed there. One of problem is various duration of phases:

production succesfull - about 25 sec production unsuccesfull - missing resources - about 25 sec production skipped - about 1 sec

So we cannot just mix these "results" together...

So AI is using own average where all phases are considered. But it is only approximate average. And also if building produces more then 1 outputs, the percent is just unreliable. Even it says 40% you might need another building to increase production of particular ware.

BTW I tweaked AI another bit, I am going to propose for merging it, I hope some improvements will be visible... face-smile.png


Top Quote
king_of_nowhere
Avatar
Topic Opener
Joined: 2014-09-15, 18:35
Posts: 1668
Ranking
One Elder of Players
Posted at: 2015-09-18, 02:07

Tibor wrote:

in fact there is an circular buffer for 20 last results - but "skipped" is not pushed there. One of problem is various duration of phases:

production succesfull - about 25 sec production unsuccesfull - missing resources - about 25 sec production skipped - about 1 sec

So we cannot just mix these "results" together...

So AI is using own average where all phases are considered. But it is only approximate average. And also if building produces more then 1 outputs, the percent is just unreliable. Even it says 40% you might need another building to increase production of particular ware.

BTW I tweaked AI another bit, I am going to propose for merging it, I hope some improvements will be visible... :)

i thought when it skipped production it just counted production skipped for 25 seconds, or whatever is the normal working interval. that would be the proper way to calculate it.


Top Quote
wl-zocker

Joined: 2011-12-30, 17:37
Posts: 495
Ranking
Tribe Member
Location: Germany
Posted at: 2015-09-18, 11:15

We already use the list of the 20 last tries that king_of_nowhere suggested. It is only updated when the production is successful or failed, but not when it is skipped.

The timing is a bit difficult:

Buildings with one output have the following code:

[work]
sleep=50000
return=skipped unless economy needs grout
consume=coal raw_stone:2 water:2
animate=working 32000
produce=grout:2

This means that skipping and failing (in the line consume=) both take 50s. Producing a ware take another 32s (due to the animation).

The sleep command has to be before the return=skipped to avoid busy waiting (see https://code.launchpad.net/~wl-zocker/widelands/bug571796/+merge/225387 or the associated bug report).

Buildings with different outputs have the following code:

[smelt_iron]
return=skipped unless economy needs iron
sleep=32000
consume=coal ironore
animate=working 35000
produce=iron

(and the same for gold)

Here, skipping is very fast (see https://bugs.launchpad.net/widelands/+bug/571796/comments/12 for the reason). Again, being successful takes longer than failing.

A productivity based on the time spent in different programs seems too complicated. The current way calculates the productivity based on successful/tried attempts. I am fine with this. A well has mine=water 1 100 65 2, and it will show a productivity of 65% on average. A smelting works smelts iron, gold, iron. If it has no gold ores (but enough coal and iron ores), it will show 65% (so two thirds), which is intuitive. A more elaborate discussion (which I did not read face-smile.png ) can be found at https://bugs.launchpad.net/widelands/+bug/796644.


"Only few people know how much one has to know in order to know how little one knows." - Werner Heisenberg

Top Quote
einstein13
Avatar
Joined: 2013-07-29, 00:01
Posts: 1118
Ranking
One Elder of Players
Location: Poland
Posted at: 2015-09-18, 16:41

wl-zocker wrote:

We already use the list of the 20 last tries that king_of_nowhere suggested. It is only updated when the production is successful or failed, but not when it is skipped.

Now I am not sure if it works properly. From my experience, the buildings are calculating %s as +/- 5% every fail/success production. And as king_of_nowhere mentioned, that is not working properly.

You can see the problem when... The example:

let we have a mill with no grain inside. The productivity is 0%. Let it take one grain. The productivity will go up 5% (good behaviour), but next step the mill will not work and the productivity will go down to 0%. Correct percentage should stay at 5% for 19 more periods of work (if mill have production timing as 10 seconds, 5% should stay for 190 seconds).

If I am wrong, please tell me face-wink.png I have quite old experience: from April this year.


einstein13
calculations & maps packages: http://wuatek.no-ip.org/~rak/widelands/
backup website files: http://kartezjusz.ddns.net/upload/widelands/

Top Quote
wl-zocker

Joined: 2011-12-30, 17:37
Posts: 495
Ranking
Tribe Member
Location: Germany
Posted at: 2015-09-18, 17:55

I've just tested it in r7529:

I built a mill, set the wheat storage to 0 until the miller had arrived. Then I allowed one sheaf of wheat to be delivered, which was used. I set the storage to 0 again. As expected, the mill showed "5% +" as soon as the flour was ready. After 9 or 10 unsuccessful attempts (I counted the seconds, sleep=5000), the statistic changed to "5% -", and after 19 or 20 (±1) unsuccessful attempts, the productivity reached 0%. So for me it looks fine.

EDIT: I was Empire.

Edited: 2015-09-20, 10:05

"Only few people know how much one has to know in order to know how little one knows." - Werner Heisenberg

Top Quote
einstein13
Avatar
Joined: 2013-07-29, 00:01
Posts: 1118
Ranking
One Elder of Players
Location: Poland
Posted at: 2015-09-18, 19:44

Ok, so probably it is fixed now face-smile.png And I am happy for that face-smile.png


einstein13
calculations & maps packages: http://wuatek.no-ip.org/~rak/widelands/
backup website files: http://kartezjusz.ddns.net/upload/widelands/

Top Quote
king_of_nowhere
Avatar
Topic Opener
Joined: 2014-09-15, 18:35
Posts: 1668
Ranking
One Elder of Players
Posted at: 2015-09-20, 07:10

7525 is the version i'm using where i see the malfunction. although i remember it from before, i just never paid much attention to it.

Anyway, i'mm too lazy to install the new version and try it. it's quite a big coincidence that a malfunction that has existed forever would be fixed just the day i report it, but i'll trust that it's fixed.


Top Quote