The International Simutrans Forum

 

Author Topic: Bug: Industry negative input storage.  (Read 1978 times)

0 Members and 1 Guest are viewing this topic.

Offline DrSuperGood

  • Dev Team
  • Devotee
  • *
  • Posts: 2833
  • Languages: EN
Bug: Industry negative input storage.
« on: December 08, 2017, 03:22:55 AM »
Another picture shows all bug. Market somehow has managed to get an input storage for Fish of -1. Was being serviced 2 units of Fish at a time by land. I am guessing an off-by-one style error? Or maybe something transfer related?

The market lasted like this for a few minutes before eventually fixing itself to 0.

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 20268
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Bug: Industry negative input storage.
« Reply #1 on: December 10, 2017, 09:57:07 PM »
Thank you for your report. Are you able to upload a saved game in which this issue can reliably be reproduced in a specific location?

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 20268
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Bug: Industry negative input storage.
« Reply #2 on: January 11, 2018, 03:48:21 PM »
Can I check whether this issue still occurs? If so, I will need to be able to reproduce it in order to fix it; are you able to upload a saved game in which this issue can reliably be reproduced, or, if this occurs on the Bridgewater-Brunel server, let me know exactly where it occurs there?

Offline DrSuperGood

  • Dev Team
  • Devotee
  • *
  • Posts: 2833
  • Languages: EN
Re: Bug: Industry negative input storage.
« Reply #3 on: January 11, 2018, 07:31:10 PM »
Seeing how industry was not profitable I gave up caring. I have seen it happen a few times but not too sure of the cause.

It mostly seems to occur as a shop runs out of input while more input is still to arrive. Seeing how negative input would mean that the signed input storage amount is less than 0, one could probably detect for it by running the server game, possibly even fast forward, and breaking when a less than 0 branch is run for that input. If no such braches exist one could temporarily be added to test for it.

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 20268
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Bug: Industry negative input storage.
« Reply #4 on: January 11, 2018, 07:40:59 PM »
If anyone can find a place where this can reliably be reproduced, I should be most grateful - it is not feasible for me to try to reproduce this sort of thing speculatively.

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 20268
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Bug: Industry negative input storage.
« Reply #5 on: January 13, 2018, 01:57:31 PM »
Can I check whether this issue still occurs? If so, I will need to be able to reproduce it in order to fix it; are you able to upload a saved game in which this issue can reliably be reproduced, or, if this occurs on the Bridgewater-Brunel server, let me know exactly where it occurs there?

Offline Jando

  • *
  • Posts: 506
Re: Bug: Industry negative input storage.
« Reply #6 on: January 13, 2018, 03:01:19 PM »
Can I check whether this issue still occurs? If so, I will need to be able to reproduce it in order to fix it; are you able to upload a saved game in which this issue can reliably be reproduced, or, if this occurs on the Bridgewater-Brunel server, let me know exactly where it occurs there?

Hard to say, James. On current maps it's near impossible to find a working freight connection (almost no consumers on maps and the few existing consumers will will have an upstream supplier with no work force). Thus very few freight routes exist. I'd suggest dealing with this issue at a later time after maps allow more freight connections.

Offline ACarlotti

  • *
  • Posts: 483
Re: Bug: Industry negative input storage.
« Reply #7 on: January 31, 2018, 09:25:19 AM »
I believe I've located this bug in add_consuming_passengers, and can convince myself that it's more likely to go wrong (i.e. sufficiently negative to be shown as such given the rounding) in the particular case of fish in the market.

It seems that consuming passenger try to buy in goods in proportion to the production factor for each input, but if they can't buy something, they try to buy something else instead. For instance (as I understand), I go to the market and try to buy 1 unit of fruit, 1 unit of vegatables, .33 units of meat and 2 units of fish. But suppose there's only .5 units of fruit, .5 units of vegatables, no meat but plenty of fish. I think (according to the code), I then buy 8 units of fish.
So my question to you James is: what are the passengers intended to do? Because I'm pretty sure that that's not the same as what they currently do.


P.S. I think my observations in the code are demonstrating the fact that it's often easier for someone else to proofread (or debug) your work than to proofread it yourself, since if you already know what it's supposed to do, then it's easy to misread it and think that it does do that. (This sentence referring to the generic 'you'.)

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 20268
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Bug: Industry negative input storage.
« Reply #8 on: January 31, 2018, 11:21:49 PM »
I believe I've located this bug in add_consuming_passengers, and can convince myself that it's more likely to go wrong (i.e. sufficiently negative to be shown as such given the rounding) in the particular case of fish in the market.

It seems that consuming passenger try to buy in goods in proportion to the production factor for each input, but if they can't buy something, they try to buy something else instead. For instance (as I understand), I go to the market and try to buy 1 unit of fruit, 1 unit of vegatables, .33 units of meat and 2 units of fish. But suppose there's only .5 units of fruit, .5 units of vegatables, no meat but plenty of fish. I think (according to the code), I then buy 8 units of fish.
So my question to you James is: what are the passengers intended to do? Because I'm pretty sure that that's not the same as what they currently do.

Thank you very much for looking into this - this is most helpful.

To answer your question: the idea is that passengers who cannot buy one product because it is out of stock instead buy the same quantity of other products that are in stock. So, if a passenger wanted to buy 1 fish, 1 meat and 1 bread, but there was no meat, the passenger would instead buy 2 fish and 1 bread. The idea is that passengers/customers buy the same total amount of product, but instead of spreading accross different product types, they concentrate their purchases on products that are available.

Quote
P.S. I think my observations in the code are demonstrating the fact that it's often easier for someone else to proofread (or debug) your work than to proofread it yourself, since if you already know what it's supposed to do, then it's easy to misread it and think that it does do that. (This sentence referring to the generic 'you'.)

I can readily believe this - I certainly find it to be true with written text. Making mistakes in any non-trivial coding is really extraordinarily easy, especially in a project as complex as Simutrans-Extended where so many different things interact in such complex ways that it is very hard to keep all the relevant details in one's mind at the same time.

Offline DrSuperGood

  • Dev Team
  • Devotee
  • *
  • Posts: 2833
  • Languages: EN
Re: Bug: Industry negative input storage.
« Reply #9 on: February 01, 2018, 12:16:17 AM »
Quote
To answer your question: the idea is that passengers who cannot buy one product because it is out of stock instead buy the same quantity of other products that are in stock. So, if a passenger wanted to buy 1 fish, 1 meat and 1 bread, but there was no meat, the passenger would instead buy 2 fish and 1 bread. The idea is that passengers/customers buy the same total amount of product, but instead of spreading across different product types, they concentrate their purchases on products that are available.
Except it has to be scaled. For example instead of buying 1 meat they would buy 6 fish or so because meat is only consumed at 33% while fish is consumed at 200%. If this scaling is not done people could exploit the mechanic, eg by not providing fish they could sell insane quantities of meat which usually is only rarely sold.

On top of this there should be a penalty to sales because it is the wrong type. There is only so much fish someone might want to buy when they actually wanted to buy vegetables, fruit or meat. Again this is to prevent exploit where one could make more money from a shop by not supplying some of its cheaper inputs so that more of the more valuable inputs are sold instead.

For testing purposes I would say trying that only half the consumption power of unavailable inputs can be transferred to other available inputs, and the amount is scaled appropriately based on the consumption rate of the input.

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 20268
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Bug: Industry negative input storage.
« Reply #10 on: February 01, 2018, 12:24:27 AM »
There is a penalty for the desired goods being out of stock: there is a proportionate chance that passengers will simply not make the journey at all. See fabrik_t::out_of_stock_selective().

Offline ACarlotti

  • *
  • Posts: 483
Re: Bug: Industry negative input storage.
« Reply #11 on: February 01, 2018, 12:26:22 AM »
At the moment I think the code tries to get passengers to buy alternative goods, but does so using the factories internal units, which I think are not in proportion to the displayed units. If these are different, then should it be working in the displayed units?

In any case, I'm not sure that buying alternative goods is necessarily desirable. Suppose I've been supply a load of fish to a market, which people have been buying as fast as I can send them, because they can't get anything else. Then a vegetables chain opens up, and suddenly the consumers don't want as many fish, which become oversupplied. This seems unrealistic - in this case the supply of vegetables could well be replacing home grown stuff, so should add to the overall level of goods bought at the market. And there're probably other consumer industries that I haven't encountered in 1780 where this also doesn't make sense. Sure, there are cases where buying an alternative good is reasonable, but it certainly isn't realistic in all cases, and I'm not convinced it's worth having in its current (intended) form.

Added after seeing the post at 12:16:
Ah, yes, I suppose buying 2 meat instead of 2 fish is unreasonable. But so too, I feel, is buying 6 fish instead of 1 meat. So maybe the best answer is to disable buying of alternative goods.

Thought experiment: If meat and fish (and so on) were instead sold in separate industries that were side by side, what would be the effect on demand in one if the other were undersupplied? (I can't answer this for the game at present because I don't know all the production factors well enough.

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 20268
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Bug: Industry negative input storage.
« Reply #12 on: February 01, 2018, 12:41:51 AM »
To answer the question - using internal units is intended, as these are more accurate than the displayed units (each internal unit being a fraction of each displayed unit). Rounding up from internal units alone should not be able to cause negative numbers in displayed units, however.

In relation to alternative goods - the idea is that the industry can supply fewer people if it has less stock. Suppose a consumer industry demands two inputs: A and B, in equal quantities, 50 each per month. To satisfy all of the consumer demand, one would have to supply the industry with 100 units per month, assuming that the exact same number of customers visited as matched the industry's visitor demand. Those visiting passengers would represent successful trips.

However, if one were to supply the industry with only type A, 50 units per month, one could quite readily supply 100 passengers per month with only 50 units (although half the passengers who wanted to travel to that consumer industry would not be able to do so because their desired B product was not available, the alternative destination system means that it is likely that man other passengers would attempt to travel to the shop if the local population were large enough). Thus, one could get just as many successful passenger trips out of the industry by supplying it with only half the input product. So, to compensate for that, the passengers consume twice as much of the input product to make sure that one still needs to supply 100 units to the industry to satisfy 100 passengers.

(Incidentally, I cannot recall now, as it has been some months since I implemented this feature, whether this does scale by the demand percentages - I suspect that it may well do, but I am not sure).

Offline ACarlotti

  • *
  • Posts: 483
Re: Bug: Industry negative input storage.
« Reply #13 on: February 01, 2018, 01:12:12 AM »
Ah, ok. So the right way to think about is not that one person is arriving and buying multiple things, but rather a whole bunch of people arrive, and then we determine retrospectively what they came here to buy. So if only good A is available, then they must all have come to buy that (and only half as many passengers will come). On the other hand, if good B is also available, then we expect that some of them came to buy good A and some of them came to buy good B.

I believe I understand what's intended now, and will go and think about how to fix the bug, and also make the distribution of purchases more balanced than at present. And, if the above interpretation is correct, I'll shove it in a comment in the code.

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 20268
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Bug: Industry negative input storage.
« Reply #14 on: February 01, 2018, 01:51:25 AM »
Yes, I suppose that that is one way of thinking about it. Thank you again very much for your contributions - they are much appreciated.

Offline ACarlotti

  • *
  • Posts: 483
Re: Bug: Industry negative input storage.
« Reply #15 on: February 01, 2018, 03:08:28 AM »
I've now coded this, and am going to test it for a few game months before uploading this. This will impact the balance of consumption at industries with more than two inputs (in that the previous code was biased by the order of the inputs), but hopefully won't make too much difference to gameplay.

I think there may be a bug in out_of_stock_selective where it checks the setting for rural_industries_no_staff_shortage - at present no consumers will visit rural consumer industries when this setting is set. I would imagine the intent is rather that customers can come even during a staff shortage - if that is so, then the "||" should be replaced by "&& !".


An unimportant technical observation:
I think it is still theoretically possible to consume slightly more of a good than is supposed to happen, if the passengers that set out when two goods are available only have a choice of one good when they get to the store (and vice-versa). That is, we can get slight overconsumption as a result of passengers 'checking if their desired good is available' before departing to the store. The effect is not particularly large though, and total consumption will never be greater than the total consumption if all goods were fully supplied.
An reasonably bad example case would be with two equal goods (A and B), with A always adequately supplied, but B always either runs out or is delivered between passengers deciding to go to the store, and them actually arriving at the store. Then we would have (say) two units of passengers arriving when only A is available and one unit arriving when both goods are available, which leads to 25% higher consumption of A than ideally should happen. But this is a somewhat contrived case, and overconsuption will invariably be much less.


Offline ACarlotti

  • *
  • Posts: 483
Re: Bug: Industry negative input storage.
« Reply #16 on: February 01, 2018, 08:02:59 AM »
I've now uploaded a fix of this bug. I also enabled customers for rural consumer industries (as above), and fixed a separate bug in the recording of some production/boost graphs. (Basically the history was showing two entries per past month, with even numbers showing the instantaneous end-of-month figures and odd numbers showing the monthly average.)

I also noticed that the graphs for input/output goods are inconsistent in that the storage graph shows an average for past months (but instaneous value for the current month), while the in transit graph shows the instantaneous end-of-month figure. I was going to change the in transit graph to also be an average (and update the help text to explain what these graphs show), until I realised that would require modifying the savegames. (So I guess take this as a feature request, which perhaps deserves it's own thread.)

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 20268
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Bug: Industry negative input storage.
« Reply #17 on: February 04, 2018, 04:11:35 PM »
Thank you very much for the fixes, and apologies for not having time to deal with them until now: I have now incorporated these into the master branch, and the updated version should be available with the next nightly build.