The International Simutrans Forum

Simutrans Extended => Simutrans-Extended bug reports => Simutrans-Extended development => Simutrans-Extended closed bug reports => Topic started by: Jando on April 18, 2017, 11:49:34 AM

Title: Cargo delivered at industry bug
Post by: Jando on April 18, 2017, 11:49:34 AM
It seems that industries accept too much cargo. A percentage of the cargo delivered seems to vanish after arrival and after the player gets paid for the delivery. The industry chart states that the cargo arrived, but the cargo does not get consumed or put into storage. Here is a screenshot of it:

(http://i.imgur.com/OI7dVoL.jpg)

The 3 graphs shown are from top to bottom: planks arrived, planks consumed, planks in storage. Note that the percentage number of the builder's yard accepting planks (28%) seems to be used to calculate the percentage of delivered planks that get consumed or otherwise used by the industry. The rest of the planks (72%) vanishes.

The above happens for all types of goods and all types of industries it seems, I see the same behaviour with other industries (ironworks, cement works) as well.

Thanks! :)
Title: Re: Cargo delivered at industry bug
Post by: jamespetts on April 18, 2017, 11:11:56 PM
Thank you for the report. I am afraid that I cannot see the screenshot - did you host it on Imagur, by any chance? For some reason, I can never see things on Imagur.

Would you be able to upload a saved game in which this can be reproduced reliably? I should be most grateful.
Title: Re: Cargo delivered at industry bug
Post by: Isaac Eiland-Hall on April 19, 2017, 02:26:05 AM
I've hosted the image here:

(https://files.simutrans.com/index.php/apps/files_sharing/ajax/publicpreview.php?x=1818&y=470&a=true&file=2017-04-18%2520(212423)%2520-%2520OI7dVoL.jpg&t=UOIgL3nxmQIH4rN&scalingup=0)

https://files.simutrans.com/index.php/s/UOIgL3nxmQIH4rN

Also, I'd be glad to set up an account on the site for the uploading of the saved game. :)
Title: Re: Cargo delivered at industry bug
Post by: Jando on April 19, 2017, 09:36:49 AM
Quote from: Isaac.Eiland-Hall on April 19, 2017, 02:26:05 AM
...
Also, I'd be glad to set up an account on the site for the uploading of the saved game. :)

Please do so, Isaac. The saved game is waiting for upload on my hard disc. :)
Title: Re: Cargo delivered at industry bug
Post by: Isaac Eiland-Hall on April 19, 2017, 03:46:55 PM
Set up and PM'd. :)
Title: Re: Cargo delivered at industry bug
Post by: jamespetts on April 19, 2017, 09:04:26 PM
Thank you for your help, Isaac - it is good to see a new file hosting system in place! Jando - please let me know when you have the saved game uploaded. Thank you.
Title: Re: Cargo delivered at industry bug
Post by: Jando on April 19, 2017, 09:21:25 PM
Quote from: jamespetts on April 19, 2017, 09:04:26 PM
Thank you for your help, Isaac - it is good to see a new file hosting system in place! Jando - please let me know when you have the saved game uploaded. Thank you.

James, for now uploaded to http://simutrans-germany.com/files/upload/Huntbere_1831.sve

Will use new system once I get access sorted.

And now also here I believe: http://files.simutrans.com/index.php/s/nP23nQDMvhQ1Rih
Title: Re: Cargo delivered at industry bug
Post by: jamespetts on April 19, 2017, 11:49:19 PM
Thank you very much for that. I am in the process of trying to track this down now, though it is a rather challenging issue, as it appears to occur in very complex industry code which I did not write myself (although which may have been affected by some of what I have written over time).

Would you be able to run some tests to assist me in tracking down this issue (my time is rather limited, so the more that you can help with testing, the quicker that I can fix this)? I am trying to discover whether the problem lies in the actual goods storage at the industries or whether only the statistics are affected. This is more easily done with a producing factory than a pure consumer. If the problem is just with the statistics, then the actual production of the factory should be unaffected (e.g., for a factory with 50% coal and iron ore inputs, delivering 50 units of coal and 50 units of iron ore should result in the production of 100 steel), and this should be apparent from the actual number of goods present at the receiving station. If, however, the problem lies with the actual number of goods tracked as being used by the industry, the actual production will be affected, so considerably fewer units of (for example) steel will be produced.

I notice, for example, at the ironworks at 1102,643, that the storage is shown on the graph as 1 for coal, whereas in fact the storage is given in figures above as 174. This suggests that it may well be a statistical problem, but it would be very helpful to have confirmation before looking in detail at the rather complex code dealing with the statistics rather than the equally complex but very different code dealing with the handling of actual units of product.
Title: Re: Cargo delivered at industry bug
Post by: Jando on April 20, 2017, 09:18:22 AM
Hello James!

Sure, I will gladly help with testing and have even some time on my hands to do so. I will track down the other industries on that map today, by now 2 ironworks, a cement works and a brickworks are connected, thus should give us plenty of data.
Title: Re: Cargo delivered at industry bug
Post by: jamespetts on April 20, 2017, 10:05:28 AM
That is extremely helpful, thank you.
Title: Re: Cargo delivered at industry bug
Post by: Jando on April 20, 2017, 03:20:35 PM
First findings: :)

Title: Re: Cargo delivered at industry bug
Post by: jamespetts on April 20, 2017, 09:36:19 PM
Thank you for that. Are these just findings by comparing the content of the graphs? What I am trying to discover, given that the graphs are inconsistent with one another, is with which (if any) of the inconsistent data in the graphs that the actual output of a factory correlates. For example, a steelworks with 50% coal and 50% ore inputs: if 50 actual units of coal and 50 actual units of iron ore are delivered to the factory, does it actually produce 100 units of steel such as actually find their way to the connected stop, or does it produce a lower number (e.g. 25 or somesuch)? This is what I was hoping that you would be able to test.
Title: Re: Cargo delivered at industry bug
Post by: Jando on April 20, 2017, 11:52:54 PM
Quote from: jamespetts on April 20, 2017, 09:36:19 PM
Thank you for that. Are these just findings by comparing the content of the graphs? ...

The data about arrived and delivered items is verified by comparing the graphs to the factually transported items (watching the convoys and checking the number of transported items in line management). I consider the graphs about number of arrived and delivered items as correct.

Quote from: jamespetts on April 20, 2017, 09:36:19 PM
... For example, a steelworks with 50% coal and 50% ore inputs: if 50 actual units of coal and 50 actual units of iron ore are delivered to the factory, does it actually produce 100 units of steel such as actually find their way to the connected stop, or does it produce a lower number (e.g. 25 or somesuch)? ...

It may even deliver many more items to the stop than what arrived in raw materials. :)

We have multiple steps here, from arrived to consumed, then to produced and to delivered. The bug sits in the steps from arrived to consumed and then from produced to delivered. The middle step from consumed to produced works fine and is correct. The bug also only happens when the percentage numbers in the industry window are not all 100%.

Thus in your (hypothetical?) example of the steelworks (I couldn't actually find one with 50% for both iron and coal, haha) 50% of the arrived materials would get consumed. Out of these the correct number of steel would get produced. How much steel is delivered to the stop solely depends on the percentage number in the production section of the industry window. If this number is 100% all the produced steel would get delivered. If the number is above 100% less items than produced get delivered, if that number is below 100% more items than produced get delivered to the stop.

Sorry, the new files site from Isaac seems to be down, can't post the screenshot right now, or only to Imgur that does not work for you. Back with more info tomorrow. 
Title: Re: Cargo delivered at industry bug
Post by: jamespetts on April 21, 2017, 12:27:44 AM
There is a certain critical ambiguity in what you report here, which is what I am trying to unravel: you write,

QuoteThus in your (hypothetical?) example of the steelworks (I couldn't actually find one with 50% for both iron and coal, haha) 50% of the arrived materials would get consumed. Out of these the correct number of steel would get produced.

Do you mean that the correct number would be produced given the number recorded on the "consumed" graph, or do you mean that the correct number would be produced for the number that had actually arrived?

This distinction is critical, as the former would imply a bug in the actual industry production code, whereas a latter would imply a bug in the code for displaying the graphs.
Title: Re: Cargo delivered at industry bug
Post by: Jando on April 21, 2017, 10:19:24 AM
Screenshot time with a steel mill. :)

The following 4 screnshots show the industry display of a steel mill, first screenshot after the first train with coal arrived (and the loading and unloading of the coal finished), second shot after the iron arrived and unloaded, 3rd screenshot after the delivered coal and iron got processed into steel and the 4th screenshot after the produced steel got loaded on a train to a builder's yard.

(http://files.simutrans.com/index.php/apps/files_sharing/ajax/publicpreview.php?x=1818&y=532&a=true&file=1.jpg&t=BMoH7kYSOG0n6QW&scalingup=0)
http://files.simutrans.com/index.php/s/BMoH7kYSOG0n6QW
120 units of coal arrived, note the number of coal is verified by line management. the industry display shows 120 units arrived in graph but 52 units in storage under consumption at the steel mill (43% of the arrived number)

(http://files.simutrans.com/index.php/apps/files_sharing/ajax/publicpreview.php?x=1818&y=532&a=true&file=2.jpg&t=JD9crErXajEA0Nw&scalingup=0)
http://files.simutrans.com/index.php/s/JD9crErXajEA0Nw
120 units of iron arrived, the industry display shows 120 units arrived in graph but 68 units in storage under consumption at the steel mill (57% of the arrived number)

(http://files.simutrans.com/index.php/apps/files_sharing/ajax/publicpreview.php?x=1818&y=532&a=true&file=3.jpg&t=wfAYUcSBVoTLGaL&scalingup=0)
http://files.simutrans.com/index.php/s/wfAYUcSBVoTLGaL
Third screenshot after the steel mill processed these 120 delivered units of coal and 120 delivered units of iron into 48 steel bars as stated by the industry display.

(http://files.simutrans.com/index.php/apps/files_sharing/ajax/publicpreview.php?x=1818&y=532&a=true&file=4.jpg&t=KSCw1jwjWK7QWwB&scalingup=0)
http://files.simutrans.com/index.php/s/KSCw1jwjWK7QWwB
4th screenshot after the 48 steel bars from the industry display became 110 steel bars on the train picking up the load for transport to a builder's yard.

Note that none of the numbers apart from initial delivery comes from any of the graphs, all numbers are from the textual information in the industry display.

Here is a save-game of another steel mill (I was so dumb to overwite the one from the screenshots) connected to an iron mine and colliery and builders' yard. The game is saved just before the first barge with iron ore arrives at the mill with other barges getting coal on their way: http://files.simutrans.com/index.php/s/HbK0oQSgWyHyaS1
Title: Re: Cargo delivered at industry bug
Post by: Isaac Eiland-Hall on April 21, 2017, 04:03:10 PM
I took the liberty of editing the image links, which must use the image address of the image from the share page, not the URL to the share page itself. :)
Title: Re: Cargo delivered at industry bug
Post by: Jando on April 21, 2017, 04:17:56 PM
Quote from: Isaac.Eiland-Hall on April 21, 2017, 04:03:10 PM
I took the liberty of editing the image links, which must use the image address of the image from the share page, not the URL to the share page itself. :)
Thanks, I'm still fighting to get the image on the forums right .)
Title: Re: Cargo delivered at industry bug
Post by: Ves on April 21, 2017, 05:09:39 PM
QuoteThanks, I'm still fighting to get the image on the forums right .)
What I usually do is right-click the image -> Copy image url/webb addres. Usually works :)
Title: Re: Cargo delivered at industry bug
Post by: jamespetts on April 22, 2017, 12:29:56 AM
That is very useful, thank you: the output factor of the steel mill is 40, which suggests that the production of 110 steel from 120 coal and 120 iron is close to being correct (although I should expect production of only 93; but there might be a boost, of course if passengers were delivered, which they might well have been just from walking). This therefore suggests that the internal statistics (both in the graphs and elsewhere) are where the error is likely to be. I shall have to look at this in more detail in due course. Thank you very much for testing.
Title: Re: Cargo delivered at industry bug
Post by: jamespetts on July 28, 2017, 12:05:49 AM
I have just pushed a fix for a number of errors relating to industry production/consumption/statistics. Would anyone be able to re-test to confirm whether this is fixed? Thank you for the reports.
Title: Re: Cargo delivered at industry bug
Post by: Jando on July 28, 2017, 08:32:54 AM
Jando runs to the computer to make a brand-new industry heavy map in 1850. :)

I assume this is best tested with a brand-new map cause I see all storage numbers all zero at all already connected industries after the patch. Making a new map should give better data without having to deal with pre-patch and post-patch historical statistics. :) Thank you very much, James, for addressing this issue.
Title: Re: Cargo delivered at industry bug
Post by: jamespetts on July 28, 2017, 10:31:49 AM
Quote from: Jando on July 28, 2017, 08:32:54 AM
Jando runs to the computer to make a brand-new industry heavy map in 1850. :)

I assume this is best tested with a brand-new map cause I see all storage numbers all zero at all already connected industries after the patch. Making a new map should give better data without having to deal with pre-patch and post-patch historical statistics. :) Thank you very much, James, for addressing this issue.

Yes, it is possible that some historical data from games saved before this fix was applied will be incorrect, but new data should be fine. Thank you for testing.
Title: Re: Cargo delivered at industry bug
Post by: Jando on July 29, 2017, 09:15:07 AM
Made a small test map, used public player to place industry chain colliery/iron mine-steel mill/forest-hardware factory-hardware shop. Findings:
Thank you very much, James.
Title: Re: Cargo delivered at industry bug
Post by: jamespetts on July 29, 2017, 05:29:07 PM
Thank you very much for testing this: this is very helpful. Looking into this, the problem was more than simply that the max units per month figure was displayed incorrectly: it transpired that a large number of matters related to industry production were not scaled with the meters per tile setting as is intended and as had been assumed when the industries were calibrated. I have now fixed this; would you be able to re-test? Thank you.
Title: Re: Cargo delivered at industry bug
Post by: Jando on July 29, 2017, 09:40:20 PM
Sure, I will re-run tests and report back soon.
Title: Re: Cargo delivered at industry bug
Post by: Jando on July 30, 2017, 09:56:03 AM
That was not quite intended I guess. :)

All industries (no matter whether on new or on old maps) have a max. item count that is a multiple of 16. Have seen max. item numbers ranging from 0 (zero, for many small consumers like pubs, grocers, newsagents, greengrocers, etc.) to 928 (steel mill in 1946).
Title: Re: Cargo delivered at industry bug
Post by: jamespetts on July 30, 2017, 10:49:27 AM
Thank you for spotting that - that was caused by a loss of precision in one of the calculations, which I think that I have now fixed. Would you be able to re-test? I should be grateful.
Title: Re: Cargo delivered at industry bug
Post by: Jando on July 31, 2017, 09:00:11 AM
Awfully sorry, James, problems ahead.

Made a new small test-map, January 1810 with newest nightly build. Used public player to place grain farm, forest, brewery, orchard and pub. Connected industries, transport by cart, fast-forward game for 6 game-months.

Findings:
- Apart from 1 unit of grain produced by the grain farm during the first month (January 1810) no industry ever produced or consumed anything.
- Upon saving and re-loading all storage numbers at all industries revert to zero.

Sorry, can't upload test map right now, files.simutrans seems to have a problem, cannot login. Edit: Saved game is here: http://files.simutrans.com/index.php/s/aeu169qWYqpA1Uy
Title: Re: Cargo delivered at industry bug
Post by: Jando on July 31, 2017, 04:35:05 PM
And additional info from my normal game, one game-month on fast forward. I watched the industries that had plenty of stock from deliveries in the month before.

2 power stations (stated as max. 90 and max. 82 units per month) consumed 76 and 77 units of coal, a good fit thus. Smaller industries however consumed nothing. Watched 2 hardware shops (max. units 16 and 24), a fishmonger (max. 20), a pub (max. 13) and a greengrocer (max. 8 units). All had stock in storage at the industry. None of these smaller consumers consumed anything during this month on fast forward.
Title: Re: Cargo delivered at industry bug
Post by: kittens45 on August 03, 2017, 08:53:47 PM
Is the fix a aviable yet?
Title: Re: Cargo delivered at industry bug
Post by: jamespetts on August 03, 2017, 10:06:56 PM
Not yet - I have been very busy at work this week, although I have been working on this when I have time (it is quite a complex problem that I do not fully understand yet). I did push an update yesterday that might result in a small improvement in some cases, but this is not a full fix at this stage.
Title: Re: Cargo delivered at industry bug
Post by: kittens45 on August 03, 2017, 11:18:13 PM
any fix for the next update?
Title: Re: Cargo delivered at industry bug
Post by: jamespetts on August 04, 2017, 12:35:12 AM
Quote from: kittens45 on August 03, 2017, 11:18:13 PM
any for the next update?

I do not understand the question, I am afraid.
Title: Re: Cargo delivered at industry bug
Post by: jamespetts on August 06, 2017, 05:10:52 PM
Having spent really rather a long time on this, I think that I have now managed to push a fix for two separate bugs (one relating to the industry production and another relating to checking whether too many goods were in transit.

Would you be able to re-test and confirm the fix when you have a moment? Thank you.
Title: Re: Cargo delivered at industry bug
Post by: kittens45 on August 06, 2017, 10:30:40 PM
where is the fix?
Title: Re: Cargo delivered at industry bug
Post by: jamespetts on August 06, 2017, 10:43:17 PM
As with any fix, it will be available in the next nightly build after it is announced, in this case, that available from to-morrow morning onwards.
Title: Re: Cargo delivered at industry bug
Post by: Jando on August 07, 2017, 12:28:27 PM
Greetings, James, and many thanks that you are looking into this issue.

I took my small test map (http://files.simutrans.com/index.php/s/aeu169qWYqpA1Uy) with grain farm, forest/sawmill, orchard, brewery and pub in 1810 and let the game run in fast-forward for 6 game-months.

First of all the good information:
1. Small consumers are consuming again and are consuming the correct amount.
2. Small producers are producing again and are producing the correct amount.

Some issues still exist:
1. A save/load-cycle will set the internal storage of all industries to zero. Note: internal industry storage, items stored in stop are fine.
2. Industries demand more cargo than they can consume. In fact they seem to demand all cargo the supplier produces. Thus input storage at industries builds up over time.
3. The orchard is doing funny things. It has no consumer for fruits and a very small internal storage of 2 crates. Once that storage is full it will flip between the numbers 1 and 2 every half second or so. The forest/sawmill has no consumer for planks as well, but a larger industry storage of 10 planks and does not show that flipping.

Will make another test-run with my normal game now (1940s, more varied industries) and report back later today. Thanks again, really much appreciated!

Edit: 2nd test run with normal game:
1. Save/load cycle same problem, all industry storage at zero after loading.
2. Demanding too much: I'm wondering whether that is an effect caused by zero in storage. Industries seem to demand more supplies when they have zero in stock?
3. Flipping numbers. A few small industries show this. Only seen it with small industries. Having no consumer does not seem to matter, have seen it with another small producer with active consumer as well (flipping 8 and 9 a few times per RL second in this case).
Title: Re: Cargo delivered at industry bug
Post by: kittens45 on August 10, 2017, 07:33:44 PM
Quote from: Jando on August 07, 2017, 12:28:27 PM
Greetings, James, and many thanks that you are looking into this issue.

I took my small test map (http://files.simutrans.com/index.php/s/aeu169qWYqpA1Uy) with grain farm, forest/sawmill, orchard, brewery and pub in 1810 and let the game run in fast-forward for 6 game-months.

First of all the good information:
1. Small consumers are consuming again and are consuming the correct amount.
2. Small producers are producing again and are producing the correct amount.

Some issues still exist:
1. A save/load-cycle will set the internal storage of all industries to zero. Note: internal industry storage, items stored in stop are fine.
2. Industries demand more cargo than they can consume. In fact they seem to demand all cargo the supplier produces. Thus input storage at industries builds up over time.
3. The orchard is doing funny things. It has no consumer for fruits and a very small internal storage of 2 crates. Once that storage is full it will flip between the numbers 1 and 2 every half second or so. The forest/sawmill has no consumer for planks as well, but a larger industry storage of 10 planks and does not show that flipping.

Will make another test-run with my normal game now (1940s, more varied industries) and report back later today. Thanks again, really much appreciated!

Edit: 2nd test run with normal game:
1. Save/load cycle same problem, all industry storage at zero after loading.
2. Demanding too much: I'm wondering whether that is an effect caused by zero in storage. Industries seem to demand more supplies when they have zero in stock?
3. Flipping numbers. A few small industries show this. Only seen it with small industries. Having no consumer does not seem to matter, have seen it with another small producer with active consumer as well (flipping 8 and 9 a few times per RL second in this case).

has the save/load been fixed yet?
Title: Re: Cargo delivered at industry bug
Post by: Jando on August 11, 2017, 08:42:29 AM
Please be patient, kittens45.

I'm sure James wants this issue fixed as much as we want that. But some things just don't happen fast and need time. I'm sure the issue is pretty high on James'  priority list and he will inform us when there's any progress.
Title: Re: Cargo delivered at industry bug
Post by: jamespetts on August 11, 2017, 10:38:19 PM
Thank you for your reports: I think that I have managed to fix the issue with the storage on loading/saving now. Would you be able to re-test? I should be grateful.

I will look into the other issues presently.
Title: Re: Cargo delivered at industry bug
Post by: Jando on August 12, 2017, 08:31:19 AM
Quote from: jamespetts on August 11, 2017, 10:38:19 PM
Thank you for your reports: I think that I have managed to fix the issue with the storage on loading/saving now. Would you be able to re-test? ...

Hello James, and thanks again. Tests re-run with test map at http://files.simutrans.com/index.php/s/aeu169qWYqpA1Uy

Findings:
1. Storage number of items produced at an industry is correct now after loading a game.
2. Storage number of items consumed at an industry still shows 0 after loading a game.

How to reproduce:
1. Load above saved game.
2. Open brewery window, fast forward, very soon grain will get delivered, wait until grain shows up in storage at brewery.
3. Save game. Load saved game.
4. Number of grain in storage at brewery will be zero.

Same thing happens with cider in storage at pub.
Title: Re: Cargo delivered at industry bug
Post by: jamespetts on August 12, 2017, 11:37:36 AM
Thank you for the report: I had not realised that consumer/producer storage was separate in this regard. I have now applied the same fix to consumer storage as producer storage - I should be grateful if you could re-test to confirm whether this has been fixed.

Edit: I think that I have now fixed the problem regarding the goods in transit: this required a re-calibration of the system in many different places. This will result in different (often lower) in transit numbers, so make sure that the maximum load values are now not set too high (as they are in the Industry saved game, resulting in deadlocks in some places).

Edit 2: I think that I have fixed the oscillation issue, too; I should be grateful if you could re-test this also.
Title: Re: Cargo delivered at industry bug
Post by: Jando on August 13, 2017, 12:45:29 PM
This looks very good now, James, many thanks!

- No error in storage numbers found. Save/load cycle works well.
- No error in industry demand and in-transit goods found.
- Oscillation issue fixed as well.

Good work! I'd say this can go to the solved bug reports now. :)

And aye, I'm aware of the low demand numbers resulting in some freight lines running at a loss, esp. in early years and/or to small consumers - but I see that not as a bug but as a balance issue, to be addressed during industry balance. For now industry seems to work according to the numbers in the industry window - and that's a big step forward. Many thanks again!
Title: Re: Cargo delivered at industry bug
Post by: jamespetts on August 13, 2017, 12:49:42 PM
Excellent, thank you for checking.