-
Notifications
You must be signed in to change notification settings - Fork 0
/
Population.java
executable file
·49 lines (42 loc) · 1.35 KB
/
Population.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
public class Population {
Trip[] trips;
int maxBound =0;
/** this constructor helps to create a population of all the trips **/
public Population(int vertices, boolean initialise,Graph graph) {
trips = new Trip[vertices];
if (initialise) {
for (int i = 0; i < tripsSize(); i++) {
Trip newTrip = new Trip(vertices,graph);
newTrip.generateIndividual(vertices);
saveTrip(i, newTrip);
}
}
}
/** Saves the trip in the population at a particular index **/
public void saveTrip(int index, Trip trip) {
trips[index] = trip;
}
/*** Returns a particular trip from all trips ***/
public Trip getTrip(int index) {
return trips[index];
}
/** With this method population size**/
public int tripsSize() {
return trips.length;
}
/** In this mehtod we can get the best trip in all trips **/
public Trip getFittest() {
Trip fittest = trips[0];
// Loop through individuals to find fittest
for (int i = 1; i < tripsSize(); i++) {
if (fittest.getFitness() <= getTrip(i).getFitness()) {
fittest = getTrip(i);
}
}
return fittest;
}
/** Returns meb **/
public int meb() {
return maxBound;
}
}