在Java中使用CPLEX库时的内存优化 [英] Memory optimization while using CPLEX library in Java

查看:492
本文介绍了在Java中使用CPLEX库时的内存优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用IBM CPLEX库来解决Java中的优化问题.由于主内存不足以容纳应用程序,因此我找到了CPLEX的一个属性:内存重点:让优化器使用磁盘进行存储". Memory Emphasis的默认值为0.如何在Java中更改此属性?

I am using IBM CPLEX library for an optimization problem in Java. Since main memory was not enough for the application I found a property of CPLEX : "Memory emphasis: letting the optimizer use disk for storage". Default value for Memory Emphasis is 0. How can I change this property in Java?

    for (int i = 0; i < GreenOverlayGlobals.numNodes; i++) {

        for (int j = 0; j < GreenOverlayGlobals.numNodes; j++) {

            IloLinearNumExpr expr2 = cplex.linearNumExpr();
            for (int p = 0; p < GreenOverlayGlobals.numPathPairs; p++) {

                cplex.addLe(xPath[i][j][p], xLink[i][j]); //x[i][j][p] <= x[i][j]
                expr2.addTerm(1, xPath[i][j][p]);
            }
            cplex.addLe(xLink[i][j], expr2); //x[i][j] <= sump_x[i][j][p]
        }
    }

推荐答案

您可以使用IloCplex.setParameter()方法在cplex java中设置参数.要允许将Mip树存储在磁盘上,可以使用参数可用于减少cplex的内存消耗.您可以将MemoryEmphasis设置为True,这将指示cplex尝试节省内存.您还可以通过设置参数

You set parameters in cplex java with the IloCplex.setParameter() method. To allow the mip tree to be stored on disk, you can use the NodeFileInd, and WorkDir to specify a directory for storage. Two other parameters can be used to reduce the memory consumption of cplex. You can set MemoryEmphasis to True which will instruct cplex to try to conserve memory. You can also turn on "strong branching" by setting the parameter VarSel to 3. Strong branching causes cplex to spend more time at each node selecting higher-quality child nodes, which usually make the search tree smaller.

要使用setParameter方法,请假设您有一个名为cplex的IloCplex对象.

To use the setParameter method, assuming you have an IloCplex object called cplex.

cplex.setParam(IloCplex.IntParam.VarSel, 4);
cplex.setParam(IloCplex.BoolParam.MemoryEmphasis, true);

请记住,那里的参数仅在.solve()期间影响cplex.如果在.solve()之前内存不足,则参数将不执行任何操作.由于cplex模型通常非常稀疏,因此导致过多内存消耗的最常见原因是添加了太多系数为0的项.

Keep in mind, there parameters only affect cplex during a .solve(). If you are running out of memory before the .solve(), the parameters won't do anything. Since cplex models are usually very sparse, the most common cause of excess memory consumption is adding too many terms with 0 coefficients.

这篇关于在Java中使用CPLEX库时的内存优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆