Skip to content

Commit 3cb7b05

Browse files
authored
Merge pull request #2642 from ERGO-Code/hipo
Better refinement for HiPO
2 parents 604f4ca + b0b9459 commit 3cb7b05

25 files changed

+540
-751
lines changed

cmake/sources.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ set(hipo_sources
184184
ipm/hipo/ipm/Iterate.cpp
185185
ipm/hipo/ipm/LogHighs.cpp
186186
ipm/hipo/ipm/Model.cpp
187+
ipm/hipo/ipm/Refine.cpp
187188
ipm/hipo/ipm/Solver.cpp)
188189

189190
set(hipo_headers

docs/src/installation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ git checkout 521-ts
3939

4040
Then build with
4141
```
42-
cmake -S. -B build
43-
-DGKLIB_PATH=/path_to_METIS_repo/GKlib
42+
cmake -S. -B build \
43+
-DGKLIB_PATH=/path_to_METIS_repo/GKlib \
4444
-DCMAKE_INSTALL_PREFIX=path_to_installs_dir
4545
cmake --build build
4646
cmake --install build

highs/ipm/hipo/auxiliary/Auxiliary.cpp

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -97,48 +97,6 @@ void transpose(const std::vector<Int>& ptr, const std::vector<Int>& rows,
9797
}
9898
}
9999

100-
void symProduct(const std::vector<Int>& ptr, const std::vector<Int>& rows,
101-
const std::vector<double>& vals, const std::vector<double>& x,
102-
std::vector<double>& y, double alpha) {
103-
// Matrix-vector product in CSC format, for symmetric matrix which stores only
104-
// the lower triangle.
105-
// Compute y = y + alpha * M * x
106-
107-
const Int n = ptr.size() - 1;
108-
109-
for (Int col = 0; col < n; ++col) {
110-
for (Int el = ptr[col]; el < ptr[col + 1]; ++el) {
111-
Int row = rows[el];
112-
double val = vals[el];
113-
114-
y[row] += alpha * val * x[col];
115-
if (row != col) y[col] += alpha * val * x[row];
116-
}
117-
}
118-
}
119-
120-
void symProductQuad(const std::vector<Int>& ptr, const std::vector<Int>& rows,
121-
const std::vector<double>& vals,
122-
const std::vector<double>& x, std::vector<HighsCDouble>& y,
123-
double alpha) {
124-
// Matrix-vector product in CSC format, for symmetric matrix which stores only
125-
// the lower triangle.
126-
// Compute y = y + alpha * M * x
127-
128-
const Int n = ptr.size() - 1;
129-
130-
for (Int col = 0; col < n; ++col) {
131-
for (Int el = ptr[col]; el < ptr[col + 1]; ++el) {
132-
Int row = rows[el];
133-
HighsCDouble val = vals[el];
134-
135-
y[row] += val * (HighsCDouble)x[col] * (HighsCDouble)alpha;
136-
if (row != col)
137-
y[col] += val * (HighsCDouble)x[row] * (HighsCDouble)alpha;
138-
}
139-
}
140-
}
141-
142100
void childrenLinkedList(const std::vector<Int>& parent, std::vector<Int>& head,
143101
std::vector<Int>& next) {
144102
// Create linked lists of children in elimination tree.

highs/ipm/hipo/auxiliary/Auxiliary.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <vector>
99

1010
#include "ipm/hipo/auxiliary/IntConfig.h"
11-
#include "util/HighsCDouble.h"
1211

1312
namespace hipo {
1413

@@ -20,13 +19,6 @@ void transpose(const std::vector<Int>& ptr, const std::vector<Int>& rows,
2019
void transpose(const std::vector<Int>& ptr, const std::vector<Int>& rows,
2120
const std::vector<double>& val, std::vector<Int>& ptrT,
2221
std::vector<Int>& rowsT, std::vector<double>& valT);
23-
void symProduct(const std::vector<Int>& ptr, const std::vector<Int>& rows,
24-
const std::vector<double>& vals, const std::vector<double>& x,
25-
std::vector<double>& y, double alpha = 1.0);
26-
void symProductQuad(const std::vector<Int>& ptr, const std::vector<Int>& rows,
27-
const std::vector<double>& vals,
28-
const std::vector<double>& x, std::vector<HighsCDouble>& y,
29-
double alpha);
3022
void childrenLinkedList(const std::vector<Int>& parent, std::vector<Int>& head,
3123
std::vector<Int>& next);
3224
void reverseLinkedList(std::vector<Int>& head, std::vector<Int>& next);

highs/ipm/hipo/factorhighs/DataCollector.cpp

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ void DataCollector::printTimes(const Log& log) const {
141141
<< "\n";
142142

143143
#if HIPO_TIMING_LEVEL >= 2
144-
log_stream << "\tPrepare: "
144+
log_stream << "\tPrepare fact: "
145145
<< fix(times[kTimeFactorisePrepare], 8, 4) << " ("
146146
<< fix(times[kTimeFactorisePrepare] / times[kTimeFactorise] * 100,
147147
4, 1)
@@ -189,7 +189,7 @@ void DataCollector::printTimes(const Log& log) const {
189189
<< "\n";
190190

191191
#if HIPO_TIMING_LEVEL >= 2
192-
log_stream << "\tPrepare: "
192+
log_stream << "\tPrepare solve: "
193193
<< fix(times[kTimeSolvePrepare], 8, 4) << " ("
194194
<< fix(times[kTimeSolvePrepare] / times[kTimeSolve] * 100, 4, 1)
195195
<< "%)\n";
@@ -203,14 +203,6 @@ void DataCollector::printTimes(const Log& log) const {
203203
<< fix(times[kTimeSolveSolve_sparse], 8, 4) << "\n";
204204
log_stream << "\t\tswap: " << fix(times[kTimeSolveSolve_swap], 8, 4)
205205
<< "\n";
206-
log_stream << "\tResidual: "
207-
<< fix(times[kTimeSolveResidual], 8, 4) << " ("
208-
<< fix(times[kTimeSolveResidual] / times[kTimeSolve] * 100, 4, 1)
209-
<< "%)\n";
210-
log_stream << "\tOmega: "
211-
<< fix(times[kTimeSolveOmega], 8, 4) << " ("
212-
<< fix(times[kTimeSolveOmega] / times[kTimeSolve] * 100, 4, 1)
213-
<< "%)\n";
214206
#endif
215207
log_stream << "----------------------------------------------------\n";
216208

@@ -225,68 +217,57 @@ void DataCollector::printTimes(const Log& log) const {
225217
log_stream << "BLAS time \t" << fix(total_blas_time, 8, 4)
226218
<< '\n';
227219
log_stream << "\tcopy: \t" << fix(times[kTimeBlas_copy], 8, 4)
228-
<< " ("
229-
<< fix(times[kTimeBlas_copy] / times[kTimeSolve] * 100, 4, 1)
220+
<< " (" << fix(times[kTimeBlas_copy] / total_blas_time * 100, 4, 1)
230221
<< "%) in "
231222
<< integer(blas_calls[kTimeBlas_copy - kTimeBlasStart], 10)
232223
<< " calls\n";
233224
log_stream << "\taxpy: \t" << fix(times[kTimeBlas_axpy], 8, 4)
234-
<< " ("
235-
<< fix(times[kTimeBlas_axpy] / times[kTimeSolve] * 100, 4, 1)
225+
<< " (" << fix(times[kTimeBlas_axpy] / total_blas_time * 100, 4, 1)
236226
<< "%) in "
237227
<< integer(blas_calls[kTimeBlas_axpy - kTimeBlasStart], 10)
238228
<< " calls\n";
239229
log_stream << "\tscal: \t" << fix(times[kTimeBlas_scal], 8, 4)
240-
<< " ("
241-
<< fix(times[kTimeBlas_scal] / times[kTimeSolve] * 100, 4, 1)
230+
<< " (" << fix(times[kTimeBlas_scal] / total_blas_time * 100, 4, 1)
242231
<< "%) in "
243232
<< integer(blas_calls[kTimeBlas_scal - kTimeBlasStart], 10)
244233
<< " calls\n";
245234
log_stream << "\tswap: \t" << fix(times[kTimeBlas_swap], 8, 4)
246-
<< " ("
247-
<< fix(times[kTimeBlas_swap] / times[kTimeSolve] * 100, 4, 1)
235+
<< " (" << fix(times[kTimeBlas_swap] / total_blas_time * 100, 4, 1)
248236
<< "%) in "
249237
<< integer(blas_calls[kTimeBlas_swap - kTimeBlasStart], 10)
250238
<< " calls\n";
251239
log_stream << "\tgemv: \t" << fix(times[kTimeBlas_gemv], 8, 4)
252-
<< " ("
253-
<< fix(times[kTimeBlas_gemv] / times[kTimeSolve] * 100, 4, 1)
240+
<< " (" << fix(times[kTimeBlas_gemv] / total_blas_time * 100, 4, 1)
254241
<< "%) in "
255242
<< integer(blas_calls[kTimeBlas_gemv - kTimeBlasStart], 10)
256243
<< " calls\n";
257244
log_stream << "\ttrsv: \t" << fix(times[kTimeBlas_trsv], 8, 4)
258-
<< " ("
259-
<< fix(times[kTimeBlas_trsv] / times[kTimeSolve] * 100, 4, 1)
245+
<< " (" << fix(times[kTimeBlas_trsv] / total_blas_time * 100, 4, 1)
260246
<< "%) in "
261247
<< integer(blas_calls[kTimeBlas_trsv - kTimeBlasStart], 10)
262248
<< " calls\n";
263249
log_stream << "\ttpsv: \t" << fix(times[kTimeBlas_tpsv], 8, 4)
264-
<< " ("
265-
<< fix(times[kTimeBlas_tpsv] / times[kTimeSolve] * 100, 4, 1)
250+
<< " (" << fix(times[kTimeBlas_tpsv] / total_blas_time * 100, 4, 1)
266251
<< "%) in "
267252
<< integer(blas_calls[kTimeBlas_tpsv - kTimeBlasStart], 10)
268253
<< " calls\n";
269254
log_stream << "\tger: \t" << fix(times[kTimeBlas_ger], 8, 4)
270-
<< " ("
271-
<< fix(times[kTimeBlas_ger] / times[kTimeSolve] * 100, 4, 1)
255+
<< " (" << fix(times[kTimeBlas_ger] / total_blas_time * 100, 4, 1)
272256
<< "%) in "
273257
<< integer(blas_calls[kTimeBlas_ger - kTimeBlasStart], 10)
274258
<< " calls\n";
275259
log_stream << "\ttrsm: \t" << fix(times[kTimeBlas_trsm], 8, 4)
276-
<< " ("
277-
<< fix(times[kTimeBlas_trsm] / times[kTimeSolve] * 100, 4, 1)
260+
<< " (" << fix(times[kTimeBlas_trsm] / total_blas_time * 100, 4, 1)
278261
<< "%) in "
279262
<< integer(blas_calls[kTimeBlas_trsm - kTimeBlasStart], 10)
280263
<< " calls\n";
281264
log_stream << "\tsyrk: \t" << fix(times[kTimeBlas_syrk], 8, 4)
282-
<< " ("
283-
<< fix(times[kTimeBlas_syrk] / times[kTimeSolve] * 100, 4, 1)
265+
<< " (" << fix(times[kTimeBlas_syrk] / total_blas_time * 100, 4, 1)
284266
<< "%) in "
285267
<< integer(blas_calls[kTimeBlas_syrk - kTimeBlasStart], 10)
286268
<< " calls\n";
287269
log_stream << "\tgemm: \t" << fix(times[kTimeBlas_gemm], 8, 4)
288-
<< " ("
289-
<< fix(times[kTimeBlas_gemm] / times[kTimeSolve] * 100, 4, 1)
270+
<< " (" << fix(times[kTimeBlas_gemm] / total_blas_time * 100, 4, 1)
290271
<< "%) in "
291272
<< integer(blas_calls[kTimeBlas_gemm - kTimeBlasStart], 10)
292273
<< " calls\n";

highs/ipm/hipo/factorhighs/FactorHiGHS.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ Int FHsolver::factorise(const Symbolic& S, const std::vector<Int>& rows,
4848
return fact_obj.run(N_);
4949
}
5050

51-
Int FHsolver::solve(std::vector<double>& x, Int* solve_count, double* omega) {
52-
return N_.solve(x, solve_count, omega);
53-
}
51+
Int FHsolver::solve(std::vector<double>& x) { return N_.solve(x); }
52+
53+
void FHsolver::getRegularisation(std::vector<double>& reg) { N_.getReg(reg); }
5454

5555
} // namespace hipo

highs/ipm/hipo/factorhighs/FactorHiGHS.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,8 @@ class FHsolver {
9191
const std::vector<Int>& ptr, const std::vector<double>& vals);
9292

9393
// Perform solve phase with rhs given by x, which is overwritten with the
94-
// solution. solve_count returns the number of solves performed during the
95-
// phase (including refinement). omega returns the final residual after
96-
// refinement.
97-
// For now refinement is performed automatically as part of solve,
98-
// this will change in the future.
99-
Int solve(std::vector<double>& x, Int* solve_count = nullptr,
100-
double* omega = nullptr);
94+
// solution.
95+
Int solve(std::vector<double>& x);
10196

10297
// If multiple factorisation are performed, call newIter() before each
10398
// factorisation. This is used only to collect data for debugging, if
@@ -107,6 +102,8 @@ class FHsolver {
107102
// Set values for static regularisation to be added when a pivot is selected.
108103
// If regularisation is already added to the matrix, ignore.
109104
void setRegularisation(double reg_p, double reg_d);
105+
106+
void getRegularisation(std::vector<double>& reg);
110107
};
111108

112109
} // namespace hipo

highs/ipm/hipo/factorhighs/FactorHiGHSSettings.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ const Int kBlockParallelThreshold = 5;
4747
// regularisation
4848
const double kDynamicDiagCoeff = 1e-24;
4949

50-
// refinement
51-
const Int kMaxRefinementIter = 3;
52-
const double kRefinementTolerance = 1e-12;
53-
5450
// metis
5551
const Int kMetisSeed = 42;
5652

highs/ipm/hipo/factorhighs/Factorise.cpp

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,29 +74,17 @@ Factorise::Factorise(const Symbolic& S, const std::vector<Int>& rowsA,
7474
min_diag_ = std::min(min_diag_, val);
7575
}
7676

77-
// infinity norm of columns of A
78-
inf_norm_cols_.assign(n_, 0.0);
79-
for (Int col = 0; col < n_; ++col) {
80-
for (Int el = ptrA_[col]; el < ptrA_[col + 1]; ++el) {
81-
Int row = rowsA_[el];
82-
double val = valA_[el];
83-
inf_norm_cols_[col] = std::max(inf_norm_cols_[col], std::abs(val));
84-
if (row != col)
85-
inf_norm_cols_[row] = std::max(inf_norm_cols_[row], std::abs(val));
86-
}
87-
}
88-
8977
// one norm of columns of A
90-
one_norm_cols_.assign(n_, 0.0);
78+
std::vector<double> one_norm_cols(n_, 0.0);
9179
for (Int col = 0; col < n_; ++col) {
9280
for (Int el = ptrA_[col]; el < ptrA_[col + 1]; ++el) {
9381
Int row = rowsA_[el];
9482
double val = valA_[el];
95-
one_norm_cols_[col] += std::abs(val);
96-
if (row != col) one_norm_cols_[row] += std::abs(val);
83+
one_norm_cols[col] += std::abs(val);
84+
if (row != col) one_norm_cols[row] += std::abs(val);
9785
}
9886
}
99-
A_norm1_ = *std::max_element(one_norm_cols_.begin(), one_norm_cols_.end());
87+
A_norm1_ = *std::max_element(one_norm_cols.begin(), one_norm_cols.end());
10088

10189
data_.setNorms(A_norm1_, max_diag_);
10290
}
@@ -421,11 +409,6 @@ bool Factorise::run(Numeric& num) {
421409
num.total_reg_ = std::move(total_reg_);
422410
num.swaps_ = std::move(swaps_);
423411
num.pivot_2x2_ = std::move(pivot_2x2_);
424-
num.ptrA_ = std::move(ptrA_);
425-
num.rowsA_ = std::move(rowsA_);
426-
num.valA_ = std::move(valA_);
427-
num.one_norm_cols_ = std::move(one_norm_cols_);
428-
num.inf_norm_cols_ = std::move(inf_norm_cols_);
429412
num.data_ = &data_;
430413

431414
#if HIPO_TIMING_LEVEL >= 1

highs/ipm/hipo/factorhighs/Factorise.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ class Factorise {
5151
double max_diag_{};
5252
double min_diag_{};
5353
double A_norm1_{};
54-
std::vector<double> one_norm_cols_{};
55-
std::vector<double> inf_norm_cols_{};
5654

5755
// regularisation
5856
std::vector<double> total_reg_{};

0 commit comments

Comments
 (0)