2

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.

Anthony W
  • 1,289
  • 2
  • 15
  • 28
  • I think this is answered nicely here: https://stackoverflow.com/questions/29795632/sum-of-absolute-values-constraint-in-semi-definite-programming – Anthony W Aug 07 '18 at 09:00
  • Possible duplicate of [sum of absolute values constraint in semi definite programming](https://stackoverflow.com/questions/29795632/sum-of-absolute-values-constraint-in-semi-definite-programming) – ᴀʀᴍᴀɴ Aug 07 '18 at 09:21

2 Answers2

1

right for each variable

X1 make two new non negative variables Y1 and Z1 >=0

then set a constraint

X1 == Y1 - Z1

Then your abs constraint becomes

Y1 + Z1 +.... <= 10

Stuart Mitchell
  • 1,060
  • 6
  • 7
0

You will need to have another variable and two sets of constraints for each of your absolute variables.

m += xn <= tn
m += -xn <= tn

then the sum of tn is the sum of the absolute value of xn.

Kevin Lee
  • 83
  • 6