-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
Index: ortools/linear_solver/xpress_interface.cc | ||
IDEA additional info: | ||
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | ||
<+>UTF-8 | ||
=================================================================== | ||
diff --git a/ortools/linear_solver/xpress_interface.cc b/ortools/linear_solver/xpress_interface.cc | ||
--- a/ortools/linear_solver/xpress_interface.cc (revision ed94162b910fa58896db99191378d3b71a5313af) | ||
+++ b/ortools/linear_solver/xpress_interface.cc (date 1727081541820) | ||
@@ -22,6 +22,7 @@ | ||
#include <mutex> | ||
#include <string> | ||
|
||
+#include "absl/strings/numbers.h" | ||
#include "absl/strings/str_format.h" | ||
#include "ortools/base/logging.h" | ||
#include "ortools/base/timer.h" | ||
@@ -227,7 +228,7 @@ | ||
: xprsprob_(xprsprob), | ||
event_(event), | ||
num_nodes_(num_nodes), | ||
- variable_values_(0) {}; | ||
+ variable_values_(0){}; | ||
|
||
// Implementation of the interface. | ||
MPCallbackEvent Event() override { return event_; }; | ||
@@ -260,7 +261,7 @@ | ||
// Wraps the MPCallback in order to catch and store exceptions | ||
class MPCallbackWrapper { | ||
public: | ||
- explicit MPCallbackWrapper(MPCallback* callback) : callback_(callback) {}; | ||
+ explicit MPCallbackWrapper(MPCallback* callback) : callback_(callback){}; | ||
MPCallback* GetCallback() const { return callback_; } | ||
// Since our (C++) call-back functions are called from the XPRESS (C) code, | ||
// exceptions thrown in our call-back code are not caught by XPRESS. | ||
@@ -2106,29 +2107,21 @@ | ||
} | ||
} | ||
|
||
-const char* stringToCharPtr(std::string& var) { return var.c_str(); } | ||
- | ||
-// Save the existing locale, use the "C" locale to ensure that | ||
-// string -> double conversion is done ignoring the locale. | ||
-struct ScopedLocale { | ||
- ScopedLocale() { | ||
- oldLocale = std::setlocale(LC_NUMERIC, nullptr); | ||
- auto newLocale = std::setlocale(LC_NUMERIC, "C"); | ||
- CHECK_EQ(std::string(newLocale), "C"); | ||
- } | ||
- ~ScopedLocale() { std::setlocale(LC_NUMERIC, oldLocale); } | ||
+bool stringToCharPtr(const std::string& var, const char** out) { | ||
+ *out = var.c_str(); | ||
+ return true; | ||
+} | ||
|
||
- private: | ||
- const char* oldLocale; | ||
-}; | ||
- | ||
-#define setParamIfPossible_MACRO(target_map, setter, converter) \ | ||
+#define setParamIfPossible_MACRO(target_map, setter, converter, type) \ | ||
{ \ | ||
auto matchingParamIter = (target_map).find(paramAndValuePair.first); \ | ||
if (matchingParamIter != (target_map).end()) { \ | ||
- const auto convertedValue = converter(paramAndValuePair.second); \ | ||
- VLOG(1) << "Setting parameter " << paramAndValuePair.first \ | ||
- << " to value " << convertedValue << std::endl; \ | ||
+ type convertedValue; \ | ||
+ bool ret = converter(paramAndValuePair.second, &convertedValue); \ | ||
+ if (ret) { \ | ||
+ VLOG(1) << "Setting parameter " << paramAndValuePair.first \ | ||
+ << " to value " << convertedValue << std::endl; \ | ||
+ } \ | ||
setter(mLp, matchingParamIter->second, convertedValue); \ | ||
continue; \ | ||
} \ | ||
@@ -2153,14 +2146,15 @@ | ||
} | ||
} | ||
|
||
- ScopedLocale locale; | ||
for (auto& paramAndValuePair : paramAndValuePairList) { | ||
- setParamIfPossible_MACRO(mapIntegerControls_, XPRSsetintcontrol, std::stoi); | ||
- setParamIfPossible_MACRO(mapDoubleControls_, XPRSsetdblcontrol, std::stod); | ||
+ setParamIfPossible_MACRO(mapIntegerControls_, XPRSsetintcontrol, | ||
+ absl::SimpleAtoi<int>, int); | ||
+ setParamIfPossible_MACRO(mapDoubleControls_, XPRSsetdblcontrol, | ||
+ absl::SimpleAtod, double); | ||
setParamIfPossible_MACRO(mapStringControls_, XPRSsetstrcontrol, | ||
- stringToCharPtr); | ||
+ stringToCharPtr, const char*); | ||
setParamIfPossible_MACRO(mapInteger64Controls_, XPRSsetintcontrol64, | ||
- std::stoll); | ||
+ absl::SimpleAtoi<int64_t>, int64_t); | ||
LOG(ERROR) << "Unknown parameter " << paramName << " : function " | ||
<< __FUNCTION__ << std::endl; | ||
return false; |