Skip to content

Commit 3b98b3c

Browse files
committed
[JAVA-8698] Fix bug in algorithm
1 parent 295e05c commit 3b98b3c

File tree

1 file changed

+3
-2
lines changed
  • algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/annealing

1 file changed

+3
-2
lines changed

algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/annealing/Travel.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@ public Travel(int numberOfCities) {
1818
}
1919

2020
public void generateInitialTravel() {
21-
if (travel.isEmpty())
21+
if (travel.isEmpty()) {
2222
new Travel(10);
23+
}
2324
Collections.shuffle(travel);
2425
}
2526

2627
public void swapCities() {
2728
int a = generateRandomIndex();
2829
int b = generateRandomIndex();
29-
previousTravel = travel;
30+
previousTravel = new ArrayList<>(travel);
3031
City x = travel.get(a);
3132
City y = travel.get(b);
3233
travel.set(a, y);

0 commit comments

Comments
 (0)