Skip to content

Commit 1aafc1b

Browse files
committed
Added 3-variable 2-constraint IIS test to TestCAPI.c; formatted
1 parent d6b8feb commit 1aafc1b

File tree

9 files changed

+181
-132
lines changed

9 files changed

+181
-132
lines changed

check/TestCAPI.c

Lines changed: 62 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,9 +2131,23 @@ void testDeleteRowResolveWithBasis() {
21312131

21322132
void testIis() {
21332133
void* highs = Highs_create();
2134-
// Highs_setBoolOptionValue(highs, "output_flag", dev_run);
2134+
Highs_setBoolOptionValue(highs, "output_flag", dev_run);
21352135
HighsInt ret;
21362136
double inf = Highs_getInfinity(highs);
2137+
// For the constraints
2138+
//
2139+
// x + y - z = 2
2140+
//
2141+
// x + y + z <= 5
2142+
//
2143+
// x + 2y + z <= 1
2144+
//
2145+
// with variables in [0, 1], constraints 0 and 2 form an IIS with
2146+
//
2147+
// x free (so should be removed?); 0 <= y; 0 <= z
2148+
//
2149+
// x + y - z >= 2; x + 2y + z <= 1
2150+
//
21372151
ret = Highs_addCol(highs, 0.0, 0.0, 1.0, 0, NULL, NULL);
21382152
assert(ret == 0);
21392153
ret = Highs_addCol(highs, 0.0, 0.0, 1.0, 0, NULL, NULL);
@@ -2144,7 +2158,7 @@ void testIis() {
21442158
double value_1[3] = {1, 1, -1};
21452159
double value_2[3] = {1, 1, 1};
21462160
double value_3[3] = {1, 2, 1};
2147-
ret = Highs_addRow(highs, 2.0, inf, 3, index, value_1);
2161+
ret = Highs_addRow(highs, 2.0, 2.0, 3, index, value_1);
21482162
assert(ret == 0);
21492163
ret = Highs_addRow(highs, -inf, 5.0, 3, index, value_2);
21502164
assert(ret == 0);
@@ -2181,7 +2195,7 @@ void testIis() {
21812195
Highs_setIntOptionValue(highs, "iis_strategy",
21822196
kHighsIisStrategyFromLpRowPriority);
21832197
} else {
2184-
assert(iis_num_col == 2);
2198+
assert(iis_num_col == 3);
21852199
assert(iis_num_row == 2);
21862200
HighsInt* col_index = (HighsInt*)malloc(sizeof(HighsInt) * iis_num_col);
21872201
HighsInt* row_index = (HighsInt*)malloc(sizeof(HighsInt) * iis_num_row);
@@ -2195,6 +2209,29 @@ void testIis() {
21952209
col_bound, row_bound,
21962210
col_status, row_status);
21972211
assert(ret == 0);
2212+
2213+
assert(col_index[0] == 0);
2214+
assert(col_index[1] == 1);
2215+
assert(col_index[2] == 2);
2216+
2217+
assert(row_index[0] == 0);
2218+
assert(row_index[1] == 2);
2219+
2220+
assert(col_bound[0] == kHighsIisBoundFree);
2221+
assert(col_bound[1] == kHighsIisBoundLower);
2222+
assert(col_bound[2] == kHighsIisBoundLower);
2223+
2224+
assert(row_bound[0] == kHighsIisBoundLower);
2225+
assert(row_bound[1] == kHighsIisBoundUpper);
2226+
2227+
assert(col_status[0] == kHighsIisStatusInConflict);
2228+
assert(col_status[1] == kHighsIisStatusInConflict);
2229+
assert(col_status[2] == kHighsIisStatusInConflict);
2230+
2231+
assert(row_status[0] == kHighsIisStatusInConflict);
2232+
assert(row_status[1] == kHighsIisStatusNotInConflict);
2233+
assert(row_status[2] == kHighsIisStatusInConflict);
2234+
21982235
free(col_index);
21992236
free(row_index);
22002237
free(col_bound);
@@ -2208,28 +2245,28 @@ void testIis() {
22082245
}
22092246

22102247
int main() {
2211-
// minimalApiIllegalLp();
2212-
// testCallback();
2213-
// versionApi();
2214-
// fullApi();
2215-
// minimalApiLp();
2216-
// minimalApiMip();
2217-
// minimalApiQp();
2218-
// fullApiOptions();
2219-
// fullApiLp();
2220-
// fullApiMip();
2221-
// fullApiQp();
2222-
// passPresolveGetLp();
2223-
// options();
2224-
// testGetColsByRange();
2225-
// testPassHessian();
2226-
// testRanging();
2227-
// testFeasibilityRelaxation();
2228-
// testGetModel();
2229-
// testMultiObjective();
2230-
// testQpIndefiniteFailure();
2231-
// testDualRayTwice();
2232-
// testDeleteRowResolveWithBasis();
2248+
minimalApiIllegalLp();
2249+
testCallback();
2250+
versionApi();
2251+
fullApi();
2252+
minimalApiLp();
2253+
minimalApiMip();
2254+
minimalApiQp();
2255+
fullApiOptions();
2256+
fullApiLp();
2257+
fullApiMip();
2258+
fullApiQp();
2259+
passPresolveGetLp();
2260+
options();
2261+
testGetColsByRange();
2262+
testPassHessian();
2263+
testRanging();
2264+
testFeasibilityRelaxation();
2265+
testGetModel();
2266+
testMultiObjective();
2267+
testQpIndefiniteFailure();
2268+
testDualRayTwice();
2269+
testDeleteRowResolveWithBasis();
22332270
testIis();
22342271
return 0;
22352272
}

highs/interfaces/highs_c_api.cpp

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,16 +1299,10 @@ HighsInt Highs_getPresolvedLp(const void* highs, const HighsInt a_format,
12991299
a_start, a_index, a_value, integrality);
13001300
}
13011301

1302-
HighsInt Highs_getIis(void* highs,
1303-
HighsInt* iis_num_col,
1304-
HighsInt* iis_num_row,
1305-
HighsInt* col_index,
1306-
HighsInt* row_index,
1307-
HighsInt* col_bound,
1308-
HighsInt* row_bound,
1309-
HighsInt* col_status,
1310-
HighsInt* row_status) {
1311-
1302+
HighsInt Highs_getIis(void* highs, HighsInt* iis_num_col, HighsInt* iis_num_row,
1303+
HighsInt* col_index, HighsInt* row_index,
1304+
HighsInt* col_bound, HighsInt* row_bound,
1305+
HighsInt* col_status, HighsInt* row_status) {
13121306
HighsIis iis;
13131307
HighsInt status = (HighsInt)((Highs*)highs)->getIis(iis);
13141308
if (status == (HighsInt)HighsStatus::kError) return status;
@@ -1348,15 +1342,13 @@ HighsInt Highs_getIis(void* highs,
13481342
}
13491343

13501344
HighsInt Highs_getIisLp(const void* highs, const HighsInt a_format,
1351-
HighsInt* num_col, HighsInt* num_row,
1352-
HighsInt* num_nz, HighsInt* sense, double* offset,
1353-
double* col_cost, double* col_lower,
1354-
double* col_upper, double* row_lower,
1355-
double* row_upper, HighsInt* a_start,
1356-
HighsInt* a_index, double* a_value,
1357-
HighsInt* integrality) {
1358-
return Highs_getHighsLpData(((Highs*)highs)->getIisLp(), a_format,
1359-
num_col, num_row, num_nz, sense, offset, col_cost,
1345+
HighsInt* num_col, HighsInt* num_row, HighsInt* num_nz,
1346+
HighsInt* sense, double* offset, double* col_cost,
1347+
double* col_lower, double* col_upper, double* row_lower,
1348+
double* row_upper, HighsInt* a_start, HighsInt* a_index,
1349+
double* a_value, HighsInt* integrality) {
1350+
return Highs_getHighsLpData(((Highs*)highs)->getIisLp(), a_format, num_col,
1351+
num_row, num_nz, sense, offset, col_cost,
13601352
col_lower, col_upper, row_lower, row_upper,
13611353
a_start, a_index, a_value, integrality);
13621354
}

highs/interfaces/highs_c_api.h

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,13 @@ const char* const kHighsCallbackDataOutCutpoolLowerName = "cutpool_lower";
134134
const char* const kHighsCallbackDataOutCutpoolUpperName = "cutpool_upper";
135135

136136
const HighsInt kHighsIisStrategyLight = 0;
137-
const HighsInt kHighsIisStrategyFromLpRowPriority = 1; // WIP
138-
const HighsInt kHighsIisStrategyFromLpColPriority = 2; // WIP
137+
const HighsInt kHighsIisStrategyFromLpRowPriority = 1; // WIP
138+
const HighsInt kHighsIisStrategyFromLpColPriority = 2; // WIP
139+
140+
const HighsInt kHighsIisBoundFree = 1;
141+
const HighsInt kHighsIisBoundLower = 2;
142+
const HighsInt kHighsIisBoundUpper = 3;
143+
const HighsInt kHighsIisBoundBoxed = 4;
139144

140145
const HighsInt kHighsIisStatusInConflict = 0;
141146
const HighsInt kHighsIisStatusNotInConflict = 1;
@@ -2248,13 +2253,11 @@ HighsInt Highs_getPresolvedLp(const void* highs, const HighsInt a_format,
22482253
* @returns A `kHighsStatus` constant indicating whether the call succeeded.
22492254
*/
22502255
HighsInt Highs_getIisLp(const void* highs, const HighsInt a_format,
2251-
HighsInt* num_col, HighsInt* num_row,
2252-
HighsInt* num_nz, HighsInt* sense, double* offset,
2253-
double* col_cost, double* col_lower,
2254-
double* col_upper, double* row_lower,
2255-
double* row_upper, HighsInt* a_start,
2256-
HighsInt* a_index, double* a_value,
2257-
HighsInt* integrality);
2256+
HighsInt* num_col, HighsInt* num_row, HighsInt* num_nz,
2257+
HighsInt* sense, double* offset, double* col_cost,
2258+
double* col_lower, double* col_upper, double* row_lower,
2259+
double* row_upper, HighsInt* a_start, HighsInt* a_index,
2260+
double* a_value, HighsInt* integrality);
22582261

22592262
/**
22602263
* Set a primal (and possibly dual) solution as a starting point, then run
@@ -2403,15 +2406,10 @@ HighsInt Highs_feasibilityRelaxation(void* highs,
24032406
*
24042407
* @returns A `kHighsStatus` constant indicating whether the call succeeded.
24052408
*/
2406-
HighsInt Highs_getIis(void* highs,
2407-
HighsInt* iis_num_col,
2408-
HighsInt* iis_num_row,
2409-
HighsInt* col_index,
2410-
HighsInt* row_index,
2411-
HighsInt* col_bound,
2412-
HighsInt* row_bound,
2413-
HighsInt* col_status,
2414-
HighsInt* row_status);
2409+
HighsInt Highs_getIis(void* highs, HighsInt* iis_num_col, HighsInt* iis_num_row,
2410+
HighsInt* col_index, HighsInt* row_index,
2411+
HighsInt* col_bound, HighsInt* row_bound,
2412+
HighsInt* col_status, HighsInt* row_status);
24152413
/**
24162414
* Releases all resources held by the global scheduler instance.
24172415
*

0 commit comments

Comments
 (0)