queuePriority
Class: matlab.DiscreteEventSystem
Namespace: matlab
Define priority queue storage
Syntax
storage=queuePriority(entityType,capacity,key,order)
Description
defines a priority queue that sorts entities by custom attribute. Use this function when
implementing the storage
=queuePriority(entityType
,capacity
,key
,order
)getEntityStorageImpl
method.
Input Arguments
Type of entities that the new storage element works with.
Maximum number of entities that the storage can contain, specified as a double.
Name of the attribute that is used as the key for sorting.
Direction of sorting. Specify 'ascending'
if
you want entities with smaller key values to appear in front of the
queue. Specify 'descending'
if you want entities
with greater key values to appear in front of the queue.
Output Arguments
Queue storage element that contains entities and sorts them using a custom attribute.
Examples
Define storage element as a priority queue.
% Define a storage element as a priority queue % - Queue sorts entities using a specific attribute of the entities % - Queue can store entities of type 'myEntity' % - Queue can store no more than 25 entities % - Queue uses the attribute 'age' to sort entities % - Sorting direction is 'ascending', resulting entities with % smaller 'age' attribute values to appear in front of the queue storage = obj.queuePriority('myEntity', 25, 'age', 'ascending');
In this example, a custom block allows entities to enter its storage
element through its input port. The storage element is a priority queue that
sorts the entities based on their Diameter
attribute in
ascending order. Every entity entry to the block's storage invokes an
iteration event to display the diameter and the position of each entity in
the storage.
For more information, see Create a Custom Entity Storage Block with Iteration Event.
classdef CustomEntityStorageBlockIteration < matlab.DiscreteEventSystem % A custom entity storage block with one input port and one storage element. % Nontunable properties properties (Nontunable) % Capacity Capacity = 5; end % Create the storage element with one input and one storage. methods (Access=protected) function num = getNumInputsImpl(obj) num = 1; end function num = getNumOutputsImpl(obj) num = 0; end function entityTypes = getEntityTypesImpl(obj) entityType1 = obj.entityType('Wheel'); entityTypes = entityType1; end function [inputTypes,outputTypes] = getEntityPortsImpl(obj) inputTypes = {'Wheel'}; outputTypes={}; end function [storageSpecs, I, O] = getEntityStorageImpl(obj) storageSpecs = obj.queuePriority('Wheel',obj.Capacity, 'Diameter','ascending'); I = 1; O = []; end end % Entity entry event action methods function [entity, event] = WheelEntry(obj,storage,entity, source) % Entity entry invokes an iterate event. event = obj.eventIterate(1, ''); end % The itarate event action function [entity,event,next] = WheelIterate(obj,storage,entity,tag,cur) % Display wheel id, position in the storage, and diameter. coder.extrinsic('fprintf'); fprintf('Wheel id %d, Current position %d, Diameter %d\n', ... entity.sys.id, cur.position, entity.data.Diameter); if cur.size == cur.position fprintf('End of Iteration \n') end next = true; event=[]; end end end
Version History
Introduced in R2016a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Website auswählen
Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .
Sie können auch eine Website aus der folgenden Liste auswählen:
So erhalten Sie die bestmögliche Leistung auf der Website
Wählen Sie für die bestmögliche Website-Leistung die Website für China (auf Chinesisch oder Englisch). Andere landesspezifische Websites von MathWorks sind für Besuche von Ihrem Standort aus nicht optimiert.
Amerika
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)