pythonlistdictionaryintegeroperands

unsupported operand type(s) for -: 'dict' and 'int'


r = ["EAF","AOD","LF","EAs","EAd","ALs","ALd","LCs","LCd","H"]  #sets of resources

i = ["E","A","L","EA","AL","LC"] #sets of tasks

t = [1,2,3,4,5,6,7,8,9,10,11,12] #number of timeslots

Hour=2

Price = {'Hour1': 100 ,'Hour2': 200}

R= {'EAF':2,'AOD':2,'LF':2,'EAs':1,'EAd':1,'ALs':1,'ALd':1,'LCs':1,'LCd':1,'H':1}#resource keys and its values

N = {'E':1 , 'A' : 1 , 'L' : 1 , 'EA' : 1, 'AL' :1, 'LC' :1 } #task keys and its values

#µ Declaration

task_duration={'EAF':5 , 'AOD': 4 ,'LF': 1, 'EA':1, 'AL':1, 'LC':1}

#Equipment Usage
for r in R :
   for i in N:
        u[r][i] = [-1] +[0]*(task_duration-1)+[1]
           
#Before Transfer            
for i,r in [(EAF,EAs),(AOD,ALs),(LF,LCs)]:
       u[r][i] = [0] +[0]*(task_duration-1)+[1]
   
#After Transfer
for i,r in [(AOD,EAd) ,(LF,ALd)]:
         u[r][i] = [-1] +[0]*(task_duration-1)+[0]

#Transfer tasks:
#Before Transfer:

for i,r in [(EA,EAs),(AL,ALs),(LC,LCs)]:
            u[r][i] = [-1]*(task_duration)

#After Transfer:

for i,r in [(EA,EAd),(AL,ALd),(LC,LCd)]:
            u[r][i] = [1]*(task_duration)


Error:

TypeError                                 Traceback (most recent call last)
Input In [19], in <cell line: 20>()
     20 for r in R :
     21     for i in N:
---> 22          u[r][i] = [-1] +[0]*(task_duration-1)+[1]
     24 #Before Transfer            
     25 for i,r in [(EAF,EAs),(AOD,ALs),(LF,LCs)]:

TypeError: unsupported operand type(s) for -: 'dict' and 'int'

I don't have any idea of this error. Can anyone please let me know? There are tupels in the list. I am trying to extract data from the dictionary its respective key and its values. Perform some operations with the integer data with list. It should then return a list .For Ex: u[r][i] = [-1,0,0,1]. This is the kind of result i am trying to get.I am completely unsure with the error.Kindly let me know if anyone is aware of it.


Solution

  • What exactly do you expect the output of task_duration-1 to be? task_duration is a dictionary. Did you mean {k: v-1 for k, v in task_duration.items()}?