<commit_before>#!/usr/bin/env python2
import sys, time, timeit

sys.path.append("../dev/")
import brkga, grasp, memproblem, tabumemex

def get_grasp_code(mh, filename, iters):
	"""Creates code templates."""
	if mh == 'grasp':
		command = "print grasp(problem,1,"+str(iters)+")"
		code = """ 
import memproblem
from grasp import grasp

problem = memproblem.read_problem('"""+filename+"""')
"""
	return command, code

def get_tabu_code(mh, filename, iters):
	command = "print cost"
	code = """
import memproblem
import tabumemex

problem = memproblem.read_problem('"""+filename+"""')
cost = tabumemex.tabumemex(problem, 100)
"""
	return command, code

def get_brkga_code(mh, filename, iters):
	command = "print brkgasolver.bestSolution()[0]"
	code = """
import memproblem, brkga

problem = memproblem.read_problem('"""+filename+"""')
n = problem.datastructs_n
s = time.time()
brkgasolver = brkga.brkga(problem, brkga.decoder, n, 20, s)
for i in range("""+str(iters)+"""):
	brkgasolver.evolve()
"""
	return command, code

class execute():
	"""Execute the problems with the different metaheuristics."""
	def set_problem(self, prob):
		self.problem = prob

	def __init__(self, iters, rep=4):
		self.iters = iters
		self.repeats = rep
		return
	
	def run_grasp(self, filename, prob=None):
		self.set_problem(prob)
		print("GRASP ("+filename+", "+str(self.iters)+")")

		command, code = get_grasp_code('grasp', filename, self.iters)
<commit_msg>Added printing of cost as time goes on.<commit_after>#!/usr/bin/env python2
import sys, time, timeit

sys.path.append("../dev/")
import brkga, grasp, memproblem, tabumemex

def get_grasp_code(mh, filename, iters):
	"""Creates code templates."""
	if mh == 'grasp':
		command = "print grasp(problem,1,"+str(iters)+")"
		code = """ 
import memproblem
from grasp import grasp

problem = memproblem.read_problem('"""+filename+"""')
"""
	return command, code

def get_tabu_code(mh, filename, iters):
	command = "print cost"
	code = """
import memproblem
import tabumemex

problem = memproblem.read_problem('"""+filename+"""')
cost = tabumemex.tabumemex(problem, 100)
"""
	return command, code

def get_brkga_code(mh, filename, iters):
	command = "print brkgasolver.bestSolution()[0]"
	code = """
import memproblem, brkga

problem = memproblem.read_problem('"""+filename+"""')
n = problem.datastructs_n
s = time.time()
brkgasolver = brkga.brkga(problem, brkga.decoder, n, 20, s)
for i in range("""+str(iters)+"""):
	brkgasolver.evolve()
	if i % 50 == 0:
		print brkgasolver.bestSolution()[0]
"""
	return command, code

class execute():
	"""Execute the problems with the different metaheuristics."""
	def set_problem(self, prob):
		self.problem = prob

	def __init__(self, iters, rep=4):
		self.iters = iters
		self.repeats = rep
		return
	
	def run_grasp(self, filename, prob=None):
		self.set_problem(prob)
		print("GRASP ("+filename+", "+str(self.iters)+")")

		command, code = get_grasp_code('grasp', filename, self.iters)

{'fraction_non_alphanumeric': 0.16503212715590126, 'fraction_numerical': 0.0074399729455529254, 'mean_word_length': 5.4164859002169194, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7172664', 'n_tokens_mistral': 1157, 'n_tokens_neox': 1061, 'n_words': 261}