I am trying to implement a crossover function for a genetic algorithm. V is a set of nodes. Just consider each node a unique string. $V_M$ and $V_F$ are each a set of nodes with no element in common. $V_M$ and $V_F$ are of the same size. Each member of the population consists of a $1:1$ mapping $f:V_M \rightarrow V_F$.
What is a reasonable way to implement a crossover function in this case?
I implement this in Python with the $1:1$ mappings being dictionaries from $V_M$ to $V_F$. A Python solution would be nice but is not necessary. A generic solution or a solution in another language would be fine, too.
I can implement single-point crossover like this:
# Crossover function
def crossover(parent1, parent2):
# Single - point crossover
f_values = list(parent1.values())
random_values = random.sample(f_values, 2)
value_1 = random_values[0]
key_1_1 = get_key_by_value(parent1, value_1)
value_2 = random_values[1]
key_1_2 = get_key_by_value(parent1, value_2)
key_2_1 = get_key_by_value(parent2, value_1)
key_2_2 = get_key_by_value(parent2, value_2)
child1 = parent1.copy()
child1[key_1_1] = value_2
child1[key_1_2] = value_1
child2 = parent2.copy()
child2[key_2_1] = value_2
child2[key_2_2] = value_1
return child1, child2
I imagine I can implement multi-point crossover similarly.
But how can I implement uniform crossover or blend crossover?