Gurobi / modeling-examples

Gurobi modeling examples
https://gurobi.github.io/modeling-examples/
Apache License 2.0
615 stars 272 forks source link

Multiple Lineups from Pool fantasy_basketball_1_2 #13

Closed Owen-Slater closed 1 year ago

Owen-Slater commented 1 year ago

Hello, This is a really great and detailed example of how to use gurobi to solve fantasy sports problems. I actually play draftkings , and have been trying to teach myself how to optimize using gurobi opti... Anyway, I have been attempting to use PoolSolutions to return the other solutions... example:

m.setObjective(obj, sense= GRB.MAXIMIZE)
m.setParam(GRB.Param.PoolSolutions, 500) ## finds 500 best lineups
m.setParam(GRB.Param.PoolSearchMode, 2) ## makes sure these are the best solutions (2)
m.update()

m.optimize()
nSolutions = m.SolCount
print('Number of solutions found: ' + str(nSolutions))
for e in range(nSolutions):
    m.setParam(GRB.Param.SolutionNumber, e)

    for v in m.getVars():
        if v.xN ==1:   ### Help I'm stuck

..... How would I modify your colab notebook to print and save all 500 lineups. I have tried for hours, but just don't have a deep enough understanding of the syntax with gurobi and also creating the correct df calls for this. This isn't an issue, as much as a question . Thanks so much in advance, as I know there's no benefit to you helping me. Again, great work and thank you for sharing on github.

yurchisin commented 1 year ago

Thanks for the positive feedback. The Xn attribute is for the model, try m.Xn instead of v.Xn