I am applying the CSP in python having problem when passing dictionary as a parameter to a method in python
officerDomain = range(0, 2**scheduleDays-1)
solver = MinConflictsSolver()
problem = Problem(solver)
officers = []
officers.append({'name':'Ryan', 'rank':'3'})
officers.append({'name':'Mond', 'rank':'1'})
officers.append({'name':'Eric', 'rank':'3'})
for officer in officers:
print(officer)
problem.addVariable(officer, officerDomain)
While passing the dictionary inside the list it gives the error unhashable type: 'dict'
Let's read the documentation :
addVariable(self, variable, domain)
Parameters : variable - Object representing a problem variable (type=hashable object)
So you can't use a dictionary (officer in this case) because it's unhashable. Try with officer["name"]
for example.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.