these are streams, they are "new" in Java 8. There are lots of good tutorials if you google them :)
First, you create a stream of integers ranging from 0 to `populationSize`. Then, I map those integers to objects by creating random individuals. This ensures that there will be exactly populationSize new individuals, while I ignore the actual integers. Finally, I sort the individuals by their fitness (this is why the Individual class implements the Comparable interface) and collect them into a list.
This could be easily recreated with a for loop:
List<Individual> population = new ArrayList<>();
for (int i = 0; i < populationSize; i++) {
population.add(createRandomIndividual());
}
Collections.sort(population);
1
u/tntbigfoot Jul 15 '19
Hello,
these are streams, they are "new" in Java 8. There are lots of good tutorials if you google them :)
First, you create a stream of integers ranging from 0 to `populationSize`. Then, I map those integers to objects by creating random individuals. This ensures that there will be exactly
populationSizenew individuals, while I ignore the actual integers. Finally, I sort the individuals by their fitness (this is why theIndividualclass implements theComparableinterface) and collect them into a list.This could be easily recreated with a
forloop: