Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
sgatto committed Sep 23, 2024
1 parent 160bbcf commit 2626e6a
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if (NOT DEFINED ortools_REF)
message(FATAL_ERROR "ortools_REF is not defined")
endif ()
find_package(Python3 REQUIRED COMPONENTS Interpreter Development.Module)
message("found PYTHON interpreter ${Python_EXECUTABLE} = " ${Python_EXECUTABLE})
message("found Python3 interpreter = ${Python3_EXECUTABLE}")
FetchContent_Declare(ortools
GIT_REPOSITORY ${ortools_REPO}
GIT_TAG ${ortools_REF}
Expand All @@ -23,6 +23,7 @@ FetchContent_Declare(ortools
${CMAKE_CURRENT_SOURCE_DIR}/ortools
${CMAKE_CURRENT_SOURCE_DIR}/cmake_patches
. && ${Python3_EXECUTABLE} patch.py
&& git apply ${CMAKE_CURRENT_SOURCE_DIR}/fix_locale_bug.patch
OVERRIDE_FIND_PACKAGE ON
)
message("BUILD_DEPS: " ${BUILD_DEPS})
Expand Down
96 changes: 96 additions & 0 deletions fix_locale_bug.patch
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;

0 comments on commit 2626e6a

Please sign in to comment.