Products & Services Solutions Academia Support User Community Company

Learn more about SimEvents   

Example: Varying Attribute Values Between Runs Using Rapid Simulation

Example Scenario

This example illustrates how to change values of attributes between rapid simulation runs. The example:

Prerequisites

Steps in the Example

This example uses the Distributed Processing of Multi-Class Jobs demo model.

  1. Modify the model to record a relevant simulation result. In this case, the result is the load of Service Station 1:

    1. From the MATLAB Command Window, enter sedemo_star_routing to open the model.

    2. In the current folder, save the model as star_routing_rsim.mdl.

    3. Open the Scopes subsystem by double-clicking it.

    4. From the SimEvents Sinks library, drag the Discrete Event Signal to Workspace block into the model.

    5. Branch the line from the Load_Server1 block to the Signal Scope1 block. Connect the new branch to the Discrete Event Signal to Workspace block. The blocks look like this figure:

    6. Save the model again.

  2. Modify the model to accept varying values of attributes that represent job definitions:

    1. In the Command Window, define variables called serviceprocess and servicetime:

      serviceprocess = [1 2 4 2 3 5];
      servicetime = [2 1 5 3 4 0];
    2. Open the Multiple-Class Job Generation subsystem by double-clicking it.

    3. Open the dialog box of the Set Attribute block labeled Class 1 job definition. In the A1 and A2 rows of the table, set Value From to Signal port.

    4. From the Simulink Sources library, drag two copies of the Constant block into the subsystem.

    5. Connect the Constant blocks to the A1 and A2 signal input ports of the Set Attribute block.

    6. In the block dialog boxes of the Constant blocks, set Constant value to the values in the table.

      In the Constant Block that Connects to the...Set Constant Value to...
      A1 signal input portserviceprocess
      A2 signal input portservicetime

      The blocks look like this figure:

  3. Configure and build the model for rapid simulation:

    1. From the model window, select Simulation > Configuration Parameters.

    2. In the Configuration Parameters dialog box, on the Real-Time Workshop pane, set System target file to rsim.tlc. Click Apply.

    3. In the Configuration Parameters dialog box, on the Real-Time Workshop RSim Target pane, select Enable RSim executable to load parameters from a MAT-file.

    4. In the Configuration Parameters dialog box, on the Optimization pane, select Inline parameters. Click Configure.

    5. In the Model Parameter Configuration dialog box, in the Source list section, select serviceprocess and servicetime. Click Add to table. Click OK.

    6. In the Configuration Parameters dialog box, click OK.

    7. From the model window, select Tools > Real-Time Workshop > Build Model.

  4. From the Command Window, set up input data by creating and saving a MAT-file. The file contains parameter sets. Each parameter set designates a service process vector and a service time vector for one simulation run.

    % Create a cell array with service process values in the first column,
    % and corresponding service time values in the second column.
    
    service_array = cell(3,2); % Preallocate space.
    % Baseline parameter set
    service_array(1,:) = {[1 2 4 2 3 5], [2 1 5 3 4 0]};
    % Try swapping the roles of stations 1 and 3 in the service process.
    service_array(2,:) = {[3 2 4 2 1 5], [4 1 5 3 2 0]};
    % Try moving the role of station 3 to the beginning of the service process.
    service_array(3,:) = {[3 1 2 4 2 5], [4 2 1 5 3 0]};
    
    % Create a parameter structure to store the values.
    rtP = rsimgetrtp('star_routing_rsim','AddTunableParamInfo','on');
    rtP = rsimsetrtpparam(rtP,3);
    for k = 1:3
       rtP = rsimsetrtpparam(rtP,k,...
       'serviceprocess',service_array{k,1},...
       'servicetime',service_array{k,2});
    end
    save star_routing_rsim_service rtP
  5. From the Command Window, run the executable multiple times, using a different parameter set each time:

    % Run the executable with different pairs of service process and
    % service time values. Store results in corresponding MAT-files.
    system(['star_routing_rsim -o star_routing_rsim_results1.mat '...
       '-p star_routing_rsim_service.mat@1']);
    
    system(['star_routing_rsim -o star_routing_rsim_results2.mat '...
       '-p star_routing_rsim_service.mat@2']);
    
    system(['star_routing_rsim -o star_routing_rsim_results3.mat '...
       '-p star_routing_rsim_service.mat@3']);

      Alternative   After setting appropriate environment variables, you can run the executable from a shell window instead of from the Command Window. For more information about environment variables to set, see Requirements for Running Rapid Simulations in the Real-Time Workshop documentation.

  6. Plot simulation results:

    h = figure;
    
    subplot(3,1,1);
    load star_routing_rsim_results1;
    stairs(rt_simout.time,rt_simout.signals.values);
    title(['Load of Service Station 1 with ServiceProcess = [' ...
       num2str(service_array{1,1}) ']']);
    axis([0 100 0 4.5])
    
    subplot(3,1,2);
    load star_routing_rsim_results2;
    stairs(rt_simout.time,rt_simout.signals.values);
    title(['Load of Service Station 1 with ServiceProcess = [' ...
       num2str(service_array{2,1}) ']']);
    axis([0 100 0 4.5])
    
    subplot(3,1,3);
    load star_routing_rsim_results3;
    stairs(rt_simout.time,rt_simout.signals.values);
    title(['Load of Service Station 1 with ServiceProcess = [' ...
       num2str(service_array{3,1}) ']']);
    axis([0 100 0 4.5])

Results

  


Free SimEvents Evaluation Kit

Learn how you can use SimEvents discrete-event simulation capbilities through these technical resources.

Get free kit

Trials Available

Try the latest version of discrete-event simulation products.

Get trial software
 © 1984-2010- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS