SimEvents access class/object in MATLAB

2 visualizaciones (últimos 30 días)
Thomas Briggs
Thomas Briggs el 22 de Feb. de 2020
Respondida: Altaïr el 23 de Abr. de 2025
I am trying to build a model of an OS scheduler in SimEvents. Using MATLAB code, I created a class to represent a Task that describes the behavior of the task (e.g. run for x steps, perform I/O for y steps, repeat m steps n times, and so on. I'm really stuck trying to figure out how to integrate this into the SimEvents environment.
For example, I see where I can use an entity generator, and use a MATLAB function block to return the delta-T for the next event generation. For example, the example of random generation works great.
function dt = getDT( )
dt = rand(1,1);
end
What I'd really like to do is to call my TaskList object that returns the time a new process is admitted to the system:
function dt = getDT()
dt = task_list.getNextStart();
end
But, I cannot seem to get the SimEvents system to be able to see the task_list object in the base workspace. I've tried using the ports and data manager and tag the variable as a parameter, but its not one of the known types and nothing I've tried seems to work.
Any advice?

Respuestas (1)

Altaïr
Altaïr el 23 de Abr. de 2025
An object for a custom class can be created and its corresponding method can be called within the MATLAB action section of the entity generator. Below is a sample definition of a TaskList class to illustrate this approach:
classdef TaskList
properties
% Example property to store task start times
taskStartTimes
currentIndex
end
methods
function obj = TaskList()
% Constructor to initialize the task list
% Example: Initialize with some dummy start times
obj.taskStartTimes = [0.1,0.2,0.3,0.4,0.5]; % Example start times
obj.currentIndex = 1; % Start at the first task
end
function [obj, dt] = getNextStart(obj)
% Method to get the next start time delta
if obj.currentIndex <= length(obj.taskStartTimes)
dt = obj.taskStartTimes(obj.currentIndex);
obj.currentIndex = obj.currentIndex + 1; % Move to the next task
else
dt = inf; % No more tasks, return infinity or some sentinel value
end
end
end
end
The getNextStart method provides the interval for the next entity generation. In the entity generator, set the Generation method to Time-Based and the Time source to MATLAB action. This enables the Intergeneration time action section, where the following code can be used to create a persistent TaskList object and call the getNextStart method:
persistent task_list;
if isempty(task_list)
% Initialize your task_list object here
task_list = TaskList(); % Assuming TaskList is your class
end
[task_list, dt] = task_list.getNextStart();
With this setup, the entity intergeneration times will correspond to the values specified in the taskStartTimes array.
For further information, the Specify Intergeneration Times for Entities documentation page can be accessed using the command below:
web(fullfile(docroot, 'simevents/ug/specifying-intergeneration-times-for-entities.html'))

Categorías

Más información sobre Discrete-Event Simulation en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by