@@ -18,6 +18,10 @@ FactorHiGHSSolver::FactorHiGHSSolver(Options& options, const Model& model,
1818 data_{record},
1919 log_{log},
2020 model_{model},
21+ A_{model.A ()},
22+ mA_ {A_.num_row_ },
23+ nA_{A_.num_col_ },
24+ nzA_{A_.numNz ()},
2125 options_{options} {}
2226
2327void FactorHiGHSSolver::clear () {
@@ -29,70 +33,59 @@ void FactorHiGHSSolver::clear() {
2933// Build structure and values of matrices
3034// =========================================================================
3135
32- Int FactorHiGHSSolver::buildASstructure (const HighsSparseMatrix& A,
33- Int64 nz_limit) {
36+ Int FactorHiGHSSolver::buildASstructure (Int64 nz_limit) {
3437 // Build lower triangular structure of the augmented system.
3538 // Build values of AS that will not change during the iterations.
3639
3740 log_.printDevInfo (" Building AS structure\n " );
3841
39- Int nA = A.num_col_ ;
40- Int mA = A.num_row_ ;
41- Int nzA = A.numNz ();
42-
4342 // AS matrix must fit into HighsInt
44- if ((Int64)nA + mA + nzA > nz_limit) return kStatusOverflow ;
43+ if ((Int64)nA_ + mA_ + nzA_ > nz_limit) return kStatusOverflow ;
4544
46- ptrAS_.resize (nA + mA + 1 );
47- rowsAS_.resize (nA + nzA + mA );
48- valAS_.resize (nA + nzA + mA );
45+ ptrAS_.resize (nA_ + mA_ + 1 );
46+ rowsAS_.resize (nA_ + nzA_ + mA_ );
47+ valAS_.resize (nA_ + nzA_ + mA_ );
4948
5049 Int next = 0 ;
5150
52- for (Int i = 0 ; i < nA ; ++i) {
51+ for (Int i = 0 ; i < nA_ ; ++i) {
5352 // diagonal element
5453 rowsAS_[next] = i;
5554 ++next;
5655
5756 // column of A
58- for (Int el = A .start_ [i]; el < A .start_ [i + 1 ]; ++el) {
59- rowsAS_[next] = nA + A .index_ [el];
60- valAS_[next] = A .value_ [el]; // values of AS that will not change
57+ for (Int el = A_ .start_ [i]; el < A_ .start_ [i + 1 ]; ++el) {
58+ rowsAS_[next] = nA_ + A_ .index_ [el];
59+ valAS_[next] = A_ .value_ [el]; // values of AS that will not change
6160 ++next;
6261 }
6362
6463 ptrAS_[i + 1 ] = next;
6564 }
6665
6766 // 2,2 block
68- for (Int i = 0 ; i < mA ; ++i) {
69- rowsAS_[next] = nA + i;
67+ for (Int i = 0 ; i < mA_ ; ++i) {
68+ rowsAS_[next] = nA_ + i;
7069 ++next;
71- ptrAS_[nA + i + 1 ] = ptrAS_[nA + i] + 1 ;
70+ ptrAS_[nA_ + i + 1 ] = ptrAS_[nA_ + i] + 1 ;
7271 }
7372
7473 return kStatusOk ;
7574}
7675
77- Int FactorHiGHSSolver::buildASvalues (const HighsSparseMatrix& A,
78- const std::vector<double >& scaling) {
76+ Int FactorHiGHSSolver::buildASvalues (const std::vector<double >& scaling) {
7977 // build AS values that change during iterations.
8078
8179 assert (!ptrAS_.empty () && !rowsAS_.empty ());
8280
83- Int nA = A.num_col_ ;
84- Int mA = A.num_row_ ;
85- Int nzA = A.numNz ();
86-
87- for (Int i = 0 ; i < nA; ++i) {
81+ for (Int i = 0 ; i < nA_; ++i) {
8882 valAS_[ptrAS_[i]] = -scaling[i];
8983 }
9084
9185 return kStatusOk ;
9286}
9387
94- Int FactorHiGHSSolver::buildNEstructure (const HighsSparseMatrix& A,
95- Int64 nz_limit) {
88+ Int FactorHiGHSSolver::buildNEstructure (Int64 nz_limit) {
9689 // Build lower triangular structure of AAt.
9790 // This approach uses a column-wise copy of A, a partial row-wise copy and a
9891 // vector of corresponding indices.
@@ -104,20 +97,20 @@ Int FactorHiGHSSolver::buildNEstructure(const HighsSparseMatrix& A,
10497 // create partial row-wise representation without values, and array or
10598 // corresponding indices between cw and rw representation
10699 {
107- ptrA_rw_.assign (A. num_row_ + 1 , 0 );
108- idxA_rw_.assign (A. numNz () , 0 );
100+ ptrA_rw_.assign (mA_ + 1 , 0 );
101+ idxA_rw_.assign (nzA_ , 0 );
109102
110103 // pointers of row-start
111- for (Int el = 0 ; el < A. numNz () ; ++el) ptrA_rw_[A .index_ [el] + 1 ]++;
112- for (Int i = 0 ; i < A. num_row_ ; ++i) ptrA_rw_[i + 1 ] += ptrA_rw_[i];
104+ for (Int el = 0 ; el < nzA_ ; ++el) ptrA_rw_[A_ .index_ [el] + 1 ]++;
105+ for (Int i = 0 ; i < mA_ ; ++i) ptrA_rw_[i + 1 ] += ptrA_rw_[i];
113106
114107 std::vector<Int> temp = ptrA_rw_;
115- corr_A_.assign (A. numNz () , 0 );
108+ corr_A_.assign (nzA_ , 0 );
116109
117110 // rw-indices and corresponding indices created together
118- for (Int col = 0 ; col < A. num_col_ ; ++col) {
119- for (Int el = A .start_ [col]; el < A .start_ [col + 1 ]; ++el) {
120- Int row = A .index_ [el];
111+ for (Int col = 0 ; col < nA_ ; ++col) {
112+ for (Int el = A_ .start_ [col]; el < A_ .start_ [col + 1 ]; ++el) {
113+ Int row = A_ .index_ [el];
121114
122115 corr_A_[temp[row]] = el;
123116 idxA_rw_[temp[row]] = col;
@@ -130,15 +123,15 @@ Int FactorHiGHSSolver::buildNEstructure(const HighsSparseMatrix& A,
130123 rowsNE_.clear ();
131124
132125 // ptr is allocated its exact size
133- ptrNE_.resize (A. num_row_ + 1 , 0 );
126+ ptrNE_.resize (mA_ + 1 , 0 );
134127
135128 // keep track if given entry is nonzero, in column considered
136- std::vector<bool > is_nz (A. num_row_ , false );
129+ std::vector<bool > is_nz (mA_ , false );
137130
138131 // temporary storage of indices
139- std::vector<Int> temp_index (A. num_row_ );
132+ std::vector<Int> temp_index (mA_ );
140133
141- for (Int row = 0 ; row < A. num_row_ ; ++row) {
134+ for (Int row = 0 ; row < mA_ ; ++row) {
142135 // go along the entries of the row, and then down each column.
143136 // this builds the lower triangular part of the row-th column of AAt.
144137
@@ -150,8 +143,8 @@ Int FactorHiGHSSolver::buildNEstructure(const HighsSparseMatrix& A,
150143
151144 // for each nonzero in the row, go down corresponding column, starting
152145 // from current position
153- for (Int colEl = corr; colEl < A .start_ [col + 1 ]; ++colEl) {
154- Int row2 = A .index_ [colEl];
146+ for (Int colEl = corr; colEl < A_ .start_ [col + 1 ]; ++colEl) {
147+ Int row2 = A_ .index_ [colEl];
155148
156149 // row2 is guaranteed to be larger or equal than row
157150 // (provided that the columns of A are sorted)
@@ -184,17 +177,16 @@ Int FactorHiGHSSolver::buildNEstructure(const HighsSparseMatrix& A,
184177 return kStatusOk ;
185178}
186179
187- Int FactorHiGHSSolver::buildNEvalues (const HighsSparseMatrix& A,
188- const std::vector<double >& scaling) {
180+ Int FactorHiGHSSolver::buildNEvalues (const std::vector<double >& scaling) {
189181 // given the NE structure already computed, fill in the NE values
190182
191183 assert (!ptrNE_.empty () && !rowsNE_.empty ());
192184
193185 valNE_.resize (rowsNE_.size ());
194186
195- std::vector<double > work (A. num_row_ , 0.0 );
187+ std::vector<double > work (mA_ , 0.0 );
196188
197- for (Int row = 0 ; row < A. num_row_ ; ++row) {
189+ for (Int row = 0 ; row < mA_ ; ++row) {
198190 // go along the entries of the row, and then down each column.
199191 // this builds the lower triangular part of the row-th column of AAt.
200192
@@ -205,18 +197,18 @@ Int FactorHiGHSSolver::buildNEvalues(const HighsSparseMatrix& A,
205197 const double theta =
206198 scaling.empty () ? 1.0 : 1.0 / (scaling[col] + regul_.primal );
207199
208- const double row_value = theta * A .value_ [corr];
200+ const double row_value = theta * A_ .value_ [corr];
209201
210202 // for each nonzero in the row, go down corresponding column, starting
211203 // from current position
212- for (Int colEl = corr; colEl < A .start_ [col + 1 ]; ++colEl) {
213- Int row2 = A .index_ [colEl];
204+ for (Int colEl = corr; colEl < A_ .start_ [col + 1 ]; ++colEl) {
205+ Int row2 = A_ .index_ [colEl];
214206
215207 // row2 is guaranteed to be larger or equal than row
216208 // (provided that the columns of A are sorted)
217209
218210 // compute and accumulate value
219- double value = row_value * A .value_ [colEl];
211+ double value = row_value * A_ .value_ [colEl];
220212 work[row2] += value;
221213 }
222214 }
@@ -242,13 +234,12 @@ Int FactorHiGHSSolver::analyseAS(Symbolic& S) {
242234 // in object S and the status.
243235
244236 Clock clock;
245- if (Int status = buildASstructure (model_. A () )) return status;
237+ if (Int status = buildASstructure ()) return status;
246238 info_.matrix_structure_time = clock.stop ();
247239
248240 // create vector of signs of pivots
249- std::vector<Int> pivot_signs (model_.A ().num_col_ + model_.A ().num_row_ , -1 );
250- for (Int i = 0 ; i < model_.A ().num_row_ ; ++i)
251- pivot_signs[model_.A ().num_col_ + i] = 1 ;
241+ std::vector<Int> pivot_signs (nA_ + mA_ , -1 );
242+ for (Int i = 0 ; i < mA_ ; ++i) pivot_signs[nA_ + i] = 1 ;
252243
253244 log_.printDevInfo (" Performing AS analyse phase\n " );
254245
@@ -258,14 +249,14 @@ Int FactorHiGHSSolver::analyseAS(Symbolic& S) {
258249Int FactorHiGHSSolver::analyseNE (Symbolic& S, Int64 nz_limit) {
259250 // Perform analyse phase of augmented system and return symbolic factorisation
260251 // in object S and the status. If building the matrix failed, the status is
261- // set to OoM .
252+ // set to kStatusOverflow .
262253
263254 Clock clock;
264- if (Int status = buildNEstructure (model_. A (), nz_limit)) return status;
255+ if (Int status = buildNEstructure (nz_limit)) return status;
265256 info_.matrix_structure_time = clock.stop ();
266257
267258 // create vector of signs of pivots
268- std::vector<Int> pivot_signs (model_. A (). num_row_ , 1 );
259+ std::vector<Int> pivot_signs (mA_ , 1 );
269260
270261 log_.printDevInfo (" Performing NE analyse phase\n " );
271262
@@ -284,7 +275,7 @@ Int FactorHiGHSSolver::factorAS(const HighsSparseMatrix& A,
284275 Clock clock;
285276
286277 // build matrix
287- buildASvalues (A, scaling);
278+ buildASvalues (scaling);
288279 info_.matrix_time += clock.stop ();
289280
290281 // set static regularisation, since it may have changed
@@ -308,7 +299,7 @@ Int FactorHiGHSSolver::factorNE(const HighsSparseMatrix& A,
308299 Clock clock;
309300
310301 // build matrix
311- buildNEvalues (A, scaling);
302+ buildNEvalues (scaling);
312303 info_.matrix_time += clock.stop ();
313304
314305 // set static regularisation, since it may have changed
0 commit comments