vid 5/src/genome/Genome.java
public static Genome crossOver(Genome g1, Genome g2){



        Neat neat = g1.getNeat();

        Genome genome = neat.empty_genome();

        int index_g1 = 0;
        int index_g2 = 0;

        while(index_g1 < g1.getConnections().size() && index_g2 < g2.getConnections().size()){

            ConnectionGene gene1 = g1.getConnections().get(index_g1);
            ConnectionGene gene2 = g2.getConnections().get(index_g2);

            int in1 = gene1.getInnovation_number();
            int in2 = gene2.getInnovation_number();

            if(in1 == in2){

                if(Math.random() > 0.5){
                    genome.getConnections().add(neat.getConnection(gene1));
                }else{
                    genome.getConnections().add(neat.getConnection(gene2));
                }
                index_g1++;
                index_g2++;
            }if(in1 > in2){
                //genome.getConnections().add(neat.getConnection(gene2));
                //disjoint gene of b
                index_g2++;
            }else{
                //disjoint gene of a
                genome.getConnections().add(neat.getConnection(gene1));
                index_g1 ++;
            }
        }

        while(index_g1 < g1.getConnections().size()){
            ConnectionGene gene1 = g1.getConnections().get(index_g1);
            genome.getConnections().add(neat.getConnection(gene1));
            index_g1++;
        }

        for(ConnectionGene c:genome.getConnections().getData()){
            genome.getNodes().add(c.getFrom());
            genome.getNodes().add(c.getTo());
        }

        return genome;
    }
/**
     * creates a new genome.
     * g1 should have the higher score
     *  - take all the genes of a
     *  - if there is a genome in a that is also in b, choose randomly
     *  - do not take disjoint genes of b
     *  - take excess genes of a if they exist
     * @param g1
     * @param g2
     * @return
     */
creates a new genome.
g1 should have the higher score
- take all the genes of a
- if there is a genome in a that is also in b, choose randomly
- do not take disjoint genes of b
- take excess genes of a if they exist
@param g1
@param g2
@return
creates a new genome . g1 should have the higher score - take all the genes of a - if there is a genome in a that is also in b choose randomly - do not take disjoint genes of b - take excess genes of a if they exist @param g1 @param g2 @return
public static Genome crossOver(Genome g1, Genome g2){
        Neat neat = g1.getNeat();
        Genome genome = neat.empty_genome();
        int index_g1 = 0;
        int index_g2 = 0;
        while(index_g1 < g1.getConnections().size() && index_g2 < g2.getConnections().size()){
            ConnectionGene gene1 = g1.getConnections().get(index_g1);
            ConnectionGene gene2 = g2.getConnections().get(index_g2);
            int in1 = gene1.getInnovation_number();
            int in2 = gene2.getInnovation_number();
            if(in1 == in2){
                if(Math.random() > 0.5){
                    genome.getConnections().add(neat.getConnection(gene1));
                }else{
                    genome.getConnections().add(neat.getConnection(gene2));
                }
                index_g1++;
                index_g2++;
            }if(in1 > in2){
                index_g2++;
            }else{
                genome.getConnections().add(neat.getConnection(gene1));
                index_g1 ++;
            }
        }
        while(index_g1 < g1.getConnections().size()){
            ConnectionGene gene1 = g1.getConnections().get(index_g1);
            genome.getConnections().add(neat.getConnection(gene1));
            index_g1++;
        }
        for(ConnectionGene c:genome.getConnections().getData()){
            genome.getNodes().add(c.getFrom());
            genome.getNodes().add(c.getTo());
        }
        return genome;
    }
public static Genome crossOver ( Genome g1 , Genome g2 ) { Neat neat = g1 . getNeat ( ) ; Genome genome = neat . empty_genome ( ) ; int index_g1 = 0 ; int index_g2 = 0 ; while ( index_g1 < g1 . getConnections ( ) . size ( ) && index_g2 < g2 . getConnections ( ) . size ( ) ) { ConnectionGene gene1 = g1 . getConnections ( ) . get ( index_g1 ) ; ConnectionGene gene2 = g2 . getConnections ( ) . get ( index_g2 ) ; int in1 = gene1 . getInnovation_number ( ) ; int in2 = gene2 . getInnovation_number ( ) ; if ( in1 == in2 ) { if ( Math . random ( ) > 0.5 ) { genome . getConnections ( ) . add ( neat . getConnection ( gene1 ) ) ; } else { genome . getConnections ( ) . add ( neat . getConnection ( gene2 ) ) ; } index_g1 ++ ; index_g2 ++ ; } if ( in1 > in2 ) { index_g2 ++ ; } else { genome . getConnections ( ) . add ( neat . getConnection ( gene1 ) ) ; index_g1 ++ ; } } while ( index_g1 < g1 . getConnections ( ) . size ( ) ) { ConnectionGene gene1 = g1 . getConnections ( ) . get ( index_g1 ) ; genome . getConnections ( ) . add ( neat . getConnection ( gene1 ) ) ; index_g1 ++ ; } for ( ConnectionGene c : genome . getConnections ( ) . getData ( ) ) { genome . getNodes ( ) . add ( c . getFrom ( ) ) ; genome . getNodes ( ) . add ( c . getTo ( ) ) ; } return genome ; }
creates a new genome.
creates a new genome .
//genome.getConnections().add(neat.getConnection(gene2));
 //disjoint gene of b
 //disjoint gene of a
