# timing parameters param gametime := 20; param nsubperiods := 6; # formation param nkeeper := 1; param ndefender := 2; param nmidfielder := 3; param nstriker := 1; # set number of positions param npositions := nkeeper + ndefender + nmidfielder + nstriker; # sets of players, positions, and minutes per game set Player := { "Josh", "Simon", "Jordy", "Chris", "Andy", "Richie", "Tritto", "Guy", "Neil", "Justin", "Steve", "Cory" }; set Classes := { "K", "D", "M", "S" }; set Positions := { 1 .. npositions }; set Periods := { 1 .. nsubperiods }; # entry (i,j) is 1 <=> player i can play on position j param pos[Player * Classes] := | "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 |; defstrg GetClass(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 * Positions * 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 Positions : forall in Periods : sum in Player with pos[r,GetClass(i)] == 1: x[r,i,t] == 1; subto c2: forall in Player : forall in Periods : sum in Positions with pos[r,GetClass(i)] == 1: x[r,i,t] <= 1; subto c3: forall in Player : sum in Positions * Periods with pos[r,GetClass(i)] == 1 : x[r,i,t] - sum in Player * Positions * Periods with pos[q,GetClass(i)] == 1 : (x[q,i,t]/card(Player)) == eplus[r] - eminus[r];