title: Java Fitness Function Not Working
body: <p>I have a fitness function as part of a lab and wish to apply it to a set of 'weights' (ArrayList weights).  I have created the array and stored some values in it.  I have created random binary strings (which have an 'x' at the end in order to generate random values) which I wish to also apply the fitness function to; however, the problem I am having is that the fitness function always returns a value of 0.  Am I missing something here?</p>
  
  <p>The fitness function is as follows:</p>
  
  <pre><code>public static double scalesFitness(ArrayList&lt;Double&gt; weights){  
      if (scasol.length() &gt; weights.size()) return(-1);
      double lhs = 0.0,rhs = 0.0;
  
      double L = 0.0;
      double R = 0.0;
  
      for(int i = 0; i &lt; scasol.length(); i++){
          if(scasol.charAt(i) == '0'){
          L = L += 0;
      }
      else if(scasol.charAt(i) == '1'){
          R = R += 1;
      }
      }//end for
  
      int n = scasol.length();
  
      return(L-R);
  
  }
  </code></pre>
  
  <p>Random binary string method:</p>
  
  <pre><code>private static String RandomBinaryString(int n){
      String s = new String();
  
      for(int i = 0; i &lt;= n; i++){
          int y = CS2004.UI(0,1);
              if(y == 0){
                  System.out.print(s + '0');
              }
              else if(y == 1){
                  System.out.print(s + '1');
              }
      }
  
      return(s);
  }
  </code></pre>
  
  <p>Main method (in separate class):</p>
  
  <pre><code>public static void main(String args[]){
  
      for(int i = 0; i &lt; 10; i++){
          ScalesSolution s = new ScalesSolution("10101x");
          s.println();
      }
  
      ArrayList&lt;Double&gt; weights = new ArrayList&lt;Double&gt;();
  
          weights.add(1.0);
          weights.add(2.0);
          weights.add(3.0);
          weights.add(4.0);
          weights.add(10.0);
          System.out.println();
  
      System.out.print("Fitness: ");
      System.out.print(ScalesSolution.scalesFitness(weights));
  }
  </code></pre>
  
  <p>Once run, the random binary strings work perfectly well, yet the fitness function fails to change from 0.  Here is a sample output:</p>
  
  <pre><code>1101100
  1100111
  0001111
  1001010
  1110000
  0011111
  1100111
  1011001
  0000110
  1000000
  
  Fitness: 0.0
  </code></pre>
  
  <p>If you wish to code for the whole class(es), then please let me know.</p>
  
  <p>Thank you all so much for your time.</p>
  
  <p>Mick.</p>