我有一些代码可以生成150个不同的阵容。我想使cplex尽可能接近贪婪的解决方案。我读到,如果您使epgap足够大,它将模仿贪婪的方法。这是真的?如果可以,我应该将epgap设置为什么?
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")
答案 0 :(得分:2)
不,这是不正确的(您在哪里读的?)。将参数epgap
设置为N会告诉CPLEX,只要最可行的解决方案与最优解决方案的下限(用于最小化问题)之间的相对差降到N以下,就会停止。
这没有说明如何找到最知名的可行解决方案。它可能来自任何启发式甚至来自完整的节点。
如果您明确需要贪婪的解决方案,则有两种选择: