def run(n, k, m, trial, initial_sigmas): assert isinstance(initial_sigmas, np.ndarray) gaps = utils.sigmas_to_gaps(initial_sigmas, np.max(initial_sigmas)) logger.info('gaps={}'.format(gaps)) # af_makespan, clp_makespan = 0, 1 init_gaps = gaps fractional_makespan, clp_res = clp_general.find_strategy(initial_sigmas, k, mode='per_cand') clp_makespan = utils.makespan(initial_sigmas, clp_res ) gaps = utils.sigmas_to_gaps(initial_sigmas, clp_makespan) af_res = average_fit.solve_one_gaps(k, gaps, verbose=False) af_makespan = utils.makespan(initial_sigmas, af_res) logger.info( 'n={} k={} m={} trial={} frac={} CLP={} AF={}'.format(n, k, m, trial, fractional_makespan, clp_makespan, af_makespan)) result_to_append = [n, k, m, trial, initial_sigmas, fractional_makespan, clp_makespan, af_makespan] df = pd.DataFrame(data=[result_to_append], columns=['n', 'k', 'm', 'trial', 'initial_sigmas', 'fractional_makespan', 'clp_makespan', 'af_makespan']) filename = 'results-m{}-k{}-n{}-t{}-tt{}.csv'.format(m, k, n, trials, trial) if folder is None: # s3 import boto3 csv_buffer = BytesIO() df.to_csv(csv_buffer, encoding='utf-8') s3_resource = boto3.resource('s3') s3_resource.Object('borda-rev', filename).put(Body=csv_buffer.getvalue()) else: abs_path = os.path.join(folder, filename) df.to_csv(abs_path, index=False) return result_to_append
def test_full(self): initial_sigmas = np.array([5, 6, 6, 6, 7], dtype=np.int32) k = 2 m = len(initial_sigmas) assert isinstance(initial_sigmas, np.ndarray) gaps = utils.sigmas_to_gaps(initial_sigmas, np.max(initial_sigmas)) logger.info('gaps={}'.format(gaps)) init_gaps = gaps t1 = current_milli_time() fractional_makespan, clp_res = clp_general.find_strategy( initial_sigmas, k, mode='per_cand') t2 = current_milli_time() logger.warning('Took time {}ms, fractional_makespan={}'.format( t2 - t1, fractional_makespan)) # fractional_makespan = utils.makespan(initial_sigmas, frac_res) clp_makespan = utils.makespan(initial_sigmas, clp_res) gaps = utils.sigmas_to_gaps(initial_sigmas, clp_makespan) af_res = average_fit.solve_one_gaps(k, gaps, verbose=False) af_makespan = utils.makespan(initial_sigmas, af_res) logger.info('k={} m={}frac={} CLP={} AF={}'.format( k, m, fractional_makespan, clp_makespan, af_makespan))
def test_full2(self): initial_sigmas = np.array([10, 12, 12, 12, 14], dtype=np.int32) alpha = utils.borda(5) * 2 # kind-of-Borda weights = np.array([2, 2]) m = len(initial_sigmas) assert isinstance(initial_sigmas, np.ndarray) gaps = utils.sigmas_to_gaps(initial_sigmas, np.max(initial_sigmas)) logger.info('gaps={}'.format(gaps)) init_gaps = gaps t1 = current_milli_time() fractional_makespan, clp_res = clp_R_alpha_WCM.find_strategy( initial_sigmas, alpha, weights, mode='per_cand') t2 = current_milli_time() logger.warning('Took time {}ms, fractional_makespan={}'.format( t2 - t1, fractional_makespan)) # fractional_makespan = utils.weighted_makespan(frac_res, alpha, weights, initial_sigmas) clp_makespan = utils.weighted_makespan(clp_res, alpha, weights, initial_sigmas) logger.info('weights={} m={}frac={} CLP={}'.format( weights, m, fractional_makespan, clp_makespan)) self.assertLessEqual(fractional_makespan, clp_makespan)
def run(n, alpha, weights, m, trial, initial_sigmas): assert isinstance(initial_sigmas, np.ndarray) try: gaps = utils.sigmas_to_gaps(initial_sigmas, np.max(initial_sigmas)) logger.info('gaps={}'.format(gaps)) # reverse_makespan, clp_makespan = 0, 1 init_gaps = gaps fractional_makespan, clp_res = clp_R_alpha_WCM.find_strategy( initial_sigmas, alpha, weights, mode='per_cand') clp_makespan = utils.weighted_makespan(clp_res, alpha, weights, initial_sigmas) reverse_result = reverse_algorithm.find_strategy( initial_sigmas, alpha, weights) reverse_makespan = utils.weighted_makespan(reverse_result, alpha, weights, initial_sigmas) logger.info('n={} k={} m={} trial={} frac={} CLP={} AF={}'.format( n, len(weights), m, trial, fractional_makespan, clp_makespan, reverse_makespan)) result_to_append = [ n, len(weights), m, 50 + trial, initial_sigmas, weights, fractional_makespan, clp_makespan, reverse_makespan ] df = pd.DataFrame(data=[result_to_append], columns=[ 'n', 'k', 'm', 'trial', 'initial_sigmas', 'weights', 'fractional_makespan', 'clp_makespan', 'reverse_makespan' ]) filename = 'results-m{}-k{}-n{}-t{}-tt{}.csv'.format( m, np.sum(weights), n, trials, 50 + trial) if folder is None: # s3 import boto3 csv_buffer = BytesIO() df.to_csv(csv_buffer, encoding='utf-8') s3_resource = boto3.resource('s3') s3_resource.Object('borda-zipf3', filename).put(Body=csv_buffer.getvalue()) else: abs_path = os.path.join(folder, filename) df.to_csv(abs_path, index=False) return result_to_append except Exception: logger.error( 'Failed on params n={} weights={} m={} trial={} sigmas={}'.format( n, weights, m, trial, initial_sigmas)) raise
def test_full(self): initial_sigmas = np.array([5, 6, 6, 6, 7], dtype=np.int32) k = 2 m = len(initial_sigmas) alpha = utils.borda(m) # borda assert isinstance(initial_sigmas, np.ndarray) gaps = utils.sigmas_to_gaps(initial_sigmas, np.max(initial_sigmas)) logger.info('gaps={}'.format(gaps)) init_gaps = gaps t1 = current_milli_time() fractional_makespan, clp_res = clp_R_alpha_UCM.find_strategy( initial_sigmas, alpha, k, mode='per_cand') t2 = current_milli_time() logger.warning('Took time {}ms, fractional_makespan={}'.format( t2 - t1, fractional_makespan)) # fractional_makespan = utils.makespan(initial_sigmas, frac_res, alpha=alpha) clp_makespan = utils.makespan(initial_sigmas, clp_res, alpha=alpha) gaps = utils.sigmas_to_gaps(initial_sigmas, clp_makespan) af_res = average_fit.solve_one_gaps(k, gaps, verbose=False) af_makespan = utils.makespan(initial_sigmas, af_res, alpha=alpha) logger.info('k={} m={} frac={} CLP={} AF={}'.format( k, m, fractional_makespan, clp_makespan, af_makespan)) # self.assertListEqual(clp_res.tolist(), # [[0, 0, 1, 1, 0], # [0, 1, 0, 1, 0], # [1, 0, 0, 0, 1], # [1, 0, 0, 0, 1], # [0, 1, 1, 0, 0]] # ) self.assertAlmostEqual(fractional_makespan, 10.0, delta=1e-3) self.assertEquals(clp_makespan, 10) self.assertEquals(af_makespan, 12)
def test_full2(self): initial_sigmas = np.array([10, 12, 12, 12, 14], dtype=np.int32) alpha = np.arange(5) * 2 # kind-of-Borda exa = utils.makespan( initial_sigmas, np.array([[0, 0, 1, 1, 0], [0, 1, 0, 1, 0], [1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [0, 1, 1, 0, 0]]), alpha) k = 2 m = len(initial_sigmas) assert isinstance(initial_sigmas, np.ndarray) gaps = utils.sigmas_to_gaps(initial_sigmas, np.max(initial_sigmas)) logger.info('gaps={}'.format(gaps)) init_gaps = gaps t1 = current_milli_time() fractional_makespan, clp_res = clp_R_alpha_UCM.find_strategy( initial_sigmas, alpha, k, mode='per_cand') t2 = current_milli_time() logger.warning('Took time {}ms, fractional_makespan={}'.format( t2 - t1, fractional_makespan)) # fractional_makespan = utils.fractional_makespan(initial_sigmas, frac_res, alpha=alpha) clp_makespan = utils.makespan(initial_sigmas, clp_res, alpha=alpha) logger.info('k={} m={} frac={} CLP={}'.format(k, m, fractional_makespan, clp_makespan)) # self.assertListEqual(clp_res.tolist(), # [[0, 0, 1, 1, 0], # [0, 1, 0, 1, 0], # [1, 0, 0, 0, 1], # [1, 0, 0, 0, 1], # [0, 1, 1, 0, 0]] # ) self.assertAlmostEqual(fractional_makespan, 20.0, delta=1e-3) self.assertEquals(clp_makespan, 20)