combining train waiting conditions

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
Fahrradkette
Inserter
Inserter
Posts: 45
Joined: Thu Aug 27, 2015 4:37 pm
Contact:

combining train waiting conditions

Post by Fahrradkette »

Hello there fellow factorians.

I was wondering how a combination of multiple waiting conditions evaluate. Like multiple AND/OR.

Reading the list from top to bottom, is "A && B || C" equal to "(A && B) || C" or "A && (B || C)"?
Also, is it possible to have stuff like "(A && B) || (C && D)"?

Greetings
terror_gnom
Fast Inserter
Fast Inserter
Posts: 121
Joined: Wed Apr 06, 2016 4:01 am
Contact:

Re: combining train waiting conditions

Post by terror_gnom »

Yeah, an answer would be nice :) (im currently to lazy to test it :P )
kingarthur
Smart Inserter
Smart Inserter
Posts: 1463
Joined: Sun Jun 15, 2014 11:39 am
Contact:

Re: combining train waiting conditions

Post by kingarthur »

so i ran some tests and it looks like any the conditions are read from top to bottom. any and statements are attached together. if an or statement comes after any and statements they are ignored. if a and astatement comes after an or statement it will attach to both statements in front of or behind the or statement
Attachments
and or.png
and or.png (668.52 KiB) Viewed 6908 times
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: combining train waiting conditions

Post by siggboy »

Fahrradkette wrote:Hello there fellow factorians.

I was wondering how a combination of multiple waiting conditions evaluate. Like multiple AND/OR.

Reading the list from top to bottom, is "A && B || C" equal to "(A && B) || C" or "A && (B || C)"?
Also, is it possible to have stuff like "(A && B) || (C && D)"?

Greetings
AND has higher precedence than OR, like in Boolean logic and in all programming languages. That is, "x AND y OR z = (x AND y) OR z".
Parenthesizing is not possible, but you can do it in combinators outside the station.
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: combining train waiting conditions

Post by siggboy »

kingarthur wrote:so i ran some tests and it looks like any the conditions are read from top to bottom. any and statements are attached together. if an or statement comes after any and statements they are ignored. if a and astatement comes after an or statement it will attach to both statements in front of or behind the or statement
That's incorrect. See the above post for how it actually works.
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
kingarthur
Smart Inserter
Smart Inserter
Posts: 1463
Joined: Sun Jun 15, 2014 11:39 am
Contact:

Re: combining train waiting conditions

Post by kingarthur »

maybe my description just sucks so im simply what i was trying to say my results are.
after rerunning the data it shows that
conditions 1,2, and 4 = true train will move
or
conditions 3 and 4 = true train will move

condition 4 has to be true in both case for the train to move
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: combining train waiting conditions

Post by siggboy »

kingarthur wrote:maybe my description just sucks so im simply what i was trying to say my results are.
after rerunning the data it shows that
conditions 1,2, and 4 = true train will move
or
conditions 3 and 4 = true train will move

condition 4 has to be true in both case for the train to move
Yeah I've just tested it as well. You're right.

For me this is a bug, I think I'll report it if nobody else has yet.

If you have "a AND b OR c AND d" this must always evaluate to TRUE if "a AND b" is true. I'm pretty sure that Twinsen will agree, because it's what his programming language would do as well :).
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
kingarthur
Smart Inserter
Smart Inserter
Posts: 1463
Joined: Sun Jun 15, 2014 11:39 am
Contact:

Re: combining train waiting conditions

Post by kingarthur »

definitely report it. it doesnt seem to much any expected logic
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: combining train waiting conditions

Post by siggboy »

Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: combining train waiting conditions

Post by siggboy »

Has already been moved to WontFix.

Apparently it's OK like it is because it does not say in bold red letters that you should apply common sense when looking at the UI. :?
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
Jupiter
Fast Inserter
Fast Inserter
Posts: 174
Joined: Thu Jun 23, 2016 2:38 pm
Contact:

Re: combining train waiting conditions

Post by Jupiter »

kingarthur wrote:maybe my description just sucks so im simply what i was trying to say my results are.
after rerunning the data it shows that
conditions 1,2, and 4 = true train will move
or
conditions 3 and 4 = true train will move

condition 4 has to be true in both case for the train to move
So to be clear. You mean the conditions can be parenthesized like this?:
((1 AND 2) OR 3) AND 4

Is it the general pattern that stuff gets parenthesized like this??:
(((((1 x 2) x 3) x 4) x 5) x 6)

where the numbers are conditions and x's are either AND or OR
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: combining train waiting conditions

Post by siggboy »

The expression is not parenthesized at all. It's not even a boolean expression in the common sense.

The "AND" conditions are all necessary conditions. They all form a compound statement (conjunction) that needs to be true for the train to leave.

Any "OR" conditions are sufficient conditions. So if any of the "OR" conditions is true, the train will also leave.

The statements are not meant to be read as a boolean expression.

Apparently this is what's intended, but the user interface is very misleading because it uses the keywords "AND" and "OR", which suggest that Boolean logic applies.

If they want to keep it as it is now, they should call them "necessary" and "sufficient" instead of "AND" and "OR", or make a UI with two groups of statements, one where all must be true, and another where only one must be true.
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
guitarmanmike
Burner Inserter
Burner Inserter
Posts: 14
Joined: Thu Mar 17, 2016 4:01 pm
Contact:

Re: combining train waiting conditions

Post by guitarmanmike »

So it seems like the logic is as follows.

Train Leaves = (A1 x A2 x A3 ... An) OR ((O1 + O2 + O3 ... On) >0)

Where each A term is an AND condition and each O term is an OR condition. (The 0 or 1 from the A..An conjuction is treated as a boolean.)
Jupiter
Fast Inserter
Fast Inserter
Posts: 174
Joined: Thu Jun 23, 2016 2:38 pm
Contact:

Re: combining train waiting conditions

Post by Jupiter »

guitarmanmike wrote:So it seems like the logic is as follows.

Train Leaves = (A1 x A2 x A3 ... An) OR ((O1 + O2 + O3 ... On) >0)

Where each A term is an AND condition and each O term is an OR condition. (The 0 or 1 from the A..An conjuction is treated as a boolean.)
That does not correspond with:
kingarthur wrote:maybe my description just sucks so im simply what i was trying to say my results are.
after rerunning the data it shows that
conditions 1,2, and 4 = true train will move
or
conditions 3 and 4 = true train will move

condition 4 has to be true in both case for the train to move
I think that the order in which you put things matter here. I'm not sure in what way yet.
guitarmanmike
Burner Inserter
Burner Inserter
Posts: 14
Joined: Thu Mar 17, 2016 4:01 pm
Contact:

Re: combining train waiting conditions

Post by guitarmanmike »

Jupiter wrote: That does not correspond with:
kingarthur wrote:maybe my description just sucks so im simply what i was trying to say my results are.
after rerunning the data it shows that
conditions 1,2, and 4 = true train will move
or
conditions 3 and 4 = true train will move

condition 4 has to be true in both case for the train to move
I think that the order in which you put things matter here. I'm not sure in what way yet.

You are correct it doesn't match what kingarthur gave as sample data. I was going off of what I thought siggboy was describing however his description (or my understanding of it) doesn't match the real world example.


It acts like the below from what I understand.

B1 x B2 + B3 x B4 will be evaluated like this leave = ((((B1) x B2) + B3) xB4) I would call it maybe eager parenthesis(izing) in that it immediately runs the adjacent operation then carries that result forward to the next operation.

This matches the data king arthur gave. So for example an 'AND' in the last position will be precedent and have to be true in order to evaluate the expression true. An 'OR' in the last position will make the train leave on that true boolean no matter the previous expressions. So they kind of act as opposite overrides for the previous expression the 'AND' can force a false for the expression an 'OR' can force a true.

How you order the expression will require some careful thought but the ones towards the end will tend to have more influence in the final evaluation it seems.


EDIT: Jupiter I just realized you made the same parenthetical expression just a few posts up.
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: combining train waiting conditions

Post by siggboy »

So they kind of act as opposite overrides for the previous expression the 'AND' can force a false for the expression an 'OR' can force a true.
I think we can agree that it is ROYALLY fucked up in the current implementation. Several people with an understanding of predicate logic are not able to work out straight away how multiple conditions are being evaluated.

The only official info that we have is by Rseding91 who said "it's simply evaluated from top to bottom"; whatever that means.

I've tried with this expression:

A > 0
OR B > 0
AND C > 0
OR D > 0

This is the truth table that I get from an actual train station:

A B C D T
0 0 0 0 0
0 0 0 1 1
0 0 1 0 0
0 0 1 1 1
0 1 0 0 0
0 1 0 1 1
0 1 1 0 1
0 1 1 1 1
1 0 0 0 0
1 0 0 1 1
1 0 1 0 1
1 0 1 1 1
1 1 0 0 0
1 1 0 1 1
1 1 1 1 1

So, D => T, D shortcuts to the leave condition

Eliminating D from the table, we're left with:

A B C T
0 0 0 0
0 0 1 0
0 1 0 0
0 1 1 1
1 0 0 0
1 0 1 1
1 1 0 0

That's equivalent to (A || B) && C => T

So, how do we get from
A || B && C || D
to
((A || B) && C) || D

It seems to imply what you've called "eager parenthesizing", but it's probably simply bottom to top evaluation, with the end result being compounded (what Rseding91 probably meant by "accumulated", but he said it's "top to bottom" which is definitely wrong).

I can only repeat that I think this is awful and nobody will ever understand it without serious investigation.
guitarmanmike wrote:How you order the expression will require some careful thought but the ones towards the end will tend to have more influence in the final evaluation it seems.
This won't help 99.999% of the player base, because it's simply way too arcane. Simply following boolean precedence would be a lot better.
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
guitarmanmike
Burner Inserter
Burner Inserter
Posts: 14
Joined: Thu Mar 17, 2016 4:01 pm
Contact:

Re: combining train waiting conditions

Post by guitarmanmike »

It is top to bottom in the sense that the algorithm evaluates the operations sequentially top down and the result gets passed to the next operator.

If you think of it as an algorithm which would operate on an arbitrary array of operands it kinds of makes sense to call it top down.

Operands ops = [
B1
B2
B3
B4
]

(* is AND, + is OR)
Operations opts = [
*
+
*
]

int i =0
bool res = ops (B1)
for opt : opts

res = (if opt is +) res + ops[++i] : res * ops[++i]

end

return res (zero is false ,1 or higher is true)


There is probably a more elegant way to choose the operation to perform but I think it gets the point across.
kingarthur
Smart Inserter
Smart Inserter
Posts: 1463
Joined: Sun Jun 15, 2014 11:39 am
Contact:

Re: combining train waiting conditions

Post by kingarthur »

they way i understand its function to be is that the list of conditions is read from top to bottom adding all the and statements together. or statements reset the where the list starts reading from. if you only have and statements the list starts at the top with the very first condition. if the list contains or statements anytime a or statement comes true that or statement becomes the top of the list and it will continue down the list looking for anymore and statements while ignoring any or statements that are false.
guitarmanmike
Burner Inserter
Burner Inserter
Posts: 14
Joined: Thu Mar 17, 2016 4:01 pm
Contact:

Re: combining train waiting conditions

Post by guitarmanmike »

kingarthur wrote:they way i understand its function to be is that the list of conditions is read from top to bottom adding all the and statements together. or statements reset the where the list starts reading from. if you only have and statements the list starts at the top with the very first condition. if the list contains or statements anytime a or statement comes true that or statement becomes the top of the list and it will continue down the list looking for anymore and statements while ignoring any or statements that are false.

What you just describes is a consequence of the algorithm I just described... any OR true is going to completely disregard any operations before it in an iterative boolean evaluation. The same could be said of an AND false except in the opposite effect (forcing to a 0). If you come up to an OR true the value will be true (or +1) in my algorithm and it wont matter how many OR false (+0) come after that the result will stay true (1) the only thing that could matter after an OR evaluates to true is "AND false".

It is not intuitive but it makes sense from an algorithm perspective and just requires some extra thought in ordering of your operations or resorting to doing the comparisons in a combinator.
kingarthur
Smart Inserter
Smart Inserter
Posts: 1463
Joined: Sun Jun 15, 2014 11:39 am
Contact:

Re: combining train waiting conditions

Post by kingarthur »

i had not read your post at the time i replied as yours wasnt showing yet. i didnt intend to copy what you had said already
Post Reply

Return to “Gameplay Help”