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