Skip to content

Commit 573927e

Browse files
committed
linear_solver: reapply xpress_interface fix (#4382)
* Also add few fix from rte-france/or-tools fork (`main` branch)
1 parent a90d9d9 commit 573927e

1 file changed

Lines changed: 18 additions & 25 deletions

File tree

ortools/linear_solver/xpress_interface.cc

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#include <memory>
2222
#include <mutex>
2323
#include <string>
24-
#include <numeric>
2524

25+
#include "absl/strings/numbers.h"
2626
#include "absl/strings/str_format.h"
2727
#include "ortools/base/logging.h"
2828
#include "ortools/base/timer.h"
@@ -2093,29 +2093,21 @@ void splitMyString(const std::string& str, Container& cont, char delim = ' ') {
20932093
}
20942094
}
20952095

2096-
const char* stringToCharPtr(std::string& var) { return var.c_str(); }
2097-
2098-
// Save the existing locale, use the "C" locale to ensure that
2099-
// string -> double conversion is done ignoring the locale.
2100-
struct ScopedLocale {
2101-
ScopedLocale() {
2102-
oldLocale = std::setlocale(LC_NUMERIC, nullptr);
2103-
auto newLocale = std::setlocale(LC_NUMERIC, "C");
2104-
CHECK_EQ(std::string(newLocale), "C");
2105-
}
2106-
~ScopedLocale() { std::setlocale(LC_NUMERIC, oldLocale); }
2107-
2108-
private:
2109-
const char* oldLocale;
2110-
};
2096+
bool stringToCharPtr(const std::string& var, const char** out) {
2097+
*out = var.c_str();
2098+
return true;
2099+
}
21112100

2112-
#define setParamIfPossible_MACRO(target_map, setter, converter) \
2101+
#define setParamIfPossible_MACRO(target_map, setter, converter, type) \
21132102
{ \
21142103
auto matchingParamIter = (target_map).find(paramAndValuePair.first); \
21152104
if (matchingParamIter != (target_map).end()) { \
2116-
const auto convertedValue = converter(paramAndValuePair.second); \
2117-
VLOG(1) << "Setting parameter " << paramAndValuePair.first \
2118-
<< " to value " << convertedValue << std::endl; \
2105+
type convertedValue; \
2106+
bool ret = converter(paramAndValuePair.second, &convertedValue); \
2107+
if (ret) { \
2108+
VLOG(1) << "Setting parameter " << paramAndValuePair.first \
2109+
<< " to value " << convertedValue << std::endl; \
2110+
} \
21192111
setter(mLp, matchingParamIter->second, convertedValue); \
21202112
continue; \
21212113
} \
@@ -2140,14 +2132,15 @@ bool XpressInterface::SetSolverSpecificParametersAsString(
21402132
}
21412133
}
21422134

2143-
ScopedLocale locale;
21442135
for (auto& paramAndValuePair : paramAndValuePairList) {
2145-
setParamIfPossible_MACRO(mapIntegerControls_, XPRSsetintcontrol, std::stoi);
2146-
setParamIfPossible_MACRO(mapDoubleControls_, XPRSsetdblcontrol, std::stod);
2136+
setParamIfPossible_MACRO(mapIntegerControls_, XPRSsetintcontrol,
2137+
absl::SimpleAtoi<int>, int);
2138+
setParamIfPossible_MACRO(mapDoubleControls_, XPRSsetdblcontrol,
2139+
absl::SimpleAtod, double);
21472140
setParamIfPossible_MACRO(mapStringControls_, XPRSsetstrcontrol,
2148-
stringToCharPtr);
2141+
stringToCharPtr, const char*);
21492142
setParamIfPossible_MACRO(mapInteger64Controls_, XPRSsetintcontrol64,
2150-
std::stoll);
2143+
absl::SimpleAtoi<int64_t>, int64_t);
21512144
LOG(ERROR) << "Unknown parameter " << paramName << " : function "
21522145
<< __FUNCTION__ << std::endl;
21532146
return false;

0 commit comments

Comments
 (0)