luis2810 Posted May 18, 2018 Share Posted May 18, 2018 HELLO I would like to know if exist a way to sort decreasing or ascending a state variavel vector? Thank you Link to comment Share on other sites More sharing options...
dsturrock Posted May 18, 2018 Share Posted May 18, 2018 Not directly. Choice 1) You could use the Find step in a loop to find the lowest item and copy it to another array or to an output table. If you don't really need it sorted, but just want to use them in the right order you could just clear each item as you access it and not store it elsewhere. Choice 2) You could write a custom step to do it. Choice 3) You could create an entity for each element of the array, assign a state on the entity and then stick those entities in a queue ranked by that state. Link to comment Share on other sites More sharing options...
jzhou Posted May 19, 2018 Share Posted May 19, 2018 you can write a sorting algorithms with process steps. I attached one example (built in sprint 10.171) I wrote two weeks ago. It use simple Insert Sorting algorithms, the purpose is : a timer trigger the sorting process and sort the vectors in assending way. then excecute according to the sequence...I only write one cycle, you should resetting some values in the algorithm to make it work ... This is Before Sorting: 26,25,16 ,18,22 This is After Sorting :16,18,22,25,26 This is the main sorting process Resetting values in algorithms(not in attached model). Hope it helps. You can wrting whatever sorting algorithms you want, like shell algorithms, bubble algorithms, cocktail algorithms, name a few...which can be reusable in your future projects. BTW: if you wrote this algorithms in C#, it takes 26 lines, we use 18 steps...can be less.. or just as David suggests, you can write a customised sorting STEP using simio C# API , it makes model look neat... -------------------------------------------------------------------------------------------------------------- static void InsertSort(int[] dataArray) { for (int i = 1; i < dataArray.Length; i++)//外层循环用来确定待比较的数值 { int iValue = dataArray; //保存索引1的位置,不然会被覆盖 bool isRightInsert = false; for (int j = i - 1; j >= 0; j--)//内循环确定最终的位置 { if (dataArray[j] > iValue) { dataArray[j + 1] = dataArray[j]; } else { dataArray[j + 1] = iValue;//如果0索引位置比1索引位置小,就不用移动, isRightInsert = true; break; } } //标签在循环后面,先循环确定n-1个数的顺序,最后与dataArray[0]进行判断0索引位置是否已经前移,是的话iValue为最小元素被插入到0号索引位置 if (isRightInsert == false) { dataArray[0] = iValue; } } } Model-sorting.spfx Link to comment Share on other sites More sharing options...
luis2810 Posted May 19, 2018 Author Share Posted May 19, 2018 Thank you both dsturrock and Jzhou a lot!! Programing in C# is not my best! But the option of Dsturrock of finding the lowest value and clear the content is well enough! Thank you again! Link to comment Share on other sites More sharing options...
Recommended Posts