Created
October 9, 2016 14:34
-
-
Save fabulousduck/b758f5c462e23a691da7a6b2835001e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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