simulink.schedule.OrderedSchedule Class
Namespace: simulink.schedule
Creates an OrderedSchedule
object containing priority order of
the partitions of a model
Since R2020a
Description
The simulink.schedule.OrderedSchedule
object is a representation of the
execution order of the partitions of the specified model. Access this object as a model
parameter with get_param
. You can use the
OrderedSchedule
object to modify the schedule of the partitions of the
model through the command line.
You can use set_param
to apply the schedule to the model.
Creation
get_param(mdl,'Schedule')
creates an OrderedSchedule
object for the specified model, mdl
.
Properties
Order
— Priority order of the partitions
table
Priority order of the partitions, specified as a table where:
The row names are names of the partitions.
The first column is the index of the partition. Modify the index to change the order of the partitions.
The second column shows the type of the partitions.
The third column shows the trigger of the partition. This column lists either the sample time of the partitions, or the hit times at which the partitions execute.
RateSections
— Sections of the order table
array
RateSections
is an array of objects containing a portion of the
order table with a single rate. Use RateSections
to easily modify the
order of the execution of partitions within valid groups.
Description
— Description of the OrderedSchedule
object
string
Purpose of an individual schedule object, specified as a string.
Events
— Schedule Editor events
array
Schedule Editor events that may be triggers for aperiodic partitions. Schedule
Editor events are sent by Stateflow® chart and by Input Events in Simulink®, specified as an array of simulink.schedule.Event
objects.
Examples
Create and Analyze Random Schedules for a Model Using the Schedule Editor API
This example uses the Schedule Editor API to perform operations on the schedule. Then it uses a function to generate random schedules and analyze them in Simulation Data Inspector
Open the Model and Get the Schedule Object
Open a model of a Throttle Position Control system and use get_param
to obtain the simulink.schedule.OrderedSchedule
object. This object contains the current schedule.
model = 'ScheduleEditorAPIWithSubsystemPartitions'; open_system(model); schedule = get_param(model,'Schedule')
schedule = OrderedSchedule with properties: Order: [7x3 table] RateSections: [3x1 simulink.schedule.RateSection] Events: [0x1 simulink.schedule.Event] Description: ''
Examine the Schedule Object
The schedule object has an Order
property that contains the execution order of the partitions in the model. The Order
property displays a table that contains partition names, their index, type, and their trigger.
schedule.Order
ans = 7x3 table Index Type Trigger _____ ________ _______ Cont 1 Periodic "0" TPSSecondaryRun5ms 2 Periodic "0.005" MonitorRun5ms 3 Periodic "0.005" ControllerRun5ms 4 Periodic "0.005" ActuatorRun5ms 5 Periodic "0.005" APPSnsrRun 6 Periodic "0.01" TPSPrimaryRun10ms 7 Periodic "0.01"
Use the index variable in the Order
table to change the execution order of the model
schedule.Order.Index('ActuatorRun5ms') = 2;
schedule.Order
ans = 7x3 table Index Type Trigger _____ ________ _______ Cont 1 Periodic "0" ActuatorRun5ms 2 Periodic "0.005" TPSSecondaryRun5ms 3 Periodic "0.005" MonitorRun5ms 4 Periodic "0.005" ControllerRun5ms 5 Periodic "0.005" APPSnsrRun 6 Periodic "0.01" TPSPrimaryRun10ms 7 Periodic "0.01"
Any moves within the Order
property that are made to modify the schedule should result in valid schedule. To perform the schedule modifications and valid moves easier, each partition is grouped with partitions of the same rate in the RateSections
property. Each element of the RateSection
property contains an order table with partitions of the same rate.
schedule.RateSections(2) schedule.RateSections(2).Order
ans = RateSection with properties: Rate: "0.005" Order: [4x3 table] ans = 4x3 table Index Type Trigger _____ ________ _______ ActuatorRun5ms 2 Periodic "0.005" TPSSecondaryRun5ms 3 Periodic "0.005" MonitorRun5ms 4 Periodic "0.005" ControllerRun5ms 5 Periodic "0.005"
Use the index variable to move the partitions within RateSections
.
schedule.RateSections(2).Order.Index('ActuatorRun5ms') = 5;
schedule.Order
ans = 7x3 table Index Type Trigger _____ ________ _______ Cont 1 Periodic "0" TPSSecondaryRun5ms 2 Periodic "0.005" MonitorRun5ms 3 Periodic "0.005" ControllerRun5ms 4 Periodic "0.005" ActuatorRun5ms 5 Periodic "0.005" APPSnsrRun 6 Periodic "0.01" TPSPrimaryRun10ms 7 Periodic "0.01"
Create a Function to Generate Random Schedules
In this section, we create three different functions: randomSchedule
, generateSimulationInputs
and simulateRandomSchedules
randomSchedule
function is used to create random schedules by using random permutations of index modifications in the schedule
object. Using the Order
and the RateSections
properties of the schedule
object, partitions in the schedules are moved around in different, random combinations. With these randomly created schedules, models are simulated and compared to study the effect of different schedules on simulation. In the function randomSchedule
, the input is the model name. Then use get_param
to obtain the simulink.schedule.OrderedSchedule
object of the model. The schedule
object and its properties are used to modify and randomize the schedules. Create a variable firstExecutionOrder
for the first rate section of the model. The rateSections(1).ExecutionOrder = [firstExecutionOrder(1,:); reSchedule(firstExecutionOrder(2:end,:))]
line of code calls the function reSchedule
which creates random permutations of the indexes.
type randomSchedule
function schedule = randomSchedule(model) % schedule = randomSchedule(model) Produces a % simulink.schedule.OrderedSchedule that has a randomized permutation % of the model's original execution order schedule arguments model char = bdroot end schedule = get_param(model, 'Schedule'); rateSections = schedule.RateSections; firstOrder = rateSections(1).Order; % This assumes that the slowest discrete rate is at index 1. This may % not be the case for all models (ex. JMAAB-B). rateSections(1).Order = [firstOrder(1,:); reSchedule(firstOrder(2:end,:))]; for i=2:length(rateSections) rateSections(i).Order = reSchedule(rateSections(i).Order); end schedule.RateSections = rateSections; end function out = reSchedule(in) numPartitions = height(in); in.Index = in.Index(randperm(numPartitions)); out = in; end
To analyze the effects of different schedules on the model, simulate the model with the different schedules. In this function, create an array of Simulink.SimulationInput
objects. Through this array of Simulink.SimulationInput
objects, you can apply the schedules to the model with the setModelParameters
method of the Simulink.SimulationInput
object.
type generateSimulationInputs
function in = generateSimulationInputs(model, numSimulations) % in = generateSimulationInputs(model, numSimulations) Generates % numSimulations Simulink.SimulationInput objects each containing a % different, randomized execution order schedule arguments model char = bdroot numSimulations double = 10 end in(numSimulations) = Simulink.SimulationInput(); in = in.setModelName(model); for idx = 1:numSimulations in(idx) = in(idx).setModelParameter('Schedule', randomSchedule(model)); end end
In the last function, use the array of Simulink.SimulationInput
objects to run multiple simulations. Once the simulations are complete, you can plot the output of all the simulations in Simulation Data Inspector.
type simulateRandomSchedules
function out = simulateRandomSchedules(model, numSimulations) % out = simulateRandomSchedules(model, numSimulations) Simulates a % model numSimulations number of times. Each simulation has a % randomized execution order schedule. arguments model char = bdroot numSimulations double = 10 end in = generateSimulationInputs(model, numSimulations); out = sim(in); plot(out); end
Execute the Functions
Now run the above functions for the ScheduleEditorAPIWithSubsystemPartitions
model. First, use the randomSchedule
function to create randomly generated schedules, then, use the generateSimulationInputs
function to generate an array of Simulink.SimulationInput
objects, and use the simulateRandomSchedule
function to simulate the model with different schedules and plot their results for comparison. Let's run simulations with 15 randomly generated schedules.
simulateRandomSchedules(model,15)
[20-Jul-2024 19:17:03] Running simulations... [20-Jul-2024 19:17:13] Completed 1 of 15 simulation runs [20-Jul-2024 19:17:15] Completed 2 of 15 simulation runs [20-Jul-2024 19:17:16] Completed 3 of 15 simulation runs [20-Jul-2024 19:17:17] Completed 4 of 15 simulation runs [20-Jul-2024 19:17:18] Completed 5 of 15 simulation runs [20-Jul-2024 19:17:19] Completed 6 of 15 simulation runs [20-Jul-2024 19:17:20] Completed 7 of 15 simulation runs [20-Jul-2024 19:17:21] Completed 8 of 15 simulation runs [20-Jul-2024 19:17:22] Completed 9 of 15 simulation runs [20-Jul-2024 19:17:23] Completed 10 of 15 simulation runs [20-Jul-2024 19:17:24] Completed 11 of 15 simulation runs [20-Jul-2024 19:17:25] Completed 12 of 15 simulation runs [20-Jul-2024 19:17:26] Completed 13 of 15 simulation runs [20-Jul-2024 19:17:27] Completed 14 of 15 simulation runs [20-Jul-2024 19:17:28] Completed 15 of 15 simulation runs ans = 1x15 Simulink.SimulationOutput array
Version History
Introduced in R2020a
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.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)