Jump to content

ORDER DECREASING OF A STATE VARIAVEL (VECTOR)


luis2810
 Share

Recommended Posts

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

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

sorting.jpg.3b446dd8096e51f26ef326d9670cb6c5.jpg

This is After Sorting :16,18,22,25,26

924261538_QQ20180519104440-t.thumb.jpg.0b359dd3832d92b43fe869355774486f.jpg

This is the main sorting process

406540453_QQ20180519105809-g.thumb.jpg.a3c384b0c6e939f39511f085c2b3466a.jpg

Resetting values in algorithms(not in attached model).

resetting.jpg.ab71bf84836492b064bb12ac26af46d0.jpg

 

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

×
×
  • Create New...