08-24-2018 08:15 AM - edited 08-24-2018 08:20 AM
I'm given a 2D Array of strings where each row indicates two values are connected for example:
{A,B; G,''; D,C; D,A; E,F;
C,B;
H,''}
Indicates that:
From that given input, I would like to make a VI that would output the array
{A,B,C,D; E,F,'','';
G,'','','';
H,'','',''}
I am using the open G toolkit and currently, I have this solution:
As this is a fairly critical vi I would appreciate a review to:
Solved! Go to Solution.
08-24-2018 11:03 AM
Sorry, I don't have any OGTK installed, so I cannot run your example. I would think a variant attribute based solution might be simpler. Have you tried?
08-24-2018 04:44 PM
@altenbach wrote:
I would think a variant attribute based solution might be simpler. Have you tried?
See if this works for you. 🙂 (No guarantees. Can probably be further simplified).
08-26-2018 04:44 PM
The following "breaks" your output (though the algorithm seems to work, it's just the Output that is strange) -- add another pair, (A, E), to your Input Array. Before running this, predict the output (you'll probably be wrong).
Bob Schor
08-26-2018 07:56 PM
Why is the output strange? I do not understand. A is connected to E, E is connected to F, thus A and F are connected by E.
I guess it depends on how you define a match, it appears here anything connected is considered a match.
It can be different depending on your matching criterion. Assume you are matching everything that is 10% within each other and you have the following:
A = 0.9
B = 1
C = 1.1
B & C are within 10% of each other, B is within 10% of A but A is not within 10% of B, so do they match? Much harder to match and get groups. (Sidenote: I tried to do something similar with lengths of DNA fragments and found matches with Mathematica, much more code than CA's solution 🙂 which I am still trying to understand completely.)
mcduff
08-26-2018 08:59 PM
08-26-2018 10:12 PM
@altenbach wrote:
@Bob_Schor wrote:
The following "breaks" your output
Who is "your"?
I meant the Original Poster. I understood the format for output was strings (arrays?) listing the "connected elements", with possibly spaces at the end. By adding an additional input element that resulted in "merging" two strings, I ended up with an output that seemed to be in the "wrong" format. Since the Point of the Exercise, I thought, was to have a nice algorithm that worked, rather than try to show that there were no "edge cases" that the OP missed (which is hard, in general), I demonstrated (I thought) the existence of an Edge Case, proving his algorithm was faulty. Unless I downloaded it wrong ... or my version of LabVIEW isn't working.
Bob Schor
08-27-2018 10:08 AM
@Bob_Schor wrote:
The following "breaks" your output (though the algorithm seems to work, it's just the Output that is strange) -- add another pair, (A, E), to your Input Array. Before running this, predict the output (you'll probably be wrong).
Bob Schor
You are correct! I think I'll try to fix this, but I'll end up going with @altenbach's solution. I did not know you could do that kind of grouping.
08-27-2018 10:27 AM - edited 08-27-2018 10:39 AM
@altenbach wrote:
@altenbach wrote:
I would think a variant attribute based solution might be simpler. Have you tried?
See if this works for you. 🙂 (No guarantees. Can probably be further simplified).
I didn't even know you could do this! Also, if I'm not mistaken this vi would work for an N1xN2 array as long as N2max was known at compile time.
I'd be interested to know if this could be optimized further and debugged. I think I would like to use this logic as it seems to be faster and more versatile.
08-27-2018 10:37 AM
@mcduff wrote:
Why is the output strange? I do not understand. A is connected to E, E is connected to F, thus A and F are connected by E.
I guess it depends on how you define a match, it appears here anything connected is considered a match.
It can be different depending on your matching criterion. Assume you are matching everything that is 10% within each other and you have the following:
A = 0.9
B = 1
C = 1.1
B & C are within 10% of each other, B is within 10% of A but A is not within 10% of B, so do they match? Much harder to match and get groups. (Sidenote: I tried to do something similar with lengths of DNA fragments and found matches with Mathematica, much more code than CA's solution 🙂 which I am still trying to understand completely.)
mcduff
That's an interesting problem, fortunately for me, being connected is a boolean operation. the comment about the breakage was due to the fact that adding
{'A','E'}
at the end would produce
{'','','A','B','C','D','E','F'}
Giving me two phantom connection points