Menu

Absolute Value

Help
Marco
2018-08-19
2018-12-30
  • Marco

    Marco - 2018-08-19

    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

     
  • Yingjie Lan

    Yingjie Lan - 2018-12-30

    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.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.