I have a Pulp problem that is working fine and gives me the right values, but I want to clean up the code. Here is the part in question:
prob += (select_vars['MeatA'] + select_vars['MeatB'] + select_vars['MeatC']) >= 3, ""
I want to put this into a for loop, like this:
meat_count = 0
Meats = ["MeatA", "MeatB", "MeatC"]
for i in Meats:
if select_vars[i] is not None: meat_count += 1
prob += meat_count >= 5, "Meat min"
But that is putting NoneTypes into my prob.variables() and I'm not sure why. There are no NoneTypes in my prob.variables() when I run it the first way without the for loop.
# Print out the variables with their optimal value
for v in prob.variables():
print("some none ", v)
if v.varValue > 0:
print(v.name, "=", v.varValue)