# read in the paramters
param ngames := read FILE as "2n " use 1;
param gametime := read FILE as "3n" skip 1 use 1;
param nsubperiods := read FILE as "2n" skip 2 use 1;
param nfieldplayers := read FILE as "2n" skip 3 use 1;
param nkeeper := read FILE as "2n" skip 4 use 1;
param ndefender := read FILE as "2n" skip 5 use 1;
param nmidfielder := read FILE as "2n" skip 6 use 1;
param nstriker := read FILE as "2n" skip 7 use 1;
param teamsize := read FILE as "2n" skip 8 use 1;
# set number of positions
param npositions := nkeeper + ndefender + nmidfielder + nstriker;
# read the set of players, positions, and minutes per game
set Player := { read FILE as "<2s>" skip 9 };
set Positions := { "K", "D", "M", "S" };
set C := { 1 .. npositions };
set Periods := { 1 .. nsubperiods };
# entry (i,j) is 1 <=> player i can play on position j
param pos[Player * Positions] := | "K", "D", "M", "S" |
|"Josh" | 0, 0, 1, 1 |
|"Simon" | 0, 0, 0, 1 |
|"Jordy" | 0, 0, 0, 1 |
|"Chris" | 0, 1, 1, 0 |
|"Andy" | 0, 0, 1, 0 |
|"Richie"| 0, 1, 1, 0 |
|"Tritto"| 0, 1, 0, 0 |
|"Guy" | 0, 1, 0, 0 |
|"Neil" | 0, 0, 1, 0 |
|"Justin"| 0, 0, 1, 0 |
|"Steve" | 0, 1, 0, 0 |
|"Cory" | 1, 0, 0, 0 |;
# function that return the number gameminutes per postion, e.g., 1 keeper => 1*gametime but 3 defender => 3*gametime
defnumb MinPerPos(p) := if p == "K" then nkeeper * gametime
else
if p == "D" then ndefender * gametime
else
if p == "M" then nmidfielder * gametime
else
nstriker * gametime
end
end
end;
defstrg GetPos(i) := if i <= nkeeper then "K"
else
if i <= nkeeper + ndefender then "D"
else
if i <= nkeeper + ndefender + nmidfielder then "M"
else
"S"
end
end
end;
# variable definition
var x[Player * C * Periods] binary;
var eplus[Player] real;
var eminus[Player] real;
# the model:
# 1.) objective function
# 2.) ensure that each position is used at each point in time
# 3.) ensure that each player plays on at most one position per time
# 4.) calculate the minutes over/below the average
minimize cost: sum in Player : gametime/nsubperiods * (eplus[r] + eminus[r]);
subto c1: forall * in C :
forall in Periods : sum in Player with pos[r,GetPos(i)] == 1: x[r,i,t] == 1;
subto c2: forall in Player :
forall in Periods : sum ** in C with pos[r,GetPos(i)] == 1: x[r,i,t] <= 1;
subto c3: forall in Player : sum ** in C * Periods with pos[r,GetPos(i)] == 1 : x[r,i,t]
- sum * in Player * C * Periods with pos[q,GetPos(i)] == 1 : (x[q,i,t]/card(Player)) == eplus[r] - eminus[r];