Jump to content

Automatic Recursion


Recommended Posts

I just had one of those eureka! moments when pondering the implementation of recursive calls.

I know that it does not take much effor to recurse a VI

post-208-1160751660.jpg?width=400

But what about a vi that automates the process for you and wraps it up into a neat little sub-vi

here is my vision which I don't have time to complete but I belive that the community could easily wrap their wires around

Create a VI that when dropped into a BD will do the following

  1. Create a sub-vi in the same location as the parent w/ some special namespacing
  2. drop the necessary blocks for recursion: see picture above
  3. determine the parents connector pane and set the sub-vi's pane to the same along w/ the static pane reference
  4. Copy the parents icon and do a glyph edit to mark as recursive
  5. then do a replace on the parents BD of the dropped recursion vi w/ the one just created

So I belive what would happen is the parent BD would have a sub-vi which looked almost identical which allowed for recursive calls!!!!

whatdaya think!!!

Link to comment

I'm thinking also that we could use express technology to accomplish this because it does the creation of a sub-vi for you w/out needing to make new files.

For those of you who are savvy to the express world. We have the ability to modify the source when running the configure vi. So when the express is configured (either automatically when dropped or when told so by the user) would be to modify the source VI to have the same inputs as the caller and drop the vi-server recursion fuctions in the guts.

oooooh I'm liking this.

Link to comment
For those of you who are savvy to the express world. We have the ability to modify the source when running the configure vi. So when the express is configured (either automatically when dropped or when told so by the user) would be to modify the source VI to have the same inputs as the caller and drop the vi-server recursion fuctions in the guts.

Hey that sounds very interesting ! So you can create the correct connector pane constant ! I've been waiting for that for quite some time...

Can you create such a constant given a non-typed VI ref ?

Joris

Link to comment
I'm thinking also that we could use express technology to accomplish this because it does the creation of a sub-vi for you w/out needing to make new files.

For those of you who are savvy to the express world. We have the ability to modify the source when running the configure vi. So when the express is configured (either automatically when dropped or when told so by the user) would be to modify the source VI to have the same inputs as the caller and drop the vi-server recursion fuctions in the guts.

oooooh I'm liking this.

I think an externalNode (XNode) will be better for that, because, as you modify the connector pane of the parent, the connector pane of the child (the recursive call subVI) should modify itself as well.

Edit: Another benefit is that you would not even need to create a SubVI in your project folder. The code would be right there behind the XNode.

PJM

Link to comment
I think an externalNode (XNode) will be better for that, because, as you modify the connector pane of the parent, the connector pane of the child (the recursive call subVI) should modify itself as well.

Edit: Another benefit is that you would not even need to create a SubVI in your project folder. The code would be right there behind the XNode.

PJM

I like this idea!

Link to comment
I think an externalNode (XNode) will be better for that

Quick safety tip for all you who seek to peek under the skirts of LV: external nodes and XNodes are not the same thing, though they both serve the same goal. External nodes were LV R&D's first attempt at nodes that script themselves. They have issues and have been supplanted by XNodes, our second attempt. XNodes are better, in theory*.

*"In theory", from the Latin "en theos" meaning "with God" or, more specifically, "assuming He Who Built The System doesn't change His mind." :)

Link to comment
Hey that sounds very interesting ! So you can create the correct connector pane constant ! I've been waiting for that for quite some time...

Can you create such a constant given a non-typed VI ref ?

I would find it hard to beilve that w/ all the scripting tools out there that it would be impossible... although I have not specifically tried yet.

anyone.... Bueller?....Bueller??

Link to comment

Bueller here.

http://xnodes.lavag.org/

Click on Recursion on the upper left.

I desire any and all feedback, this was a quick-as-possible venture that turned out to be quite nasty.

Source code is open for all of those curious, especially since the source code directly touts my abilities as a scripter.

Bonus features:

- Manual construction of a constant by typedef number array (that stupid ref is *not* an object creatable by the Create Object function!)

- Icon tweaking (a shadowed "R" -- which is fully customizable)

- Manual internal reconstruction upon double click (if necessary, which I don't think it should be)

Basically it's all that was talked about...just the code looks impossibly arbitrary because it took me a lot of trial and error to find out what LabVIEW would let me do.

Now if only I could convert this VI directly into :beer:

:thumbup:

- Adam Rofer

Link to comment

Nice idea. I think your example of factorial might take a second look. Maybe I did something simply wrong, but I built your example, exactly as shown and it returns an answer of 0. Makes sense, you keep subtracting one each time, til you get to zero, then pass out the eventual zero result and multiply. What am I missing here?

Link to comment

One thing I've noticed is that frames sometimes don't refresh properly, so if you have a problem finding my previously referenced item (and you've been to my documentation site before) you can simply go here:

http://xnodes.lavag.org/recursion.html

Nice idea. I think your example of factorial might take a second look. Maybe I did something simply wrong, but I built your example, exactly as shown and it returns an answer of 0. Makes sense, you keep subtracting one each time, til you get to zero, then pass out the eventual zero result and multiply. What am I missing here?

I took the code directly from NI's example:

http://zone.ni.com/devzone/cda/epd/p/id/1827

Check a few things, like if your VI is re-entrant. That needs to be the case or else my recursion thingy won't do anything but send back the default values for whatever outputs.

- Adam Rofer

Link to comment
I took the code directly from NI's example:

http://zone.ni.com/devzone/cda/epd/p/id/1827

Check a few things, like if your VI is re-entrant.

Thanks for the quick reply post. I'm low on my coffee quotient and wired the n through the True case instead of hardcoding the 1 constant. I also forgot the reentrant setting.

Works like a champ now. I'm going to take it and play with a few other examples, like getting the tree of a directory path with subdirectories. I'm also thnking of trying it for some XML parsing, etc.

Good Job Adam! This should be cross referenced with some of the other topics on recursion. I had posted one using VI server some while back. Your XNode does this much better.

Hmmm, we need to combine this with GOOP somehow, I can see some interesting possibilities.

:beer: :beer: :beer:

Link to comment
  • 1 month later...
Bueller here.

http://xnodes.lavag.org/

Click on Recursion on the upper left.

....

Basically it's all that was talked about...just the code looks impossibly arbitrary because it took me a lot of trial and error to find out what LabVIEW would let me do.

Now if only I could convert this VI directly into :beer:

:thumbup:

- Adam Rofer

The example works "almost" perfect Today I tried to expand the functionality (a second Input and Output)

Then the wires were brocken, I tried to relink etc. etc. LabVIEW Crashed etc. etc...

But Finaly I know how to do it without crashing LabVIEW and it really worked!!!

After changing someting in the vi I have always to replace the Vi..

But there is a "little" work arround (add/change the menue)...

But I still miss the thing with the beer...

Link to comment
The example works "almost" perfect Today I tried to expand the functionality (a second Input and Output)

Then the wires were brocken, I tried to relink etc. etc. LabVIEW Crashed etc. etc...

But Finaly I know how to do it without crashing LabVIEW and it really worked!!!

After changing someting in the vi I have always to replace the Vi..

But there is a "little" work arround (add/change the menue)...

But I still miss the thing with the beer...

I could try adding a function on the pull-down menu that says "Relink recursive VI", if that seems to be the problem.

In the mean time, try to double click on the VI, that should rebuild the internals without needing to do any fancy menu stuff.

Is that what caused it to crash?

As for the beer, I like beer.

- Adam

Link to comment
I could try adding a function on the pull-down menu that says "Relink recursive VI", if that seems to be the problem.

In the mean time, try to double click on the VI, that should rebuild the internals without needing to do any fancy menu stuff.

Is that what caused it to crash?

- Adam

Now it doesn't crash any more.

but double click cause every time an error in the recursive vi (code was not produced correctly) sorry I have the german version...

and if I then replace the recursive vi then I get always broken wires (exept one wire always stays on place) all others (input and output to the recursive vi) are brocken...

Update:

Now I figured out why I get broken wires:

This happens if I use a connector pane on the recursive vi that has more connections than connected wires...

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.