MCPcopy Create free account
hub / github.com/ERGO-Code/HiGHS / testFixedLp

Function testFixedLp

check/TestCAPI.c:2410–2517  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2408}
2409
2410void testFixedLp() {
2411 // The use of Highs_getFixedLp is illustrated for the MIP
2412 //
2413 // Min f = -3x_0 - 2x_1 - x_2
2414 // s.t. x_0 + x_1 + x_2 <= 7
2415 // 4x_0 + 2x_1 + x_2 = 12
2416 // x_0 >=0; x_1 >= 0; x_2 binary
2417
2418 const HighsInt num_col = 3;
2419 const HighsInt num_row = 2;
2420 const HighsInt num_nz = 6;
2421 HighsInt a_format = kHighsMatrixFormatColwise;
2422 HighsInt sense = kHighsObjSenseMinimize;
2423 double offset = 0;
2424
2425 // Define the column costs, lower bounds and upper bounds
2426 double col_cost[3] = {-3.0, -2.0, -1.0};
2427 double col_lower[3] = {0.0, 0.0, 0.0};
2428 double col_upper[3] = {1.0e30, 1.0e30, 1.0};
2429 // Define the row lower bounds and upper bounds
2430 double row_lower[2] = {-1.0e30, 12.0};
2431 double row_upper[2] = {7.0, 12.0};
2432 // Define the constraint matrix column-wise
2433 HighsInt a_start[3] = {0, 2, 4};
2434 HighsInt a_index[6] = {0, 1, 0, 1, 0, 1};
2435 double a_value[6] = {1.0, 4.0, 1.0, 2.0, 1.0, 1.0};
2436 HighsInt integrality[3] = {kHighsVarTypeContinuous, kHighsVarTypeContinuous,
2437 kHighsVarTypeInteger};
2438
2439 void* highs = Highs_create();
2440 Highs_setBoolOptionValue(highs, "output_flag", dev_run);
2441 Highs_setStringOptionValue(highs, "presolve", "off");
2442 HighsInt return_status =
2443 Highs_passMip(highs, num_col, num_row, num_nz, a_format, sense, offset,
2444 col_cost, col_lower, col_upper, row_lower, row_upper,
2445 a_start, a_index, a_value, integrality);
2446 assert(return_status == kHighsStatusOk);
2447 return_status = Highs_run(highs);
2448 double mip_objective_function_value;
2449 return_status = Highs_getDoubleInfoValue(highs, "objective_function_value",
2450 &mip_objective_function_value);
2451 assert(return_status == kHighsStatusOk);
2452
2453 double* col_value = (double*)malloc(sizeof(double) * num_col);
2454 return_status = Highs_getSolution(highs, col_value, NULL, NULL, NULL);
2455 assert(return_status == kHighsStatusOk);
2456
2457 HighsInt fixed_lp_num_col;
2458 HighsInt fixed_lp_num_row;
2459 HighsInt fixed_lp_num_nz;
2460 HighsInt fixed_lp_sense;
2461 double fixed_lp_offset;
2462 Highs_getFixedLp(highs, kHighsMatrixFormatColwise, &fixed_lp_num_col, &fixed_lp_num_row,
2463 &fixed_lp_num_nz, &fixed_lp_sense, &fixed_lp_offset, NULL, NULL, NULL, NULL, NULL,
2464 NULL, NULL, NULL);
2465
2466 assert(fixed_lp_num_col == num_col);
2467 assert(fixed_lp_num_row == num_row);

Callers 1

mainFunction · 0.85

Calls 11

Highs_createFunction · 0.85
Highs_setBoolOptionValueFunction · 0.85
Highs_passMipFunction · 0.85
Highs_runFunction · 0.85
Highs_getDoubleInfoValueFunction · 0.85
Highs_getSolutionFunction · 0.85
Highs_getFixedLpFunction · 0.85
Highs_passLpFunction · 0.85
Highs_setSolutionFunction · 0.85
Highs_destroyFunction · 0.85

Tested by

no test coverage detected