长期倾听者,第一次向S.O打电话...... 我正在提出一个之前被问过的问题,但是我不认为我聪明到足以解释如何实现这个解决方案,对此我感到抱歉。以下是我发现的问题链接:Constraints in R Multiple Integer Linear Programming
我正在最大化我的预测梦幻得分(FPTS_PREDICT_RF),在保持50000薪资上限的情况下,并且最小化我想出的“风险”计算。
现在,问题出在“flex”位置上。团队需要由9个位置组成, 1 QB 2 RB 3 WR 1 TE 1 DEF 1 FLEX
Flex可以是RB、WR或TE。
那么,我们可以有:
1 QB
2-3 RB
3-4 WR
1-2 TE
1 DEF
我试图实现#RB + #WR + #TE ==7的约束条件。
以下是相关代码:
library(Rglpk)
# number of variables
num.players <- length(final$PLAYER)
# objective:
obj <- final$FPTS_PREDICT_RF
# the vars are represented as booleans
var.types <- rep("B", num.players)
# the constraints
matrix <- rbind(as.numeric(final$position == "QB"), # num QB
as.numeric(final$position == "RB"), # num RB
as.numeric(final$position == "WR"), # num WR
as.numeric(final$position == "TE"), # num TE
as.numeric(final$position == "DEF"),# num DEF
diag(final$riskNormalized), # player's risk
final$Salary) # total cost
direction <- c("==",
"<=",
"<=",
"<=",
"==",
rep("<=", num.players),
"<=")
rhs <- c(1, # Quartbacks
3, # Running Backs
2, # Wide Receivers
1, # Tight Ends
1, # Defense
rep(10, num.players), #HERE, you need to enter a number that indicates how
#risk you are willing to be, 1 being low risk,
# 10 being high risk. 10 is max.
50000) # By default, you get 50K to spend, so leave this number alone.
sol <- Rglpk_solve_LP(obj = obj, mat = matrix, dir = direction, rhs = rhs,
types = var.types, max = TRUE)
sol #Projected Fantasy Points
能否有人帮我实现这个约束条件? 非常感谢任何帮助!
编辑:数据集“final”的链接是csv格式: https://www.dropbox.com/s/qp35wc4d380hep1/final.csv?dl=0
附加问题:对于你们中的任何一位幻想足球爱好者,我正在直接从球员历史幻想得分的标准差计算我的“风险”因素,并将此数字归一化到[0,10]的支持上。您能想到更好的方法来计算给定球员的风险吗?
#RB> = 2
,#RB <= 3
,#WR> = 3
,#WR <= 4
,#TE> = 1
,#TE <= 2
添加单独的约束条件,然后#RB +#WR +#TE == 7
。 - josliber