Skip to content

Commit d04c148

Browse files
committed
Need to have HighsIis::getLp working for row-wise incumbent LP
1 parent 4c1099f commit d04c148

File tree

4 files changed

+77
-29
lines changed

4 files changed

+77
-29
lines changed

check/TestCAPI.c

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,7 +1991,7 @@ void testDualRayTwice() {
19911991
void* highs = Highs_create();
19921992
Highs_setBoolOptionValue(highs, "output_flag", dev_run);
19931993
int ret;
1994-
double INF = Highs_getInfinity(highs);
1994+
double inf = Highs_getInfinity(highs);
19951995
ret = Highs_changeObjectiveOffset(highs, 0.0);
19961996
assert(ret == 0);
19971997
ret = Highs_setStringOptionValue(highs, "presolve", "off");
@@ -2000,9 +2000,9 @@ void testDualRayTwice() {
20002000
assert(ret == 0);
20012001
ret = Highs_addCol(highs, 0.0, 0.0, 0.0, 0, NULL, NULL);
20022002
assert(ret == 0);
2003-
ret = Highs_addCol(highs, -1.0, 0.0, INF, 0, NULL, NULL);
2003+
ret = Highs_addCol(highs, -1.0, 0.0, inf, 0, NULL, NULL);
20042004
assert(ret == 0);
2005-
ret = Highs_addCol(highs, -1.0, 0.0, INF, 0, NULL, NULL);
2005+
ret = Highs_addCol(highs, -1.0, 0.0, inf, 0, NULL, NULL);
20062006
assert(ret == 0);
20072007
HighsInt index[2] = {2, 3};
20082008
double value[2] = {1.0, -1.0};
@@ -2012,19 +2012,19 @@ void testDualRayTwice() {
20122012
index[1] = 3;
20132013
value[0] = 1.0;
20142014
value[1] = 1.0;
2015-
ret = Highs_addRow(highs, 1.0, INF, 2, index, value);
2015+
ret = Highs_addRow(highs, 1.0, inf, 2, index, value);
20162016
assert(ret == 0);
20172017
index[0] = 0;
20182018
index[1] = 2;
20192019
value[0] = -2.0;
20202020
value[1] = 1.0;
2021-
ret = Highs_addRow(highs, -INF, 0.0, 2, index, value);
2021+
ret = Highs_addRow(highs, -inf, 0.0, 2, index, value);
20222022
assert(ret == 0);
20232023
index[0] = 1;
20242024
index[1] = 3;
20252025
value[0] = -3.0;
20262026
value[1] = 1.0;
2027-
ret = Highs_addRow(highs, -INF, 0.0, 2, index, value);
2027+
ret = Highs_addRow(highs, -inf, 0.0, 2, index, value);
20282028
assert(ret == 0);
20292029
ret = Highs_run(highs);
20302030
assert(ret == 0);
@@ -2105,16 +2105,16 @@ void testDeleteRowResolveWithBasis() {
21052105
void* highs = Highs_create();
21062106
Highs_setBoolOptionValue(highs, "output_flag", dev_run);
21072107
HighsInt ret;
2108-
double INF = Highs_getInfinity(highs);
2108+
double inf = Highs_getInfinity(highs);
21092109
ret = Highs_addCol(highs, 0.0, 2.0, 2.0, 0, NULL, NULL);
2110-
ret = Highs_addCol(highs, 0.0, -INF, INF, 0, NULL, NULL);
2111-
ret = Highs_addCol(highs, 0.0, -INF, INF, 0, NULL, NULL);
2110+
ret = Highs_addCol(highs, 0.0, -inf, inf, 0, NULL, NULL);
2111+
ret = Highs_addCol(highs, 0.0, -inf, inf, 0, NULL, NULL);
21122112
HighsInt index_1[2] = {0, 2};
21132113
double value_1[2] = {2.0, -1.0};
21142114
ret = Highs_addRow(highs, 0.0, 0.0, 2, index_1, value_1);
21152115
HighsInt index_2[1] = {1};
21162116
double value_2[1] = {6.0};
2117-
ret = Highs_addRow(highs, 10.0, INF, 1, index_2, value_2);
2117+
ret = Highs_addRow(highs, 10.0, inf, 1, index_2, value_2);
21182118
Highs_run(highs);
21192119
double col_value[3] = {0.0, 0.0, 0.0};
21202120
Highs_getSolution(highs, col_value, NULL, NULL, NULL);
@@ -2131,6 +2131,54 @@ void testDeleteRowResolveWithBasis() {
21312131

21322132
void testIis() {
21332133
void* highs = Highs_create();
2134+
// Highs_setBoolOptionValue(highs, "output_flag", dev_run);
2135+
HighsInt ret;
2136+
double inf = Highs_getInfinity(highs);
2137+
ret = Highs_addCol(highs, 0.0, 0.0, 1.0, 0, NULL, NULL);
2138+
assert(ret == 0);
2139+
ret = Highs_addCol(highs, 0.0, 0.0, 1.0, 0, NULL, NULL);
2140+
assert(ret == 0);
2141+
ret = Highs_addCol(highs, 0.0, 0.0, 1.0, 0, NULL, NULL);
2142+
assert(ret == 0);
2143+
HighsInt index[3] = {0, 1, 2};
2144+
double value_1[3] = {1, 1, -1};
2145+
double value_2[3] = {1, 1, 1};
2146+
double value_3[3] = {1, 2, 1};
2147+
ret = Highs_addRow(highs, 2.0, inf, 3, index, value_1);
2148+
assert(ret == 0);
2149+
ret = Highs_addRow(highs, -inf, 5.0, 3, index, value_2);
2150+
assert(ret == 0);
2151+
ret = Highs_addRow(highs, -inf, 1.0, 3, index, value_3);
2152+
assert(ret == 0);
2153+
2154+
HighsInt iis_num_col;
2155+
HighsInt iis_num_row;
2156+
ret = Highs_getIis(highs,
2157+
&iis_num_col, &iis_num_row,
2158+
NULL, NULL,
2159+
NULL, NULL,
2160+
NULL, NULL);
2161+
assert(ret == 0);
2162+
2163+
HighsInt* col_index = (HighsInt*)malloc(sizeof(HighsInt) * iis_num_col);
2164+
HighsInt* row_index = (HighsInt*)malloc(sizeof(HighsInt) * iis_num_row);
2165+
HighsInt* col_bound = (HighsInt*)malloc(sizeof(HighsInt) * iis_num_col);
2166+
HighsInt* row_bound = (HighsInt*)malloc(sizeof(HighsInt) * iis_num_row);
2167+
2168+
HighsInt num_col;
2169+
HighsInt num_row;
2170+
HighsInt num_nz;
2171+
HighsInt sense;
2172+
double offset;
2173+
ret = Highs_getLp(highs, kHighsMatrixFormatRowwise,
2174+
&num_col, &num_row, &num_nz,
2175+
&sense, &offset,
2176+
NULL, NULL, NULL,
2177+
NULL, NULL,
2178+
NULL, NULL, NULL,
2179+
NULL);
2180+
Highs_run(highs);
2181+
21342182
Highs_destroy(highs);
21352183
}
21362184

highs/interfaces/highs_c_api.cpp

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

1302-
HighsInt Highs_getIis(const void* highs,
1303-
HighsInt iis_num_col,
1304-
HighsInt iis_num_row,
1302+
HighsInt Highs_getIis(void* highs,
1303+
HighsInt* iis_num_col,
1304+
HighsInt* iis_num_row,
13051305
HighsInt* col_index,
13061306
HighsInt* row_index,
13071307
HighsInt* col_bound,
@@ -1312,25 +1312,25 @@ HighsInt Highs_getIis(const void* highs,
13121312
HighsIis iis;
13131313
HighsInt status = (HighsInt)((Highs*)highs)->getIis(iis);
13141314
if (status == (HighsInt)HighsStatus::kError) return status;
1315-
iis_num_col = iis.col_index_.size();
1316-
iis_num_row = iis.row_index_.size();
1315+
*iis_num_col = iis.col_index_.size();
1316+
*iis_num_row = iis.row_index_.size();
13171317
if (col_index != nullptr) {
1318-
for (size_t i = 0; i < iis_num_col; i++) {
1318+
for (size_t i = 0; i < *iis_num_col; i++) {
13191319
col_index[i] = iis.col_index_[i];
13201320
}
13211321
}
13221322
if (row_index != nullptr) {
1323-
for (size_t i = 0; i < iis_num_row; i++) {
1323+
for (size_t i = 0; i < *iis_num_row; i++) {
13241324
row_index[i] = iis.row_index_[i];
13251325
}
13261326
}
13271327
if (col_bound != nullptr) {
1328-
for (size_t i = 0; i < iis_num_col; i++) {
1328+
for (size_t i = 0; i < *iis_num_col; i++) {
13291329
col_bound[i] = iis.col_bound_[i];
13301330
}
13311331
}
13321332
if (row_bound != nullptr) {
1333-
for (size_t i = 0; i < iis_num_row; i++) {
1333+
for (size_t i = 0; i < *iis_num_row; i++) {
13341334
row_bound[i] = iis.row_bound_[i];
13351335
}
13361336
}

highs/interfaces/highs_c_api.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,14 +2404,14 @@ HighsInt Highs_feasibilityRelaxation(void* highs,
24042404
* @returns A `kHighsStatus` constant indicating whether the call succeeded.
24052405
*/
24062406
HighsInt Highs_getIis(void* highs,
2407-
const HighsInt iis_num_col,
2408-
const HighsInt iis_num_row,
2409-
const HighsInt* col_index,
2410-
const HighsInt* row_index,
2411-
const HighsInt* col_bound,
2412-
const HighsInt* row_bound,
2413-
const HighsInt* col_status,
2414-
const HighsInt* row_status);
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);
24152415
/**
24162416
* Releases all resources held by the global scheduler instance.
24172417
*

highs/lp_data/HighsIis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ bool HighsIis::rowValueBounds(const HighsLp& lp, const HighsOptions& options) {
189189
upper_row_value += value * lower;
190190
}
191191
}
192-
lower_value[iRow] = lower_row_value;
193-
upper_value[iRow] = upper_row_value;
192+
lower_value.push_back(lower_row_value);
193+
upper_value.push_back(upper_row_value);
194194
}
195195
}
196196
bool below_lower;

0 commit comments

Comments
 (0)