Я работаю над проблемой оптимизации ограничений и использую полку pyomo для моделирования проблемы. Я нахожусь на начальной стадии проблемы, и когда я пытаюсь инициализировать модель, я получаю сообщение об ошибке.
У меня есть следующие данные:
A = ['20668','20845','21905','21976','22372','22373','22430','22441','22571','22577','22727','22760']
Date = ['05/01/2020','05/02/2020','05/03/2020','05/04/2020','05/05/2020]
time = ['23:00:00','00:00:00','01:00:00','02:00:00','03:00:00','04:00:00','05:00:00','06:00:00','07:00:00','08:00:00','09:00:00','10:00:00','11:00:00','12:00:00','13:00:00','14:00:00','15:00:00','16:00:00','17:00:00','18:00:00','19:00:00','20:00:00','21:00:00','22:00:00']
Сначала я создаю словарь для создания пары ключ-значение
date_time = {day: time for day in date}
И затем инициализирую модель
Инициализирую модель
model = ConcreteModel()
# binary variables representing if a worker is scheduled somewhere
model.works = Var(((worker, Date , time) for worker in A for day in Date for shift in date_time[day]),
within=Binary, initialize=0)
# binary variables representing if a worker is necessary
model.needed = Var(workers, within=Binary, initialize=0)
Я получаю следующее ошибка. Так как я очень плохо знаком с pyomo, я не знаю, что здесь происходит.
TypeError Traceback (most recent call last)
~\Anaconda3\lib\site-packages\pyomo\core\base\sets.py in add(self, *args)
823 try:
--> 824 if tmp in self:
825 #
~\Anaconda3\lib\site-packages\pyomo\core\base\sets.py in __contains__(self, element)
997 if self._constructed and self.concrete is True:
--> 998 return self._set_contains(element)
999 #
~\Anaconda3\lib\site-packages\pyomo\core\base\sets.py in _set_contains(self, element)
1301 """
-> 1302 return element in self.value
1303
TypeError: unhashable type: 'list'
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
<ipython-input-102-6fe4bb01a65a> in <module>
4 # binary variables representing if a worker is scheduled somewhere
5 model.works = Var(((worker, date, shifts) for worker in workers for day in date for shift in days_shifts[day]),
----> 6 within=Binary, initialize=0)
7
8 # binary variables representing if a worker is necessary
~\Anaconda3\lib\site-packages\pyomo\core\base\block.py in __setattr__(self, name, val)
568 # Pyomo components are added with the add_component method.
569 #
--> 570 self.add_component(name, val)
571 else:
572 #
~\Anaconda3\lib\site-packages\pyomo\core\base\block.py in add_component(self, name, val)
908 #
909 if hasattr(val, '_index'):
--> 910 self._add_temporary_set(val)
911 #
912 # Add the component to the underlying Component store
~\Anaconda3\lib\site-packages\pyomo\core\base\block.py in _add_temporary_set(self, val)
731 if isinstance(val._index, _SetDataBase) and \
732 val._index.parent_component().local_name == "_unknown_":
--> 733 self._construct_temporary_set(val._index, val.local_name + "_index")
734 if isinstance(getattr(val, 'initialize', None), _SetDataBase) and \
735 val.initialize.parent_component().local_name == "_unknown_":
~\Anaconda3\lib\site-packages\pyomo\core\base\block.py in _construct_temporary_set(self, obj, name)
755 return tobj
756 elif isinstance(obj, Set):
--> 757 self.add_component(name, obj)
758 return obj
759 raise Exception("BOGUS")
~\Anaconda3\lib\site-packages\pyomo\core\base\block.py in add_component(self, name, val)
1008 _blockName, str(data))
1009 try:
-> 1010 val.construct(data)
1011 except:
1012 err = sys.exc_info()[1]
~\Anaconda3\lib\site-packages\pyomo\core\base\sets.py in construct(self, values)
1274 else:
1275 all_numeric=False
-> 1276 self.add(val)
1277 if all_numeric:
1278 self._bounds = (first,last)
~\Anaconda3\lib\site-packages\pyomo\core\base\sets.py in add(self, *args)
831 self._add(tmp, False)
832 except TypeError:
--> 833 raise TypeError("Problem inserting "+str(tmp)+" into set "+self.name)
834
835 def remove(self, element):
Может кто-нибудь помочь мне понять, с чем я столкнулся здесь и как это исправить
Заранее большое спасибо !!