我在一个基于教程的VRP优化问题中工作。 当我添加subtours约束时,我得到一个错误。 我遵循这个教程:https://www.youtube.com/watch?v=eMsqsmftWOQ&t=2398s
from docplex.mp.model import Model
mdl = Model('CVRP')
x = mdl.binary_var_dict(arcos, name = 'x')
u = mdl.continuous_var_dict(nodos, ub = Q, name = 'u')
mdl.minimize(mdl.sum(distancia[i,j]*x[i,j] for i,j in arcos))
mdl.add_constraints(mdl.sum(x[i,j] for j in nodos if i!= j) == 1 for i in clientes)
mdl.add_constraints(mdl.sum(x[i,j] for i in nodos if i!= j) == 1 for j in clientes)
mdl.add_indicator_constraints(mdl.indicator_constraint(x[i,j],u[i]+q[j]==u[j]) for i,j in arcos if i!=0 and j!= 0) #This is the line
上下文:
clientes = [x for x in range(1, n+1)]
nodos = [0]+clientes
arcos = {(i,j) for i in nodos for j in nodos if i != j}
Q = 15
错误列表为:
C:\Users\Jose Godoy\PycharmProjects\Huevos hermanos\venv\lib\site-packages\docplex\mp\__init__.py:35: RuntimeWarning: docplex is not officially supported on 32 bits. Use it at your own risk.
warnings.warn("docplex is not officially supported on 32 bits. Use it at your own risk.", RuntimeWarning)
Traceback (most recent call last):
File "C:/Users/Jose Godoy/PycharmProjects/Huevos hermanos/VRP.py", line 41, in <module>
mdl.add_indicator_constraints(mdl.indicator_constraint(x[i,j],u[i]+q[j]==u[j]) for i,j in arcos if i!=0 and j!= 0)
File "C:\Users\Jose Godoy\PycharmProjects\Huevos hermanos\venv\lib\site-packages\docplex\mp\model.py", line 3014, in add_indicator_constraints
ind_indices = self.__engine.create_batch_indicator_constraints(indcts)
File "C:\Users\Jose Godoy\PycharmProjects\Huevos hermanos\venv\lib\site-packages\docplex\mp\engine.py", line 465, in create_batch_indicator_constraints
return self.create_batch_cts(indicators)
File "C:\Users\Jose Godoy\PycharmProjects\Huevos hermanos\venv\lib\site-packages\docplex\mp\engine.py", line 449, in create_batch_cts
self._increment_cts(len(ct_seq))
TypeError: object of type 'generator' has no len()
我认为公式的语法是可以的,和教程一样,所以我认为是库中的一个问题,因为我得到了一个警告消息
RuntimeWarning: docplex is not officially supported on 32 bits. Use it at your own risk.
warnings.warn("docplex is not officially supported on 32 bits. Use it at your own risk.", RuntimeWarning)
你知道我怎么修吗?你知道吗
我解决了这个问题。 我加了一个
所以这项工作对我来说:
相关问题 更多 >
编程相关推荐