<commit_before># Parliamentary Political Competitions: A New Approach To Global Optimization
# As seen in the paper by <NAME> & <NAME>
# Implemented by <NAME>

from DefineInitialParties import *
from IntraGroupCompetition import *
from InterGroupCooperation import *

def POA(CostFunction, dim=10, nparties=4, nmembers=5, ncandidates=2,
		lower_bound=0, upper_bound=10, max_eval=10000, merge_probability=0.01,
		deletion_probability=0.001, bias=0.3, member_weighting=0.01,
		candidate_weighting=1, groups_to_merge=2, groups_to_delete=1):

	# Domain of the function, tuple including lower and upper bounds
	domain = (lower_bound, upper_bound)

	# Define the initial parties and candidates
	candidates, candidates_fitness, members, members_fitness = DefineInitialParties(CostFunction,
			nparties, nmembers, ncandidates, dim, domain)

	evaluations = nparties * nmembers
	group_power = np.zeros(nparties)

	while evaluations < max_eval:
		for i in range(0,len(candidates)):
			# Intragroup Competition: regular members try to become candidates of their group
			candidates[i], candidates_fitness[i], members[i], members_fitness[i], group_power[i], new_evaluations = IntraGroupCompetition(CostFunction,
					candidates[i], candidates_fitness[i], members[i], members_fitness[i], domain,
					bias, candidate_weighting, member_weighting)

		# Intergroup Cooperation: best groups try to merge into a greater one, and weakest groups may disappear
		candidates, candidates_fitness, members, members_fitness, group_power = InterGroupCooperation(candidates, candidates_fitness,
				members, members_fitness, group_power, groups_to_merge, merge_probability, groups_to_delete, deletion_probability)

		# print("Iteration {:4}, best solution: {:e}".format(iterations, np.min(candidates_fitness)))

		evaluations += new_evaluations<commit_msg>Added return statement for best solution found<commit_after># Parliamentary Political Competitions: A New Approach To Global Optimization
# As seen in the paper by <NAME> & <NAME>
# Implemented by <NAME>

from DefineInitialParties import *
from IntraGroupCompetition import *
from InterGroupCooperation import *

def POA(CostFunction, dim=10, nparties=4, nmembers=5, ncandidates=2,
		lower_bound=0, upper_bound=10, max_eval=10000, merge_probability=0.01,
		deletion_probability=0.001, bias=0.3, member_weighting=0.01,
		candidate_weighting=1, groups_to_merge=2, groups_to_delete=1):

	# Domain of the function, tuple including lower and upper bounds
	domain = (lower_bound, upper_bound)

	# Define the initial parties and candidates
	candidates, candidates_fitness, members, members_fitness = DefineInitialParties(CostFunction,
			nparties, nmembers, ncandidates, dim, domain)

	evaluations = nparties * nmembers
	group_power = np.zeros(nparties)

	while evaluations < max_eval:
		for i in range(0,len(candidates)):
			# Intragroup Competition: regular members try to become candidates of their group
			candidates[i], candidates_fitness[i], members[i], members_fitness[i], group_power[i], new_evaluations = IntraGroupCompetition(CostFunction,
					candidates[i], candidates_fitness[i], members[i], members_fitness[i], domain,
					bias, candidate_weighting, member_weighting)

		# Intergroup Cooperation: best groups try to merge into a greater one, and weakest groups may disappear
		candidates, candidates_fitness, members, members_fitness, group_power = InterGroupCooperation(candidates, candidates_fitness,
				members, members_fitness, group_power, groups_to_merge, merge_probability, groups_to_delete, deletion_probability)

		# print("Iteration {:4}, best solution: {:e}".format(iterations, np.min(candidates_fitness)))

		evaluations += new_evaluations

	return np.min(candidates_fitness)
{'fraction_non_alphanumeric': 0.08671140939597316, 'fraction_numerical': 0.016107382550335572, 'mean_word_length': 6.8277310924369745, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '1002008', 'n_tokens_mistral': 1238, 'n_tokens_neox': 1109, 'n_words': 309}