java - Crossover function of two vector error -
the goal of function use 1 point crossover function between 2 vector new hybrid "son" vector having element first vector , second 1 .
public vector crossover(int sol1,int sol2){ int size; vector sol1 = new vector(); vector sol2 = new vector(); sol1 = (vector) allpop.get(sol1); sol2 = (vector) allpop.get(sol2); int crosspoint = (int) sol1.size()/2 ; vector son = new vector(); son= (vector) sol1.clone() ; if (sol1.size() < sol2.size()) size = sol1.size(); else size = sol2.size(); for(int j=(crosspoint-1);j<size;j++) son.set(j,sol2.get(j)); return son; } sometimes works , gives me "java.lang.arrayindexoutofboundsexception " error .. ideas ?
attach debugger, see on values fails. i'd wager crosspoint equal 0 when sol1.size() 1 or less, index j equal -1, throw exception.
Comments
Post a Comment