Logic network long(ish) expressions

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
Roaders
Burner Inserter
Burner Inserter
Posts: 18
Joined: Mon Jan 15, 2024 1:33 pm
Contact:

Re: Logic network long(ish) expressions

Post by Roaders »

OK, I think I got it working and covered all the edge cases.

Heavily based on Tertius's implementation.
  • I uase a constant combinator to set the required amount of each good with a negative value
  • I combine these negative values with the value in storage to calculate the deficit
  • I use this deficit to control the inserters (not got to using 1 inserter and changing the filtered item yet)
  • I use a decider combinator with ANYTHING < 0 to set the train limit for the station (calls a train when we are low on any item)
  • I use a constant combinator with each good set to -1 and a decider combinator to get a list of goods that are not on the train (train has run out)
  • I use a decider combinator with EACH < 0 to get a list of items that still need offloading. I then make this -1 by multiplying by -1
  • I use a Decider Combinator with EVERYTHING > 0 to make sure each good is either satisfied or is not on the train
The other little issue I had was with a train arriving and then blowing straight through the station. I think that this was because when the train is not there then all of the goods are marked as satisfied as there is no train so it assumes that the train has run out of everything. I guess that if the wait condition is satisfied before the train arrives it stops then goes straight away without re-evaluating the condition. To solve this I had to add the train ID to the logic so that the exit condition is only met when there is a train at the station.

I like this solution. I am specifying the number of goods that I want in one place (rather than in inserters and in combinators). I am not relying on the result adding up to a magic number so it's easy to add more goods. The same combinators are being used to evaluate the train limit and the wait condition.

It does look messy though... I could probably tidy it up a bit but it's hard moving things around as all the wires are removed when you move something!

Thanks again for all the help.


Pi-C
Smart Inserter
Smart Inserter
Posts: 1654
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Logic network long(ish) expressions

Post by Pi-C »

Roaders wrote:
Tue Jan 23, 2024 7:02 am
The other little issue I had was with a train arriving and then blowing straight through the station. I think that this was because when the train is not there then all of the goods are marked as satisfied as there is no train so it assumes that the train has run out of everything. I guess that if the wait condition is satisfied before the train arrives it stops then goes straight away without re-evaluating the condition. To solve this I had to add the train ID to the logic so that the exit condition is only met when there is a train at the station.
Does that mean that you're relying on a specific ID, or are you checking whether there is any train ID (i.e. whether the train station sends a signal 'T')? (I know there is a blueprint, but I can't use the game right now.)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

mmmPI
Smart Inserter
Smart Inserter
Posts: 2747
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: Logic network long(ish) expressions

Post by mmmPI »

Roaders wrote:
Tue Jan 23, 2024 7:02 am
It does look messy though... I could probably tidy it up a bit but it's hard moving things around as all the wires are removed when you move something!
You can use this mod to tidy things up https://mods.factorio.com/mod/PickerDollies , Ctrl + arrow moves a combinator without breaking wire.

Happy to hear you find a satisfying solution, will have a look at it :)
Tertius wrote:
Mon Jan 22, 2024 8:37 pm
The -1 is used to mark a signal, not to increase or decrease a value so it isn't zero any more.

So I convert zero to negative to mark the zeroes. Positive values destroy the mark. Then filter all surviving negatives and create 1 for each match.
I understand that, but also in other cases you could use positive (+1) value to mark signals if/when they are all negative, since then adding 1 would mark the signals that are 0 to be filtered as the only "positive" surviving. Here (with trains) positive value destroy the mark because number of material in the train are quantities that can't be negative, but such train content can be sign flipped and would then require such positive marking instead of negative. ( value of same sign as the signal destroy the mark)

I like your explanations i'm always learning a lot, but i thought you were being too harsh saying adding +1 or -1 is a sign of something not done right, potentially discouraging players to use a trick.

I thought saying "because train content are integers and quantity" was correctly describing the cases in which such marking with an offset of 1 could be used but thinking more of it i prefer "value of same sign as the signal destroy the mark".

But it's still not exact/perfect, part of what makes this marking possible is also that we are using only addition and subtraction here, because +1 or -1 wouldn't work the same way for marking value if there was some division or multiplication occuring to the quantities after adding or removing 1.

I don't have enough experience/knowledge to know how to rephrase the conditions for which adding 1 or removing 1 would constitute a marking, and when it is increasing or decreasing a value so it isn't zero any more so as to explain it to other players but I think it is getting clearer with the discussion.

Roaders
Burner Inserter
Burner Inserter
Posts: 18
Joined: Mon Jan 15, 2024 1:33 pm
Contact:

Re: Logic network long(ish) expressions

Post by Roaders »

Pi-C wrote:
Tue Jan 23, 2024 7:41 am
Does that mean that you're relying on a specific ID, or are you checking whether there is any train ID (i.e. whether the train station sends a signal 'T')? (I know there is a blueprint, but I can't use the game right now.)
Just using any id. Making sure that T > 0.

mmmPI
Smart Inserter
Smart Inserter
Posts: 2747
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: Logic network long(ish) expressions

Post by mmmPI »

Pi-C wrote:
Tue Jan 23, 2024 7:41 am
Roaders wrote:
Tue Jan 23, 2024 7:02 am
The other little issue I had was with a train arriving and then blowing straight through the station. I think that this was because when the train is not there then all of the goods are marked as satisfied as there is no train so it assumes that the train has run out of everything. I guess that if the wait condition is satisfied before the train arrives it stops then goes straight away without re-evaluating the condition. To solve this I had to add the train ID to the logic so that the exit condition is only met when there is a train at the station.
Does that mean that you're relying on a specific ID, or are you checking whether there is any train ID (i.e. whether the train station sends a signal 'T')? (I know there is a blueprint, but I can't use the game right now.)
It is checking whether there is any train ID, and it makes a T signal positive amongst negative 1 representing missing material hold in the train and being unloaded. If there are only positive signal at this decider, it output 1 "locomotive" signal, which i suppose is the train schedule departure condition, but the train itself is not present in the blueprint so can't see the schedule :cry:

train arriving and then blowing straight through the station can be solved sometimes adding a 0 second waiting time, or a 1 second waiting time in the train schedule, depending on the situations to let the circuit logic happens, and i suppose Roaders used another way which is adding a departure condition reading circuit network for that 1 locomotive signal. This would be adding a few ticks of waiting time, just what's necessary for the logic of "train should leave or not" to happen.

Roaders
Burner Inserter
Burner Inserter
Posts: 18
Joined: Mon Jan 15, 2024 1:33 pm
Contact:

Re: Logic network long(ish) expressions

Post by Roaders »

Ok so the 1 second thing might be a bit simpler. With multiple wait conditions does it just execute them in order or does it leave if any of them are matched or what?
Sorry that the train isn't in the blueprint... First time I have exported ANY blueprint from the game so didn't think about adding the train!

Roaders
Burner Inserter
Burner Inserter
Posts: 18
Joined: Mon Jan 15, 2024 1:33 pm
Contact:

Re: Logic network long(ish) expressions

Post by Roaders »

Yes, a 1 second wait condition AND trainSatisfied = 1 as the wait condition worked. I can remove some combinatores and make it a little bit simpler.

mmmPI
Smart Inserter
Smart Inserter
Posts: 2747
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: Logic network long(ish) expressions

Post by mmmPI »

Roaders wrote:
Tue Jan 23, 2024 8:20 am
Sorry that the train isn't in the blueprint... First time I have exported ANY blueprint from the game so didn't think about adding the train!
It was not meant as a negative critic but more as an "innocent" way of mentionning it was possible to include train(schedule) in blueprints in case you didn't know and also a disclaimer i couldn't be 100% sure :)
Roaders wrote:
Tue Jan 23, 2024 8:37 am
Yes, a 1 second wait condition AND trainSatisfied = 1 as the wait condition worked. I can remove some combinatores and make it a little bit simpler.
I am not exactly remembering when the train goes through the station without even braking, when it stops at the station but 0 tick not enough for any logic to occur, and when it stops for just enough time for circuit logic to occur. Maybe 0 second inactivity would be faster than 1 second waiting time, and still achieve the same purpose of delaying the train long enough for circuit logic to not be skipped. I remember facing those problems several time and improvising ^^.

I think you correctly identified the cause of the particular problem here :
Roaders wrote:
Tue Jan 23, 2024 7:02 am
I think that this was because when the train is not there then all of the goods are marked as satisfied as there is no train so it assumes that the train has run out of everything. I guess that if the wait condition is satisfied before the train arrives it stops then goes straight away without re-evaluating the condition. To solve this I had to add the train ID to the logic so that the exit condition is only met when there is a train at the station.

Roaders
Burner Inserter
Burner Inserter
Posts: 18
Joined: Mon Jan 15, 2024 1:33 pm
Contact:

Re: Logic network long(ish) expressions

Post by Roaders »

a wait period of 0 seconds did not work BTW. It made a difference. The train stopped and inserters managed 1 sweep of the arm but then the train left. 1 second means that the expression is correctly re-evaluated when the train arrives.

mmmPI
Smart Inserter
Smart Inserter
Posts: 2747
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: Logic network long(ish) expressions

Post by mmmPI »

Maybe 0 second inactivity would act different than 0 second waiting time, since inserter started a swing, i'm not sure again how exactly the game handle those timing conditions, and against what other time to compare it or if it make sense given the more general picture.

Tertius
Filter Inserter
Filter Inserter
Posts: 671
Joined: Fri Mar 19, 2021 5:58 pm
Contact:

Re: Logic network long(ish) expressions

Post by Tertius »

mmmPI wrote:
Tue Jan 23, 2024 7:47 am
I like your explanations i'm always learning a lot, but i thought you were being too harsh saying adding +1 or -1 is a sign of something not done right, potentially discouraging players to use a trick.
I seek beauty in creating circuit setups. Adding an 1 as workaround to make some signal not vanish is ugly, so I don't like it. It's a workaround, and workarounds tend to add more edge cases, for which you need workarounds as well, so it adds up in complexity and in ugliness.
The best thing for me is if you get a simple setup where everything just comes together.

I don't want you never use +/-1. Just where it's really necessary.
For example, I have a train loading station, the counterpart of what we're discussing here. My loading station computes the diff between train content and required amount and loads this into the train. But the moment where the train connects the train content isn't yet subtracted due to combinator latency, so the first inserter swing is a full stack filter inserter hand with some random item from the ANYTHING selection, no matter if it is already in the train or not.

I found out that virtual signals (A-Z) seem to have priority in the ANYTHING selection so if you feed a virtual signal in addition, ANYTHING picks that virtual signal before everything else, this is set as filter, and the inserter stalls. After some latency,, the train content comes through the circuit, including the negative of the train id. So if I use T=1 as virtual signal to stall the inserter, this T=1 is canceled out by the negative of the train ID T, and the inserter gets its intended filter at the same time and everything comes together. This also avoids the edge case that a train in manual mode is standing at the station. In this case, active inserters activate automatically and fill into the train whatever they grab. So in this case, 2 edge cases are avoided by the workaround and none introduced, so I do this of course.

robot256
Filter Inserter
Filter Inserter
Posts: 596
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: Logic network long(ish) expressions

Post by robot256 »

Tertius wrote:
Mon Jan 22, 2024 9:31 pm
Roaders wrote:
Mon Jan 22, 2024 8:12 pm
The issue is that I no longer get a value of 4 to signal that the train should leave because one of the values cancels out and is not included. I think I can use the everything wild card though. If I say everything must be greater than 0 then if the value doesn't exist the train can still leave. Thanks again
I developed a lengthy and elaborated answer and wanted to show how to do things without that ugly +/-1. After some time with no success, I looked into my existing station to see how I solved it in there.
Well, I didn't solve it. Sorry.

Instead, I used "5 seconds inactivity" as waiting condition in the train schedule. This means, if there is no inserter or fluid pumping activity for more than 5 seconds, the train will leave. But as long as there is activity, the train will stay.
This is the solution I always use. Each inserter is filtered for one item and has either a circuit or logistic condition to enable when that item has less than the desired amount in the outpost. Then the train waits for inactivity. When every item is either satisfied or empty on the train, the inserters stop working, the inactivity timer expires and the train leaves. No combinatora at all.

mmmPI
Smart Inserter
Smart Inserter
Posts: 2747
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: Logic network long(ish) expressions

Post by mmmPI »

Tertius wrote:
Tue Jan 23, 2024 1:49 pm
I seek beauty in creating circuit setups. Adding an 1 as workaround to make some signal not vanish is ugly, so I don't like it. It's a workaround, and workarounds tend to add more edge cases, for which you need workarounds as well, so it adds up in complexity and in ugliness.
The best thing for me is if you get a simple setup where everything just comes together.
I heard that perfection is achieved not when there is nothing more to add , but when there is nothing to remove. I think beauty is much more subjective, and often times for me it's the little imperfections that plays a role :) Perfection is hard to achieve, but you can find beauty in the little things.

I understand what you mean by workaround i think , but irony to me is your last sentence also using the term workaround to describe your solution :lol:
Tertius wrote:
Tue Jan 23, 2024 1:49 pm
I don't want you never use +/-1. Just where it's really necessary.
For example, I have a train loading station, the counterpart of what we're discussing here. My loading station computes the diff between train content and required amount and loads this into the train. But the moment where the train connects the train content isn't yet subtracted due to combinator latency, so the first inserter swing is a full stack filter inserter hand with some random item from the ANYTHING selection, no matter if it is already in the train or not.

I found out that virtual signals (A-Z) seem to have priority in the ANYTHING selection so if you feed a virtual signal in addition, ANYTHING picks that virtual signal before everything else, this is set as filter, and the inserter stalls. After some latency,, the train content comes through the circuit, including the negative of the train id. So if I use T=1 as virtual signal to stall the inserter, this T=1 is canceled out by the negative of the train ID T, and the inserter gets its intended filter at the same time and everything comes together. This also avoids the edge case that a train in manual mode is standing at the station. In this case, active inserters activate automatically and fill into the train whatever they grab. So in this case, 2 edge cases are avoided by the workaround and none introduced, so I do this of course.
I'm not sure i'm getting exactly what you described, but i think i got the principle of it, from what i understand one could also use the train ID fed in a decider to make it T=1 when there is a train, and multiply this by what the inserters are supposed to have as filter ( each * T => each ). This way when T=0, it nullify their filters, only when a train is detected it would start loading similar to OP did to prevent the train from departing too early right ?

I'm less after "perfect" blueprints than after collection of tools or tricks, workarounds are tools, i will probably use the +/-1 thing even when it's not strictly necessary, just to go faster sometimes to implement a logic, as proof of concept to have a vertical slice of someting working without investing too much time on making intermediate steps that would stay for long, thinking it's always possible to try and reduce/optimize it later if it end up being used more than once or even at all in a game x). To me what's good to remember is what it means when the workaround is used.

Considering the path to perfection, you start with nothing, you add a bunch of thing untill it works, and then you remove all you can while it still work. Workarounds are meant to be used in the first phase of experimentation and in the very last to me. When you have this complicated problem that your usual tool can't solve, you try adding something "ugly" or "naive" or "that shouldn't work used properly" or "what if ?", and also at the end, when you try to optimize the most and you can do something "ugly" meant as " something you wouldn't have done before because you'd have to keep built upon it but since it's the final optimization touch you allow yourself doing it because it won't get touched anymore again".

Also the minimalist (footprint) solution is often time the most beautiful i would tend to agree on that subjective view, but sometimes you want it minimalist in other criterion than footprint. I had contraptions left not fully optimized/reduced because it would have broken symmetry :)

Roaders
Burner Inserter
Burner Inserter
Posts: 18
Joined: Mon Jan 15, 2024 1:33 pm
Contact:

Re: Logic network long(ish) expressions

Post by Roaders »

I've refined this a little bit now. SOme improvements:
  • I only have 1 constant combinator. I get negative values using arithmetic combinators on the single combinator that specifies the quantities of each good
  • I now ignore the goods that are not on the train unless there is a train in the station. This stops the race condition where a train arrives and immediately leaves
  • I only request a train if the goods are below half the level that I set. This stops a train immediately being recalled if 1 item is used.


Post Reply

Return to “Gameplay Help”