Search code examples
pythoncplexgreedy

CPLEX and epgap


I have some code that generates 150 different lineups. I want to make cplex use as close to a greedy solution as possible. I read that if you make the epgap large enough it will mimic that of a greedy approach. Is this true? and if so what should I set the epgap to?

import pulp
from pulp import *
from pulp.solvers import CPLEX_PY
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.CPLEX_PY(msg=0,epgap=.1)
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])
optimizer.set_max_repeating_players(7)
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)), "minutes run time")

Solution

  • No, this is not true (where did you read that?). Setting parameter epgap to N tells CPLEX to stop as soon as the relative difference between the best known feasible solution and the lower bound (for minimization problems) on an optimal solution falls below N.

    This does not say anything about how the best known feasible solution was found. It could have come from any heuristic or even from an integral node.

    If you explicitly need a greedy solution then you have two options:

    1. Compute that greedy solution yourself
    2. Modify your model so that the only feasible solution is the greedy solution.