From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Implementing a Graph Data Structure

Solved!
Go to solution

First time posting here, I was introduced to LabVIEW while participating in FIRST.

 

I was reading about Graph Data Structures, and wanted to see if I could use them in LabVIEW, as it looked like a good way to relate information. Unfortunately, it appears that the straight forward way that I attempted will not work. I tried creating a typedef which consisted of a cluster of two elements, an array of linked nodes and an array of edge weights. Alas, I found you can't have recursive data types, as the array of linked nodes in the typedef needed to be the same as the typedef. I know why this is after a bit of searching, but I was wondering if there was a way to get around this. From my research, it seems like using a root class and a child class is one possible, but advanced way of doing it.

 

I am currently thinking of just representing the linked nodes of a node as an array of index numbers which you can use to get the referenced nodes from the graph array. This means that the graph array cannot be sorted or otherwise modified so that the index numbers won't work, you can only add objects onto the end. Is this thinking right, or is there a different way to go about this?

0 Kudos
Message 1 of 3
(2,843 Views)
Solution
Accepted by topic author lukepike

Not an easy problem, as recursion is not native to LV programming (much less than any other language I used except assembler).

 

But the solution to your index number problem is to use 'keys'. Each node should have a unique key (number), so you can adress it (search for the key) even if the array is sorted in some way.

 

Again, it is not native to LV. This means, that you need to program the logic other languages use for that on your own (pseudo-pointers, handles, keys, hashes).

 

From a practical side: I would not implement the graph in LV itself but access a graph from some other source (data base?) via an interface (ActiveX, .NET). To learn a bit more about how to do it, try playing around with the tree control (it is a limited graph).

 

Felix

Message 2 of 3
(2,830 Views)

Thanks for the tips! I agree with your suggestion to use a database, I've used Microsoft Access databases with LabVIEW before with good success. I got the graph working and traversing using a key in LabVIEW, your solution did the trick. I originally just wanted to mess around with the concept of graphs, and this will work for now. If I ever need to use it in a more serious context, I'll probably go with the database.

0 Kudos
Message 3 of 3
(2,821 Views)