Segmentation Fault from libgurobi100.so
回答済みHello,
I recently cloned a C++ project that uses the Gurobi solver. I just booted my computer with Ubuntu, so I installed Gurobi and downloaded my academic license.
This code is supposed to work correctly, but an error persists when I run :
0x00007ffff59786db in PRIVATE00000000008d2227 () from /home/timothy/opt/gurobi1003/linux64/lib/libgurobi100.so
Here's some additional information:
I'm using a CMake project and here are the values I've specified for the variables:
GUROBI_CXX_LIBRARY: /home/timothy/opt/gurobi1003/linux64/lib/libgurobi_c++.a
GUROBI_INCLUDE_DIRS: /home/timothy/opt/gurobi1003/linux64/include/
GUROBI_LIBRARY: /home/timothy/opt/gurobi1003/linux64/lib/libgurobi100.so
I'm just starting out with CMake and it's possible I'll make mistakes.
Here is the portion of code that is causing problems:
GRBenv* env;
GRBmodel *model;
int savedStdout = dup(1);
close(1);
int newStdout = open("/dev/null", O_WRONLY);
assert(newStdout == 1);
// Create the Gurobi model.
GRBloadenv(&env, "");
GRBnewmodel(env, &model, nullptr, 0, nullptr, nullptr, nullptr, nullptr, nullptr);
// Restore stdout.
close(newStdout);
newStdout = dup(savedStdout);
assert(newStdout == 1);
close(savedStdout);
if (_data.verbosity < 2)
GRBsetintparam(GRBgetenv(model), "outputflag", 0);
GRBsetintparam(GRBgetenv(model), "threads", 1);
GRBsetintattr(model, "modelsense", GRB_MINIMIZE);
// Add the variables.
auto obj = new double[_data.maximalRectangles.size()];
auto lb = new double[_data.maximalRectangles.size()];
auto ub = new double[_data.maximalRectangles.size()];
auto vtype = new char[_data.maximalRectangles.size()];
for (std::size_t i = 0; i < _data.maximalRectangles.size(); ++i)
{
obj[i] = 1.0;
lb[i] = 0.0;
ub[i] = _refined ? 2.0 : 1.0;
vtype[i] = GRB_INTEGER;
}
GRBaddvars(model, _data.maximalRectangles.size(), 0, nullptr, nullptr, nullptr, obj, lb, ub, vtype, nullptr);
delete[] obj;
delete[] lb;
delete[] ub;
delete[] vtype;
// Actually add the variables.
GRBupdatemodel(model);
std::vector<int> indices;
std::vector<double> coefficients;
indices.reserve(_data.maximalRectangles.size());
coefficients.reserve(_data.maximalRectangles.size());
for (std::size_t s = 0; s < _data.numNonzeros(); ++s)
{
indices.clear();
for (std::size_t r = 0; r != _data.maximalRectangles.size(); ++r)
{
auto rectangle = _data.maximalRectangles[r];
if (rectangle->nonzeros[s])
indices.push_back(r);
}
coefficients.clear();
coefficients.resize(indices.size(), 1.0);
GRBaddconstr(model, indices.size(), &indices[0], &coefficients[0], '>', 1.0, nullptr);
}
if (_refined)
{
for (std::size_t i = 0; i < _data.numFoolingPairs(); ++i)
{
const FoolingPair& fp = _data.foolingPairs[i];
indices.clear();
for (std::size_t r = 0; r != _data.maximalRectangles.size(); ++r)
{
auto rectangle = _data.maximalRectangles[r];
if (rectangle->nonzeros[fp.nonzero1] || rectangle->nonzeros[fp.nonzero2])
indices.push_back(r);
}
coefficients.clear();
coefficients.resize(indices.size(), 1.0);
GRBaddconstr(model, indices.size(), &indices[0], &coefficients[0], '>', 2.0, nullptr);
}
}
if (_data.verbosity > 1)
{
std::cerr << "\n Initialized IP with " << _data.maximalRectangles.size() << " variables and "
<< (_data.numNonzeros() + (_refined ? _data.numFoolingPairs() : 0)) << " constraints." << std::endl;
}
GRBupdatemodel(model);
GRBoptimize(model);
Thank you in advance for your help,
Timothy
-
正式なコメント
This post is more than two years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support. -
Hi Timothy,
A quick google is throwing up words like "corrupted files" etc. On the off-chance it is something like this can you try removing the Gurobi folders you have installed and going through the download/installation process as described in How do I install Gurobi Optimizer?
- Riley
0 -
It would be helpful if you could post a minimal, self-contained version of the code that includes the definitions of the data you're using.
0
投稿コメントは受け付けていません。
コメント
3件のコメント