classdef RE
% RE defines Random Environment objects, which interact with the 
% Layered Queueing Network (LQN) model to extend its modeling capabilities. 
% More details on Random Environments and their interaction with LQN models can be found 
% on the LINE documentation, available at http://code.google.com/p/line
%
% Properties:
% ID:                   unique identifier of this RE (integer)
% numStages:            number of environmental stages in the RE (integer)
% Q:                    generator matrix of the Markov chain that describes
%                       the RE dynamics (double matrix)
% resetRules:           rules to define how the ongoing services behave under a stage transition (string array)
% stageNames:           stages' names (string array)
% parameters:           list of the parameters in the LQN model that are affected by this RE
%
% Copyright (c) 2012-2015, Imperial College London 
% All rights reserved.

properties
    ID;         % id
    numStages;  % number of environmental stages
    Q;          % generator matrix
    resetRules; % reset rule for each stage transition
    stageNames; % name for each stage
    parameters; % list of parameters associated to this RE
end

methods
    
    %constructor
    function obj = RE(ID, numStages, Q, resetRules, stageNames)
        if nargin > 3           
            obj.ID = ID;
            obj.numStages = numStages;
            obj.resetRules = resetRules;
            obj.Q = Q;
            obj.parameters = cell(0);
        end
        if nargin > 4
           obj.stageNames = stageNames;
        else
            obj.stageNames = cell(numStages,1);
            for i = 1:obj.numStages
                obj.stageNames{i,1} = ['stage',int2str(i)];
            end
        end
    end
    
    %addParameter
    % each parameter affected by this RE is added by providing:
    % elemID:       unique identifier of the element in the model to be affected
    % paramName:    name of the parameter of the element that is directly affected by the RE
    % factors:      list of the factors that modify the value of the parameter.
    %               the effective parameter value in each stage is obtained
    %               by multiplying its default value by the factors.
    %               There must be one factor for each stage in the RE            
    function obj = addParameter(obj, elemID, paramName, factors)
        if nargin == 4 && length(factors)==obj.numStages
            obj.parameters(end+1,:) = {elemID, paramName, factors};
        else
            disp(sprintf('Too few or too many parameters when adding parameter % of %s  ',paramName,elemID));
        end
    end
end
    
    
end
