News:

Use the "Forum Search"
It may help you to find anything in the forum ;).

Bug: Industry negative input storage.

Started by DrSuperGood, December 08, 2017, 03:22:55 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

DrSuperGood

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.

jamespetts

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?
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

jamespetts

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?
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

DrSuperGood

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.

jamespetts

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.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

jamespetts

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?
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Jando

Quote from: jamespetts 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?

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.

ACarlotti

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'.)

jamespetts

Quote from: ACarlotti 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.

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.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

DrSuperGood

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.

jamespetts

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().
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

ACarlotti

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.

jamespetts

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).
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

ACarlotti

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.

jamespetts

Yes, I suppose that that is one way of thinking about it. Thank you again very much for your contributions - they are much appreciated.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

ACarlotti

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.


ACarlotti

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.)

jamespetts

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.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.