-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndividual.java
More file actions
84 lines (74 loc) · 1.83 KB
/
Individual.java
File metadata and controls
84 lines (74 loc) · 1.83 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import java.util.Arrays;
/*********************************************************
* Filename: Individual.java
* Author: Charles Walker
* Created: 11/08/23
* Modified:
*
* Purpose:
* Acts as the base that all individuals that make up the population are
* copied from. Holds an integer array called chromosome that holds the
* route locations, or genes, as well as the fitness level of that route.
*
* Attributes:
* -fitness: double
* -chromosome: int[]
*
*
* Methods:
* +<<constructor>>Individual(int)
* +getFitness(): double
* +setFitness(int): void
* +getChromosome: int[]
* +setChromosome(int[]): void
* +setGene(int,int): void
* +getGene(): int
* +printChromosome(): void
*
*********************************************************/
public class Individual {
private double fitness;
private int[] chromosome;
public Individual(int genes) {
chromosome = new int[genes];
}
public double getFitness() {
return fitness;
}
public void setFitness(double value) {
fitness = value;
}
public int[] getChromosome() {
return this.chromosome;
}
public void setChromosome(int[] genes) {
this.chromosome = genes;
}
public void setGene(int value, int index){
chromosome[index] = value;
}
public int getGene(int index) {
return chromosome[index];
}
public void printChromosome() {
System.out.print("");
for(int i = 0; i < chromosome.length; i++) {
System.out.print(chromosome[i]+",");
}
}
}
/*public void genVariation() {
boolean next = false;
int nextI = 0;
genVariation=pop.getPopSize();
for(int i = 0; i < pop.getPopSize()-1; i=nextI) {
for(int j = i+1; j < pop.getPopSize()&&!next; j++) {
if(Arrays.equals(pop.getInd(i).getChromosome(), pop.getInd(j).getChromosome())) {
genVariation--;
next = true;
nextI = j+1;
}
}
next = false;
}
}*/