@@ -241,16 +241,16 @@ void assertLogical(const char* name, const HighsInt is) {
241241void createBlendingLp (void * highs ) {
242242 // Special variant of the blending LP, with redundant constraint so
243243 // that LP is reduced by presolve - but not to empty!
244- const double inf = Highs_getInfinity (highs );
244+ const double kHighsInf = Highs_getInfinity (highs );
245245
246246 HighsInt num_col = 2 ;
247247 HighsInt num_row = 3 ;
248248 HighsInt num_nz = 6 ;
249249 HighsInt sense = -1 ;
250250 double col_cost [2 ] = {8 , 10 };
251251 double col_lower [2 ] = {0 , 0 };
252- double col_upper [2 ] = {inf , inf };
253- double row_lower [3 ] = {- inf , - inf , - inf };
252+ double col_upper [2 ] = {kHighsInf , kHighsInf };
253+ double row_lower [3 ] = {- kHighsInf , - kHighsInf , - kHighsInf };
254254 double row_upper [3 ] = {500 , 120 , 210 };
255255 HighsInt a_index [6 ] = {0 , 1 , 0 , 1 , 0 , 1 };
256256 double a_value [6 ] = {0.5 , 0.5 , 0.3 , 0.5 , 0.7 , 0.5 };
@@ -488,41 +488,64 @@ void minimalApiQp() {
488488 HighsInt num_col = 3 ;
489489 HighsInt num_row = 1 ;
490490 HighsInt num_nz = 2 ;
491- HighsInt q_num_nz = 4 ;
492491 HighsInt a_format = kHighsMatrixFormatColwise ;
493- HighsInt q_format = kHighsHessianFormatTriangular ;
494492 HighsInt sense = kHighsObjSenseMinimize ;
495493 double offset = 0 ;
496494 double col_cost [3 ] = {0.0 , -1.0 , -3.0 };
497495 double col_lower [3 ] = {- inf , - inf , - inf };
498496 double col_upper [3 ] = {inf , inf , inf };
499497 double row_lower [1 ] = {- inf };
500498 double row_upper [1 ] = {2 };
499+
501500 HighsInt a_start [3 ] = {0 , 1 , 1 };
502501 HighsInt a_index [2 ] = {0 , 0 };
503502 double a_value [2 ] = {1.0 , 1.0 };
503+
504+ // Start with triangular Hessian, then
505+ HighsInt q_format = kHighsHessianFormatTriangular ;
506+ HighsInt q_num_nz = 4 ;
504507 HighsInt q_start [3 ] = {0 , 2 , 3 };
505508 HighsInt q_index [4 ] = {0 , 2 , 1 , 2 };
506509 double q_value [4 ] = {2.0 , -1.0 , 0.2 , 2.0 };
507510
511+ double required_x [3 ] = {0.5 , 5.0 , 1.5 };
512+
508513 double * col_value = (double * )malloc (sizeof (double ) * num_col );
514+
509515 HighsInt model_status ;
510- HighsInt return_status = Highs_qpCall (
511- num_col , num_row , num_nz , q_num_nz , a_format , q_format , sense , offset ,
512- col_cost , col_lower , col_upper , row_lower , row_upper , a_start , a_index ,
513- a_value , q_start , q_index , q_value , col_value , NULL , NULL , NULL , NULL ,
514- NULL , & model_status );
516+ HighsInt return_status =
517+ Highs_qpCall ( num_col , num_row , num_nz , q_num_nz , a_format , q_format , sense , offset ,
518+ col_cost , col_lower , col_upper , row_lower , row_upper , a_start , a_index ,
519+ a_value , q_start , q_index , q_value , col_value , NULL , NULL , NULL , NULL ,
520+ NULL , & model_status );
515521 assert (return_status == kHighsStatusOk );
516522 assertIntValuesEqual ("Model status for QP qph" , model_status ,
517- kHighsModelStatusOptimal );
518- double required_x [3 ] = {0.5 , 5.0 , 1.5 };
519- if (dev_run ) {
520- for (HighsInt iCol = 0 ; iCol < num_col ; iCol ++ ) {
521- printf ("x%d1 = %g\n" , (int )iCol , col_value [iCol ]);
522- assertDoubleValuesEqual ("Solution value for QP qph" , col_value [iCol ],
523- required_x [iCol ]);
524- }
523+ kHighsModelStatusOptimal );
524+ for (HighsInt iCol = 0 ; iCol < num_col ; iCol ++ ) {
525+ if (dev_run ) printf ("x%d1 = %g\n" , (int )iCol , col_value [iCol ]);
526+ assertDoubleValuesEqual ("Solution value for QP qph" , col_value [iCol ],
527+ required_x [iCol ]);
525528 }
529+
530+ HighsInt square_q_format = kHighsHessianFormatSquare ;
531+ HighsInt square_q_num_nz = 5 ;
532+ HighsInt square_q_start [3 ] = {0 , 2 , 3 };
533+ HighsInt square_q_index [5 ] = {0 , 2 , 1 , 0 , 2 };
534+ double square_q_value [5 ] = {2.0 , -1.0 , 0.2 , -1.0 , 2.0 };
535+
536+ Highs_qpCall (num_col , num_row , num_nz , square_q_num_nz , a_format , square_q_format , sense , offset ,
537+ col_cost , col_lower , col_upper , row_lower , row_upper , a_start , a_index ,
538+ a_value , square_q_start , square_q_index , square_q_value , col_value , NULL , NULL , NULL , NULL ,
539+ NULL , & model_status );
540+ assert (return_status == kHighsStatusOk );
541+ assertIntValuesEqual ("Model status for QP qph" , model_status ,
542+ kHighsModelStatusOptimal );
543+ for (HighsInt iCol = 0 ; iCol < num_col ; iCol ++ ) {
544+ if (dev_run ) printf ("x%d1 = %g\n" , (int )iCol , col_value [iCol ]);
545+ assertDoubleValuesEqual ("Solution value for QP qph" , col_value [iCol ],
546+ required_x [iCol ]);
547+ }
548+
526549 free (col_value );
527550}
528551
@@ -1513,23 +1536,33 @@ void testPassHessian() {
15131536 HighsInt index [1 ] = {0 };
15141537 double value [1 ] = {-2.0 };
15151538 HighsInt return_status ;
1516- return_status = Highs_passHessian (highs , 1 , 1 , 1 , start , index , value );
1517- assertIntValuesEqual ("Return of passHessian" , return_status , kHighsStatusOk );
1518- Highs_run (highs );
1519- // Solving max -x^2 + 2x
1539+
15201540 const double optimal_objective_value = 1 ;
15211541 const double primal = 1 ;
15221542 const double dual = 0 ;
1523- assertIntValuesEqual ("Status" , Highs_getModelStatus (highs ),
1524- kHighsModelStatusOptimal ); // kOptimal
15251543 double col_value [1 ] = {-123.0 };
15261544 double col_dual [1 ] = {0.0 };
1527- Highs_getSolution (highs , col_value , col_dual , NULL , NULL );
1528- double objective_value = Highs_getObjectiveValue (highs );
1529- assertDoubleValuesEqual ("Objective" , objective_value ,
1530- optimal_objective_value );
1531- assertDoubleValuesEqual ("Primal" , col_value [0 ], primal );
1532- assertDoubleValuesEqual ("Dual" , col_dual [0 ], dual );
1545+
1546+ for (HighsInt k = 0 ; k < 2 ; k ++ ) {
1547+ HighsInt q_format = -1 ;
1548+ if (k == 0 ) {
1549+ q_format = kHighsHessianFormatTriangular ;
1550+ } else {
1551+ q_format = kHighsHessianFormatSquare ;
1552+ }
1553+ return_status = Highs_passHessian (highs , 1 , 1 , q_format , start , index , value );
1554+ assertIntValuesEqual ("Return of passHessian" , return_status , kHighsStatusOk );
1555+ Highs_run (highs );
1556+ // Solving max -x^2 + 2x
1557+ assertIntValuesEqual ("Status" , Highs_getModelStatus (highs ),
1558+ kHighsModelStatusOptimal ); // kOptimal
1559+ Highs_getSolution (highs , col_value , col_dual , NULL , NULL );
1560+ double objective_value = Highs_getObjectiveValue (highs );
1561+ assertDoubleValuesEqual ("Objective" , objective_value ,
1562+ optimal_objective_value );
1563+ assertDoubleValuesEqual ("Primal" , col_value [0 ], primal );
1564+ assertDoubleValuesEqual ("Dual" , col_dual [0 ], dual );
1565+ }
15331566
15341567 Highs_destroy (highs );
15351568}
0 commit comments