0

I am trying to formulate a linear program that will assign different number of employees to start in different days. Each group of employees starting on a day will get two days off during the week. However, the schedule is unknown. For example, employees starting Monday can be off any two days in the week. Since the number that will start on day (i) is unknown and whether they will have a day off or not is unknown, I will have the product of two decision variables - one is an integer xi (employees starting on day i) and a binary variable yij (whether the employees starting on day i have a day off on day j).

I am done with formulation and here it is:

Decision variables 1: xi (employees starting on day i) Decision variables 2: yij (1 if employees starting on day i are working on day j, or 0 if employees starting on day i are off on day j)

Objective function: Minimize total employees-- sum (i in 1..7) xi

Subject to: xi*yij >= Requiredj (the number of available workers on day j have to satisfy the demand on day j)

I am trying to code this on CPLEX but i dont know how to make xi*yij linear and write the code....can anyone please help me?

Thank you.

2 Answers2

1

Let y be a binary variable an x be a continuous/integer variable for which 0 <= x <= u holds. Introduce a continuous/integer variable z to hold the product z = x * y

Add following constraints to force z to take the value of x * y:

z <= u * y
z <= x
z >= x − u * (1 − y)
y >= 0

By doing above, we have linearised the product of a continuous/integer variable with binary variable. Above can be expressed easily in any programming language API of all popular open / commercial solver.

0

In How to with OPL How to multiply a decision variable by a boolean decision variable in CPLEX ?

// suppose we want b * x <= 7 

dvar int x in 2..10;
dvar boolean b;

dvar int bx;

maximize x;
subject to
{
  
// Linearization  
bx<=7;

 

2*b<=bx;
bx<=10*b;

bx<=x-2*(1-b);
bx>=x-10*(1-b);

// if we use CP we could write directly
// b*x<=7

// or rely on logical constraints within CPLEX
// (b==1) => (bx==x);
// (b==0) => (bx==0);
}
Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15
  • Thank you really for your help! However I am trying to write this on CPLEX and i am not sure what i am doing wrong, can you help me figure out? I am new to the software and this whole concept Can you tell me how to write the code on cplex with matrices? – Wassen Mohammad Nov 06 '21 at 18:42
  • When you say you want help to write the code, what language and API are you trying to use? What have you tried so far? Just to point out that it is usually easier to think about the real problem in real-world terms and relate your variables and constraints to the real-world entities. Trying to think and work in terms of matrices is often not helpful. Internally inside CPLEX there are matrices and similar structures, but we don't need to think in those terms. Modelling languagues and tools make things simpler to get right. – TimChippingtonDerrick Nov 07 '21 at 09:23