From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Example Code

Advanced Data Structures in LabVIEW

Code and Documents

Attachment

Overview

In the context of computer programs "Data" is a unit of information.  A "Data Structure" is when you organize data for your application.  LabVIEW has many native data structures like clusters, queues, and objects.  This article is dedicated to talking about building higher and more advanced forms of data structures in LabVIEW.  For the 1.0 version we will be providing examples of Linked Lists, Trees, and Graphs in entirely native LabVIEW.  LabVIEW Object-Oriented programming (LVOOP) and Data Value References (DVRs) technology was used to implement these examples.

Description

Linked List

A linked list is a data structure that consists of nodes that are linked sequentially.  Linked lists can be visualized as a chain, where each link in the chain is a node.  In AdvDataStructures.lvproj (attached below) navigate to the LinkedList virtual folder to see the implementation in LabVIEW.  An example of how to use the linked list can be found in ClassBased\Applications\PriorityQueue\PQMain.vi.  PQMain.vi demonstrates how to build upon a linked list to make a Priority Queue.  Priority Queues are used in applications that need schedulers.

LinkedList.png

Tree

A tree data structure is similar to linked list, except each node has a single parent node, and unlimited child nodes.  In AdVDataStructures.lvproj navigate to the Tree virtual folder to see a implementation of a tree in LabVIEW.  To see an example of how to solve the travelling salesman problem using a tree data structure open Applications\RouteMinimizing\FindRouteExample.vi.

Tree.png

Graph

A graph is a data structure that allows for any number of nodes to link to another node. In the most generic graph definition, there are no restrictions on how nodes are linked.  In AdvDataStructures.lvproj navigate to the Graph virtual folder to see graph implementation in LabVIEW.  There are two examples of how to use a graph.  The first is a shortest path demonstration located in Applications\Occupancy Grid\ShorestPath.vi.  The second is a sudoku puzzle solver found in Applications\SudokuSolver\SudokuSolver.vi.

Graph.png

Conclusion

The code provided is meant to be a starting place for developers who would like to solve problems that can benefit from a linked list, tree, or graph example.  Below are two versions of the code AdvDataStructures100.zip (LV2009) and AdvancedDataStructures110.zip (LV2010).  Both are very similar, but I updated the content in AdvancedDataStructures110.zip for the NI Week Alliance Day 2011.  I have included a UML representation of the class hierarchy.  Anyone may contribute to the source code.  If there are specific problems you would like to see solved email me at brian.kindinger@ni.com.

Steps to Implement or Execute Code

  1. Open one of the attached .zip files
  2. Copy the "Advanced Data Structures" folder to your computer
  3. Open "AdvDataStruct.lvproj"
  4. Open relevant code


Requirements to Run

Software

LabVIEW 2010 or Later

Hardware

N/A

Additional Images

Data Structures

StructInLabVIEW.png

Brian K.

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
BSGMike
Member
Member
on

This looks extremely interesting. However I only have Labview 8.5 so can't open the code. Would there be any chance of posting an 8.5 version please? It would be much appreciated.

Brian_K.
NI Employee (retired)
on

Unfortunatily I cannot because it uses Data Value References which are a feature of LabVIEW 2009.  They could be replaced with single element queues though.  SEQs should be slightly slower though.

Brian K.
brijesh
Member
Member
on

This is really Interesting Topic. And Thanks You so Much for sharing.

CLAD
Labiew programmer
Roger1
Member
Member
on

Got an error opening AdvancedDataStructures110.zip

Brian_K.
NI Employee (retired)
on

Any hints on what the error is?  Does the 100 version work for you?

Brian K.
Roger1
Member
Member
on

This time the zip file wasn't corrupted.

Enjoy looking at your code, especially the FindRoute Example. Brings back memories of homework assignments in my college days but with a new LV twist.

Brian_K.
NI Employee (retired)
on

That's is pretty much what got me started on the specific Applications.  I said to myself what did I do in college, and can I do it in LabVIEW?  I call it advanced because they turned out to be tricky to make in LabVIEW despite the fact that it was moderately difficult in C.  What is interesting is that when you properly do it in LabVIEW the speed of the code is on par with low level C implementations (which is a complement to the compiler R&D group).

Brian K.
Marian_O
Active Participant
Active Participant
on

Thanks for the live presentation at the NI Week Alliance Day

Marian Vorderer
WG-
Member
Member
on

I want to add that this implementation of advancded datastructures has a few fallbacks.

The linked list and many of the other abstract datastructures works with data value references (DVR). The DVR needs to be created before inserting it into the linked list. The problem is is that it is now still possible to change data in the DVR hence the data also changes in the linked list. Further if you would insert the DVR at a certain point and later insert the same DVR again you will get a loop in your linked list. I.e. A->B->C then add A again you will get A->B->C->A and A again points to B. Henc if you want to add data of a class twice in the linked list you have to create two DVR's.

Brian_K.
NI Employee (retired)
on

WouterG,

You are correct in that the access to the DVR outside of the linked list is still possible in this example.  In reality you would probably create a API based on the data structures that protect inproper access.

Brian K.
abhinandan
Member
Member
on

i am new to labview and i would like to know how to use the vi's which i have downloaded here

is there a video which i can watch to get started ?

Brian_K.
NI Employee (retired)
on

This is from a presentation I gave at Alliance Day NI Week 2010 and 2011.  Above is the presentation.  If you are new to LabVIEW I would not suggest starting with this code, as it can be pretty complex without really helping you get started.  I suggest something more like this http://www.ni.com/gettingstarted/labviewbasics/

Brian K.
HomelessD
Member
Member
on

Kudos, Brian.  Nice Job.  I'm glad I circled back around to this topic, every couple years, to see if someone had posted this.  Been waiting for someone to create a "vector" since Labview OO came out.  Thanks, now I have no excuses to write my application...lol

 

Contributors