How can I give entities an attribute from a file?

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?

 Accepted Answer

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 Comments

Thank you for your answer. I dont have so much experience in Matlab and Simulink, so I dont get this working. I now tried something with the Set Attribute block and a from workspace block. In the from workspace block I want to use a variable (vector from 1000x1) with the 'Allocation number'. I get an error that the vector has to be at least 2 columns instead of only one. My entities enter the system with an exponential distribution, so I cannot put something with time in the first column of the vector I guess. Is an Entity Departure Counter an option to use?
You could use a lookup table where the Table Data is the vector and the breakpoints would be 1:numel(vector)
The input to the table is the entity departure counter. The output from the lookup table would connect to a set attribute block. This table should output a new value from the vector every time the entity departure counter increases.
Now I have a 1-D Lookup Table, with in the first column the numbers {1,2,3,...n}, in the second column is the vector. I added a Entity Departure Counter, which gives a signal to the Lookup Table and then goes to the Set Attibute block where it should give the attribute. From the Entity Departure Counter the entities itself go also to the SetAttribute block.
I want to separate the entities with an output switch with for testing only 2 output ports. Now I get this error: Error in Output Switch' block. Selected port must be an integer > 0 and <= 2, the number of switch paths. The value of 0.000000 at time 1.000000 is invalid.
Are there zero's in your vector? The output switch is 1-based indexing so in this case it expects a value of 1 or 2 to determine the path. If there are zero's you can leave the vector alone and just add 1 to the output of the lookup table for the desired result.
No there are no zeros in my vector, thats why I dont understand it. There are only 1 and 2 as values.
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.
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.

Sign in to comment.

More Answers (2)

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 Comment

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.

Sign in to comment.

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?

Categories

Find more on Discrete-Event Simulation in Help Center and File Exchange

Products

Asked:

Ry
on 28 Dec 2012

Community Treasure Hunt

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

Start Hunting!