Created
October 9, 2016 14:50
-
-
Save fabulousduck/0523ada1f2eae41961cd96ddc677a042 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 { | |
dpC := dataPoints | |
//solution with start point | |
solution := []point{dpC[0]} | |
//remove start point so it cant be picked to visit | |
dpC = append(dpC[:0],dpC[1:]...) | |
//loop over the remaining points | |
for i := 0; i < len(dpC); i++ { | |
//grab random index from te dpC slice | |
randomPoint := rand.Intn(len(dpC)) | |
//add the random point to the solution slice | |
solution = append(solution, dpC[randomPoint]) | |
//remove it from the dpC slice so it cant be picked again | |
dpC = append(dpC[:randomPoint], dpC[randomPoint+1:]...) | |
} | |
//append the start position back on to the slice so we end at the same position again | |
solution = append(solution, solution[0]); | |
fmt.Println(solution) | |
return solution | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment