[email protected] @BWKnopper github.com/bknopper
func (candidateSolution *CandidateSolution) recombine(otherParent CandidateSolution) CandidateSolutions {
/* get routes of both parents */
parentRoute1 := candidateSolution.VisitingCities
parentRoute2 := otherParent.VisitingCities
/* randomize cutIndex for "cross-and-fill point" */
cutIndex := int32(rand.Intn(len(parentRoute1)))
/* initialize the routes for the children */
childRoute1 := make(Cities, len(parentRoute1))
childRoute2 := make(Cities, len(parentRoute1))
/* get the first part of both parent routes using the cut index */
partRoute1 := parentRoute1[0:cutIndex]
partRoute2 := parentRoute2[0:cutIndex]
/* copy the first part of the parents cut into the children */
copy(childRoute1, partRoute1)
copy(childRoute2, partRoute2)
candidateSolution.crossFill(childRoute1, parentRoute2, cutIndex)
candidateSolution.crossFill(childRoute2, parentRoute1, cutIndex)
/* create new children using the new children routes */
child1 := NewCandidateSolution(getBaseCity(), childRoute1);
child2 := NewCandidateSolution(getBaseCity(), childRoute2);
/* put the children in a list and return it */
return CandidateSolutions{child1, child2}
}