combining train waiting conditions
-
- Inserter
- Posts: 45
- Joined: Thu Aug 27, 2015 4:37 pm
- Contact:
combining train waiting conditions
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
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
-
- Fast Inserter
- Posts: 121
- Joined: Wed Apr 06, 2016 4:01 am
- Contact:
Re: combining train waiting conditions
Yeah, an answer would be nice (im currently to lazy to test it )
-
- Smart Inserter
- Posts: 1463
- Joined: Sun Jun 15, 2014 11:39 am
- Contact:
Re: combining train waiting conditions
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 (668.52 KiB) Viewed 6908 times
Re: combining train waiting conditions
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".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
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
Re: combining train waiting conditions
That's incorrect. See the above post for how it actually works.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
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
-
- Smart Inserter
- Posts: 1463
- Joined: Sun Jun 15, 2014 11:39 am
- Contact:
Re: combining train waiting conditions
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
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
Re: combining train waiting conditions
Yeah I've just tested it as well. You're right.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
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
-
- Smart Inserter
- Posts: 1463
- Joined: Sun Jun 15, 2014 11:39 am
- Contact:
Re: combining train waiting conditions
definitely report it. it doesnt seem to much any expected logic
Re: combining train waiting conditions
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
Re: combining train waiting conditions
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.
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
Re: combining train waiting conditions
So to be clear. You mean the conditions can be parenthesized like this?: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
((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
Re: combining train waiting conditions
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.
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
-
- Burner Inserter
- Posts: 14
- Joined: Thu Mar 17, 2016 4:01 pm
- Contact:
Re: combining train waiting conditions
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.)
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.)
Re: combining train waiting conditions
That does not correspond with: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.)
I think that the order in which you put things matter here. I'm not sure in what way yet.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
-
- Burner Inserter
- Posts: 14
- Joined: Thu Mar 17, 2016 4:01 pm
- Contact:
Re: combining train waiting conditions
Jupiter wrote: That does not correspond with:I think that the order in which you put things matter here. I'm not sure in what way yet.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
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.
Re: combining train waiting conditions
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.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.
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.
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.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.
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
-
- Burner Inserter
- Posts: 14
- Joined: Thu Mar 17, 2016 4:01 pm
- Contact:
Re: combining train waiting conditions
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.
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.
-
- Smart Inserter
- Posts: 1463
- Joined: Sun Jun 15, 2014 11:39 am
- Contact:
Re: combining train waiting conditions
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.
-
- Burner Inserter
- Posts: 14
- Joined: Thu Mar 17, 2016 4:01 pm
- Contact:
Re: combining train waiting conditions
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.
-
- Smart Inserter
- Posts: 1463
- Joined: Sun Jun 15, 2014 11:39 am
- Contact:
Re: combining train waiting conditions
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