• Gurobi Staff

Hello José, unfortunately there isn't a shorthand for doing this in gurobipy yet, but I have taken note of your feature request in our development backlog.

For now you will have to model the absolute values per variable.  For example, to compute a minimum 1-norm solution to an underdetermined linear system you could do:

import numpy as npimport gurobipy as gpA = np.random.rand(30, 100)x_true = np.random.rand(100)b = A @ x_truem = gp.Model() x = m.addMVar(100, lb=-np.inf)m.addConstr(A @ x == b)# 'absx' takes absolute value of 'x'absx = m.addMVar(100)for v, absv in zip(x.tolist(), absx.tolist()):    m.addConstr(absv == gp.abs_(v))# minimize 1-norm of xm.setObjective(absx.sum())m.optimize()print("Solution 1-norm: {}".format(np.sum(np.abs(x.X))))

Thank you so much Robert!

• Gurobi Staff

Hi José,

Gurobi 9.5 was recently released. Included in this release is the norm() general constraint helper function that can be used to set a decision variable equal to the norm of the other decision variables. The supported norms are 0-, 1-, 2-, and infinity.

We hope this new feature works well for you. Please let us know if you find any issues using this.

Best regards,

Maliheh