LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
delegate.m
1function varargout = delegate(self, method, nretout, varargin)
2this_model = self.model;
3
4switch class(this_model)
5 case 'Network'
6 % first try with chosen solver, if the method is not available
7 % or fails keep going with the other candidates
8 if length(self.candidates)>1
9 chosenSolver = chooseSolver(self, method);
10 line_debug('AUTO solver analysis: chosen=%s, supports_model=%d', class(chosenSolver), chosenSolver.supports(self.model));
11 if chosenSolver.supports(self.model)
12 proposedSolvers = {chosenSolver, self.candidates{:}}; %#ok<CCAT>
13 else
14 proposedSolvers = self.candidates;
15 end
16 else % if the user wishes to use a precise solver
17 proposedSolvers = {self.solvers{:}};
18 end
19 for s=1:length(proposedSolvers)
20 try
21 switch nretout
22 case 0
23 proposedSolvers{s}.(method)(varargin{:});
24 case 1
25 varargout{1} = proposedSolvers{s}.(method)(varargin{:});
26 case 2
27 [r1,r2] = proposedSolvers{s}.(method)(varargin{:});
28 varargout{1} = r1;
29 varargout{2} = r2;
30 case 3
31 [r1,r2,r3] = proposedSolvers{s}.(method)(varargin{:});
32 varargout{1} = r1;
33 varargout{2} = r2;
34 varargout{3} = r3;
35 case 4
36 [r1,r2,r3,r4] = proposedSolvers{s}.(method)(varargin{:});
37 varargout{1} = r1;
38 varargout{2} = r2;
39 varargout{3} = r3;
40 varargout{4} = r4;
41 case 5
42 [r1,r2,r3,r4,r5] = proposedSolvers{s}.(method)(varargin{:});
43 varargout{1} = r1;
44 varargout{2} = r2;
45 varargout{3} = r3;
46 varargout{4} = r4;
47 varargout{5} = r5;
48 case 6
49 [r1,r2,r3,r4,r5,r6] = proposedSolvers{s}.(method)(varargin{:});
50 varargout{1} = r1;
51 varargout{2} = r2;
52 varargout{3} = r3;
53 varargout{4} = r4;
54 varargout{5} = r5;
55 varargout{6} = r6;
56 case 7
57 [r1,r2,r3,r4,r5,r6,r7] = proposedSolvers{s}.(method)(varargin{:});
58 varargout{1} = r1;
59 varargout{2} = r2;
60 varargout{3} = r3;
61 varargout{4} = r4;
62 varargout{5} = r5;
63 varargout{6} = r6;
64 varargout{7} = r7;
65 end
66 line_debug('Successful method execution completed by %s', proposedSolvers{s}.getName);
67 if self.options.verbose
68 %line_printf('Successful method execution completed by %s.\n',proposedSolvers{s}.getName);
69 end
70 return
71 catch ME
72 if ~isempty(strfind(ME.message,'Unrecognized method'))
73 if self.options.verbose
74 line_printf('Method unsupported by %s.\n',proposedSolvers{s}.getName);
75 end
76 else
77 %keyboard
78 line_warning(mfilename,[ME.message,'\n']);
79 end
80 end
81 end
82 case 'LayeredNetwork'
83 % first try with chosen solver, if the method is not available
84 % or fails keep going with the other candidates
85 chosenSolver = chooseSolver(self,method);
86 % LayeredNetwork solvers use static-style supports(model) signature
87 try
88 [supportsModel, ~] = chosenSolver.supports(self.model);
89 catch
90 % Fallback: assume solver supports the model if supports() signature differs
91 supportsModel = true;
92 end
93 if supportsModel
94 proposedSolvers = {chosenSolver, self.candidates{:}}; %#ok<CCAT>
95 else
96 proposedSolvers = self.candidates;
97 end
98 for s=1:length(proposedSolvers)
99 try
100 switch nretout
101 case 0
102 proposedSolvers{s}.(method)(varargin{:});
103 case 1
104 varargout{1} = proposedSolvers{s}.(method)(varargin{:});
105 case 2
106 [r1,r2] = proposedSolvers{s}.(method)(varargin{:});
107 varargout{1} = r1;
108 varargout{2} = r2;
109 case 3
110 [r1,r2,r3] = proposedSolvers{s}.(method)(varargin{:});
111 varargout{1} = r1;
112 varargout{2} = r2;
113 varargout{3} = r3;
114 case 4
115 [r1,r2,r3,r4] = proposedSolvers{s}.(method)(varargin{:});
116 varargout{1} = r1;
117 varargout{2} = r2;
118 varargout{3} = r3;
119 varargout{4} = r4;
120 case 5
121 [r1,r2,r3,r4,r5] = proposedSolvers{s}.(method)(varargin{:});
122 varargout{1} = r1;
123 varargout{2} = r2;
124 varargout{3} = r3;
125 varargout{4} = r4;
126 varargout{5} = r5;
127 case 6
128 [r1,r2,r3,r4,r5,r6] = proposedSolvers{s}.(method)(varargin{:});
129 varargout{1} = r1;
130 varargout{2} = r2;
131 varargout{3} = r3;
132 varargout{4} = r4;
133 varargout{5} = r5;
134 varargout{6} = r6;
135 case 7
136 [r1,r2,r3,r4,r5,r6,r7] = proposedSolvers{s}.(method)(varargin{:});
137 varargout{1} = r1;
138 varargout{2} = r2;
139 varargout{3} = r3;
140 varargout{4} = r4;
141 varargout{5} = r5;
142 varargout{6} = r6;
143 varargout{7} = r7;
144 end
145 if self.options.verbose
146 line_printf('Successful method execution completed by %s.\n',proposedSolvers{s}.getName);
147 end
148 return
149 catch
150 if self.options.verbose
151 line_printf('Switching %s.\n',proposedSolvers{s}.getName);
152 end
153 end
154 end
155end
156% If we reach here, all solvers failed
157line_error(mfilename, 'All candidate solvers failed to execute method ''%s''.', method);
158end