Skip to content

Commit 9f10a5d

Browse files
committed
Numeric is now only used within FHsolver, which now has a solve function. A bit cleaner
1 parent 2d71109 commit 9f10a5d

File tree

7 files changed

+49
-38
lines changed

7 files changed

+49
-38
lines changed

highs/ipm/hipo/factorhighs/FactorHiGHS.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,15 @@ Int FHsolver::analyse(Symbolic& S, const std::vector<Int>& rows,
4141
return an_obj.run(S);
4242
}
4343

44-
Int FHsolver::factorise(Numeric& N, const Symbolic& S,
45-
const std::vector<Int>& rows,
44+
Int FHsolver::factorise(const Symbolic& S, const std::vector<Int>& rows,
4645
const std::vector<Int>& ptr,
4746
const std::vector<double>& vals) {
4847
Factorise fact_obj(S, rows, ptr, vals, regul_, log_, data_, sn_columns_);
49-
return fact_obj.run(N);
48+
return fact_obj.run(N_);
49+
}
50+
51+
Int FHsolver::solve(std::vector<double>& x, Int* solve_count, double* omega) {
52+
return N_.solve(x, solve_count, omega);
5053
}
5154

5255
} // namespace hipo

highs/ipm/hipo/factorhighs/FactorHiGHS.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ It is stored using three arrays:
2222
2323
The direct solver uses the following objects:
2424
- Symbolic, to store the symbolic factorization;
25-
- Numeric, to store the numeric factorization;
2625
- FHsolver, to perform analyse and factorise phases.
2726
2827
Define a vector signs that contains the expected sign of each pivot (1 or -1).
@@ -32,13 +31,10 @@ M^{-1} * rhs.
3231
Then, the factorization is performed as follows.
3332
3433
Symbolic S;
35-
Numeric N(S);
36-
3734
FHsolver FH;
3835
FH.analyse(S, rows, ptr, signs);
39-
FH.factorise(N, S, rows, ptr, val);
40-
41-
N.solve(rhs);
36+
FH.factorise(S, rows, ptr, val);
37+
FH.solve(x);
4238
4339
Printing to screen is achieved using the interface in auxiliary/Log.h. Pass an
4440
object of type Log for normal printing:
@@ -64,6 +60,7 @@ class FHsolver {
6460
const Log* log_;
6561
DataCollector data_;
6662
Regul regul_;
63+
Numeric N_;
6764

6865
const Int nb_; // block size
6966
static const Int default_nb_ = 128;
@@ -88,9 +85,18 @@ class FHsolver {
8885
// numerical factorisation in object N. Matrix is moved into the object, so
8986
// rows, ptr, vals are invalid afterwards.
9087
// See ReturnValues.h for errors.
91-
Int factorise(Numeric& N, const Symbolic& S, const std::vector<Int>& rows,
88+
Int factorise(const Symbolic& S, const std::vector<Int>& rows,
9289
const std::vector<Int>& ptr, const std::vector<double>& vals);
9390

91+
// Perform solve phase with rhs given by x, which is overwritten with the
92+
// solution. solve_count returns the number of solves performed during the
93+
// phase (including refinement). omega returns the final residual after
94+
// refinement.
95+
// For now refinement is performed automatically as part of solve,
96+
// this will change in the future.
97+
Int solve(std::vector<double>& x, Int* solve_count = nullptr,
98+
double* omega = nullptr);
99+
94100
// If multiple factorisation are performed, call newIter() before each
95101
// factorisation. This is used only to collect data for debugging, if
96102
// expensive data collection is turned on at compile time.

highs/ipm/hipo/factorhighs/Factorise.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ bool Factorise::run(Numeric& num) {
388388
if (flag_stop_) return true;
389389

390390
// move factorisation to numerical object
391+
num.S_ = &S_;
391392
num.sn_columns_ = &sn_columns_;
392393
num.total_reg_ = std::move(total_reg_);
393394
num.swaps_ = std::move(swaps_);

highs/ipm/hipo/factorhighs/Numeric.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
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"
@@ -12,15 +13,14 @@
1213

1314
namespace hipo {
1415

15-
Numeric::Numeric(const Symbolic& S) : S_{S} {}
16-
17-
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 {
1818
// Return the number of solves performed
1919

2020
assert(sn_columns_);
2121

2222
// initialise solve handler
23-
SH_.reset(new HybridSolveHandler(S_, *sn_columns_, swaps_, pivot_2x2_));
23+
SH_.reset(new HybridSolveHandler(*S_, *sn_columns_, swaps_, pivot_2x2_));
2424

2525
SH_->setData(data_);
2626

@@ -33,7 +33,7 @@ std::pair<Int, double> Numeric::solve(std::vector<double>& x) const {
3333
#endif
3434

3535
// permute rhs
36-
permuteVectorInverse(x, S_.iperm());
36+
permuteVectorInverse(x, S_->iperm());
3737

3838
// make a copy of permuted rhs, for refinement
3939
const std::vector<double> rhs(x);
@@ -60,7 +60,7 @@ std::pair<Int, double> Numeric::solve(std::vector<double>& x) const {
6060
#endif
6161

6262
// unpermute solution
63-
permuteVector(x, S_.iperm());
63+
permuteVector(x, S_->iperm());
6464

6565
#if HIPO_TIMING_LEVEL >= 2
6666
if (data_) data_->sumTime(kTimeSolvePrepare, clock_fine.stop());
@@ -70,7 +70,10 @@ std::pair<Int, double> Numeric::solve(std::vector<double>& x) const {
7070
if (data_) data_->sumTime(kTimeSolve, clock.stop());
7171
#endif
7272

73-
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;
7477
}
7578

7679
std::vector<double> Numeric::residual(const std::vector<double>& rhs,
@@ -234,7 +237,7 @@ double Numeric::computeOmega(const std::vector<double>& b,
234237
void Numeric::conditionNumber() const {
235238
HighsRandom random;
236239

237-
const Int n = S_.size();
240+
const Int n = S_->size();
238241

239242
// estimate largest eigenvalue with power iteration:
240243
// x <- x / ||x||

highs/ipm/hipo/factorhighs/Numeric.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Numeric {
2222
std::vector<std::vector<double>> pivot_2x2_{};
2323

2424
// symbolic object
25-
const Symbolic& S_;
25+
const Symbolic* S_;
2626

2727
// object to handle solve phase in different formats
2828
mutable std::unique_ptr<SolveHandler> SH_;
@@ -43,11 +43,10 @@ class Numeric {
4343
// dynamic regularisation applied to the matrix
4444
std::vector<double> total_reg_{};
4545

46-
Numeric(const Symbolic& S);
47-
4846
// Full solve with refinement
49-
// Return pair (number of solves, final residual)
50-
std::pair<Int, double> solve(std::vector<double>& x) const;
47+
// Return also number of solves and final residual
48+
Int solve(std::vector<double>& x, Int* solve_count = nullptr,
49+
double* omega = nullptr) const;
5150

5251
// Iterative refinement
5352
std::pair<Int, double> refine(const std::vector<double>& rhs,

highs/ipm/hipo/ipm/FactorHiGHSSolver.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ FactorHiGHSSolver::FactorHiGHSSolver(Options& options, const Model& model,
1313
IpmData* record, const LogHighs& log)
1414
: FH_(&log, options.block_size),
1515
S_{},
16-
N_(S_),
1716
regul_{regul},
1817
info_{info},
1918
data_{record},
@@ -298,7 +297,7 @@ Int FactorHiGHSSolver::factorAS(const HighsSparseMatrix& A,
298297

299298
// factorise matrix
300299
clock.start();
301-
if (FH_.factorise(N_, S_, rowsLower, ptrLower, valLower))
300+
if (FH_.factorise(S_, rowsLower, ptrLower, valLower))
302301
return kStatusErrorFactorise;
303302
if (info_) {
304303
info_->factor_time += clock.stop();
@@ -333,8 +332,7 @@ Int FactorHiGHSSolver::factorNE(const HighsSparseMatrix& A,
333332
// modify them.
334333
std::vector<Int> ptrNE(ptrNE_);
335334
std::vector<Int> rowsNE(rowsNE_);
336-
if (FH_.factorise(N_, S_, rowsNE, ptrNE, valNE_))
337-
return kStatusErrorFactorise;
335+
if (FH_.factorise(S_, rowsNE, ptrNE, valNE_)) return kStatusErrorFactorise;
338336
if (info_) {
339337
info_->factor_time += clock.stop();
340338
info_->factor_number++;
@@ -353,14 +351,16 @@ Int FactorHiGHSSolver::solveNE(const std::vector<double>& rhs,
353351
lhs = rhs;
354352

355353
Clock clock;
356-
auto solve_data = N_.solve(lhs);
354+
Int solve_count;
355+
double final_res;
356+
Int solve_status = FH_.solve(lhs, &solve_count, &final_res);
357357
if (info_) {
358358
info_->solve_time += clock.stop();
359-
info_->solve_number += solve_data.first;
359+
info_->solve_number += solve_count;
360360
}
361361
if (data_) {
362-
data_->back().num_solves += solve_data.first;
363-
data_->back().omega = std::max(data_->back().omega, solve_data.second);
362+
data_->back().num_solves += solve_count;
363+
data_->back().omega = std::max(data_->back().omega, final_res);
364364
}
365365

366366
return kStatusOk;
@@ -381,14 +381,16 @@ Int FactorHiGHSSolver::solveAS(const std::vector<double>& rhs_x,
381381
rhs.insert(rhs.end(), rhs_y.begin(), rhs_y.end());
382382

383383
Clock clock;
384-
auto solve_data = N_.solve(rhs);
384+
Int solve_count;
385+
double final_res;
386+
Int solve_status = FH_.solve(rhs, &solve_count, &final_res);
385387
if (info_) {
386388
info_->solve_time += clock.stop();
387-
info_->solve_number += solve_data.first;
389+
info_->solve_number += solve_count;
388390
}
389391
if (data_) {
390-
data_->back().num_solves += solve_data.first;
391-
data_->back().omega = std::max(data_->back().omega, solve_data.second);
392+
data_->back().num_solves += solve_count;
393+
data_->back().omega = std::max(data_->back().omega, final_res);
392394
}
393395

394396
// split lhs

highs/ipm/hipo/ipm/FactorHiGHSSolver.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ class FactorHiGHSSolver : public LinearSolver {
1919
// symbolic factorisation
2020
Symbolic S_;
2121

22-
// numeric factorisation
23-
Numeric N_;
24-
2522
// normal equations data
2623
std::vector<Int> ptrNE_, rowsNE_;
2724
std::vector<double> valNE_;

0 commit comments

Comments
 (0)