ma méthode ne retourne pas le vecteur mis à jour ?
Bonjour,
Je suis coincé sur ce petit code qui comporte deux classes: individu qui génère un vecteur aléatoire et la classe mutation qui mis a jour et affiche le nouveau individu.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| public class individu implements constant {
Random random = new Random();
double[] parent = new double[2];
double[] stepSize = new double[1];
//===============crrer vecteur initial============
public individu(){
System.out.print("[");
for (int i=0; i<parent.length; i++) {
parent[i]= range();
System.out.print(parent[i]);
System.out.print(" ");
}
System.out.print("] ");
for(int i=0; i<stepSize.length; i++) {
stepSize[i]=random.nextDouble();
System.out.println("step size "+ stepSize[i]);
}
} |
voila la classe mutation qui returne toujours l'individu initiale
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| public class mutation implements constant {
public static individu mutate(individu parent) {
individu fils = new individu();
fils.stepSize= parent.stepSize;
for (int i=0; i<fils.stepSize.length; i++) {
fils.stepSize[i]= fils.stepSize[i] * Math.exp(MUTATION_T_N * random.nextGaussian());
System.out.println(fils.stepSize[i]);
}
for(int i=0; i<NUMBER_OF_DIMENSION; i++) {
fils.parent[i]=fils.parent[i] + random.nextGaussian()*fils.stepSize[0];
}
return fils; // j'attend le nouveau individu
}
} |
Aprés l'exécution je reçois aucune mise a jour de l'individu créer
Code:
1 2 3 4 5 6 7 8 9 10
| public class run {
public static void main(String[] args) {
// creer un objet individu
individu vector = new individu();
vector.setFitness();
mutation.mutate(vector);
}
} |
Merci d'avance ))