Skip to content

Commit ccb5e4a

Browse files
committed
Now using getColOrRowName in getColName and getRowName
1 parent 4416368 commit ccb5e4a

File tree

4 files changed

+38
-74
lines changed

4 files changed

+38
-74
lines changed

highs/Highs.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,15 +1349,12 @@ class Highs {
13491349
return ekk_instance_.primal_phase1_dual_;
13501350
}
13511351

1352-
13531352
/**
13541353
* @brief Generalisation of getColName and getRowName. Advanced
13551354
* method: for HiGHS C++ and C API
13561355
*/
1357-
HighsStatus getColOrRowName(const HighsLp& lp,
1358-
const bool is_col,
1359-
const HighsInt index,
1360-
std::string& name) const;
1356+
HighsStatus getColOrRowName(const HighsLp& lp, const bool is_col,
1357+
const HighsInt index, std::string& name) const;
13611358

13621359
/**
13631360
* @brief Development methods

highs/interfaces/highs_c_api.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,19 +1067,20 @@ HighsInt Highs_getRowsByMask(const void* highs, const HighsInt* mask,
10671067
}
10681068

10691069
static HighsInt Highs_getHighsLpColOrRowName(const void* highs,
1070-
const HighsLp& lp,
1071-
const bool is_col,
1072-
const HighsInt index,
1073-
char* name) {
1070+
const HighsLp& lp,
1071+
const bool is_col,
1072+
const HighsInt index, char* name) {
10741073
std::string name_v;
1075-
HighsStatus status = ((Highs*)highs)->getColOrRowName(lp, is_col, index, name_v);
1074+
HighsStatus status =
1075+
((Highs*)highs)->getColOrRowName(lp, is_col, index, name_v);
10761076
if (status == HighsStatus::kError) return kHighsStatusError;
10771077
strcpy(name, name_v.c_str());
10781078
return kHighsStatusOk;
10791079
}
10801080

10811081
HighsInt Highs_getRowName(const void* highs, const HighsInt row, char* name) {
1082-
return Highs_getHighsLpColOrRowName(highs, ((Highs*)highs)->getLp(), false, row, name);
1082+
return Highs_getHighsLpColOrRowName(highs, ((Highs*)highs)->getLp(), false,
1083+
row, name);
10831084
}
10841085

10851086
HighsInt Highs_getRowByName(const void* highs, const char* name,
@@ -1091,7 +1092,8 @@ HighsInt Highs_getRowByName(const void* highs, const char* name,
10911092
}
10921093

10931094
HighsInt Highs_getColName(const void* highs, const HighsInt col, char* name) {
1094-
return Highs_getHighsLpColOrRowName(highs, ((Highs*)highs)->getLp(), true, col, name);
1095+
return Highs_getHighsLpColOrRowName(highs, ((Highs*)highs)->getLp(), true,
1096+
col, name);
10951097
}
10961098

10971099
HighsInt Highs_getColByName(const void* highs, const char* name,
@@ -1333,12 +1335,16 @@ HighsInt Highs_getPresolvedLp(const void* highs, const HighsInt a_format,
13331335
a_start, a_index, a_value, integrality);
13341336
}
13351337

1336-
HighsInt Highs_getPresolvedColName(const void* highs, const HighsInt col, char* name) {
1337-
return Highs_getHighsLpColOrRowName(highs, ((Highs*)highs)->getPresolvedLp(), true, col, name);
1338+
HighsInt Highs_getPresolvedColName(const void* highs, const HighsInt col,
1339+
char* name) {
1340+
return Highs_getHighsLpColOrRowName(highs, ((Highs*)highs)->getPresolvedLp(),
1341+
true, col, name);
13381342
}
13391343

1340-
HighsInt Highs_getPresolvedRowName(const void* highs, const HighsInt row, char* name) {
1341-
return Highs_getHighsLpColOrRowName(highs, ((Highs*)highs)->getPresolvedLp(), false, row, name);
1344+
HighsInt Highs_getPresolvedRowName(const void* highs, const HighsInt row,
1345+
char* name) {
1346+
return Highs_getHighsLpColOrRowName(highs, ((Highs*)highs)->getPresolvedLp(),
1347+
false, row, name);
13421348
}
13431349

13441350
HighsInt Highs_getIis(void* highs, HighsInt* iis_num_col, HighsInt* iis_num_row,

highs/interfaces/highs_c_api.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2262,7 +2262,8 @@ HighsInt Highs_getPresolvedLp(const void* highs, const HighsInt a_format,
22622262
*
22632263
* @returns A `kHighsStatus` constant indicating whether the call succeeded.
22642264
*/
2265-
HighsInt Highs_getPresolvedColName(const void* highs, const HighsInt col, char* name);
2265+
HighsInt Highs_getPresolvedColName(const void* highs, const HighsInt col,
2266+
char* name);
22662267

22672268
/**
22682269
* Get the name of a row of the presolved LP.
@@ -2273,7 +2274,8 @@ HighsInt Highs_getPresolvedColName(const void* highs, const HighsInt col, char*
22732274
*
22742275
* @returns A `kHighsStatus` constant indicating whether the call succeeded.
22752276
*/
2276-
HighsInt Highs_getPresolvedRowName(const void* highs, const HighsInt row, char* name);
2277+
HighsInt Highs_getPresolvedRowName(const void* highs, const HighsInt row,
2278+
char* name);
22772279

22782280
/**
22792281
* Get the data from a HiGHS IIS LP.

highs/lp_data/Highs.cpp

Lines changed: 15 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2403,37 +2403,30 @@ HighsStatus Highs::setSolution(const HighsSolution& solution) {
24032403
return returnFromHighs(return_status);
24042404
}
24052405

2406-
HighsStatus Highs::getColOrRowName(const HighsLp& lp,
2407-
const bool is_col,
2408-
const HighsInt index,
2409-
std::string& name) const {
2406+
HighsStatus Highs::getColOrRowName(const HighsLp& lp, const bool is_col,
2407+
const HighsInt index,
2408+
std::string& name) const {
24102409
HighsInt num_index = is_col ? lp.num_col_ : lp.num_row_;
24112410
if (index < 0 || index >= num_index) {
24122411
highsLogUser(this->options_.log_options, HighsLogType::kError,
2413-
"Index %d for %s name is outside the range [0, "
2414-
"num_%s = %d)\n",
2415-
int(index),
2416-
is_col ? "column" : "row",
2417-
is_col ? "col" : "row",
2418-
int(num_index));
2412+
"Index %d for %s name is outside the range [0, "
2413+
"num_%s = %d)\n",
2414+
int(index), is_col ? "column" : "row", is_col ? "col" : "row",
2415+
int(num_index));
24192416
return HighsStatus::kError;
24202417
}
2421-
const HighsInt num_index_name = is_col ?
2422-
this->model_.lp_.col_names_.size() :
2423-
this->model_.lp_.row_names_.size();
2418+
const HighsInt num_index_name = is_col ? this->model_.lp_.col_names_.size()
2419+
: this->model_.lp_.row_names_.size();
24242420
if (index >= num_index_name) {
24252421
highsLogUser(options_.log_options, HighsLogType::kError,
24262422
"Index %d for %s name is outside the range [0, "
24272423
"num_%s_name = %d)\n",
2428-
int(index),
2429-
is_col ? "column" : "row",
2430-
is_col ? "col" : "row",
2431-
int(num_index_name));
2424+
int(index), is_col ? "column" : "row", is_col ? "col" : "row",
2425+
int(num_index_name));
24322426
return HighsStatus::kError;
24332427
}
2434-
name = is_col ?
2435-
this->model_.lp_.col_names_[index] :
2436-
this->model_.lp_.row_names_[index];
2428+
name = is_col ? this->model_.lp_.col_names_[index]
2429+
: this->model_.lp_.row_names_[index];
24372430
return HighsStatus::kOk;
24382431
}
24392432

@@ -3220,24 +3213,7 @@ HighsStatus Highs::getCols(const HighsInt* mask, HighsInt& num_col,
32203213
}
32213214

32223215
HighsStatus Highs::getColName(const HighsInt col, std::string& name) const {
3223-
const HighsInt num_col = this->model_.lp_.num_col_;
3224-
if (col < 0 || col >= num_col) {
3225-
highsLogUser(
3226-
options_.log_options, HighsLogType::kError,
3227-
"Index %d for column name is outside the range [0, num_col = %d)\n",
3228-
int(col), int(num_col));
3229-
return HighsStatus::kError;
3230-
}
3231-
const HighsInt num_col_name = this->model_.lp_.col_names_.size();
3232-
if (col >= num_col_name) {
3233-
highsLogUser(options_.log_options, HighsLogType::kError,
3234-
"Index %d for column name is outside the range [0, "
3235-
"num_col_name = %d)\n",
3236-
int(col), int(num_col_name));
3237-
return HighsStatus::kError;
3238-
}
3239-
name = this->model_.lp_.col_names_[col];
3240-
return HighsStatus::kOk;
3216+
return getColOrRowName(this->model_.lp_, true, col, name);
32413217
}
32423218

32433219
HighsStatus Highs::getColByName(const std::string& name, HighsInt& col) {
@@ -3325,24 +3301,7 @@ HighsStatus Highs::getRows(const HighsInt* mask, HighsInt& num_row,
33253301
}
33263302

33273303
HighsStatus Highs::getRowName(const HighsInt row, std::string& name) const {
3328-
const HighsInt num_row = this->model_.lp_.num_row_;
3329-
if (row < 0 || row >= num_row) {
3330-
highsLogUser(
3331-
options_.log_options, HighsLogType::kError,
3332-
"Index %d for row name is outside the range [0, num_row = %d)\n",
3333-
int(row), int(num_row));
3334-
return HighsStatus::kError;
3335-
}
3336-
const HighsInt num_row_name = this->model_.lp_.row_names_.size();
3337-
if (row >= num_row_name) {
3338-
highsLogUser(
3339-
options_.log_options, HighsLogType::kError,
3340-
"Index %d for row name is outside the range [0, num_row_name = %d)\n",
3341-
int(row), int(num_row_name));
3342-
return HighsStatus::kError;
3343-
}
3344-
name = this->model_.lp_.row_names_[row];
3345-
return HighsStatus::kOk;
3304+
return getColOrRowName(this->model_.lp_, false, row, name);
33463305
}
33473306

33483307
HighsStatus Highs::getRowByName(const std::string& name, HighsInt& row) {

0 commit comments

Comments
 (0)