Been working on this for a couple of hours so thought I'd ask, When I create an array of this object the memory array which is given a random input causes the rest of the array to have the same output: see code below.
Bee Class:
private class Bee{
private int status;
private float[] memory;
private double quality;
private int visits;
private Bee(int status, float[] memory, double quality, int visits){
this.status = status;
this.memory = memory;
this.quality = quality;
this.visits = visits;
}
}
The individual bees quality when printed are different yet their memory stay all the same.
for(int i = 0; i < this.bees.length; i++){
System.out.println(this.bees[i].memory[0]+" "+this.bees[i].memory[1]);
System.out.println(this.bees[i].quality);
}
Sample Output:
3.4968524 8.354554
1581.5435920638447
3.4968524 8.354554
82.46318172154176
3.4968524 8.354554
66.25267691464408
I don't understand why the quality is working but not the memory?
Any help or suggestions would be greatly appreciated.
EDIT:
for(int i = 0; i < totalNumberbees; i++){
int beestatus;
if(i < numberInactive){
beestatus = 0;//inactive
indexesOfInactivebees[i] = i;
} else if(i < (numberInactive + numberScout)){
beestatus = 2;//scout
} else{
beestatus = 1;//active
}
float[] randomMemory = GenerateRandomMemory();
this.bees[i] = new Bee(beestatus, randomMemory, MeasureQuality(randomMemory), 0);
}
private float[] GenerateRandomMemory(){
float[] result = new float[this.functionData.vars.length];
result = this.functionData.vars;
for(int i = 0; i < result.length; i++){
float r1 = new Random().nextFloat()*10;
result[i] = r1;
}
return result;
}
Here is the GenerateRandomClass and the rest of the code the initialises the bees.