I have made a model to optimize FPL team selection and tried running for 3 rounds of the season. However I am getting an error for the data set "Pq" which is the set of players p allowed to play in position q and is indexed by the set Q.
The error message is " data element 'Pq' has already been set". I am also getting a processing failed error.
This set is present in the data file below.
Could someone please help? Thanks
.Mod File -
t//SETS
{string} P = ...; //Set of all players
{string} Q = ...; // Set of all positions
int Rounds = ...; // number of rounds
{string} Pq[Q]; // Set of all players p in P who are allowed to play in position q in Q
//{string} Qp[P]; // Set of all positions q in Q, where player p in P is allowed to play
range R = 1..Rounds;
// PARAMETERS
float points[P][R]; // points of player p in round R
float price[P][R]; // Price of player p in round R
float B = ...; // Budget
int C_min[Q]; // min Available spots of Postion Q
int C_max[Q]; // Max available spots of Position Q
int X[R] = ...; // Number of players whose scores count towards team score in each round
int T_total = ...; // max number of trades that can be used
int T[R] = ...; // trades per round
//DECISION VARIABLES
dvar boolean x[P][R]; // If player p is in team for round r
dvar boolean y[P][R]; // If the score of player p is included in round r
dvar boolean C[P][R]; // If player p is captain for round r
dvar boolean t_in[P][R]; // If player p is traded into the team for round r (r > 1)
dvar boolean t_out[P][R]; // If player p is traded out of the team for round r (r > 1)
dvar float+ b[R]; // Remaining budget at round r
//12.1 OBJECTIVE FN
maximize sum(p in P, r in R) (points[p][r] * (y[p][r] + 2*C[p][r]));
// CONSTRAINTS
subject to{
// 12.2 trade constraint per season
forall(p in P, r in R: r > 1)
t_in[p][r] <= T_total;
// 12.3 Limiting the number of trades per round
forall(r in R)
sum(p in P) t_in[p][r] <= T[r];
// 12.4 update of trades per round -> Q removed as each player can only play one postions
forall (p in P, r in R: r > 1)
x[p][r] - x[p][r-1] == t_in[p][r] - t_out[p][r];
// 12.5 Captain selection
forall (r in R)
sum(p in P) C[p][r] == 1;
//12.6 captain position selection -> removed Q as again, all positions assumed scoring
forall(r in R, p in P)
x[p][r] >= C[p][r];
// 12.7 Max available spots of each position
forall (r in R, q in Q)
sum(p in Pq[q]) x[p][r] <= C_max[q];
// 12.7a Min available spots of each position
forall (r in R, q in Q)
sum(p in Pq[q]) x[p][r] >= C_min[q];
//12.9 player has to be in scoring position for score to be counted
forall(p in P, r in R)
y[p][r] == x[p][r];
// 12.10 No of players whose scores count towards team score in each round
forall(r in R)
sum(p in P) y[p][r] == X[r];
// 12.11 Value of initial side + Remaining budget <= Budget
b[1] + sum(p in P) price[p][1] * x[p][1] == B;
// 12.12 remaining budget calculation
forall(r in R:r>1)
b[r] == b[r-1] + sum(p in P) price[p][r] * t_out[p][r] - sum(p in P) price[p][r] * t_in[p][r];
}
Data file -
//SETS
// set of players p
P = {"Trippier","White","Schar", "Mings","Van Dijk", "Shaw", "Saliba",
"Raya", "Alisson", "De Gea","Pope", "Sa",
"Haaland", "Watkins", "Wilson", "Jesus", "Mitrovic", "Firmino",
"De Bruyne","Salah", "Rashford", "Martinelli", "Almiron", "Trossard","Eze", "Son"};
// set of postions q
Q = {"GK", "DEF", "MID", "FWD"};
**// indexed by q, set of players p allowed to play in Q position
Pq = {{"Raya", "Alisson", "De Gea", "Pope", "Sa"},
{"Trippier", "White", "Schar", "Mings", "Van Dijk", "Shaw", "Saliba"},
{"De Bruyne", "Salah", "Rashford", "Martinelli", "Almiron", "Trossard", "Eze", "Son"},
{"Haaland", "Watkins", "Wilson", "Jesus", "Mitrovic", "Firmino"}
};**
Rounds = 3;
X = 11; // Number of players whose scores count towards team score in each round
T = 1; // trades per round
// PARAMETERS
// points scored by player p in P in round r in R
points = [
[7, 7, 6], [5, 1, 7], [15, 5, 0], [0, 2, 1], [1, 2, 1], [0, -1, 0], [8, -1, 14],
[1, 2, 1], [1, 2, 1], [1, 1, 3], [6, 10, 3], [2, 15, 3],
[13, -1, 6], [1, 11, 6], [6, 2, 6], [2, 19, 4], [13, -1, 6], [1, 0, 2],
[6, 14, 5], [12, 2, 8], [2, 1, 10], [8, 8, 6], [3, 3, 7], [1, 3, 8], [2, 6, 3], [5, 2, 3]
];
// The price of player p in P in round r in R
price = [
[5.0, 5.0, 5.0], [4.5, 4.5, 4.5], [4.5, 4.6, 4.6], [4.5, 4.5, 4.4], [6.5, 6.5, 6.5], [5.0, 5.0, 4.9], [4.5, 4.5, 4.5],
[4.5, 4.5, 4.5], [5.5, 5.5, 5.5], [5.0, 5.0, 4.9], [5.0, 5.0, 5.0], [5.0, 5.0, 5.0],
[11.5, 11.6, 11.7], [7.5, 7.4, 7.4], [7.5, 7.5, 7.5], [8.0, 8.0, 8.1], [6.5, 6.6, 6.6], [8.0, 8.0, 8.0],
[12.0, 12.0, 12.1], [13.0, 13.0, 13.0], [6.5, 6.5, 6.3], [6.0, 6.1, 6.3], [5.0, 5.0, 5.0], [6.5, 6.5, 6.5], [5.5, 5.5, 5.5], [12.0, 12.0, 11.9]
];
// 100 million
B = 100.0;
// min number of available spots (capacity) of position q in Q
C_min = {1,3,3,1};
C_max = {1,5,5,3};
// Total transfers over season.
T_total = 3;
I need this code to run so that i can proceed with attaching excel sheet data for all the players in the premier league.
I am doing this for my maste's thesis and any help would be appreciated!
First, when your values are defined in the .dat you should use ... in the .mod
For instance you should write
{string} Pq[Q]=...; // Set of all players p in P who are allowed to play in position q in Q
//{string} Qp[P]; // Set of all positions q in Q, where player p in P is allowed to play
range R = 1..Rounds;
// PARAMETERS
float points[P][R]=...; // points of player p in round R
float price[P][R]=...; // Price of player p in round R
float B = ...; // Budget
int C_min[Q]=...; // min Available spots of Postion Q
int C_max[Q]=...; // Max available spots of Position Q
int X[R] = ...; // Number of players whose scores count towards team score in each round
int T_total = ...; // max number of trades that can be used
int T[R] = ...; // trades per round
Second, you mix [ and { in your .dat
I would rather write
// set of players p
P = {"Trippier","White","Schar", "Mings","Van Dijk", "Shaw", "Saliba",
"Raya", "Alisson", "De Gea","Pope", "Sa",
"Haaland", "Watkins", "Wilson", "Jesus", "Mitrovic", "Firmino",
"De Bruyne","Salah", "Rashford", "Martinelli", "Almiron", "Trossard","Eze", "Son"};
// set of postions q
Q = {"GK", "DEF", "MID", "FWD"};
Pq = [{"Raya", "Alisson", "De Gea", "Pope", "Sa"},
{"Trippier", "White", "Schar", "Mings", "Van Dijk", "Shaw", "Saliba"},
{"De Bruyne", "Salah", "Rashford", "Martinelli", "Almiron", "Trossard", "Eze", "Son"},
{"Haaland", "Watkins", "Wilson", "Jesus", "Mitrovic", "Firmino"}
];
Rounds = 3;
X = [11]; // Number of players whose scores count towards team score in each round
T = [1]; // trades per round
// PARAMETERS
// points scored by player p in P in round r in R
points = [
[7, 7, 6], [5, 1, 7], [15, 5, 0], [0, 2, 1], [1, 2, 1], [0, -1, 0], [8, -1, 14],
[1, 2, 1], [1, 2, 1], [1, 1, 3], [6, 10, 3], [2, 15, 3],
[13, -1, 6], [1, 11, 6], [6, 2, 6], [2, 19, 4], [13, -1, 6], [1, 0, 2],
[6, 14, 5], [12, 2, 8], [2, 1, 10], [8, 8, 6], [3, 3, 7], [1, 3, 8], [2, 6, 3], [5, 2, 3]
];
// The price of player p in P in round r in R
price = [
[5.0, 5.0, 5.0], [4.5, 4.5, 4.5], [4.5, 4.6, 4.6], [4.5, 4.5, 4.4], [6.5, 6.5, 6.5], [5.0, 5.0, 4.9], [4.5, 4.5, 4.5],
[4.5, 4.5, 4.5], [5.5, 5.5, 5.5], [5.0, 5.0, 4.9], [5.0, 5.0, 5.0], [5.0, 5.0, 5.0],
[11.5, 11.6, 11.7], [7.5, 7.4, 7.4], [7.5, 7.5, 7.5], [8.0, 8.0, 8.1], [6.5, 6.6, 6.6], [8.0, 8.0, 8.0],
[12.0, 12.0, 12.1], [13.0, 13.0, 13.0], [6.5, 6.5, 6.3], [6.0, 6.1, 6.3], [5.0, 5.0, 5.0], [6.5, 6.5, 6.5], [5.5, 5.5, 5.5], [12.0, 12.0, 11.9]
];
// 100 million
B = 100.0;
// min number of available spots (capacity) of position q in Q
C_min = [1,3,3,1];
C_max = [1,5,5,3];
// Total transfers over season.
T_total = 3;