33#include " DataCollector.h"
44#include " FactorHiGHSSettings.h"
55#include " HybridSolveHandler.h"
6+ #include " ReturnValues.h"
67#include " Timing.h"
78#include " ipm/hipo/auxiliary/Auxiliary.h"
89#include " ipm/hipo/auxiliary/Log.h"
1213
1314namespace hipo {
1415
15- Numeric::Numeric (const Symbolic& S) : S_{S} {
16- // initialise solve handler
17- SH_.reset (new HybridSolveHandler (S_, sn_columns_, swaps_, pivot_2x2_));
18- }
19-
20- std::pair<Int, double > Numeric::solve (std::vector<double >& x) const {
16+ Int Numeric::solve (std::vector<double >& x, Int* solve_count,
17+ double * omega) const {
2118 // Return the number of solves performed
2219
20+ if (!sn_columns_ || !S_) return kRetInvalidPointer ;
21+
22+ // initialise solve handler
23+ SH_.reset (new HybridSolveHandler (*S_, *sn_columns_, swaps_, pivot_2x2_));
24+
2325 SH_->setData (data_);
2426
2527#if HIPO_TIMING_LEVEL >= 1
@@ -31,7 +33,7 @@ std::pair<Int, double> Numeric::solve(std::vector<double>& x) const {
3133#endif
3234
3335 // permute rhs
34- permuteVectorInverse (x, S_. iperm ());
36+ permuteVectorInverse (x, S_-> iperm ());
3537
3638 // make a copy of permuted rhs, for refinement
3739 const std::vector<double > rhs (x);
@@ -58,7 +60,7 @@ std::pair<Int, double> Numeric::solve(std::vector<double>& x) const {
5860#endif
5961
6062 // unpermute solution
61- permuteVector (x, S_. iperm ());
63+ permuteVector (x, S_-> iperm ());
6264
6365#if HIPO_TIMING_LEVEL >= 2
6466 if (data_) data_->sumTime (kTimeSolvePrepare , clock_fine.stop ());
@@ -68,7 +70,10 @@ std::pair<Int, double> Numeric::solve(std::vector<double>& x) const {
6870 if (data_) data_->sumTime (kTimeSolve , clock.stop ());
6971#endif
7072
71- return {refine_data.first + 1 , refine_data.second };
73+ if (solve_count) *solve_count = refine_data.first + 1 ;
74+ if (omega) *omega = refine_data.second ;
75+
76+ return kRetOk ;
7277}
7378
7479std::vector<double > Numeric::residual (const std::vector<double >& rhs,
@@ -229,73 +234,4 @@ double Numeric::computeOmega(const std::vector<double>& b,
229234 return omega_1 + omega_2;
230235}
231236
232- void Numeric::conditionNumber () const {
233- HighsRandom random;
234-
235- const Int n = S_.size ();
236-
237- // estimate largest eigenvalue with power iteration:
238- // x <- x / ||x||
239- // y <- M * x
240- // lambda = ||y||
241-
242- double lambda_large{};
243- std::vector<double > x (n);
244- for (Int i = 0 ; i < n; ++i) x[i] = random.fraction ();
245-
246- for (Int iter = 0 ; iter < 10 ; ++iter) {
247- // normalize x
248- double x_norm = norm2 (x);
249- vectorScale (x, 1.0 / x_norm);
250-
251- // multiply by matrix
252- std::vector<double > y (n);
253- symProduct (ptrA_, rowsA_, valA_, x, y);
254-
255- double norm_y = norm2 (y);
256-
257- if (std::abs (lambda_large - norm_y) / std::max (1.0 , lambda_large) < 1e-2 ) {
258- // converged
259- break ;
260- }
261-
262- lambda_large = norm_y;
263- x = std::move (y);
264- }
265-
266- // estimate inverse of smallest eigenvalue with inverse power iteration:
267- // x <- x / ||x||
268- // y <- M^-1 * x
269- // lambda_inv = ||y||
270-
271- double lambda_small_inv{};
272- for (Int i = 0 ; i < n; ++i) x[i] = random.fraction ();
273-
274- for (Int iter = 0 ; iter < 10 ; ++iter) {
275- // normalize x
276- double x_norm = norm2 (x);
277- vectorScale (x, 1.0 / x_norm);
278-
279- // solve with matrix
280- std::vector<double > y (x);
281- SH_->forwardSolve (y);
282- SH_->diagSolve (y);
283- SH_->backwardSolve (y);
284-
285- double norm_y = norm2 (y);
286-
287- if (std::abs (lambda_small_inv - norm_y) / std::max (1.0 , lambda_small_inv) <
288- 1e-2 ) {
289- // converged
290- break ;
291- }
292-
293- lambda_small_inv = norm_y;
294- x = std::move (y);
295- }
296-
297- // condition number: lambda_large / lambda_small
298- double cond = lambda_large * lambda_small_inv;
299- }
300-
301237} // namespace hipo
0 commit comments