Ограничения индикаторов (объект типа «генератор» не имеет len ()) - PullRequest
0 голосов
/ 01 июня 2019

Я работаю над проблемой оптимизации 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)

Знаете, как я могу это исправить?

1 Ответ

0 голосов
/ 01 июня 2019

Я решил это.Я добавил

[]

Так что эта работа для меня:

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
...