Suppose I have a set of decision variables in my PuLP definition:
vals = [-v for k, v in (DecisionVars.items())]
And I want to create a constraint related to the absolute value of the sum of all constraints. So something like:
for i in range(len(DecisionVars)):
prob += lpSum(abs(vals[:i+1])) <= some_limit, "Absolute constraint"
But I cant seem to apply the abs()
operator to my constraints?
UPDATE
Ok, if I make use of the information in this post sum of absolute values constraint in semi definite programming then my question can be formulated differently. I am now trying to evaluate:
abs(x1) + abs(x2) + abs(x3) <= some_limit
As pointed out in the link above, the answer might be to create a 1-norm of the vector x (where x is the vector of decision variables as above). I can see that numpy
has numpy.linalg.norm
but I cannot see how this can recursively create my set of constraints in PuLP. I'm struggling to create the correct syntax using lpSum
.