-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathFlowEntityBuilder.m
79 lines (75 loc) · 2.99 KB
/
FlowEntityBuilder.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
%% Flow Entity Builder
% In addition to functionality of <EntityBuilder>, *FlowEntityBuilder* can generate the
% local and global identifiers for flow entities.
classdef FlowEntityBuilder < EntityBuilder
properties (Access = private)
local_flow_identifier;
end
properties (SetAccess = {?FlowEntityBuilder,?RandomEventDispatcher})
Parent;
end
properties (Dependent)
% Type is derived from <EnityBuilder>
Type;
end
methods
%%
% See also <EntityBuilder>.
% The |arrival_rate| and |service_interval| of flow in a slice is parameters of
% the slice.
% |Parent|: parent slice of the builder aand flow entities produced by this builder.
function this = FlowEntityBuilder(varargin)
if isstruct(varargin{1})
flow_opt = varargin{1};
arrive_rate = flow_opt.ArrivalRate;
service_interval = flow_opt.ServiceInterval;
if nargin >= 2
parent = varargin{2};
else
parent = [];
end
% flow_opt = rmfield(flow_opt, {'ArrivalRate', 'ServiceInterval'});
elseif nargin >= 2
arrive_rate = varargin{1};
service_interval = varargin{2};
if nargin >= 3
parent = varargin{3};
else
parent = [];
end
flow_opt = [];
else
error('error: arguments not enough.');
end
this@EntityBuilder(arrive_rate, service_interval, flow_opt);
this.Parent = parent;
this.local_flow_identifier = SerialNumber(1, [], true);
end
function t = get.Type(~)
t = EntityType.Flow;
end
function entity = Build(this, time_arrive, time_serve, flow_id)
% build the entity
if nargin == 3
flow_id = [];
end
max_len = max([length(time_serve), length(time_arrive), length(flow_id)]);
local_id = this.local_flow_identifier.next(max_len);
entity = FlowEntity(time_arrive, time_serve, this, local_id, flow_id);
end
end
methods(Access=protected)
function newobj = copyElement(this)
newobj = copyElement@EntityBuilder(this);
%% Deep Copy Issue
% *Parent* is an exterior link. When performing copy, we should not make a copy of this
% object. Instead, the link should be updated by the caller of the _copy_ function. To
% secure the original data, we detach the link in the new copy from the original data.
%
% See also <Entity>, <RandomEventDispatcher.copyElement>.
if ~isempty(this.Parent)
newobj.Parent = this.Parent.empty();
end
end
end
end