I'm working on a genetic algorithm, right now I'm stuck on populating, because two separate array instances of a link class seemingly keep effecting each other, and I can't figure out why.
here is the relevant code for my problem, let me know if you need more:
private ArrayList<Link> mNetwork = new ArrayList<Link>();
private ArrayList<Link> network = new ArrayList<Link>();
public GeneticAlgorithm(ArrayList<Link> network, int populationSize,
int tournamentsSize, double crossoverProb, double mutationProb) {
mNetwork = network;
mPopulationSize = populationSize;
mTournamentsSize = tournamentsSize;
mCrossoverProb = crossoverProb;
mMutationProb = mutationProb;
createInitialPopulation();
}
public void createInitialPopulation() {
for(int z = 0; z < mPopulationSize; z++){
network = mNetwork;
for(int i = 0; i < network.size(); i++){
int linkRan = ran.nextInt(10);
if(linkRan == 6){
network.get(i).setActive(1);
if(mNetwork.get(i).getActive() ==network.get(i).getActive(){
System.out.println("These Shouldn't match");
}
}
else{
network.get(i).setActive(0);
}
}
}
}
The "These shouldn't match" prints out every time, and I don't know why, this is a problem, because I want to use the initial network as a way to reset the values when populating.
Also the Link class isn't set to static or anything like that, but if you want to see more of the code just ask, because I'm pretty sure this should be all that's necessary, but it could very well not be.