comparison m-toolbox/classes/@ssm/simplify.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % SIMPLIFY enables to do model simplification
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 %
5 % DESCRIPTION: SIMPLIFY allows you to eliminate input/state/output variables.
6 %
7 % CALL: [ssm] = SIMPLIFY(ssm, pl);
8 %
9 % INPUTS :
10 % ssm - a ssm object
11 % pl - an option plist
12 %
13 % OPTIONS :
14 % plist with parameters 'inputs', 'states' and 'outputs' to indicate which
15 % inputs, states and outputs variables are taken in account. This requires
16 % proper variable naming. If a variable called appears more that once it
17 % will be used once only.
18 %
19 % OUTPUTS:
20 % The output array are of size Nsys*Noptions
21 % sys_out - (array of) ssm objects without the specified information
22 %
23 %
24 % <a href="matlab:utils.helper.displayMethodInfo('ssm', 'simplify')">Parameters Description</a>
25 %
26 % VERSION: $Id: simplify.m,v 1.15 2011/04/08 08:56:22 hewitson Exp $
27 %
28 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29
30 function varargout = simplify(varargin)
31
32 import utils.const.*
33 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
34 %% starting initial checks
35
36 % Check if this is a call for parameters
37 if utils.helper.isinfocall(varargin{:})
38 varargout{1} = getInfo(varargin{3});
39 return
40 end
41
42 % Collect input variable names
43 in_names = cell(size(varargin));
44 for ii = 1:nargin,in_names{ii} = inputname(ii);end
45
46 % Collect all SSMs and plists
47 [sys, ssm_invars, rest] = utils.helper.collect_objects(varargin(:), 'ssm', in_names);
48 [pl, invars2, rest] = utils.helper.collect_objects(rest(:), 'plist');
49 if ~isempty(rest)
50 pl = combine(pl, plist(rest{:}));
51 end
52 pl = combine(pl, getDefaultPlist);
53
54 Nsys = numel(sys);
55 if Nsys ~= 1
56 error('### Please input (only) one SSM model');
57 end
58
59 % Decide on a deep copy or a modify, depending on the output
60 sys = copy(sys, nargout);
61
62 %% begin function body
63
64 % Loop over input systems
65 for i_sys=1:Nsys
66 doSimplify(sys(i_sys), pl);
67 %% updating size fields
68 sys(i_sys).addHistory(ssm.getInfo(mfilename), pl , ssm_invars(i_sys), sys(i_sys).hist );
69 %% checking system has some inputs and outputs left
70 if sys(i_sys).Ninputs == 0
71 error('The ssm object has no inputs, which is not allowed!')
72 elseif sys(i_sys).Noutputs == 0
73 error('The ssm object has no outputs, which is not allowed!')
74 end
75 end
76
77 if nargout == numel(sys)
78 for ii = 1:numel(sys)
79 varargout{ii} = sys(ii);
80 end
81 else
82 varargout{1} = sys;
83 end
84 end
85
86
87 %--------------------------------------------------------------------------
88 % Get Info Object
89 %--------------------------------------------------------------------------
90 function ii = getInfo(varargin)
91
92 if nargin == 1 && strcmpi(varargin{1}, 'None')
93 sets = {};
94 pl = [];
95 else
96 sets = {'Default'};
97 pl = getDefaultPlist;
98 end
99 % Build info object
100 ii = minfo(mfilename, 'ssm', 'ltpda', utils.const.categories.op, '$Id: simplify.m,v 1.15 2011/04/08 08:56:22 hewitson Exp $', sets, pl);
101 end
102
103 %--------------------------------------------------------------------------
104 % Get Default Plist
105 %--------------------------------------------------------------------------
106 function pl = getDefaultPlist()
107 pl = plist();
108
109 p = param({'inputs', ['Specify the inputs. Give one of:<ul>'...
110 '<li>A cell-array of input port names.</li>'...
111 '<li>A cell-array of logical arrays specifying which input ports to use for each input block.</li>'...
112 '<li>A cell-array of double values specifying which input ports to use for each input block.<li>'...
113 '<li>The string ''ALL'' to use all inputs.']}, paramValue.STRING_VALUE('ALL'));
114 pl.append(p);
115
116 p = param({'states', 'Specify the states. Specify the states as for the ''inputs'' parameter.'}, paramValue.STRING_VALUE('ALL'));
117 pl.append(p);
118
119 p = param({'outputs', 'Specify the outputs. Specify the outputs as for the ''inputs'' parameter.'}, paramValue.STRING_VALUE('ALL'));
120 pl.append(p);
121
122 end
123