What are the priorities for the train leave conditions?

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
TheUnknown007
Fast Inserter
Fast Inserter
Posts: 129
Joined: Sun May 03, 2015 9:17 pm
Contact:

What are the priorities for the train leave conditions?

Post by TheUnknown007 »

I'm a long time player, and I love the new train stop leaving conditions, but I am a bit confused as to how exactly they are evaluated.

Example scenario; leave stop when:
circuit: green signal > 0
OR empty inventory
AND time 5 seconds passed

In 0.13.x, they where evaluated from top to bottom, so the train would leave if ( (green signal > 0 OR the inventory is empty) AND 5 seconds have passed), which allowed the train to be refueled.
However, as of 0.14.0, they evaluate it differently, and my trains now leave as soon as the green signal > 0, which is pretty much always true. The train leaves immediately, and it isn't refueled, so I now constantly have trains run out of fuel while driving.

So, onto the questions:
1) In what order are the train stop leaving conditions evaluated?
.options:
..top to bottom ( ( ( (A OR B) AND C) OR D) AND E),
..bottom to top (A OR (B AND (C OR (D AND E) ) ) ),
..OR first ( (A OR B) AND (C OR D) AND E),
..AND first (A OR (B AND C) OR (D AND E) ),
..something else (explanation with examples please)

2) Is this going to stay this way, or will it change again (question for the devs)?
Neemys
Filter Inserter
Filter Inserter
Posts: 461
Joined: Sat Apr 09, 2016 6:16 pm
Contact:

Re: What are the priorities for the train leave conditions?

Post by Neemys »

Changelog for 0.13.18 wrote: Changed train wait conditions to use standard boolean precedence for evaluation, instead of a simple left to right accumulative evaluation.
boolean precedence said that AND is evaluated before any OR

So to take your example, before 0.18
(circuit: green signal > 0 OR empty inventory) AND time 5 seconds passed
the train leave when either circuit network signal or inventory empty, AND at least 5 second pass.

Now it's :
circuit: green signal > 0 OR (empty inventory AND time 5 seconds passed)
So the train leave if either circuit network signal send OR (empty inventory and time passed), so time is only relevent for empty inventory.

If you want now something similar than before you must write it

Code: Select all

circuit: green signal > 0
AND time 5 seconds passed
OR empty inventory
AND time 5 seconds passed


Also, for refueling, there is the condition "inactivity", it see if any inserter take or fill any train inventory (including locomotive) for the passed x seconds. So it will not leave if an inserter is refuelling.
Want more space restriction ? Or maybe you want to be forced to use train for other thing than ore and oil ? Try Building Platform Mod !
TheUnknown007
Fast Inserter
Fast Inserter
Posts: 129
Joined: Sun May 03, 2015 9:17 pm
Contact:

Re: What are the priorities for the train leave conditions?

Post by TheUnknown007 »

WHYYYYYYYY?

Why do we need to repeat any condition that we want as an AND with highest priority? Why couldn't it just stay the simple top to bottom evaluation? (Okay, this was probably internal optimization, but it's SO INCONVENIENT from a user perspective)
User avatar
Deadly-Bagel
Smart Inserter
Smart Inserter
Posts: 1498
Joined: Wed Jul 13, 2016 10:12 am
Contact:

Re: What are the priorities for the train leave conditions?

Post by Deadly-Bagel »

In some ways yes, in other ways no.

For example if you wanted it to trigger when EITHER A or B are > 0 (but NOT both):

A > 0
AND B < 1
OR A < 1
AND B > 0

Old system.. not even sure it's possible without adding combinators. Bit too burned out atm to think that much but it's not a simple solution.
Money might be the root of all evil, but ignorance is the heart.
TheUnknown007
Fast Inserter
Fast Inserter
Posts: 129
Joined: Sun May 03, 2015 9:17 pm
Contact:

Re: What are the priorities for the train leave conditions?

Post by TheUnknown007 »

Well, that is a valid excuse (I don't think it is possible either. The only way would be to unload the complete train and then set it off after loading with some very complicated combinator logic)

Onto the next point: when will we get the possibility to copy-paste ( & drag and drop) conditions / train stops? (Should I make that a feature request?)
User avatar
Deadly-Bagel
Smart Inserter
Smart Inserter
Posts: 1498
Joined: Wed Jul 13, 2016 10:12 am
Contact:

Re: What are the priorities for the train leave conditions?

Post by Deadly-Bagel »

YES!

My oil trains typically go to oil outpost 1, then unloading, then OO2, then unloading, then OO3... Each time the logic is the same but it has a bit of a setup since it only runs if there is a demand for oil using circuit logic, if there is then it waits for inactivity OR 20 seconds (rare but all my empty barrels might be at my outposts full of oil so the train is being slowly loaded with barrels as they are emptied). Also the logic for each outpost needs setting up one by one.. The ability to simply copy wait logic between stops would be fantastic.
Money might be the root of all evil, but ignorance is the heart.
Neemys
Filter Inserter
Filter Inserter
Posts: 461
Joined: Sat Apr 09, 2016 6:16 pm
Contact:

Re: What are the priorities for the train leave conditions?

Post by Neemys »

In case you don't know, you can copy/paste locomotive color and schedule like you copy paste any other entity.

Copy and pasting single condition or group of condition is a nice feature to ask I think. Moving Station order in schedule too would be great.
Want more space restriction ? Or maybe you want to be forced to use train for other thing than ore and oil ? Try Building Platform Mod !
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: What are the priorities for the train leave conditions?

Post by siggboy »

TheUnknown007 wrote:WHYYYYYYYY?

Why do we need to repeat any condition that we want as an AND with highest priority? Why couldn't it just stay the simple top to bottom evaluation? (Okay, this was probably internal optimization, but it's SO INCONVENIENT from a user perspective)
The old implementation ("top to bottom") was easier to implement, which was the only reason why it was that way.

"Top to bottom" effectively amounted to (((A op B) op C) op D), where "op" can be "AND"/"OR". That might be what you want in some cases, but in general it's very difficult to work out what actually happens.

Also, "AND" taking priority over "OR" is the standard behaviour in almost all computer programming languages, so it's what people expect who are familiar with computer programming (a sizeable fraction of the Factorio player base).

Neither approach is "better" in a general sense, but "AND" preceding "OR" is easier to work out than the implicit parenthesizing from the top-to-bottom evaluation.

Explicit parenthesizing is not possible, and you need external combinator logic if you want to do that (e.g. if you want to construct (A OR B) AND (C OR D)); but that hasn't changed with the change in the evaluation order inside the train station.

--

You should also investigate the SmartTrains mod, it's for people like you who require non-standard train routing. You can take it very far, doing things that are simply impossible with Vanilla Factorio.
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
TheUnknown007
Fast Inserter
Fast Inserter
Posts: 129
Joined: Sun May 03, 2015 9:17 pm
Contact:

Re: What are the priorities for the train leave conditions?

Post by TheUnknown007 »

Not entirely true, with the new evaluation order it is always possible to rewrite the expression to an equivalent expression that works:
it is possible to rewrite your expression to the equivalent A AND C OR A AND D OR B AND C OR B AND D, which will give the desired outcome in the new evaluation order.
Except negation, that is not possible yet (leave when: (NOT 10 seconds passed) OR 20 seconds passed. I dunno, maybe someone has a ridiculously controlled train network / schedule?)

I'll look into mods if I ever get bored of the vanilla game (estimate: in 2 billion years)
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: What are the priorities for the train leave conditions?

Post by siggboy »

TheUnknown007 wrote:Not entirely true, with the new evaluation order it is always possible to rewrite the expression to an equivalent expression that works:
it is possible to rewrite your expression to the equivalent A AND C OR A AND D OR B AND C OR B AND D
OK, that's "multiplying" out the expression, but it's not "explicit parenthesizing" and it does make the original expression a lot longer. But of course it's correct in general, good point.
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
TheUnknown007
Fast Inserter
Fast Inserter
Posts: 129
Joined: Sun May 03, 2015 9:17 pm
Contact:

Re: What are the priorities for the train leave conditions?

Post by TheUnknown007 »

It isn't ideal yet, but it works. We could make a request for extended logic (explicit parentesizing and negation)
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: What are the priorities for the train leave conditions?

Post by siggboy »

I'd much prefer a few fixes to combinators (let's add "not equals" there, it's been missing for years), and adding stuff like "go to station" and a useful output port to train stations; and make rails connectable to read cargo wagons.

The "leave conditions" on a train schedule are ultimately very limited, no matter how much parenthesizing and logic options you add. If you can only run trains in a circle and maybe stop them for a while it's not cutting it. It must be possible to tell the train directly where to go, from a circuit.
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
Neemys
Filter Inserter
Filter Inserter
Posts: 461
Joined: Sat Apr 09, 2016 6:16 pm
Contact:

Re: What are the priorities for the train leave conditions?

Post by Neemys »

TheUnknown007 wrote: Except negation, that is not possible yet (leave when: (NOT 10 seconds passed) OR 20 seconds passed. I dunno, maybe someone has a ridiculously controlled train network / schedule?)
Negation is not needed. If you need any negation for a condition, there il already a way to do that unmodded by either changing the condition or adding other.
TheUnknown007 wrote:It isn't ideal yet, but it works. We could make a request for extended logic (explicit parentesizing and negation)
It add complexity to the ui and is unecessary.
siggboy wrote: The "leave conditions" on a train schedule are ultimately very limited, no matter how much parenthesizing and logic options you add. If you can only run trains in a circle and maybe stop them for a while it's not cutting it. It must be possible to tell the train directly where to go, from a circuit.
Yeah it's the only thing that I find missing, changing by circuit the schedule. I will see if the proposition have been properly been made and if not, make the proposition. I'm doing a save with my mod and it's mandatory to control train properly. Now it ended up as "smelter->science->smelter->circuit-> smelter->multipurpose (and so on)" to be sure everyone have what it need.
Want more space restriction ? Or maybe you want to be forced to use train for other thing than ore and oil ? Try Building Platform Mod !
TheUnknown007
Fast Inserter
Fast Inserter
Posts: 129
Joined: Sun May 03, 2015 9:17 pm
Contact:

Re: What are the priorities for the train leave conditions?

Post by TheUnknown007 »

Neemys wrote:
TheUnknown007 wrote: Except negation, that is not possible yet (leave when: (NOT 10 seconds passed) OR 20 seconds passed. I dunno, maybe someone has a ridiculously controlled train network / schedule?)
Negation is not needed. If you need any negation for a condition, there il already a way to do that unmodded by either changing the condition or adding other.
Well then, explain to me how to do this without negation, cause I don't see it: leave when: (NOT 10 seconds passed) OR 20 seconds passed. (in normal words: leave either within 10 seconds, or after 20 seconds, but not between 10 and 20 seconds)
Neemys
Filter Inserter
Filter Inserter
Posts: 461
Joined: Sat Apr 09, 2016 6:16 pm
Contact:

Re: What are the priorities for the train leave conditions?

Post by Neemys »

Oh you are right, when going through all condition to check if we can write then as not, I missed time passed. But instead of extending expression with not and parenthesis (which will make the ui more complicated), they should just add a new condition that stated "Not x second passed". All other can be negated is some way already.
Want more space restriction ? Or maybe you want to be forced to use train for other thing than ore and oil ? Try Building Platform Mod !
TheUnknown007
Fast Inserter
Fast Inserter
Posts: 129
Joined: Sun May 03, 2015 9:17 pm
Contact:

Re: What are the priorities for the train leave conditions?

Post by TheUnknown007 »

inactivity also can't be negated.

Also, negation is just one button, what is the big deal?

And, if done minimally, explicit parenthesizing would also only be one button ('add parenthesis', adds a opening and closing parenthese, select the opening parenthese and click on 'add condition' to add a condition within the parenthesis), but it would make adding something that must be true for all conditions (don't leave on the red signal) much more user friendly.
Neemys
Filter Inserter
Filter Inserter
Posts: 461
Joined: Sat Apr 09, 2016 6:16 pm
Contact:

Re: What are the priorities for the train leave conditions?

Post by Neemys »

Inactivity need to be negated ? Why having the train leave if inserter around it were busy filling/empty it ? As train emptyness is a condition (even the kind of content) It's more reliable to check what's inside (or not inside) and leave when we want instead of leave if inserter spend more than x second filling the train. If you are worry the train spend too much time, add a time passed condition.

If we just want to add "NOT" into schedule, adding new condition as I stated before is better.

Adding parenthesis is not that simple :

- How should the gui display them to be readable and understandable easily ? (in schedule condition list)
- How missing/surplus of parenthesis should be handle ? Train giving error ? Add missing in the end, remove surplus one from the top ? Should it display a warning ? in the gui or as a popup message on close ?
- Internal structure will be changed and the code edited as well (and bring bug at the same time).
- Every time you add button into gui, there will always be people that use them wrongly or don't understand them. Then you need to provide support for them.

It IS doable but is the result worth the trouble ? I'm not against the idea, but I will not make the post for it nor support the suggestion.
Want more space restriction ? Or maybe you want to be forced to use train for other thing than ore and oil ? Try Building Platform Mod !
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: What are the priorities for the train leave conditions?

Post by siggboy »

It's certainly not worth the trouble to add parenthesizing and an appropriate UI for it.

As I've said before, the leave conditions don't really make train stations a lot more powerful than they were in 0.12. Even if you only had the "circuit condition" and the possibility to look into train wagons (connectable rails), you could do everything that you can do right now (and more) with reasonable effort without the need for special UI and all sorts of fine-grained conditions.

E.g.: "item count" = connect rails to station, use circuit condition; "train full / empty" = same if the rails output status signals that signify full (or empty) wagons; "inactivity" = counter that resets on wagon content change; "time passed" = simple counter

Nothing of this requires more than 2 combinators if you have connectable rails that provides reasonable outputs. You can also parenthesize to your heart's content, and even blueprint your "expressions" for re-use and sharing.

Also, show me a leave condition with more than, say, 4 terms and I'll show you that it's overengineered. That leaves simple expressions which don't require parenthesizing.

If you want powerful train routing you need "go to" or "jump to" inputs, i.e. you number the train stations on the schedule and then take the next stop from an input to the train station. So the trains won't be forced to follow a fixed route.

In short, I don't really care how fancy it is to tell the train (not) to leave, as long as I can't tell it WHERE to go after it leaves.
Last edited by siggboy on Wed Sep 07, 2016 1:19 am, edited 1 time in total.
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
TheUnknown007
Fast Inserter
Fast Inserter
Posts: 129
Joined: Sun May 03, 2015 9:17 pm
Contact:

Re: What are the priorities for the train leave conditions?

Post by TheUnknown007 »

I am not saying that it would be useful to have a NOT inactivity for 5 seconds. Although it might be useful when you have an oil outpost: don't leave until there where at least 10 seconds of loading.

For the parenthesis: simply add a pair each time: ('A' and 'B' are conditions)

Code: Select all

A
'add parenthesis'

Code: Select all

A
AND (
)
Where the parenthesis are initially empty. This would behave the same as A AND true. In order to add something in the parenthesis, select the opening parenthese...

Code: Select all

A
AND ( // this line is selected
)
... and add a condition

Code: Select all

A
AND (
  B
)
Removing: either it can be done be selecting any of them (opening / closing parenthese) or only when selecting the opening parenthese.
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: What are the priorities for the train leave conditions?

Post by siggboy »

TheUnknown007 wrote:I am not saying that it would be useful to have a NOT inactivity for 5 seconds. Although it might be useful when you have an oil outpost: don't leave until there where at least 10 seconds of loading.
There's an option to have the train wait for x seconds and then leave (it's obviously going to "load" during that time, unless there's absolutely nothing to load which wouldn't make a difference). It even existed in 0.12. I still wouldn't use it, not at an oil outpost or anywhere else, I'd want the train to contain at least "x" or "be full".

If the train station only had a circuit condition (and a circuit interface to the wagons/loco/station) then people would be forced to think for a second and wouldn't come up with non-solutions to non-issues.
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
Post Reply

Return to “Gameplay Help”