In software engineering it is important to estimate the effects that an input with size n will have in the performance of an algorithm. This concept exists from long time and it has strong foundations.
In the industrial automation world, either when programming a PLC or scripting in SCADA, for example, it is possible to get inspiration from these ideas and to apply these best practices. In fact, depending on the algorithm and the array size the PLC processing time could be heavily impacted and affect the whole manufacturing process.
Below are shown a few classical examples for Search and Sort algorithms:
Below are shown a few classical examples for Search and Sort algorithms:
The notation is called Big O and it means the worst case scenario "O(f(n))". The smaller the function f(n) the faster is the execution and the better it is.
- Bubble Sort O(n*n): Shift position of adjacent pairs, placing the smaller elements to the right and the bigger to the left.
- Selection Sort O(n*n): Look for the smaller element in the non-sorted array, and place it in the first position.
- Insertion
Sort O(n*n): EScan the array shifting position when necessary with insertion.
- Merge Sort O(n*log(n)): Breakdown the array into smaller arrays and shift positions when necessary. Build the array again after the elements are in the correct order.
- Linear Search O(n): Scan the array until find the desired value.
- Binary Search O(log(n)): When the array has been sorted or indexed, breakdown the array and repeat this process in the closer direction..
There are lots of sites on internet showing animations with these algorithms in practice and they are a nice way to visualize these effects.
To check some of these algorithms in a PLC example, check out the sample code from Rockwell called "TimestampDataSorting.ACD", that has a Bubble sort routine and a Insertion sort routine, both written in Structured Text (ST) language.
To check some of these algorithms in a PLC example, check out the sample code from Rockwell called "TimestampDataSorting.ACD", that has a Bubble sort routine and a Insertion sort routine, both written in Structured Text (ST) language.
Typically the file is located on the following path (C:\Users\Public\Documents\Studio 5000\Samples\ENU\vXX\Rockwell Automation)
No comments:
Post a Comment