I am looking to find the best replacement item for an old item. An old item can have several potential options for replacement items. I want to only choose one replacement item for each old item.
So in data form lets say that the color is the old item
Color-Number
Red-1
Red-2
Red-3
Blue-1
Blue-2
At the end, I want only one red and one blue selected.
For my variable I am using:
used_vars = LpVariable.dicts("Used",Option,0,1,LpInteger)
This is to indicate if I used an option or not.
Then for my constraint I want each item to be used only once to be used in all the options so I tried this for my constraint...
prob += lpSum([used_vars['Red']])==1
prob += lpSum([used_vars['Blue']])==1
However, I get this error... Key Error 'Red'.
So what's the best way to write this constraint?
**UPDATE
I have also tried
for x in final_color_list:
prob += sum([used_vars[x] for i in Option] )==1, ''