# linearize¶

flopt.convert.linearize(prob)[source]

linearize of problem

Parameters

prob (Problem) –

Examples

```import flopt

x = flopt.Variable.array('x', 3, cat='Binary')

prob = flopt.Problem()
prob += x[0] - 2*x[1] - x[0]*x[1]*x[2]

print('[ original ]')
prob.show()
>>> [ original ]
>>>  Name: None
>>>   Type         : Problem
>>>   sense        : minimize
>>>   objective    : x_0-(2*x_1)-((x_0*x_1)*x_2)
>>>   #constraints : 0
>>>   #variables   : 3 (Binary 3)

from flopt.convert import linearize

linearize(prob)

print('[ linearized ])
prob.show()
>>> [ linearized ]
>>>  Name: None
>>>   Type         : Problem
>>>   sense        : minimize
>>>   objective    : 0-mul_1+x_0-(2*x_1)
>>>   #constraints : 6
>>>   #variables   : 5 (Binary 5)

>>>   C 0, name for_mul_0_1, mul_0-x_0 <= 0
>>>   C 1, name for_mul_0_2, mul_0-x_1 <= 0
>>>   C 2, name for_mul_0_3, mul_0-(x_0+x_1-1) >= 0
>>>   C 3, name for_mul_1_1, mul_1-mul_0 <= 0
>>>   C 4, name for_mul_1_2, mul_1-x_2 <= 0
>>>   C 5, name for_mul_1_3, mul_1-(mul_0+x_2-1) >= 0
```

# binarize¶

flopt.convert.binarize(prob)[source]

binarize of problem

Parameters

prob (Problem) –

Examples

```import flopt

x = flopt.Variable.array('x', 2, cat='Binary')
y = flopt.Variable('y', lowBound=1, upBound=3, cat='Integer')

prob = flopt.Problem()
prob += y * x[0] + x[1]

print('[ original ]')
prob.show()
>>> [ original ]
>>>  Name: None
>>>   Type         : Problem
>>>   sense        : minimize
>>>   objective    : y_0*x_0+x_1
>>>   #constraints : 0
>>>   #variables   : 3 (Binary 2, Integer 1)

from flopt.convert import linearize, binarize

binarize(prob)

print('[ binarized ]')
prob.show()
>>> [ binarized ]
>>>  Name: None
>>>   Type         : Problem
>>>   sense        : minimize
>>>   objective    : x_0*(1*bin_y_0_0+2*bin_y_0_1+3*bin_y_0_2)+x_1
>>>   #constraints : 2
>>>   #variables   : 6 (Binary 5, Integer 1)

>>>   C 0, name for_bin_y_0_sum, bin_y_0_0+bin_y_0_2+bin_y_0_1-1 == 0
>>>   C 1, name for_bin_y_0_eq, y_0-(1*bin_y_0_0+2*bin_y_0_1+3*bin_y_0_2) == 0

linearize(prob)

print('[ linearized ]')
prob.show()
>>> [ linearized ]
>>>  Name: None
>>>   Type         : Problem
>>>   sense        : minimize
>>>   objective    : mul_0+2*mul_1+3*mul_2+x_1
>>>   #constraints : 11
>>>   #variables   : 9 (Binary 8, Integer 1)

>>>   C 0, name for_bin_y_0_sum, bin_y_0_0+bin_y_0_1+bin_y_0_2-1 == 0
>>>   C 1, name for_bin_y_0_eq, -bin_y_0_0-(2*bin_y_0_1)-(3*bin_y_0_2)+y_0 == 0
>>>   C 2, name for_mul_0_1, mul_0-bin_y_0_0 <= 0
>>>   C 3, name for_mul_0_2, mul_0-x_0 <= 0
>>>   C 4, name for_mul_0_3, mul_0-(bin_y_0_0+x_0-1) >= 0
>>>   C 5, name for_mul_1_1, mul_1-bin_y_0_1 <= 0
>>>   C 6, name for_mul_1_2, mul_1-x_0 <= 0
>>>   C 7, name for_mul_1_3, mul_1-(bin_y_0_1+x_0-1) >= 0
>>>   C 8, name for_mul_2_1, mul_2-bin_y_0_2 <= 0
>>>   C 9, name for_mul_2_2, mul_2-x_0 <= 0
>>>   C 10, name for_mul_2_3, mul_2-(bin_y_0_2+x_0-1) >= 0
```