How can I give entities an attribute from a file?

2 ビュー (過去 30 日間)
Ry
Ry 2012 年 12 月 28 日
My Time-based entity generator generates standard entities and i want to give them attributes. Therefore I added a Set Attribute block. My entities need to be allocated to one of the 5 available servers. I have a vector with 1000 values, for the first 1000 entities, with the server to which they should be allocated. So this is a vector with [1;1;1;1;1;1;2;1;.....;4;5;1]. I have the vector in a file: Allocation.m. How do I add the server to which each entity should be allocated to the entity with this vector?
  2 件のコメント
Walter Roberson
Walter Roberson 2012 年 12 月 28 日
Is this Simulink?
Ry
Ry 2012 年 12 月 28 日
Oh yes! Sorry, for not adding this

サインインしてコメントする。

採用された回答

Ryan G
Ryan G 2012 年 12 月 28 日
Say you define the vector in the m-file:
myVec = [1,2,4,5,2,3...1,1,1]; %server numbers
And you want to assign the next entity with the next element in the vector. You can use an Attribute Function (MATLAB Function for SimEvents) and Persistent Variables to keep the order of the vector.
In the block you would have code like this:
persistent counter
counter = counter+1;
out_newAttribute = myVec(counter);
This should iterate the counter every time a new entity enters the MATLAB function and assign the portion of myVec (server routing) to the entity.
  7 件のコメント
Ryan G
Ryan G 2013 年 1 月 3 日
Do you keep generating entities after the vector has been exhausted? Try changing the extrapolation method to clipped. That should allow the simulation to continue running, but I have a feeling you are generating a number of entities greater than the number of elements in the vector.
Ryan G
Ryan G 2013 年 1 月 3 日
Furthermore you can use the option in the output switch 'from signal port p' instead of 'from attribute' if you don't want to add an attribute to the entity.

サインインしてコメントする。

その他の回答 (2 件)

Ry
Ry 2013 年 1 月 4 日
It works now, I changed the extrapolation method to clipped. Thanks! Now I have another problem, the entity generator is blocked because the service times are too long compared to the arrival rate and the buffer is full. If the buffer is full I want new arriving entities to be dropped in an entity sink until the buffer is not full anymore. Is this possible in Simulink, and how?
  1 件のコメント
Ryan G
Ryan G 2013 年 1 月 4 日
Use another output switch with the default setting 'first output port which is not blocked'. Have the first port going to your other switch, have the second port go to a sink.

サインインしてコメントする。


Ry
Ry 2013 年 1 月 7 日
Thank you. This also works now. Per server that I have there are two servers to choose. One server with 0,25 probability, and the other with 0,75 (=> this I implemented with an output switch with four equiprobable output ports and a pathcombiner with 3 input ports for the 0,75 probability). But there is an additional condition: only one of those servers can be used at a time. How can I implement this?

カテゴリ

Help Center および File ExchangeRoute Entities and Simulink Messages についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by