y=|x1-x2| for binary variable is the same as y = x1 xor x2. This can be written as:
y <= x1+x2
y >= x1-x2
y >= x2-x1
y <= 2-x1-x2
(see here).
When x1,x2 are continuous variables between 0 and U you can write:
y1-y2 = x1-x2
y = y1+y2
y1 <= delta*U
y2 <= (1-delta)*U
y1>=0
y2>=0
delta in {0,1}
In many cases this can be simplified.
Answer from Erwin Kalvelagen on Stack OverflowGurobi
support.gurobi.com › hc › en-us › community › posts › 16825969921297-bad-operand-type-for-abs-gurobipy-LinExpr
bad operand type for abs(): 'gurobipy.LinExpr' – Gurobi Help Center
When I run this, it gives the error "bad operand type for abs(): 'gurobipy.LinExpr' " in this line M.addConstr(A[i]*diag_y*expected_demand +epsilon*np.linalg.norm(A[i]*diag_y*P,np.inf) <= c[i])
Google Groups
groups.google.com › g › gurobi › c › d3q4JWw1ntI
How to use abs() function with decision variables
Hi, I am trying to use abs function with decision variables but Gurobi gives this output : TypeError: bad operand type for abs(): 'gurobipy.LinExpr'
Stack Overflow
stackoverflow.com › questions › 75928026 › facing-a-typeerror-unsupported-operand-types-for-gurobipy-linexpr-and
python 3.x - Facing a TypeError: unsupported operand type(s) for +=: 'gurobipy.LinExpr' and 'GenExprAbs' when using .abs_() in gurobipy - Stack Overflow
# Define the objective function obj = gp.quicksum( gp.quicksum(gp.abs_(pp[i] * x[i, j] - targ) for i in set_I) for j in set_J ) + gp.quicksum( gp.quicksum( gp.abs_( l[i] * x[i, j] / gp.quicksum(x[i, j] for i in set_I) - actual_proportion ) for i in set_I ) for j in set_J ) model.setObjective(obj, GRB.MINIMIZE) However, I ran into the error that is TypeError: unsupported operand type(s) for +=: 'gurobipy.LinExpr' and 'GenExprAbs'.
Stack Overflow
stackoverflow.com › questions › 34574346 › gurobipythonhow-to-use-abs-function-with-decision-variables
typeerror - Gurobi:Python:How to use abs() function with decision variables - Stack Overflow
January 3, 2016 - TypeError: bad operand type for abs(): 'gurobipy.LinExpr' Here the code that gurobi directs me for the error; PPP = quicksum((1 / (1+AAA)**y)*abs(W2G[p]+S2G[p]-EPD[p])*BBB*CCC for y in range(1,DDD+1) for p in range(1,EEE+1)) **W2G and S2G are ...
Google Groups
groups.google.com › g › gurobi › c › YUWqUfk3PSc
How to find absolute of a linear expression?
July 12, 2016 - TypeError: bad operand type for abs(): 'gurobipy.LinExpr'
Gurobi
support.gurobi.com › hc › en-us › community › posts
Posts – Gurobi Help Center
bad operand type for abs(): 'gurobipy.LinExpr' Answered · İrem Bahtiyar · July 08, 2023 12:09 · 0 votes 3 comments · MATLAB Gurobi model.A Answered · Elvin Dulce · July 08, 2023 03:51 · 0 votes 2 comments · Any cheat sheet or documention for syntaxes in gurobipy?
CopyProgramming
copyprogramming.com › howto › bad-operand-type-for-abs-generator
Python: Type Error in Absolute Value Generator
April 28, 2023 - Type Error in abs() Function: 'list' is Not a Valid Operand, Obtaining the Absolute Value of a Linear Expression, Binary operation && cannot be performed due to incorrect operand type, Bad Operand types
Gurobi
support.gurobi.com › hc › en-us › community › posts › 20034527892497-TypeError-unsupported-operand-type-s-for-gurobipy-LinExpr-and-list
TypeError: unsupported operand type(s) for -: 'gurobipy.LinExpr' and 'list' – Gurobi Help Center
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[23], line 165 163 for t in T: 164 for k in A: --> 165 model.addConstr(gp.quicksum(yfOmega[f, t + tf[f][0], omega] for f in F if af[f] == k and t + tf[f] <= 96 ) <= AtkOmega[k, t, omega]) #AtkOmega[k, t, omega] 169 for omega in Omega: 170 for t in T: File src/gurobipy/model.pxi:3607, in gurobipy.Model.addConstr() TypeError: unsupported operand type(s) for -: 'gurobipy.LinExpr' and 'list' To give further insights, tf is a one dimensional dictionary {0:4,1:6,2:23....} ..
Gurobi
support.gurobi.com › hc › en-us › community › posts › 360048204931-Need-help-with-Objective-function
Need help with Objective function – Gurobi Help Center
August 8, 2019 - I am trying to convert an objective function from scipy to Gurobi as follows but getting "unsupported operand type(s) for ** or pow(): 'gurobipy.LinExpr' and 'float'". Any idea how I could re-write...
Stack Overflow
stackoverflow.com › questions › tagged › gurobi
Highest scored 'gurobi' questions - Page 22 - Stack Overflow
First of all thanks in advance, and sorry if I made the question too long, I tried to be the clearest as possible. I am trying to install the gurobipy module in my enviroment on Pycharm.
Stack Overflow
stackoverflow.com › questions › 58698935 › gurobi-addconstr-unsupported-operand-types-for-bool-and-nonetype
python 3.x - Gurobi - addConstr: unsupported operand type(s) for -: 'bool' and 'NoneType' - Stack Overflow
November 5, 2019 - 3 AttributeError: 'gurobipy.LinExpr' object has no attribute '__colno__' 4 TypeError: unsupported operand type(s) for +: 'generator' and 'generator' 0 Gurobi specifies a problem as infeasible although it is not ·
Google Groups
groups.google.com › g › gurobi › c › TWMxsATe5iQ
Var' object is not iterable, TypeError: 'gurobipy.LinExpr' object is not iterable
July 19, 2018 - However, I got an error message "unsupported operand type(s) for ** or pow(): 'gurobipy.LinExpr' and 'int'".
Google Groups
groups.google.com › g › gurobi › c › uUWaMfx54DA
TypeError: unsupported operand type(s) for -: 'bool' and 'NoneType'
... Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message ... You should verify that the objects stored in g[i][j][k][l] and g[j][i][k][l] are of type Var or LinExpr for all i, j, k and l.