DimaKudosh / pydfs-lineup-optimizer

Daily Fantasy Sports lineup optimzer for all popular daily fantasy sports sites
MIT License
418 stars 157 forks source link

Greedy Heuristic #75

Closed austinjohnson closed 5 years ago

austinjohnson commented 5 years ago

From the docs I have read that the CBC solver uses a greedy heuristic by default however, when I run this code it is not choosing players using a greedy approach. Do you have any insight on this?

import pulp
from pulp import *
from pulp.solvers import PULP_CBC_CMD
from pydfs_lineup_optimizer import get_optimizer, Site, Sport,CSVLineupExporter
from pydfs_lineup_optimizer.solvers.pulp_solver import PuLPSolver
import time

start_time = time.time()
class CustomPuLPSolver(PuLPSolver):
    LP_SOLVER = PULP_CBC_CMD(threads=8)
optimizer = get_optimizer(Site.FANDUEL, Sport.BASEBALL, solver=CustomPuLPSolver)
optimizer.load_players_from_csv("/Users/austi/Desktop/MLB/PLAYERS_LIST.csv")
optimizer.restrict_positions_for_opposing_team(['P'], ['1B','C','2B','3B','SS','OF','UTIL'])
optimizer.set_spacing_for_positions(['SS','C','1B','3B','OF','2B'], 4)
optimizer.set_team_stacking([4,3])
optimizer.set_max_repeating_players(6)
lineups = list(optimizer.optimize(n=150))
for lineup in lineups:
    print(lineup)
exporter = CSVLineupExporter(lineups)
exporter.export('MLB_result.csv')
print(round(((time.time() - start_time)/60)), "minute run time")
austinjohnson commented 5 years ago

Capture1

austinjohnson commented 5 years ago

This is my player list and I was under the assumption it should choose Verlander first every time and construct all my lineups around him if it were using a greedy heuristic.

DimaKudosh commented 5 years ago

I'm not sure about implementation details of this algorithm because It was implemented in third-party library. I think some lineups hasn't top player because of set_max_repeating_players rule that removes repeated players combinations on each iteration. For example I ran optimization for 100 lineups and got 96 lineups with top player with this rule and 100 without.