hi all,

need help for linearizing step function.

say "y" is depending on "x" such that,

y= ax if x is between 1 and 2

y= bx if x is between 3 and 4

y= cx if x is between 5 and 6

a, b and c are parameters/constant which will have values 8 or 9.

"y" is not final objective function and a, b and c must choose value either 8 or 9.

solution requested for maximizing/minimizing "y".

thanks.

# Linearizing step function

Hi @chrdttchavan ,

One way of linearizing this is to use binary variables. I would recommend you to create a set Ranges (with index r) - each element in this set corresponds to the different steps/ranges you have for x.

Set

Ranges := data{Range-1, Range-2, Range-3}.

Parameters,

LowerLimit(r) := {1, 3, 5};

UpperLimit(r) := {3, 4, 6};

MultiplicationFactor(r) := {a, b, c};.

BinaryVariable(r).

Now have the following constraints.

Constraint_1

y = sum[r, BinaryVariable(r)*MultiplicationFactor(r)]

Constraint_2

sum[r, BinaryVariable(r)] = 1

Constraint_3(r)

x >= BinaryVariable(r) * LowerLimit(r)

Constraint_4(r)

X <= (1-BinaryVariable(r))*M + UpperLimit(r)

Here, M is a sufficiently large positive number. You can use M = 10 for your case.

You are essentially using BinaryVariable(r) to track in which range does the value of x lie in, and based on the value of BinaryVariable(r), you can calculate the value of y.

One way of linearizing this is to use binary variables. I would recommend you to create a set Ranges (with index r) - each element in this set corresponds to the different steps/ranges you have for x.

Set

Ranges := data{Range-1, Range-2, Range-3}.

Parameters,

LowerLimit(r) := {1, 3, 5};

UpperLimit(r) := {3, 4, 6};

MultiplicationFactor(r) := {a, b, c};.

BinaryVariable(r).

Now have the following constraints.

Constraint_1

y = sum[r, BinaryVariable(r)*MultiplicationFactor(r)]

Constraint_2

sum[r, BinaryVariable(r)] = 1

Constraint_3(r)

x >= BinaryVariable(r) * LowerLimit(r)

Constraint_4(r)

X <= (1-BinaryVariable(r))*M + UpperLimit(r)

Here, M is a sufficiently large positive number. You can use M = 10 for your case.

You are essentially using BinaryVariable(r) to track in which range does the value of x lie in, and based on the value of BinaryVariable(r), you can calculate the value of y.

### Reply

## Sign up

Already have an account? Login

**Please use your business or academic e-mail address to register**

## Login to the community

No account yet? Create an account

Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.