vid 5/src/genome/Genome.java
public double distance(Genome g2){

        Genome g1 = this;

        int highest_innovation_gene1 = g1.getConnections().get(g1.getConnections().size()-1).getInnovation_number();
        int highest_innovation_gene2 = g2.getConnections().get(g2.getConnections().size()-1).getInnovation_number();

        if(highest_innovation_gene1 < highest_innovation_gene2){
            Genome g = g1;
            g1 = g2;
            g2 = g;
        }

        int index_g1 = 0;
        int index_g2 = 0;

        int disjoint = 0;
        int excess = 0;
        double weight_diff = 0;
        int similar = 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){
                //similargene
                similar ++;
                weight_diff += Math.abs(gene1.getWeight() - gene2.getWeight());
                index_g1++;
                index_g2++;
            }if(in1 > in2){
                //disjoint gene of b
                disjoint ++;
                index_g2++;
            }else{
                //disjoint gene of a
                disjoint ++;
                index_g1 ++;
            }
        }

        weight_diff /= similar;
        excess = g1.getConnections().size() - index_g1;


        double N = Math.max(g1.getConnections().size(), g2.getConnections().size());
        if(N < 20){
            N = 1;
        }

        return neat.getC1()  * disjoint / N + neat.getC2() * excess / N + neat.getC3() * weight_diff;

    }
/**
     * calculated the distance between this genome g1 and a second genome g2
     *  - g1 must have the highest innovation number!
     *
     * @param g2
     * @return
     */
calculated the distance between this genome g1 and a second genome g2
- g1 must have the highest innovation number!

@param g2
@return
calculated the distance between this genome g1 and a second genome g2 - g1 must have the highest innovation number! @param g2 @return
public double distance(Genome g2){
        Genome g1 = this;
        int highest_innovation_gene1 = g1.getConnections().get(g1.getConnections().size()-1).getInnovation_number();
        int highest_innovation_gene2 = g2.getConnections().get(g2.getConnections().size()-1).getInnovation_number();
        if(highest_innovation_gene1 < highest_innovation_gene2){
            Genome g = g1;
            g1 = g2;
            g2 = g;
        }
        int index_g1 = 0;
        int index_g2 = 0;
        int disjoint = 0;
        int excess = 0;
        double weight_diff = 0;
        int similar = 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){
                similar ++;
                weight_diff += Math.abs(gene1.getWeight() - gene2.getWeight());
                index_g1++;
                index_g2++;
            }if(in1 > in2){
                disjoint ++;
                index_g2++;
            }else{
                disjoint ++;
                index_g1 ++;
            }
        }
        weight_diff /= similar;
        excess = g1.getConnections().size() - index_g1;
        double N = Math.max(g1.getConnections().size(), g2.getConnections().size());
        if(N < 20){
            N = 1;
        }
        return neat.getC1()  * disjoint / N + neat.getC2() * excess / N + neat.getC3() * weight_diff;
    }
public double distance ( Genome g2 ) { Genome g1 = this ; int highest_innovation_gene1 = g1 . getConnections ( ) . get ( g1 . getConnections ( ) . size ( ) - 1 ) . getInnovation_number ( ) ; int highest_innovation_gene2 = g2 . getConnections ( ) . get ( g2 . getConnections ( ) . size ( ) - 1 ) . getInnovation_number ( ) ; if ( highest_innovation_gene1 < highest_innovation_gene2 ) { Genome g = g1 ; g1 = g2 ; g2 = g ; } int index_g1 = 0 ; int index_g2 = 0 ; int disjoint = 0 ; int excess = 0 ; double weight_diff = 0 ; int similar = 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 ) { similar ++ ; weight_diff += Math . abs ( gene1 . getWeight ( ) - gene2 . getWeight ( ) ) ; index_g1 ++ ; index_g2 ++ ; } if ( in1 > in2 ) { disjoint ++ ; index_g2 ++ ; } else { disjoint ++ ; index_g1 ++ ; } } weight_diff /= similar ; excess = g1 . getConnections ( ) . size ( ) - index_g1 ; double N = Math . max ( g1 . getConnections ( ) . size ( ) , g2 . getConnections ( ) . size ( ) ) ; if ( N < 20 ) { N = 1 ; } return neat . getC1 ( ) * disjoint / N + neat . getC2 ( ) * excess / N + neat . getC3 ( ) * weight_diff ; }
calculated the distance between this genome g1 and a second genome g2
  - g1 must have the highest innovation number!
calculated the distance between this genome g1 and a second genome g2 - g1 must have the highest innovation number!
//similargene
 //disjoint gene of b
 //disjoint gene of a
