Topic: productivity percentage of buildings is wrong
king_of_nowhere Topic Opener |
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 |
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 |
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 |
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... Top Quote |
king_of_nowhere Topic Opener |
Posted at: 2015-09-18, 02:07
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 |
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:
This means that skipping and failing (in the line The sleep command has to be before the Buildings with different outputs have the following code:
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 "Only few people know how much one has to know in order to know how little one knows." - Werner Heisenberg Top Quote |
einstein13 |
Posted at: 2015-09-18, 16:41
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 I have quite old experience: from April this year. einstein13 |
wl-zocker |
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, 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 |
Posted at: 2015-09-18, 19:44
Ok, so probably it is fixed now And I am happy for that einstein13 |
king_of_nowhere Topic Opener |
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 |