Page 1 of 5

### round up fluids reading train inventory

Posted: Sun Jun 04, 2017 4:41 pm
Problem:
Controlling pumps for unloading is cumbersome with stops showing 0 while there's 0.x fluid left in wagons.

Using the empty condition does not work if you want to have that train drop off oil and pick up sulfuric acid.

Solution:
Stops reading train inventories should always round up fluids to next integer.

### Re: round up fluids reading train inventory

Posted: Sun Jun 04, 2017 4:47 pm
+1

### Re: round up fluids reading train inventory

Posted: Sun Jun 04, 2017 5:56 pm
+1000

This issue is currently driving me batty.

### Re: round up fluids reading train inventory

Posted: Sun Jun 04, 2017 6:04 pm
you can set it to if fluid is <1 solves the issue mostly for trains you don't intend to carry different fluids at different times.

### Re: round up fluids reading train inventory

Posted: Sun Jun 04, 2017 6:14 pm
JohnyDL wrote:you can set it to if fluid is <1 solves the issue mostly for trains you don't intend to carry different fluids at different times.
You don't seem to get the point.
Fluids are double values.
Stops show fluid values by truncating them to integer, making it impossible to discern if something is truly 0 or <1 if you prefer that.

### Re: round up fluids reading train inventory

Posted: Sun Jun 04, 2017 6:41 pm
actually I do get the point of the difference between <1 and =0 what I don't get the point about 100% is why it matters <1 is actually <0.5 thanks to current rounding and a loss of that little only matters once and happens as rounding errors eventually anyway. You need 200+ deliveries for it to prevent 2 oil processes happening that could otherwise have worked 75000 oil per wagon*4/100 gives 3000 processes per train an equivalent loss of 1 in 600,000. it's a negligible loss like asking for a nuclear reactor to deliver 1 extra kilowatt

### Re: round up fluids reading train inventory

Posted: Mon Jun 05, 2017 4:54 am
JohnyDL wrote:actually I do get the point of the difference between <1 and =0 what I don't get the point about 100% is why it matters <1 is actually <0.5 thanks to current rounding and a loss of that little only matters once and happens as rounding errors eventually anyway. You need 200+ deliveries for it to prevent 2 oil processes happening that could otherwise have worked 75000 oil per wagon*4/100 gives 3000 processes per train an equivalent loss of 1 in 600,000. it's a negligible loss like asking for a nuclear reactor to deliver 1 extra kilowatt
With the way fluids work in factorio a tank gets locked to a fluid with even trace amounts of a fluid inside.
The problem is we don't see these trace amounts in circuit network. It should output 0 only when a tank is truly empty and ready to take in any fluid.

### Re: round up fluids reading train inventory

Posted: Mon Jun 05, 2017 9:44 am
Seems to me the real solution to the problem should be "Use integers instead of floats for fluid values". Though that would probably be a headache to change.

### Re: round up fluids reading train inventory

Posted: Mon Jun 05, 2017 9:52 am
Roxor128 wrote:Seems to me the real solution to the problem should be "Use integers instead of floats for fluid values". Though that would probably be a headache to change.
Yes I thought the same a while ago.
Maybe the developers can provide some insights why they decided for floats.

### Re: round up fluids reading train inventory

Posted: Mon Jun 05, 2017 10:02 am
Yes I agree if you need to 100% empty to change fluids then that's an issue but if you need to do that then you probably don't need the circuit network interfering at all. if you're using it as a detection to stop mixing fluids the train is probably going back and forth between the same stations if you need to change fluid it's probably a one off procedure and you can turn off the circuit controls to do it. I can't think of any good reason why I'd want to have 2 different fluids using the same wagon even an edge case where you're delivering petroleum gas and taking away sulphuric acid from the same set up I'd want 2 trains so that the train doesn't act as a bottle neck.

Another alternative is adding in a small delay on your detection line, if there's a delay of say 10 ticks that's more than enough time to empty the last tiny bit of fluid.

### Re: round up fluids reading train inventory

Posted: Mon Jun 05, 2017 10:23 am
JohnyDL wrote:Yes I agree if you need to 100% empty to change fluids then that's an issue but if you need to do that then you probably don't need the circuit network interfering at all. if you're using it as a detection to stop mixing fluids the train is probably going back and forth between the same stations if you need to change fluid it's probably a one off procedure and you can turn off the circuit controls to do it. I can't think of any good reason why I'd want to have 2 different fluids using the same wagon even an edge case where you're delivering petroleum gas and taking away sulphuric acid from the same set up I'd want 2 trains so that the train doesn't act as a bottle neck.

Another alternative is adding in a small delay on your detection line, if there's a delay of say 10 ticks that's more than enough time to empty the last tiny bit of fluid.
LOL you should try the Logistic Train Network mod.

### Re: round up fluids reading train inventory

Posted: Mon Jun 05, 2017 10:39 am
Love that mod never use it for fluids though there's no point. so few endpoints in that network it's simpler to do it manually

### Re: round up fluids reading train inventory

Posted: Mon Jun 05, 2017 12:06 pm
steinio wrote:
Roxor128 wrote:Seems to me the real solution to the problem should be "Use integers instead of floats for fluid values". Though that would probably be a headache to change.
Yes I thought the same a while ago.
Maybe the developers can provide some insights why they decided for floats.
As a programmer, I can say there are certainly a few reasons to use floats when writing something. The main ones I can think of off the top of my head being these three:

1. Being the computer equivalent of scientific notation, they have a very large range (10^308 down to 10^-308 for 64-bit floats).

2. Algorithms are often easier to implement with floats rather than just integers.

3. Some APIs require their use for certain functions (eg. OpenGL uses them for things like coordinates and colours, and both HLSL and GLSL use them for all colour values).

Hope that helps give a little insight.

### Re: round up fluids reading train inventory

Posted: Mon Jun 05, 2017 12:29 pm
steinio wrote:
Roxor128 wrote:Seems to me the real solution to the problem should be "Use integers instead of floats for fluid values". Though that would probably be a headache to change.
Yes I thought the same a while ago.
Maybe the developers can provide some insights why they decided for floats.
I'm curious for the reasoning behind the usage of float for fluids myself. No recipe needs fractions for crafting.

### Re: round up fluids reading train inventory

Posted: Mon Jun 05, 2017 3:47 pm
most likely it's there to produce the desired flow behaviour on pipes, if there's a drop off of 0.1% per pipe and its calculated pipe by pipe and rounded each time once you drop below 500 fluid in a pipe with integers the drop off effect would stop.

### Re: round up fluids reading train inventory

Posted: Mon Jun 05, 2017 3:55 pm
Oh no, not this again.
I remember the rounding method was changed about 2 times due to problems like this.
Won't rounding up(in all cases including storage tanks, since it has to be consistent) cause other problems in other setups?

I'll add this to my TODO and hopefully we can fix it.
We might implement a mechanic where large high pressure fluids would destroy static small amounts of leftover fluid. This would also solve the "delete and replace all pipes because I accidentally put the wrong fluid in it for 1 second" problem.
We are also considering remove all the pipe fluid physics and replacing it with a much simpler model, similar to how electric networks work.

### Re: round up fluids reading train inventory

Posted: Mon Jun 05, 2017 4:12 pm
Twinsen I think it sounds like a better case for a check on disconnect of pump if it's a bug fix (though I'm still not bothered by it)

on event pump disconnect: if fluid in tank <1 then delete fluid from tank force add fluid to pump even if over full

### Re: round up fluids reading train inventory

Posted: Mon Jun 05, 2017 8:44 pm
Related bug report thread (which was moved to "Not a bug"):

viewtopic.php?f=23&t=47626 0.15.10 Fluid wagon leaving even though condition is not met

### Re: round up fluids reading train inventory

Posted: Sun Jul 16, 2017 6:52 pm
Playing with the Logistic Train Network mod myself, and this fluid rounding problem is destroying my life ;_;

So, first, here's the solution I created for my fluid train depot:
2017-07-16 13_37_08-Factorio 0.15.30 [Streaming].png (2.06 MiB) Viewed 4886 times
My current theory is any configuration other than a single unbroken line results in fractions of fluid getting stuck in a pipe. This configuration allows a continuous pressure differential to entirely drain the pipe.

Second, here's my current problem:
2017-07-16 13_42_32-Greenshot.png (1.89 MiB) Viewed 4886 times
The train is set to leave when its contents are empty, or, after a long timeout. Now, I can change both of these settings in the LTN Mod, and I'm going to. But as it stands I have no way to fully empty the train using the circuit network. I can fully empty a cargo wagon using the circuit network, but I can't fully unload a fluid wagon using the circuit network.

Rounding up, from my player's perspective, or maybe decimalizing the circuit network, seem simplest? But then that also introduces fuck-knows-what behind the scenes, which makes sense to me too.
Maybe the simplest solution is to have fluids destroy with the higher pressure winning.

The pressure destruction method would probably open up some really cool options and designs for plumbing too. Maybe single-pipe refinery setups...

### Re: round up fluids reading train inventory

Posted: Fri Jul 21, 2017 9:48 am
It's not as simple as rounding up.

If I round up soon there will be a flood of complaints from a different group of people saying that their storage tank logic no longer works, because there is 0.00001 fluid in their storage tank that they can't pump out. Or similar problems to this.