Good mornings friends, I have a problem with random TSP indexes. I want to get the actual tsp path at random its index, but only the 'intermediate coordinates' index is random while the start and end point coordinates stay the same. even if the tsp index is random, the actual random tsp path will still start at index 0 as the starting point. this is my code
public List<Coord> randVertex(int max) {
List<Coord> result = new ArrayList<>(listVertex); // copy of vertexList
Collections.shuffle(result);
Random r = new Random();
if (max < result.size()) {
// result is shuffled and therefore randomized
// no duplicate vertex appear in the result here
result = result.subList(0, max);
} else { // add randomly more elements
while (result.size() < max) {
result.add(result.get(r.nextInt(result.size())));
}
}
return result;
}
Aucun commentaire:
Enregistrer un commentaire