mathematical optimization - How to get absolute value of a linear expression? -


i working on optimization problem on gurobi.all variables of binary type.i have variable y equal absolute of difference of 2 binary decision variables.however,when tried use abs() function,i output.

typeerror: bad operand type abs(): 'gurobipy.linexpr' 

therefore,i squaring difference (since difference -1,0 or 1). causes higher optimization time(quadratic expressions after squaring). there alternative this?

also,there case(not binary variables) difference of 2 variables may not -1,0 or 1.how take absolute in case?

y=|x1-x2| binary variable same y = x1 xor x2. can written as:

y <= x1+x2  y >= x1-x2  y >= x2-x1  y <= 2-x1-x2 

(see here).

when x1,x2 continuous variables between 0 , u 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 can simplified.


Comments

Popular posts from this blog

Angularjs unit testing - ng-disabled not working when adding text to textarea -

sql - invalid in the select list because it is not contained in either an aggregate function -

How to start daemon on android by adb -