@@ -1820,7 +1820,6 @@ void testGetModel() {
18201820 assert (ck_sense == sense );
18211821
18221822 double * ck_col_cost = (double * )malloc (sizeof (double ) * ck_num_col );
1823- ;
18241823 double * ck_col_lower = (double * )malloc (sizeof (double ) * ck_num_col );
18251824 double * ck_col_upper = (double * )malloc (sizeof (double ) * ck_num_col );
18261825 double * ck_row_lower = (double * )malloc (sizeof (double ) * ck_num_row );
@@ -2242,6 +2241,115 @@ void testIis() {
22422241 Highs_destroy (highs );
22432242}
22442243
2244+ void testFixedLp () {
2245+ // The use of Highs_getFixedLp is illustrated for the MIP
2246+ //
2247+ // Min f = -3x_0 - 2x_1 - x_2
2248+ // s.t. x_0 + x_1 + x_2 <= 7
2249+ // 4x_0 + 2x_1 + x_2 = 12
2250+ // x_0 >=0; x_1 >= 0; x_2 binary
2251+
2252+ const HighsInt num_col = 3 ;
2253+ const HighsInt num_row = 2 ;
2254+ const HighsInt num_nz = 6 ;
2255+ HighsInt a_format = kHighsMatrixFormatColwise ;
2256+ HighsInt sense = kHighsObjSenseMinimize ;
2257+ double offset = 0 ;
2258+
2259+ // Define the column costs, lower bounds and upper bounds
2260+ double col_cost [3 ] = {-3.0 , -2.0 , -1.0 };
2261+ double col_lower [3 ] = {0.0 , 0.0 , 0.0 };
2262+ double col_upper [3 ] = {1.0e30 , 1.0e30 , 1.0 };
2263+ // Define the row lower bounds and upper bounds
2264+ double row_lower [2 ] = {-1.0e30 , 12.0 };
2265+ double row_upper [2 ] = {7.0 , 12.0 };
2266+ // Define the constraint matrix column-wise
2267+ HighsInt a_start [3 ] = {0 , 2 , 4 };
2268+ HighsInt a_index [6 ] = {0 , 1 , 0 , 1 , 0 , 1 };
2269+ double a_value [6 ] = {1.0 , 4.0 , 1.0 , 2.0 , 1.0 , 1.0 };
2270+ HighsInt integrality [3 ] = {kHighsVarTypeContinuous , kHighsVarTypeContinuous ,
2271+ kHighsVarTypeInteger };
2272+
2273+ void * highs = Highs_create ();
2274+ Highs_setBoolOptionValue (highs , "output_flag" , dev_run );
2275+ Highs_setStringOptionValue (highs , "presolve" , "off" );
2276+ HighsInt return_status =
2277+ Highs_passMip (highs , num_col , num_row , num_nz , a_format , sense , offset ,
2278+ col_cost , col_lower , col_upper , row_lower , row_upper ,
2279+ a_start , a_index , a_value , integrality );
2280+ assert (return_status == kHighsStatusOk );
2281+ return_status = Highs_run (highs );
2282+ double mip_objective_function_value ;
2283+ return_status = Highs_getDoubleInfoValue (highs , "objective_function_value" ,
2284+ & mip_objective_function_value );
2285+ assert (return_status == kHighsStatusOk );
2286+
2287+ double * col_value = (double * )malloc (sizeof (double ) * num_col );
2288+ return_status = Highs_getSolution (highs , col_value , NULL , NULL , NULL );
2289+ assert (return_status == kHighsStatusOk );
2290+
2291+ HighsInt fixed_lp_num_col ;
2292+ HighsInt fixed_lp_num_row ;
2293+ HighsInt fixed_lp_num_nz ;
2294+ HighsInt fixed_lp_sense ;
2295+ double fixed_lp_offset ;
2296+ Highs_getFixedLp (highs , kHighsMatrixFormatColwise , & fixed_lp_num_col , & fixed_lp_num_row ,
2297+ & fixed_lp_num_nz , & fixed_lp_sense , & fixed_lp_offset , NULL , NULL , NULL , NULL , NULL ,
2298+ NULL , NULL , NULL );
2299+
2300+ assert (fixed_lp_num_col == num_col );
2301+ assert (fixed_lp_num_row == num_row );
2302+ assert (fixed_lp_num_nz == num_nz );
2303+ assert (fixed_lp_sense == sense );
2304+
2305+ double * fixed_lp_col_cost = (double * )malloc (sizeof (double ) * fixed_lp_num_col );
2306+ double * fixed_lp_col_lower = (double * )malloc (sizeof (double ) * fixed_lp_num_col );
2307+ double * fixed_lp_col_upper = (double * )malloc (sizeof (double ) * fixed_lp_num_col );
2308+ double * fixed_lp_row_lower = (double * )malloc (sizeof (double ) * fixed_lp_num_row );
2309+ double * fixed_lp_row_upper = (double * )malloc (sizeof (double ) * fixed_lp_num_row );
2310+ HighsInt * fixed_lp_a_start = (HighsInt * )malloc (sizeof (HighsInt ) * fixed_lp_num_col );
2311+ HighsInt * fixed_lp_a_index = (HighsInt * )malloc (sizeof (HighsInt ) * fixed_lp_num_nz );
2312+ double * fixed_lp_a_value = (double * )malloc (sizeof (double ) * num_nz );
2313+
2314+ // Get the arrays
2315+ Highs_getFixedLp (highs , kHighsMatrixFormatColwise , & fixed_lp_num_col , & fixed_lp_num_row ,
2316+ & fixed_lp_num_nz , & fixed_lp_sense , & fixed_lp_offset , fixed_lp_col_cost , fixed_lp_col_lower ,
2317+ fixed_lp_col_upper , fixed_lp_row_lower , fixed_lp_row_upper , fixed_lp_a_start , fixed_lp_a_index ,
2318+ fixed_lp_a_value );
2319+
2320+ return_status = Highs_passLp (highs ,
2321+ fixed_lp_num_col , fixed_lp_num_row , fixed_lp_num_nz ,
2322+ kHighsMatrixFormatColwise ,
2323+ fixed_lp_sense , fixed_lp_offset ,
2324+ fixed_lp_col_cost , fixed_lp_col_lower , fixed_lp_col_upper ,
2325+ fixed_lp_row_lower , fixed_lp_row_upper ,
2326+ fixed_lp_a_start , fixed_lp_a_index , fixed_lp_a_value );
2327+ assert (return_status == kHighsStatusOk );
2328+
2329+ return_status = Highs_setSolution (highs , col_value , NULL , NULL , NULL );
2330+ assert (return_status == kHighsStatusOk );
2331+
2332+ return_status = Highs_run (highs );
2333+ double objective_function_value ;
2334+ return_status = Highs_getDoubleInfoValue (highs , "objective_function_value" ,
2335+ & objective_function_value );
2336+ assert (return_status == kHighsStatusOk );
2337+ assert (objective_function_value == mip_objective_function_value );
2338+
2339+
2340+ free (col_value );
2341+ free (fixed_lp_col_cost );
2342+ free (fixed_lp_col_lower );
2343+ free (fixed_lp_col_upper );
2344+ free (fixed_lp_row_lower );
2345+ free (fixed_lp_row_upper );
2346+ free (fixed_lp_a_start );
2347+ free (fixed_lp_a_index );
2348+ free (fixed_lp_a_value );
2349+
2350+ Highs_destroy (highs );
2351+ }
2352+
22452353int main () {
22462354 minimalApiIllegalLp ();
22472355 testCallback ();
@@ -2265,7 +2373,8 @@ int main() {
22652373 testQpIndefiniteFailure ();
22662374 testDualRayTwice ();
22672375 testDeleteRowResolveWithBasis ();
2268- testIis ();
2376+ testIis ();
2377+ testFixedLp ();
22692378 return 0 ;
22702379}
22712380// testSetSolution();
0 commit comments