examples/shiftcover.mod
changeset 1 c445c931472f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/examples/shiftcover.mod	Mon Dec 06 13:09:21 2010 +0100
     1.3 @@ -0,0 +1,244 @@
     1.4 +/* File: shiftcover.mod */
     1.5 +
     1.6 +/* WORKFORCE SHIFT COVERAGE assignment problem */
     1.7 +
     1.8 +/* Written by Larry D'Agostino <larrydag -at- sbcglobal -dot- com>
     1.9 +     
    1.10 +     Maximize Productivity with Industrial Engineer and Operations Research Tools
    1.11 +     http://industrialengineertools.blogspot.com
    1.12 +
    1.13 +
    1.14 +/* The WORKFORCE SHIFT COVERAGE is an assigment problem that determines
    1.15 +   the schedule of crew given available time and shifts.  
    1.16 +   
    1.17 +   The objective is to cover the available time given hourly demand with the minimum 
    1.18 +    number of crew members.
    1.19 +   
    1.20 +    This is a set covering problem that is very common among finding crew
    1.21 +     and shift allocations.  Notice in the data section the workforce shift allocation
    1.22 +     per day of the week.*/
    1.23 +
    1.24 +
    1.25 +/* ----- Model PARAMTERS and SETS -----*/
    1.26 +
    1.27 +param numhrs;
    1.28 +/* number of hours of operations in a given day */
    1.29 +
    1.30 +param dys;
    1.31 +/* number of days in a week */
    1.32 +
    1.33 +set S;
    1.34 +/* set of crew shifts */
    1.35 +
    1.36 +set H := 1..numhrs;
    1.37 +/* set of hours of a day*/
    1.38 +
    1.39 +set D;
    1.40 +/* set of days of a week*/
    1.41 +
    1.42 +param dmnd{h in H, d in D};
    1.43 +/* demand for crew members given h hour and d day */
    1.44 +
    1.45 +param shifts{d in D, h in H, s in S};
    1.46 +/* shifts to assign to crew members given d day, h hour, and s shift schedule
    1.47 +
    1.48 +/*----- Model VARIABLES -----*/
    1.49 +
    1.50 +var crew{s in S}, integer, >=0;
    1.51 +/*  number of crew assigned to shift S */
    1.52 +
    1.53 +
    1.54 +/*----- Model CONSTRAINTS -----*/
    1.55 +
    1.56 +s.t. Coverage{h in H, d in D}: sum{s in S} crew[s]*shifts[d,h,s] >= dmnd[h,d];
    1.57 +/* number of crew to cover with a shift  given hourly demand and day */
    1.58 +
    1.59 +
    1.60 +/*----- Model OBJECTIVE -----*/
    1.61 +
    1.62 +minimize obj: sum{s in S} crew[s];
    1.63 +/* minimize number of crew to cover demand*/
    1.64 +
    1.65 +solve;
    1.66 +display crew;
    1.67 +
    1.68 +printf "\n";
    1.69 +printf "Total Crew: %3d\n\n", sum{s in S} crew[s];
    1.70 +
    1.71 +
    1.72 +
    1.73 +printf "\n\n";
    1.74 +printf "Weekly Crew Schedule\n\n";
    1.75 +printf "Hour ";
    1.76 +printf{d in D} "  %s  ", d;
    1.77 +printf "\n";
    1.78 +for {h in H} {
    1.79 +  printf " %2s  ",h;
    1.80 +  printf{d in D} " %3d   ", sum{s in S} crew[s]*shifts[d,h,s];
    1.81 +  printf "\n";
    1.82 +}
    1.83 +printf"\n";
    1.84 +
    1.85 +
    1.86 +
    1.87 +data;
    1.88 +
    1.89 +param numhrs := 16;
    1.90 +
    1.91 +set D := SUN, MON, TUE, WED, THU, FRI, SAT;
    1.92 +
    1.93 +set S := Sh1, Sh2, Sh3, Sh4, Sh5, Sh6, Sh7, Sh8, Sh9;
    1.94 +
    1.95 +param dmnd :   SUN  MON     TUE     WED     THU     FRI     SAT :=
    1.96 +1               0   3       3       4       3       2       0
    1.97 +2               0   14      14      16      14      12      12
    1.98 +3               0   24      24      27      24      20      15
    1.99 +4               0   28      28      32      28      23      15
   1.100 +5               0   33      33      37      33      24      16
   1.101 +6               0   34      34      38      34      24      15
   1.102 +7               0   35      35      39      35      25      11
   1.103 +8               0   35      35      40      35      27      0
   1.104 +9               0   34      34      39      34      25      0
   1.105 +10              0   31      31      35      31      24      0
   1.106 +11              2   24      24      27      24      25      0
   1.107 +12              3   19      19      21      19      21      0
   1.108 +13              2   24      24      27      24      13      0
   1.109 +14              2   16      16      18      16      0       0
   1.110 +15              0   7       7       7       7       0       0
   1.111 +16              0   5       5       5       5       0       0;
   1.112 +
   1.113 +
   1.114 +param shifts := 
   1.115 +['SUN',*,*]:
   1.116 +                   Sh1  Sh2  Sh3  Sh4  Sh5  Sh6  Sh7  Sh8  Sh9 :=
   1.117 +1                   0    0    0    0    0    0    0    0    0
   1.118 +2                   0    0    0    0    0    0    0    0    0
   1.119 +3                   0    0    0    0    0    0    0    0    0
   1.120 +4                   0    0    0    0    0    0    0    0    0
   1.121 +5                   0    0    0    0    0    0    0    0    0
   1.122 +6                   0    0    0    0    0    0    0    0    0
   1.123 +7                   0    0    0    0    0    0    0    0    0
   1.124 +8                   0    0    0    0    0    0    0    0    0
   1.125 +9                   0    0    0    0    0    0    0    0    0
   1.126 +10                  0    0    0    0    0    0    0    0    0
   1.127 +11                  0    0    0    0    0    0    0    0    1
   1.128 +12                  0    0    0    0    0    0    0    0    1
   1.129 +13                  0    0    0    0    0    0    0    0    1
   1.130 +14                  0    0    0    0    0    0    0    0    1
   1.131 +15                  0    0    0    0    0    0    0    0    0
   1.132 +16                  0    0    0    0    0    0    0    0    0
   1.133 +
   1.134 +
   1.135 +['MON',*,*]:
   1.136 +                   Sh1  Sh2  Sh3  Sh4  Sh5  Sh6  Sh7  Sh8  Sh9 :=
   1.137 +1                   1    0    0    0    0    0    0    0    0
   1.138 +2                   1    1    0    0    0    0    0    0    0
   1.139 +3                   1    1    1    0    0    0    0    0    0
   1.140 +4                   1    1    1    1    0    0    0    0    0
   1.141 +5                   0    1    1    1    1    0    0    0    0
   1.142 +6                   1    0    1    1    1    1    0    0    1
   1.143 +7                   1    1    0    1    1    1    1    0    1
   1.144 +8                   1    1    1    0    1    1    1    1    1
   1.145 +9                   1    1    1    1    0    1    1    1    1
   1.146 +10                  0    1    1    1    1    0    1    1    1
   1.147 +11                  0    0    1    1    1    1    0    1    0
   1.148 +12                  0    0    0    1    1    1    1    0    1
   1.149 +13                  0    0    0    0    1    1    1    1    1
   1.150 +14                  0    0    0    0    0    1    1    1    1
   1.151 +15                  0    0    0    0    0    0    1    1    1
   1.152 +16                  0    0    0    0    0    0    0    1    1
   1.153 +
   1.154 +['TUE',*,*]:
   1.155 +                   Sh1  Sh2  Sh3  Sh4  Sh5  Sh6  Sh7  Sh8  Sh9 :=
   1.156 +1                   1    0    0    0    0    0    0    0    0
   1.157 +2                   1    1    0    0    0    0    0    0    0
   1.158 +3                   1    1    1    0    0    0    0    0    0
   1.159 +4                   1    1    1    1    0    0    0    0    0
   1.160 +5                   0    1    1    1    1    0    0    0    0
   1.161 +6                   1    0    1    1    1    1    0    0    1
   1.162 +7                   1    1    0    1    1    1    1    0    1
   1.163 +8                   1    1    1    0    1    1    1    1    1
   1.164 +9                   1    1    1    1    0    1    1    1    1
   1.165 +10                  0    1    1    1    1    0    1    1    1
   1.166 +11                  0    0    1    1    1    1    0    1    0
   1.167 +12                  0    0    0    1    1    1    1    0    1
   1.168 +13                  0    0    0    0    1    1    1    1    1
   1.169 +14                  0    0    0    0    0    1    1    1    1
   1.170 +15                  0    0    0    0    0    0    1    1    1
   1.171 +16                  0    0    0    0    0    0    0    1    1
   1.172 +
   1.173 +['WED',*,*]:
   1.174 +                   Sh1  Sh2  Sh3  Sh4  Sh5  Sh6  Sh7  Sh8  Sh9 :=
   1.175 +1                   1    0    0    0    0    0    0    0    0
   1.176 +2                   1    1    0    0    0    0    0    0    0
   1.177 +3                   1    1    1    0    0    0    0    0    0
   1.178 +4                   1    1    1    1    0    0    0    0    0
   1.179 +5                   0    1    1    1    1    0    0    0    0
   1.180 +6                   1    0    1    1    1    1    0    0    1
   1.181 +7                   1    1    0    1    1    1    1    0    1
   1.182 +8                   1    1    1    0    1    1    1    1    1
   1.183 +9                   1    1    1    1    0    1    1    1    1
   1.184 +10                  0    1    1    1    1    0    1    1    1
   1.185 +11                  0    0    1    1    1    1    0    1    0
   1.186 +12                  0    0    0    1    1    1    1    0    1
   1.187 +13                  0    0    0    0    1    1    1    1    1
   1.188 +14                  0    0    0    0    0    1    1    1    1
   1.189 +15                  0    0    0    0    0    0    1    1    1
   1.190 +16                  0    0    0    0    0    0    0    1    1
   1.191 +
   1.192 +['THU',*,*]:
   1.193 +                   Sh1  Sh2  Sh3  Sh4  Sh5  Sh6  Sh7  Sh8  Sh9 :=
   1.194 +1                   1    0    0    0    0    0    0    0    0
   1.195 +2                   1    1    0    0    0    0    0    0    0
   1.196 +3                   1    1    1    0    0    0    0    0    0
   1.197 +4                   1    1    1    1    0    0    0    0    0
   1.198 +5                   0    1    1    1    1    0    0    0    0
   1.199 +6                   1    0    1    1    1    1    0    0    0
   1.200 +7                   1    1    0    1    1    1    1    0    0
   1.201 +8                   1    1    1    0    1    1    1    1    0
   1.202 +9                   1    1    1    1    0    1    1    1    0
   1.203 +10                  0    1    1    1    1    0    1    1    0
   1.204 +11                  0    0    1    1    1    1    0    1    0
   1.205 +12                  0    0    0    1    1    1    1    0    0
   1.206 +13                  0    0    0    0    1    1    1    1    0
   1.207 +14                  0    0    0    0    0    1    1    1    0
   1.208 +15                  0    0    0    0    0    0    1    1    0
   1.209 +16                  0    0    0    0    0    0    0    1    0
   1.210 +
   1.211 +['FRI',*,*]:
   1.212 +                   Sh1  Sh2  Sh3  Sh4  Sh5  Sh6  Sh7  Sh8  Sh9 :=
   1.213 +1                   1    0    0    0    0    0    0    0    0
   1.214 +2                   1    1    0    0    0    0    0    0    0
   1.215 +3                   1    1    1    0    0    0    0    0    0
   1.216 +4                   1    1    1    1    0    0    0    0    0
   1.217 +5                   0    1    1    1    1    0    0    0    0
   1.218 +6                   1    0    1    1    1    1    0    0    0
   1.219 +7                   1    1    0    1    1    1    1    0    0
   1.220 +8                   1    1    1    0    1    1    1    1    0
   1.221 +9                   1    1    1    1    0    1    1    1    0
   1.222 +10                  0    1    1    1    1    0    1    1    0
   1.223 +11                  0    0    1    1    1    1    0    1    0
   1.224 +12                  0    0    0    1    1    1    1    0    0
   1.225 +13                  0    0    0    0    1    1    1    1    0
   1.226 +14                  0    0    0    0    0    1    1    1    0
   1.227 +15                  0    0    0    0    0    0    1    1    0
   1.228 +16                  0    0    0    0    0    0    0    1    0
   1.229 +
   1.230 +['SAT',*,*]:
   1.231 +                   Sh1  Sh2  Sh3  Sh4  Sh5  Sh6  Sh7  Sh8  Sh9 :=
   1.232 +1                   0    0    0    0    0    0    0    0    0
   1.233 +2                   0    0    0    0    0    0    0    0    1
   1.234 +3                   0    0    0    0    0    0    0    0    1
   1.235 +4                   0    0    0    0    0    0    0    0    1
   1.236 +5                   0    0    0    0    0    0    0    0    1
   1.237 +6                   0    0    0    0    0    0    0    0    1
   1.238 +7                   0    0    0    0    0    0    0    0    1
   1.239 +8                   0    0    0    0    0    0    0    0    0
   1.240 +9                   0    0    0    0    0    0    0    0    0
   1.241 +10                  0    0    0    0    0    0    0    0    0
   1.242 +11                  0    0    0    0    0    0    0    0    0
   1.243 +12                  0    0    0    0    0    0    0    0    0
   1.244 +13                  0    0    0    0    0    0    0    0    0
   1.245 +14                  0    0    0    0    0    0    0    0    0
   1.246 +15                  0    0    0    0    0    0    0    0    0
   1.247 +16                  0    0    0    0    0    0    0    0    0;