Hello, I would like to use the absolute value in constraints and objective function. I believe that the absolute value can be desugared to plain linear constraints with shadow variables.
Does PyMathProg support this feature?
I have tried the following:
model('foo') x = var('x') y = var('y') abs(x - y) < 42
which fails with:
Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: bad operand type for abs(): '_parex'
Best, Marco
Since abs(x-y) <= 42 is not a linear function, this is not directly supported. However, you can get the same effect in PYMPROG with:
-42 <= x-y <= 42
hope it helps, sorry for the late response.
Log in to post a comment.
Hello,
I would like to use the absolute value in constraints and objective function.
I believe that the absolute value can be desugared to plain linear constraints with shadow variables.
Does PyMathProg support this feature?
I have tried the following:
which fails with:
Best,
Marco
Since abs(x-y) <= 42 is not a linear function, this is not directly supported. However, you can get the same effect in PYMPROG with:
-42 <= x-y <= 42
hope it helps, sorry for the late response.