Skip to content

Instantly share code, notes, and snippets.

@fabulousduck
Created October 9, 2016 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabulousduck/b758f5c462e23a691da7a6b2835001e4 to your computer and use it in GitHub Desktop.
Save fabulousduck/b758f5c462e23a691da7a6b2835001e4 to your computer and use it in GitHub Desktop.
func (algorithm *algorithm) putRandomCandidateSolutions(dataPoints []point, amount int){
for i := 0; i < amount; i++ {
algorithm.candidateSolutions = append(algorithm.candidateSolutions,randomSolution(dataPoints))
}
}
func randomSolution(dataPoints []point) []point {
candidateSolution := []point{dataPoints[0]}
dataPoints = append(dataPoints[:0], dataPoints[1:]...)
for i := 0; i < len(dataPoints)-1; i++ {
randomInt := rand.Intn(len(dataPoints));
candidateSolution = append(candidateSolution, dataPoints[randomInt])
dataPoints = append(dataPoints[:randomInt],dataPoints[randomInt+1:]...)
}
candidateSolution = append(candidateSolution, candidateSolution[0]);
fmt.Println(candidateSolution)
return candidateSolution
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment