[英]How to copy a SoPlex model?
I am using SoPlex to set up a lp and solve it.我正在使用 SoPlex 设置 lp 并解决它。 I then try to make a copy of the original lp and modify it.然后我尝试制作原始 lp 的副本并修改它。 My code looks like this:我的代码如下所示:
int main()
{
using namespase soplex;
SoPlex spx;
// add columns
// add rows
auto status = spx.optimize();
SoPlex copy(spx);
// modify some columns
status = copy.optimize();
return 0;
}
When I run my code in valgrind, I notice that memory allocated by methods inside the SoPlex
copy constructor are not freed.当我在 valgrind 中运行我的代码时,我注意到SoPlex
复制构造函数中的方法分配的内存没有被释放。
Is there a memory leak inside SoPlex
or am I not using it correctly? SoPlex
内部是否存在内存泄漏,或者我没有正确使用它?
You are using the copy functionality correctly.您正在正确使用复制功能。 There is indeed a memory leak in SoPlex that is going to be fixed in the next version. SoPlex 中确实存在内存泄漏,将在下一个版本中修复。
In the meantime you could try to apply this patch for SoPlex-4.0.1:同时,您可以尝试将此补丁应用于 SoPlex-4.0.1:
diff --git a/src/soplex/slufactor.cpp b/src/soplex/slufactor.cpp
index ae41604..a3314d8 100644
--- a/src/soplex/slufactor.cpp
+++ b/src/soplex/slufactor.cpp
@@ -1230,8 +1230,6 @@ SLUFactor::SLUFactor(const SLUFactor& old)
l.rperm = 0;
solveCount = 0;
- solveTime = TimerFactory::createTimer(timerType);
- factorTime = TimerFactory::createTimer(timerType);
try
{
@@ -1326,16 +1324,23 @@ void SLUFactor::freeAll()
if(l.rperm)
spx_free(l.rperm);
+
+ if(solveTime)
+ {
+ solveTime->~Timer();
+ spx_free(solveTime);
+ }
+
+ if(factorTime)
+ {
+ factorTime->~Timer();
+ spx_free(factorTime);
+ }
}
SLUFactor::~SLUFactor()
{
freeAll();
-
- solveTime->~Timer();
- factorTime->~Timer();
- spx_free(solveTime);
- spx_free(factorTime);
}
static Real betterThreshold(Real th)
diff --git a/src/soplex/spxbasis.cpp b/src/soplex/spxbasis.cpp
index 6370e89..40d201b 100644
--- a/src/soplex/spxbasis.cpp
+++ b/src/soplex/spxbasis.cpp
@@ -1363,6 +1363,7 @@ SPxBasis::~SPxBasis()
factor = 0;
}
+ theTime->~Timer();
spx_free(theTime);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.