66#include " Highs.h"
77#include " catch.hpp"
88#include " io/Filereader.h"
9+ #include " ipm/hipo/factorhighs/FactorHighs_c_api.h"
910#include " ipm/hipo/ipm/Solver.h"
1011#include " ipm/hipo/ipm/Status.h"
1112#include " lp_data/HighsCallback.h"
@@ -127,4 +128,80 @@ TEST_CASE("test-hipo-freevar", "[highs_hipo]") {
127128 runHipoTest (highs, " perold.mps" , -9.381e3 , expected_status, " on" );
128129 runHipoTest (highs, " perold.mps" , -9.381e3 , expected_status, " off" );
129130 highs.resetGlobalScheduler (true );
131+ }
132+
133+ TEST_CASE (" test-hipo-linear-solver" , " [highs_hipo]" ) {
134+ // problem size
135+ const int n = 5 ;
136+ const int nz = 10 ;
137+
138+ // define the lower triangle in CSC format, with 0-based indexing
139+ int ptr[n + 1 ] = {0 , 3 , 5 , 8 , 9 , 10 };
140+ int rows[nz] = {0 , 2 , 3 , 1 , 2 , 2 , 3 , 4 , 3 , 4 };
141+ double vals[nz] = {5 , 3 , 4 , 3 , 2 , 9 , -1 , 1 , 8 , 1 };
142+
143+ // matrix is spd, so expect all pivots to be positive
144+ int signs[n] = {1 , 1 , 1 , 1 , 1 };
145+
146+ // rhs and expected solution
147+ double rhs[n] = {1 , 2 , 3 , 4 , 5 };
148+ const double lhs[n] = {0.457627118644068 , 1.118644067796610 ,
149+ -0.677966101694915 , 0.186440677966102 ,
150+ 5.677966101694915 };
151+
152+ // initialise with default number of threads
153+ const int num_threads = 0 ;
154+ int initialise_status = FactorHighs_initialise (num_threads);
155+ REQUIRE (initialise_status == 0 );
156+ void * S = FactorHighs_symbolic_create ();
157+ void * FH = FactorHighs_create ();
158+
159+ // set options
160+ const int logging_on = dev_run;
161+ FactorHighs_setLogging (FH , logging_on);
162+
163+ const int block_size = 64 ;
164+ FactorHighs_setBlockSize (FH , block_size);
165+
166+ const int pivoting_off = 0 ;
167+ FactorHighs_setPivoting (FH , pivoting_off);
168+
169+ FactorHighs_setRegularisation (FH , 0.0 , 0.0 );
170+
171+ // compute ordering with metis
172+ int perm[n];
173+ int metis_status = FactorHighs_reorderMetis (FH , n, nz, rows, ptr, perm);
174+ REQUIRE (metis_status == 0 );
175+
176+ // perform analyse phase
177+ int analyse_status =
178+ FactorHighs_analyse (FH , S, n, nz, rows, ptr, signs, perm);
179+ REQUIRE (analyse_status == 0 );
180+
181+ // print extended statistics of symbolic factorisation
182+ int verbose = 1 ;
183+ FactorHighs_symbolic_print (FH , S, verbose);
184+
185+ // factorise the matrix
186+ int factorise_status = FactorHighs_factorise (FH , S, n, nz, rows, ptr, vals);
187+ REQUIRE (factorise_status == 0 );
188+
189+ // compute the inertia of the factorisation
190+ int pos, neg, zero;
191+ double zero_tolerance = 1e-16 ;
192+ FactorHighs_inertia (FH , &pos, &neg, &zero, zero_tolerance);
193+
194+ // triangular solve
195+ int solve_status = FactorHighs_solve (FH , rhs, 1 );
196+ REQUIRE (solve_status == 0 );
197+
198+ // compute error
199+ double error = 0.0 ;
200+ for (int i = 0 ; i < n; ++i) error += fabs (rhs[i] - lhs[i]);
201+ REQUIRE (error < 1e-12 );
202+
203+ // terminate
204+ FactorHighs_symbolic_destroy (S);
205+ FactorHighs_destroy (FH );
206+ FactorHighs_terminate ();
130207}
0 commit comments