
Priority Queues - Simulink/SImevents
    5 views (last 30 days)
  
       Show older comments
    
I am trying to create a model that prioritize entities with either a 1 or a 2. I am now trying to write code that would allow me to take five entities of type 1 and then take one entity of type 2 so I can still process type 2 entities just at a slower rate until all the 1's are complete. The code below is how I am intializing my entities.
rnump=rand();
if rnump<.5
    entity.Type=randi(2);
    entity.ServiceTime = 2;
else
    entity.Type=randi(2);
    entity.ServiceTime = 3;
end
entitySys.priority = entity.Type;

This is what I am seeing when I use the "Data inspector" tool. But I would like for five type 1 entities to be complete then one type 2 then back to five type 1 entities and so on. Is something like this possible? Any help or tips would be greatly appreciated. Thank you in advanced.
My Queue block is set to Priority with entitySys.priority as my priority source and ascending as my sorting direction.
1 Comment
  Kevin Chien
    
 on 12 Apr 2019
				Hi Nathan,
You could use the built-in function on Entity Queue, instead of event action. 
On Entity Queue > Queue type, select "Priority", and specify "Priority source". This tells Entity Queue which entity can leave first, according to its "Priority source" value.  Please see the attached model.  In this setup, only Type 1 entity can reach Entity Terminator. Even though both types of entities enter queue simultaneously, only Type 1 entities depart and enter Entity Server, because they have higher priorities, and the server is busy serving them and them only (due to capicity 1).
In addition, you can model such queue (and with more complicated behaviors) in Matlab Discrete-Event System. For example,  open SimEvents library, find the "Design Ptterns" block, double click on it, and look for "Selection Queue" template (as shown in "SimEvents_design_pattern" picture).
Hope this help!
Thanks,
Kevin

Answers (0)
See Also
Categories
				Find more on Messages in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
