Skip to content

Instantly share code, notes, and snippets.

@leobessa
Last active November 23, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leobessa/56166fa3b784ca9bc541 to your computer and use it in GitHub Desktop.
Save leobessa/56166fa3b784ca9bc541 to your computer and use it in GitHub Desktop.
Seminário de MQ

Problema

Um hospital deseja gerar a escala de plantão noturna de 5 farmacêuticos para o mês de Dezembro de 2015. Durante todo o mês será necessária a presença de pelo menos 2 farmacêuticos de plantão. Os farmacêuticos f1, f2, f3, f4 e f5 trabalham no regime 12X36, com cargas horárias quem demandam 12, 13, 10, 12 e 10 plantões respectivamte. Além disso, todos funcionários devem ter pelo menos 1 (uma) folga de 24h (ao todo ou em parte) no domingo a cada 4 semanas.

Formulação do problema usando PL

Seja X uma matriz 5x31, onde:

x[i,j] = 1 caso fj estaja escalado para o plantão do dia i
x[i,j] = 0 c.c.
    var working {i in DAYS, j in WORKERS} integer >= 0, <= 1;

Restriçoes:

a) pelo menos 2 farmacêuticos de plantão

    subject to Min_Service {i in DAYS}:
      sum {j in WORKERS} working[i,j] >= 2;

b) cargas horárias quem demandam 12, 13, 10, 12 e 10 plantões

    subject to Demand_13 {j in {2}}:
      sum {i in DAYS} working[i,j] >= 13;
      
    subject to Demand_12 {j in {1,4}}:
      sum {i in DAYS} working[i,j] >= 12;
     
    subject to Demand_10 {j in {3,5}}:
      sum {i in DAYS} working[i,j] >= 10;

c) pelo menos 1 folga no domingo

    subject to SundayRest {j in WORKERS}:
      sum {i in SUNDAYS} working[i,j] <= 3;

d) regime 12X36

    subject to Max_Consecutive {j in WORKERS, i in 2..31}:
      (sum {a in {1}} working[i-1,j] + working[i,j]) <= 1;

Objetivo

Deseja-se minimizar a soma de todos os x[i,j].

    minimize Total_Work: sum {i in DAYS, j in WORKERS} working[i,j];

Solução

option solver cplex;
solve;
display working;

display {i in DAYS} sum {j in WORKERS} working[i,j];

display {j in WORKERS} sum {i in DAYS} working[i,j];

display {j in WORKERS} sum {i in SUNDAYS} working[i,j];

CPLEX 12.6.1.0: optimal integer solution; objective 62

201 MIP simplex iterations

0 branch-and-bound nodes

No basis.

working [,]

 :    1   2   3   4   5    :=
 1    1   1   0   0   0
 2    0   0   0   1   1
 3    1   1   0   0   0
 4    0   0   0   1   1
 5    1   0   1   0   0
 6    0   1   0   1   0
 7    0   0   1   0   1
 8    0   1   0   1   0
 9    0   0   1   0   1
 10   1   1   0   0   0
 11   0   0   1   1   0
 12   1   0   0   0   1
 13   0   1   0   1   0
 14   0   0   1   0   1
 15   1   0   0   1   0
 16   0   1   1   0   0
 17   0   0   0   1   1
 18   1   1   0   0   0
 19   0   0   1   1   0
 20   1   0   0   0   1
 21   0   1   1   0   0
 22   1   0   0   1   0
 23   0   1   0   0   1
 24   0   0   1   1   0
 25   1   1   0   0   0
 26   0   0   1   0   1
 27   1   0   0   1   0
 28   0   1   1   0   0
 29   0   0   0   1   1
 30   0   1   1   0   0
 31   1   0   0   0   1
 ;

 sum{j in WORKERS} working[i,j] [*] :=
  1 2    4 2    7 2   10 2   13 2   16 2   19 2   22 2   25 2   28 2   31 2
  2 2    5 2    8 2   11 2   14 2   17 2   20 2   23 2   26 2   29 2
  3 2    6 2    9 2   12 2   15 2   18 2   21 2   24 2   27 2   30 2

;

 sum{i in DAYS} working[i,j] [*] :=
 1  12
 2  13
 3  12
 4  13
 5  12

;

 sum{i in SUNDAYS} working[i,j] [*] :=
 1  2
 2  2
 3  0
 4  3
 5  1

;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment