Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An alternative crossover function #1

Open
aycignl opened this issue May 15, 2018 · 0 comments
Open

An alternative crossover function #1

aycignl opened this issue May 15, 2018 · 0 comments

Comments

@aycignl
Copy link

aycignl commented May 15, 2018

Hi Burak.
Many thnx for your implementation✌🏼
With my friend Cagla Yaman, we implement an alternative two-point crossover function using your code environment.
I hope this will be helpful for other people👍🏼
Best.

def crossover(parents):
	parent1 = parents[0]
	parent2 = parents[1]
	length_of_parent = len(parent1)
	first_point = int(length_of_parent / 2 - length_of_parent / 4)
	second_point = int(length_of_parent - first_point)
	intersect = parent1[first_point:second_point]

	child = []
	index = 0
	for pos2 in range(len(parent2)):
		if first_point <= index < second_point:
			child.extend(intersect)
			index = second_point
		if parent2[pos2] not in intersect:
				child.append(parent2[pos2])
				index += 1

	return child
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant