XiongPengNUS/rsome

How to model constraint on sum of absolue values: sum(abs(x))

Closed this issue · 1 comments

I would need to implement constraint on sum of absolute values.
(E.g.: natural constraint for "Leverage" in portfolio optimization problem, while allowing negative weights)

Naive solution would be:
max_leverage = 2
model.st(sum(abs(x)) <= max_leverage)

But this will ends up with error:
"TypeError: 'Convex' object is not iterable"

Is there reccomended way how to approach this problem?

This is in fact 1-norm and you could use the code:

from rsome import norm

model.st(norm(x, 1) <= max_leverage)