CPLEX二次目标CPLEX错误1017:不适用于混合整数问题 [英] CPLEX quadratic objective CPLEX Error 1017: Not available for mixed-integer problems

查看:133
本文介绍了CPLEX二次目标CPLEX错误1017:不适用于混合整数问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用cplex解决以下线性程序:

I'm trying to solve the following linear program using cplex:

def generate_linear_program(self):
    problem = cplex.Cplex()
    problem.objective.set_sense(problem.objective.sense.minimize)
    for index, track in enumerate(self.tracks):
        tokens = track['track'].split('_')
        problem.variables.add(names = ['c' + str(tokens[1])], ub = [1.0], types = ['C'])
    problem.variables.add(names = ['e' + str(index) for index, param in enumerate(self.params)],
        types = ['C'] * len(self.params),
        ub = [param['c'] - param['u'] * param['r'] for param in self.params],
        lb = [param['c'] - param['u'] * param['r'] - param['c'] * sum(param['tracks'][track] for track in param['tracks']) for param in self.params])
    problem.variables.add(names = ['l' + str(index) for index, param in enumerate(self.params)],
        #obj = [1.0] * len(self.params),
        types = ['C'] * len(self.params))
    problem.objective.set_quadratic([0.0] * len(self.tracks) + [1.0] * len(self.params) + [0.0] * len(self.params))
    # add some linear constraints here
    problem.solve()

当我调用 solve()时,Cplex抱怨错误消息 CPLEX错误1017:不适用于混合整数问题.如果我删除上面的二次目标,而是通过取消注释上面代码的注释行( obj = [1.0] * len(self.params),)来添加线性目标,则它可以正常工作.

When I call solve() Cplex complains with the error message CPLEX Error 1017: Not available for mixed-integer problems. If I remove the quadratic objective above and instead add a linear objective by uncommenting the commented line of code above (obj = [1.0] * len(self.params),), it works without a problem.

堆栈跟踪:

File "/share/src/python/kmer/programming.py", line 373, in solve
    problem.solve()
File "/home/user/local/cplex/lib/python/cplex/__init__.py", line 998, in solve
    _proc.qpopt(self._env._e, self._lp)
File "/home/user/local/cplex/lib/python/cplex/_internal/_procedural.py", line 499, in qpopt
    check_status(env, status)
File "/home/user/local/cplex/lib/python/cplex/_internal/_procedural.py", line 171, in __call__
    raise CplexSolverError(error_string, env, status)
cplex.exceptions.errors.CplexSolverError: CPLEX Error  1017: Not available for mixed-integer problems.

为了更好地了解此处发生的情况,当目标是二次方时,我正在尝试最小化某些误差项的平方和.当目标变为线性时,我将这些项的绝对值的总和最小化.名称以 e 开头的变量是错误术语,而 l s将通过以下约束变为其绝对值:

To get a better idea of what is happening here, when the objective is quadratic I'm trying to minimize the sum of the squares of some error terms. When the objective becomes linear, I'm minimizing the sum of the absolute values of those terms. The variables whose names start with e are the error terms and the ls will become their absolute value through these constraints:

    for index, params in enumerate(self.params):
        problem.linear_constraints.add(
            lin_expr = [cplex.SparsePair(
                ind = [len(self.tracks) + len(self.params) + index, len(self.tracks) + index],
                val = [1.0, 1.0],
            )],
            rhs = [0],
            senses = ['G']
        )
        problem.linear_constraints.add(
            lin_expr = [cplex.SparsePair(
                ind = [len(self.tracks) + len(self.params) + index, len(self.tracks) + index],
                val = [1.0, -1.0],
            )],
            rhs = [0],
            senses = ['G']
        )

l< index> 变量在存在二次目标的情况下实际上是无用的.

The l<index> variables are actually useless in presence of the quadratic objective.

还有其他一些线性约束,在这里我不能包括,但由于以下两个原因,它们绝对不是问题的原因:

There are other linear constraints which I can't include here yet they are definitely not the cause of the problem because of the two following reasons:

  1. 线性物镜的存在没有问题
  2. 当我使用二次目标将它们注释掉时,我仍然遇到相同的错误.

我在这里想念什么?

推荐答案

很容易错过

如果指定了类型,则问题类型将是MIP,即使所有变量被指定为连续的.

If types is specified, the problem type will be a MIP, even if all variables are specified to be continuous.

如果您从对 Cplex.variables.add 的调用中删除了可选的 types 参数,则该问题将消失.例如,代替:

If you remove the optional types argument from your calls to Cplex.variables.add, the problem should go away. For example, instead of:

problem.variables.add(names = ['c' + str(tokens[1])], ub = [1.0], types = ['C'])

使用:

problem.variables.add(names = ['c' + str(tokens[1])], ub = [1.0])

当您具有线性目标时,它起作用的原因是,为了方便起见,在使用 CPXERR_NOT_FOR_MIP失败 CPXlpopt 后,将其传递到 CPXmipopt 中代码>(错误1017).而当我们调用 CPXqpopt 时,则不会应用此逻辑.

The reason it works when you have a linear objective is that it's being passed into CPXmipopt, as a convenience, after failing CPXlpopt with a CPXERR_NOT_FOR_MIP (error 1017). Whereas, when we call CPXqpopt, this logic is not applied.

这篇关于CPLEX二次目标CPLEX错误1017:不适用于混合整数问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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