def penSolve(num_process=1,time_limit=None,solver=0): sol = ScheduleNPB.Solve() leagues = ['p','s'] initial_position = dict() for league in leagues: status, obj, e = sol.SolveWithReluxation("r_pre",league=league,threads=num_process,timeLimit=time_limit,solverName=solver) if status==1: preserve(e,'pen_r_pre_'+league) e = Load('pen_r_pre_'+league+'.pkl') initial_position[league] = sol.FinalPosition(e, league, 'r_pre') position_for_inter = sol.Merge(initial_position['p'],initial_position['s']) status, obj, e = sol.SolveWithReluxation('i', initialPosition = position_for_inter, threads=num_process,timeLimit=time_limit,solverName=solver) if status==1: preserve(e,'pen_i_ps') e = Load('pen_i_ps.pkl') initial_position['r'] = sol.FinalPosition(e, None, 'i') for league in leagues: status, obj, e = sol.SolveWithReluxation("r_post",league=league,initialPosition=initial_position['r'],threads=num_process,timeLimit=time_limit,solverName=solver) if status==1: preserve(e,'pen_r_post_'+league)
def main(num_process=1, options=[], time_limit=None, solver=0, ini_pos=False): output = ScheduleNPB.Output() leagues = ['p', 's'] Solve(num_process, options, time_limit=time_limit, solver=solver, option=options, ini_pos=ini_pos) for league in leagues: filename = 'r_pre_' + league + '.pkl' e = Load(filename) output.getSchedule(e, 'r_pre', league=league) e = Load('i_ps.pkl') output.getSchedule(e, 'i') for league in leagues: filename = 'r_post_' + league + '.pkl' e = Load(filename) output.getSchedule(e, 'r_post', league=league) output.MergeRegularSchedule() output.checkAnswer() dists = output.TotalDists() for team in range(12): print(dists[team])
def main(): output = Output() D = output.D leagues = ['s','p'] for league in leagues: filename = 'r_pre_'+league+'.pkl' e = Load(filename) output.getSchedule(e, 'r_pre', league=league) e = Load('i_ps.pkl') output.getSchedule(e, 'i') for league in leagues: filename= 'r_post_'+league+'.pkl' e = Load(filename) output.getSchedule(e, 'r_post', league=league) output.MergeRegularSchedule() output.getWholeSchedule() data = convert('r_post', 'p', output) dist = calcDist(data,'r_post', 'p', output) print(dist) data = two_Opt.two_Opt(data) data = convert('r_post', 's', output) dist = calcDist(data,'r_post', 's', output) print(dist) data = two_Opt.two_Opt(data) dist = calcDist(data,'r_post', 's', output) print(dist)
def main(distance=False, tables=False, pen=''): output = ScheduleNPB.Output() leagues = ['s', 'p'] for league in leagues: filename = pen + 'r_pre_' + league + '.pkl' e = Load(filename) output.getSchedule(e, 'r_pre', league=league) e = Load(pen + 'i_ps.pkl') output.getSchedule(e, 'i') for league in leagues: filename = pen + 'r_post_' + league + '.pkl' e = Load(filename) output.getSchedule(e, 'r_post', league=league) output.getWholeSchedule() output.MergeRegularSchedule() if distance: dists = output.TotalDists() for team in range(12): print(dists[team]) if tables: output.GameTables() output.checkAnswer()
def Solve(num_process=1,options=[],time_limit=None,solver=0): """ This is a function of computing schedules with minimized traveling distance. Solutions are saved as .pkl files. Save directory path is "./result/pkl/" Parameters ---------- num_process : int Number of threads. Default : 1 options : list Solve options Default : [] time_limit : int Maximum seconds for solver Default : None solver : int Unique number of solver you use 0 : CBC solver (default) 1 : CPLEX Returns ------- None """ initial_position = dict() sol = ScheduleNPB.Solve() leagues = ['p', 's'] for league in leagues: status, obj, e = sol.Solve("r_pre",league=league,threads=num_process,timeLimit=time_limit,solverName=solver,option=options,initialSolution=True) if status==1: preserve(e,'r_pre_'+league) e = Load('r_pre_'+league+'.pkl') initial_position[league] = sol.FinalPosition(e, league, 'r_pre') position_for_inter = sol.Merge(initial_position['p'],initial_position['s']) status, obj, e = sol.Solve('i', initialPosition = position_for_inter, threads=num_process,timeLimit=time_limit,solverName=solver,option=options,initialSolution=True) if status==1: preserve(e,'i_ps') e = Load('i_ps.pkl') initial_position['r'] = sol.FinalPosition(e, None, 'i') for league in leagues: status, obj, e = sol.Solve("r_post",league=league,initialPosition=initial_position['r'],threads=num_process,timeLimit=time_limit,solverName=solver,option=options,initialSolution=True) if status==1: preserve(e,'r_post_'+league)
def Solve(num_process=1, options=[], time_limit=None, solver=0, ini_pos=False): """ """ initial_position = dict() sol = ScheduleNPB.Solve() leagues = ['p', 's'] index = 0 for league in leagues: status, obj, e = sol.Solve("r_pre", league=league, threads=num_process, timeLimit=time_limit, solverName=solver, option=options, initialPosition=ini_pos) if status == 1: preserve(e, 'r_pre_' + league) e = Load('r_pre_' + league + '.pkl') initial_position[league] = sol.FinalPosition(e, league, 'r_pre') position_for_inter = sol.Merge(initial_position['p'], initial_position['s']) status, obj, e = sol.Solve('i', initialPosition=position_for_inter, threads=num_process, timeLimit=time_limit, solverName=solver, option=options, initialPosition=ini_pos) if status == 1: preserve(e, 'i_ps') e = Load('i_ps.pkl') initial_position['r'] = sol.FinalPosition(e, None, 'i') for league in leagues: status, obj, e = sol.Solve("r_post", league=league, initialPosition=initial_position['r'], threads=num_process, timeLimit=time_limit, solverName=solver, option=options, initialPosition=ini_pos) if status == 1: preserve(e, 'r_post_' + league)
def LoadData(): output = Output() leagues = ['s', 'p'] for league in leagues: filename = 'r_pre_' + league + '.pkl' e = Load(filename) output.getSchedule(e, 'r_pre', league=league) e = Load('i_ps.pkl') output.getSchedule(e, 'i') for league in leagues: filename = 'r_post_' + league + '.pkl' e = Load(filename) output.getSchedule(e, 'r_post', league=league) output.getWholeSchedule() output.MergeRegularSchedule() return output.schedules['all']
def main(m=False, p=False): output = ScheduleNPB.Output() leagues = ['s', 'p'] for league in leagues: filename = 'r_pre_' + league + '.pkl' e = Load(filename) output.getSchedule(e, 'r_pre', league=league) e = Load('i_ps.pkl') output.getSchedule(e, 'i') for league in leagues: filename = 'r_post_' + league + '.pkl' e = Load(filename) output.getSchedule(e, 'r_post', league=league) output.getWholeSchedule() output.MergeRegularSchedule() if m: output.createMovies() if p: output.Visualize()
def partSolve(num_process=1, options=[], time_limit=None, solver=0): initial_position = dict() sol = ScheduleNPB.Solve() leagues = ['p', 's'] for league in leagues: e = Load('r_pre_' + league + '.pkl') initial_position[league] = sol.FinalPosition(e, league, 'r_pre') position_for_inter = sol.Merge(initial_position['p'], initial_position['s']) status, e = sol.Solve('i', initialPosition=position_for_inter, threads=num_process, timeLimit=time_limit, solverName=solver, option=options) preserve(e, 'i_ps')