title: Java Simulated Annealing from Pseudocode
body: <p>I am currently working on a project (TSP) and am attempting to convert some simulated annealing pseudocode into Java.  I have been successful in the past at converting pseudocode into Java code, however I am unable to convert this successfully.</p>
  
  <p>The pseudocode is:</p>
  
  <pre><code>T0(T and a lowercase 0)    Starting temperature
  Iter    Number of iterations
  λ    The cooling rate
  
  1.  Set T = T0 (T and a lowercase 0)
  2.  Let x = a random solution
  3.  For i = 0 to Iter-1
  4.  Let f = fitness of x
  5.  Make a small change to x to make x’
  6.  Let f’ = fitness of new point
  7.  If f’ is worse than f then
  8.      Let p = PR(f’, f, Ti (T with a lowercase i))
  9.      If p &gt; UR(0,1) then
  10.         Undo change (x and f)
  11.     Else
  12.         Let x = x’
  13.     End if
  14.     Let Ti(T with a lowercase i) + 1 = λTi(λ and T with a lowercase i)
  15. End for
  Output:  The solution x
  </code></pre>
  
  <p>If somebody could show me a basic mark-up of this in Java I would be extremely grateful - I just can't seem to figure it out!</p>
  
  <p>I am working across multiple classes using a number of functions (which I will not list as it is irrelevant for what I am asking).  I already have a <code>smallChange()</code> method and a <code>fitness</code> function - could there be a chance that I would need to create a number of different versions of said methods?  For example, I have something like:</p>
  
  <pre><code>public static ArrayList&lt;Integer&gt; smallChange(ArrayList&lt;Integer&gt; solution){
  
  //Code is here.
  
  }
  </code></pre>
  
  <p>Could I possibly need another version of this method which accepts different parameters?  Something along the lines of:</p>
  
  <pre><code>public static double smallChange(double d){
  
  //Code is here.
  
  }
  </code></pre>
  
  <p>All I require is a basic idea of how this would look when written in Java - I will be able to adapt it to my code once I know what it should look like in the correct syntax, but I cannot seem to get past this particular hurdle.</p>