You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
schematic<- readRDS("schematic.rds")
draft_group<-schematic$draft_grouprules<-schematic$rulesdraft_group_id<-schematic$draft_group_idmax_points<-NULLmod<-ompr::MIPModel() |>ompr::add_variable(draftable_id[i],
i=draft_group$row_number,
type="binary") |>ompr::add_variable(competition_id[j],
j= unique(draft_group$competition_id),
type="binary") |>ompr::set_objective(
ompr::sum_over(draft_group$exp_fp[i] *draftable_id[i],
i=draft_group$row_number), "max"
) |># The sum of all player salaries must be less than salary cap max valueompr::add_constraint(
ompr::sum_over(draft_group$salary[i] *draftable_id[i],
i=draft_group$row_number) <=rules$salary_cap_max_value
)
# Optionally set an upper bound on the number of expected fantasy points# This is used to get multiple lineupsif (!is.null(max_points)) {
mod<-mod|>ompr::add_constraint(
ompr::sum_over(draft_group$exp_fp[i] *draftable_id[i],
i=draft_group$row_number) <=max_points
)
}
# Ensure at least two competitions are presentif (!is.na(rules$game_count_min_value)) {
mod<-mod|># force group binary variables to be 1 if item is in groupompr::add_constraint(
ompr::sum_over(
draftable_id[i],
i=draft_group$row_number[which(draft_group$competition_id==j)]
) -10000*competition_id[j] <=0,
j= unique(draft_group$competition_id)
) |># force at least one binary variable for item inclusion to be 1 for all items in group# if group binary is 1ompr::add_constraint(
competition_id[j] -10000*ompr::sum_over(
draftable_id[i],
i=draft_group$row_number[which(draft_group$competition_id==j)]
) <=0,
j= unique(draft_group$competition_id)
) |># force at least two competitionsompr::add_constraint(
ompr::sum_over(
competition_id[j],
j= unique(draft_group$competition_id)
) >=2
)
}
# Ensure player is selected max one timeif (rules$unique_players) {
mod<-mod|>ompr::add_constraint(
ompr::sum_over(draftable_id[i],
i=draft_group$row_number[which(draft_group$player_id==player_id)]) <=1,
player_id=draft_group$player_id
)
}
# Set player constraints for NBA classicif (rules$game_type_id==70) {
# Ensure at least 1 player in each positionmod<-mod|>ompr::add_constraint(
ompr::sum_over(
draftable_id[i],
i=draft_group$row_number[which(draft_group$position==position)]
) >=1,
position= unique(draft_group$position)
)
}
ompr::solve_model(mod, ompr.roi::with_ROI(solver="symphony"))
ROI.plugin.symphony
causes R to crash sometimes.Here is a reprex:
schematic.rds.zip
The text was updated successfully, but these errors were encountered: