Skip to content

Commit efc864d

Browse files
committed
Created getIndexFromName in HighsLpUtils
1 parent ac8b4a9 commit efc864d

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

highs/lp_data/HighsLpUtils.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2588,6 +2588,34 @@ void writeBasisFile(FILE*& file, const HighsOptions& options,
25882588
}
25892589
}
25902590

2591+
HighsStatus getIndexFromName(const HighsLogOptions& log_options,
2592+
std::string& from_method,
2593+
const bool is_column,
2594+
std::string& name,
2595+
std::unordered_map<std::string, int> name2index,
2596+
HighsInt& index,
2597+
const std::vector<std::string>& names) {
2598+
auto search = name2index.find(name);
2599+
if (search == name2index.end()) {
2600+
highsLogUser(log_options, HighsLogType::kError,
2601+
"%s: %s name %s is not found\n", from_method.c_str(),
2602+
is_column ? "column" : "row",
2603+
name.c_str());
2604+
return HighsStatus::kError;
2605+
}
2606+
if (search->second == kHashIsDuplicate) {
2607+
highsLogUser(log_options, HighsLogType::kError,
2608+
"%s: %s name %s is duplicated\n", from_method.c_str(),
2609+
is_column ? "column" : "row",
2610+
name.c_str());
2611+
return HighsStatus::kError;
2612+
}
2613+
index = search->second;
2614+
assert(names[index] == name);
2615+
return HighsStatus::kOk;
2616+
}
2617+
2618+
25912619
HighsStatus readBasisFile(const HighsLogOptions& log_options,
25922620
HighsLp& lp, HighsBasis& basis,
25932621
const std::string filename) {

highs/lp_data/HighsLpUtils.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ using std::vector;
3030
void writeBasisFile(FILE*& file, const HighsOptions& options,
3131
const HighsLp& lp, const HighsBasis& basis);
3232

33+
HighsStatus getIndexFromName(const HighsLogOptions& log_options,
34+
std::string& from_method,
35+
const bool is_column,
36+
std::string& name,
37+
std::unordered_map<std::string, int> name2index,
38+
HighsInt& index,
39+
const std::vector<std::string>& names);
40+
3341
HighsStatus readBasisFile(const HighsLogOptions& log_options,
3442
HighsLp& lp, HighsBasis& basis,
3543
const std::string filename);

0 commit comments

Comments
 (0)