I'm following this guide on LPSolve, which I've used in the past, but I'm now getting the result "Error: no feasible solution found"
my data.table looks like so:
Position Name...ID Name ID Roster.Position Salary Game.Info TeamAbbrev AvgPointsPerGame
1 G Ben Bishop (11402606) ben bishop 11402606 G 8400 ARI@DAL 10/04/2018 08:30PM ET DAL 4.40
2 G Anton Khudobin (11402601) anton khudobin 11402601 G 8200 ARI@DAL 10/04/2018 08:30PM ET DAL 4.36
3 G Connor Hellebuyck (11402708) connor hellebuyck 11402708 G 7700 WPG@STL 10/04/2018 08:00PM ET WPG 5.42
4 C Tyler Seguin (11402648) tyler seguin 11402648 C/UTIL 7700 ARI@DAL 10/04/2018 08:30PM ET DAL 4.75
5 G Laurent Brossoit (11402681) laurent brossoit 11402681 G 7500 WPG@STL 10/04/2018 08:00PM ET WPG 2.26
6 G Eric Comrie (11402730) eric comrie 11402730 G 7500 WPG@STL 10/04/2018 08:00PM ET WPG 2.47
From there I modified to
New_proj$Position <- as.factor(New_proj$Position)
New_proj$Salary <-as.numeric(New_proj$Salary)
#### Prepare constraint matrix of zeros #####
A <- matrix(0, nrow = 6, ncol = nrow(New_proj))
#Designate the positions that are equivalent to each other when generating the optimal lineup
#There are 7 distinct positions and 1 constraint in which salary is < 50,000
#I.e. A player with the position 1B/2B can fill the 1B or the 2B position
#Add a "1" to all position that can fill that position slot
#Set C parameters
j<-1
i<-1
for (i in 1:nrow(New_proj)){
if (New_proj$Position[i]=="C" )
A[j,i]<-1
}
#W
j<-2
i<-1
for (i in 1:nrow(New_proj)){
if (New_proj$Position[i]=="LW" ||
New_proj$Position[i]=="RW" )
A[j,i]<-1
}
#D
j<-3
i<-1
for (i in 1:nrow(New_proj)){
if (New_proj$Position[i]=="D" )
A[j,i]<-1
}
#G
j<-4
i<-1
for (i in 1:nrow(New_proj)){
if (New_proj$Position[i]=="G" )
A[j,i]<-1
}
#U
j<-5
i<-1
for (i in 1:nrow(New_proj)){
if (New_proj$Position[i]=="C" ||
New_proj$Position[i]=="LW" ||
New_proj$Position[i]== "RW"||
New_proj$Position[i]=="D" )
A[j,i]<-1
}
A[6, ] <- New_proj$Salary # salary <= 50000
# Prepare input for LP solver
objective.in <- New_proj$AvgPointsPerGame
const.mat <- A[]
const.dir <- c("==", "==", "==", "==","==", "<=")
const.rhs <- c(2, 3, 2, 1,1, 50000)
# Generate optimal lineup with lp solve
require(lpSolve)
sol <- lp(direction = "max", objective.in, # maximize objective function
const.mat, const.dir, const.rhs # constraints
) # use binary variables only
### View the solution
inds <- which(sol$solution == 1)
Error: object 'dataset' not found
sol
Error: no feasible solution found
I can't tell where the difference is. I've also followed another tutorial which gives the same "no feasible solution" but I can't for the life of me figure out why. That suggests that there is some disconnect between what I'm asking it and what's in the matrix but I can't see where.
Any thoughts welcome.