LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
runAnalyzer.m
1function runtime = runAnalyzer(self, options)
2% RUNTIME = RUNANALYZER(OPTIONS)
3% Run the solver
4
5if nargin<2
6 options = self.options;
7end
8
9% Reset random seed
10Solver.resetRandomGeneratorSeed(options.seed);
11
12line_debug('AUTO solver starting: method=%s, lang=%s, model=%s', options.method, options.lang, class(self.model));
13
14% Check if using Java backend
15switch options.lang
16 case 'java'
17 % Use Java SolverAUTO
18 jmodel = LINE2JLINE(self.model);
19 M = jmodel.getNumberOfStations;
20 R = jmodel.getNumberOfClasses;
21 jsolver = JLINE.SolverAuto(jmodel, options);
22 [QN, UN, RN, WN, AN, TN] = JLINE.arrayListToResults(jsolver.getAvgTable);
23 runtime = jsolver.result.runtime;
24 CN = [];
25 XN = [];
26 QN = reshape(QN', R, M)';
27 UN = reshape(UN', R, M)';
28 RN = reshape(RN', R, M)';
29 TN = reshape(TN', R, M)';
30 WN = reshape(WN', R, M)';
31 AN = reshape(AN', R, M)';
32 self.setAvgResults(QN, UN, RN, TN, AN, WN, CN, XN, runtime, options.method, NaN);
33 self.result.SelectedSolver = char(jsolver.result.selectedSolver);
34 return
35 case 'matlab'
36 % Fall through to MATLAB implementation below
37end
38
39% Delegate to the appropriate solver
40switch class(self.model)
41 case 'Network'
42 % Select the best solver
43 if length(self.candidates) > 1
44 chosenSolver = self.chooseSolver('getAvg');
45 if chosenSolver.supports(self.model)
46 proposedSolvers = {chosenSolver, self.candidates{:}};
47 else
48 proposedSolvers = self.candidates;
49 end
50 else
51 proposedSolvers = {self.solvers{:}};
52 end
53
54 % Try each proposed solver
55 line_debug('AUTO trying %d candidate solvers', length(proposedSolvers));
56 for s = 1:length(proposedSolvers)
57 try
58 solver = proposedSolvers{s};
59 line_debug('AUTO attempting solver: %s', solver.getName());
60 runtime = solver.runAnalyzer(options);
61
62 % Copy results from the successful solver
63 if ~isempty(solver.result)
64 self.result = solver.result;
65 % Update the solver name to reflect AUTO solver
66 self.result.('solver') = self.getName();
67 self.result.SelectedSolver = solver.getName();
68 end
69
70 if self.options.verbose
71 line_printf('AUTO solver: analysis completed successfully by %s.\n', solver.getName());
72 end
73 return;
74 catch ME
75 if self.options.verbose
76 line_printf('AUTO solver: %s failed with error: %s\n', proposedSolvers{s}.getName(), ME.message);
77 end
78 end
79 end
80
81 % If we get here, all solvers failed
82 line_error(mfilename, 'All candidate solvers failed to analyze the model.');
83
84 case 'LayeredNetwork'
85 % Similar logic for LayeredNetwork
86 line_debug('AUTO handling LayeredNetwork model');
87 chosenSolver = self.chooseSolver('getAvg');
88 if chosenSolver.supports(self.model)
89 proposedSolvers = {chosenSolver, self.candidates{:}};
90 else
91 proposedSolvers = self.candidates;
92 end
93
94 line_debug('AUTO trying %d candidate solvers for LayeredNetwork', length(proposedSolvers));
95 for s = 1:length(proposedSolvers)
96 try
97 solver = proposedSolvers{s};
98 line_debug('AUTO attempting solver: %s', solver.getName());
99 runtime = solver.runAnalyzer(options);
100
101 % Copy results from the successful solver
102 if ~isempty(solver.result)
103 self.result = solver.result;
104 % Update the solver name to reflect AUTO solver
105 self.result.('solver') = self.getName();
106 self.result.SelectedSolver = solver.getName();
107 end
108
109 if self.options.verbose
110 line_printf('AUTO solver: analysis completed successfully by %s.\n', solver.getName());
111 end
112 return;
113 catch ME
114 if self.options.verbose
115 line_printf('AUTO solver: %s failed with error: %s\n', proposedSolvers{s}.getName(), ME.message);
116 end
117 end
118 end
119
120 % If we get here, all solvers failed
121 line_error(mfilename, 'All candidate solvers failed to analyze the model.');
122end
123
124end