BenBrostoff / draftfast

A tool to automate and optimize DraftKings and FanDuel lineup construction.
278 stars 113 forks source link

Get the next best solution? #138

Closed joecaraccio closed 4 years ago

joecaraccio commented 5 years ago

Is there anyway to generate multiple solutions? I can't tell if I am missing something in the documentation but say picking a particular player stack.. and I want to see the top 5 highest scores, not just the most optimal

Not sure if I am missing something in the documentation, or if there is a way to do it with OR Tools..

This is all incredible!

sharkiteuthis commented 5 years ago

Yes, we used to have this documented but it got lost when we refactored everything, I think.

You can run the optimizer as many times as you want and give it the previously-generated lineups so that it will return the best lineup not already generated. It looks like this:

    roster = run(
        rule_set=rules.DK_NFL_RULE_SET,
        player_pool=players,
        verbose=True
    )
    second_roster = run(
        rule_set=rules.DK_NFL_RULE_SET,
        player_pool=players,
        optimizer_settings=OptimizerSettings(
            existing_rosters=[roster],
        ),
        verbose=True
)

@BenBrostoff leaving this open because we should update the documentation

sharkiteuthis commented 5 years ago

@joecaraccio There is also a run_multi function that can be used like this:

N = 10
rosters, _ = run_multi(
        iterations=N,
        rule_set=rules.DK_NFL_RULE_SET,
        player_pool=players,
)

It's intended to be used with lineup constraints and player groups but without any other arguments it will just return the N best lineups.

dfshead commented 4 years ago
roster = run(
    rule_set=rules.DK_NFL_RULE_SET,
    player_pool=players,
    verbose=True
)
second_roster = run(
    rule_set=rules.DK_NFL_RULE_SET,
    player_pool=players,
    optimizer_settings=OptimizerSettings(
        existing_rosters=[roster],
    ),
    verbose=True

)

I'm also trying to use this. Is this the exact formatting? I'm getting tons of indent errors.

Could you show me an example using a salary csv?

dfshead commented 4 years ago
from draftfast import rules
>>> from draftfast.optimize import run
>>> from draftfast.csv_parse import salary_download
>>> from draftfast.rules import FAN_DUEL
>>> from draftfast.lineup_constraints import LineupConstraints
>>>
>>> player_pool = salary_download.generate_players_from_csvs(
...   salary_file_location='C:/Data/FDSalaries.csv',
...   game=FAN_DUEL,
...   ruleset=rules.FD_NBA_RULE_SET,
... )
>>>
>>> roster = run(
...   rule_set=rules.FD_NBA_RULE_SET,
...   player_pool=player_pool,
...   verbose=True,
... )
Optimal roster for: NBA
+----------+-----------------+------+---------+--------+--------------------+----------+--------+
| Position | Player          | Team | Matchup | Salary |         Projection | vs. Avg. | Locked |
+----------+-----------------+------+---------+--------+--------------------+----------+--------+
| PG       | Ben Simmons     | PHI  | PHI@ORL |  7,600 |               28.5 |     0.00 |        |
| PG       | D.J. Augustin   | ORL  | PHI@ORL |  4,500 |  23.09382685908565 |     0.00 |        |
| SG       | Zach LaVine     | CHI  | CHI@TOR |  7,100 |               31.5 |     0.00 |        |
| SG       | Khris Middleton | MIL  | MIL@WAS |  6,800 |               30.0 |     0.00 |        |
| SF       | Tobias Harris   | PHI  | PHI@ORL |  7,300 |               28.5 |     0.00 |        |
| SF       | Otto Porter     | CHI  | CHI@TOR |  6,600 |               23.5 |     0.00 |        |
| PF       | Thaddeus Young  | CHI  | CHI@TOR |  7,400 |               29.0 |     0.00 |        |
| PF       | Aaron Gordon    | ORL  | PHI@ORL |  7,000 |               28.0 |     0.00 |        |
| C        | Brook Lopez     | MIL  | MIL@WAS |  5,400 | 24.644443841628085 |     0.00 |        |
+----------+-----------------+------+---------+--------+--------------------+----------+--------+

Projected Score: 246.74          Cost: $59,700
>>>
>>> second_roster = run(
...     rule_set=rules.FD_NBA_RULE_SET,
...     player_pool=player_pool,
...     optimizer_settings=OptimizerSettings(
...             existing_rosters=[roster],
...     ),
...     verbose=True
... )
Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
NameError: name 'OptimizerSettings' is not defined
>>>

This is what I'm getting.

dfshead commented 4 years ago

@joecaraccio There is also a run_multi function that can be used like this:

N = 10
rosters, _ = run_multi(
        iterations=N,
        rule_set=rules.DK_NFL_RULE_SET,
        player_pool=players,
)

It's intended to be used with lineup constraints and player groups but without any other arguments it will just return the N best lineups.

Found the issue.

verbose=True should be in the function.

Very happy. Thanks for the hard work guys.

BenBrostoff commented 4 years ago

Closing this, seems fixed @dfshead