I am currently working on a project (TSP) and am trying to convert some simulated annealing pseudo code to Java. I have been successful in the past when converting pseudocode to Java code, however I cannot successfully convert it.
Pseudocode:
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 > 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
If anyone could show me the basic Java inscription, I would be extremely grateful - I just can't figure it out!
I work through several classes, using a number of functions (which I will not list, since it does not matter for what I ask). I already have a smallChange() method and a fitness function - can there be a chance that I will need to create several different versions of the specified methods? For example, I have something like:
public static ArrayList<Integer> smallChange(ArrayList<Integer> solution){
Maybe I need another version of this method that takes different parameters? Something like:
public static double smallChange(double d){
All I need is a basic idea of ββwhat it will look like when writing in Java - I can adapt it to my code when I know how it will look in the correct syntax, but I can not get past this special let.
Thanks.
Mick
java algorithm artificial-intelligence simulated-annealing pseudocode
MusTheDataGuy
source share