Skip to content

Commit

Permalink
Added home path resolution for option "scratch"
Browse files Browse the repository at this point in the history
  • Loading branch information
mapgccv committed Oct 22, 2024
1 parent 68e2052 commit 0a47807
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
18 changes: 18 additions & 0 deletions solvers/baronmp/baronmpcommon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace mp {
#ifdef WIN32
constexpr const char* EXENAME = "baronin.exe";
char SEP = '\\';
volatile DWORD BaronmpCommon::pid;
#else
constexpr const char* EXENAME = "baronin";
char SEP = '/';
Expand Down Expand Up @@ -167,6 +168,20 @@ int BaronmpCommon::run(const std::vector<std::string>& args) {
return 0;
}

std::filesystem::path resolveTilde(const std::filesystem::path& p) {
std::string pathStr = p.string();

// Check if the path starts with a tilde (~)
if (!pathStr.empty() && pathStr[0] == '~') {
const char* home = std::getenv("HOME"); // Get the HOME environment variable
if (home) {
// Replace tilde with the home directory
pathStr.replace(0, 1, home);
}
}

return std::filesystem::path(pathStr);
}

/**
* Initialize baronDir and nlFilePath
Expand All @@ -183,6 +198,9 @@ void BaronmpCommon::initDirectories(const std::string& stub,
// Check if scratch directory is valid or create it if possible
if (!scratch.empty()) {
fs::path scratch_path(scratch);
#ifndef WIN32
scratch_path = resolveTilde(scratch_path);
#endif
if (overwrite)
{
if (fs::exists(scratch_path))
Expand Down
2 changes: 1 addition & 1 deletion solvers/baronmp/baronmpcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ class BaronmpCommon :
#ifndef WIN32
static volatile pid_t pid;
#else
DWORD pid;
static volatile DWORD pid;
#endif
static constexpr double Infinity() { return INFINITY; }
static constexpr double MinusInfinity() { return -INFINITY; }
Expand Down
2 changes: 1 addition & 1 deletion solvers/baronmp/baronmpmodelapi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace mp {
{
if (vtypes[i] == VTYPE::BIN)
continue;
if (lower && vtypes[i] == VTYPE::POS)
if (lower && bounds[i]==0 && vtypes[i] == VTYPE::POS)
continue;
if (bounds[i] != bnd)
{
Expand Down

0 comments on commit 0a47807

Please sign in to comment.