CPLEX二次目标CPLEX错误1017:不适用于混合整数问题 [英] CPLEX quadratic objective CPLEX Error 1017: Not available for mixed-integer problems
问题描述
我正在尝试使用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 l
s 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:
- 线性物镜的存在没有问题
- 当我使用二次目标将它们注释掉时,我仍然遇到相同的错误.
我在这里想念什么?