Comparing one or many signals with one or many signals

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
Post Reply
Hctib
Burner Inserter
Burner Inserter
Posts: 5
Joined: Sun Jan 28, 2018 12:19 am
Contact:

Comparing one or many signals with one or many signals

Post by Hctib »

In short: I need to figure out how to compare a list of signals with a list of signals and output only matched signals.
In details:
I have two train stations, the first outputs "T+train id", the second "U+train id". I also have a list of train ids. I need a circuit setup that checks if a train is on the id list and if it is, the setup should output the signal from the station ("T+train id" or "U+train id") that matches the list. I made a scheme to help understand what I mean:
Image

I can make this setup simply using as many combinators as cases there are, but I want to have a large list of train ids, let's say 30, and many stations, let's say 8. That way I would need 8*30=240 combinators and I would need to set each combinator manually, so that would be really painful, especially, when I'm planning to use this setup as a blueprint with different number of stations and different ids. That's why I need a setup in which I would only change ids on constant combinators and add train stations.

Assumption: Every train has different id, so the same id can't appear on both stations at once (there can't be T268 and U268 at once)

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3699
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Comparing one or many signals with one or many signals

Post by DaveMcW »

Decider combinator: Each = T → T (input count)
Arithmetic combinator: T * -1 → T

The decider combinator returns T + matching signal.
The arithmetic combinator returns -T.
When merged, the result is the matching signal.

You will need another pair of combinators for U.

Hctib
Burner Inserter
Burner Inserter
Posts: 5
Joined: Sun Jan 28, 2018 12:19 am
Contact:

Re: Comparing one or many signals with one or many signals

Post by Hctib »

Do you mean that?
AC
DC
Wiring
It would work only if ids were "T" type signals. That means I would need to duplicate also whole id list for "U". Or it even may not work, as it always passes "T", even if it doesn't match.
Besides, it doesn't compare "one or many signals" with "one or many signals", but only "one signal" with "one or many signals", so that's not really the solution I'm looking for. Anyway, thank you very much.

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3699
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Comparing one or many signals with one or many signals

Post by DaveMcW »

Look at the electric pole for the final result after the +T and -T have cancelled out.

Hctib wrote:
Fri Sep 21, 2018 1:04 pm
Besides, it doesn't compare "one or many signals" with "one or many signals", but only "one signal" with "one or many signals", so that's not really the solution I'm looking for.
It is impossible to do a 2-dimensional comparison with a fixed number of combinators in a fixed time. You either need to use more combinators, or check one signal per tick.

quyxkh
Smart Inserter
Smart Inserter
Posts: 1027
Joined: Sun May 08, 2016 9:01 am
Contact:

Re: Comparing one or many signals with one or many signals

Post by quyxkh »

To amplify DaveMcW's ncd: deciders can only compare a single pair of values, if you've got S stations each comparing against T train IDs that's S×T comparisons. You'll either need S×T deciders or pump S station readouts one per tick through T deciders one per tick, taking S ticks.

Besides, if you have 8 U stations each with a train in them, you can't put 8 different train IDs on a single output wire without further trickery, what are you planning to do with your outputs?

Rather than multiply the incoming ID's by -1 I'd premultiply the ID's in the constant combinators, that cuts one tick out of your delay.

Edit: the basic station-readout-multiplex trick is, have your central station run a clock on the readout multiplex red circuit using say the black signal as the address strobe. At each station, set a constant combinator with black set to the -ve of one less than the station's chosen ID (you pick, how is an exercise). Greenwire that and whatever station-readout signals you want to a black=0⇒Everything combinator whose input and output are both also redwired to the multiplex circuit. So if the station ID's 7, wire black=-6 into the constant combinator, the address strobe will do 1…2…3…4…5…6…7… and on tick 6 your decider's input will be redwire (multiplex circuit) black 6, greenwire (station-readout circuit) black -6, sum is black 0 so it'll add the station's signals (with black=0) to the multiplex circuit the next tick, when its address strobe will read 7.

Edit 2: that trick has a problem with three alternate solutions. The problem is, the Everything output includes the black=0 sum from the previous tick but also includes the rest of the signals from the multiplix input's previous tick. The alternatives are: add an idle cycle on the multiplex circuit (leave even ID's unassigned); or add an address isolator and one-tick readout delay, so multiplex red⇒ black+0⇒black red⇒ decider, constant -(station ID-2) green⇒decider, station readout green⇒ decider, decider is as before, black=0⇒Everything red=>multiplex; or use two wires for the multiplex, red is control driven only by the central station, green carries the data readouts including any other control data the station was responding to.
snap@T551257=3392x864-27.75-14.5,z2.jpg
snap@T551257=3392x864-27.75-14.5,z2.jpg (81.16 KiB) Viewed 2880 times

Hctib
Burner Inserter
Burner Inserter
Posts: 5
Joined: Sun Jan 28, 2018 12:19 am
Contact:

Re: Comparing one or many signals with one or many signals

Post by Hctib »

Thanks DaveMcW and quyxkh for useful suggestions. I managed to create what I was looking for. I didn't use 'stations encoding', like you quyxkh showed, because I need one cable for each station due to other reasons. In case someone wants to check it:
1
2


What does it do?
Compares each value from the left side with each value from the right side. Outputs matches.
To start, you have to put each signal in each station's constant combinator (alternatively connect station via arithmetic combinator 'each+0 output each'). You need to connect inputs respectively starting from number 1. Then put the id's according to the same rule. Finally turn off and on activator ('C' constant combinator). The output will appear on the memory cell, so be sure to make the signal go out one way to prevent corrupting the output. If it was powered up while building or while setting up inputs, it may get some values in the memory cells and latch highlighted on the 2. image. To reset that, clear and set those 3 combinators outputs again.

Cells:
Cells
To make this setup work, you actually need only one Station Cell and one ID Cell, so if you're not using some, you can delete them. However, if constant combinator signal is empty in this and further Cells, they are not taken into account when comparing, so deleting is not compulsory if Cells are empty. You can also add as much of them, as you need. Amount of Station Cells is independent from the amount if ID Cells. If deleting - delete from the top. If adding - blueprint 2 cells below and paste them overlaping one to preserve wiring. Then, in the decider combinator closest to the mid, set parameter to Z(or Y)=n+1, where 'n' is the number in the combinator below.

How does it work?
If it was code, it would look like this

It takes the first signal from first Station Cell. Compares with signal from the first ID Cell, then with signal from the second ID Cell, and so on until it find a match or go through all ID Cells with content (warning: see limitation 4.). Then it takes the second signal from the Station Cell and again compares with each of the ID Cells' signals.

Limitations:
1. ID Cell signal has to be 'I' type. If you want other type, you need to change 'I's on 2 combinators next to the output. It doesn't support situation, when IDs are signals of differnt type.
2. Station Cell signal type can't be 'C' nor ID Cell signal type (default 'I'; if you change ID to other type, then it can't be that type)
3. Either each Station Cell signals are of different types or you need to take out signals from the output as soon as they appear to prevent suming up of the same type signals.
4. If there is a gap in Cells, the setup will calculate length incorrectly. To prevent this, make sure the Cells are filled with signals from the bottom to the top. Another option is to set Z-length 'L' to specific value. This would look like in this blueprint:


In case someone wants to understand that, I have a spacious version which is far more readable than this compact version, just ask.
Thanks to Carla Moreno for his one tick pulse machine (https://www.youtube.com/watch?v=jHrqWAL5nzA)

Post Reply

Return to “Gameplay Help”