简体   繁体   中英

How to abs a Expression in mosek.fusion.Model?

I want to solve the optimization of maximizing the objective which is the sum of the absolute value of a matrix. However, I cannot find the accurate way to get that:

for example:

import mosek.fusion as mf
from mosek.fusion import Model, Domain, Expr, ObjectiveSense

with Model('lol') as M:
    x = M.variable('x', [5,1], Domain.inRange(-1,1))
    M.objective('obj', ObjectiveSense.Maximize, abs(x))
    M.solve()

does not work

Type Error: bad operand type for abs(): 'RangedVariable'

How can I get the absolute value of x ?

First, you can't just apply arbitrary Python functions to mosek.fusion objects! Consult https://docs.mosek.com/8.1/pythonfusion/api-reference.html for what is available.

Second, maximizing absolute value is not a convex problem! You will have to use mixed-integer programming if you really want to model it. Consult https://docs.mosek.com/modeling-cookbook/mio.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM