Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4104786
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:09:44+00:00 2026-05-20T21:09:44+00:00

I am currently working on a project (TSP) and am attempting to convert some

  • 0

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.

The pseudocode is:

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 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!

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 smallChange() method and a fitness 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:

public static ArrayList<Integer> smallChange(ArrayList<Integer> solution){

//Code is here.

}

Could I possibly need another version of this method which accepts different parameters? Something along the lines of:

public static double smallChange(double d){

//Code is here.

}

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T21:09:45+00:00Added an answer on May 20, 2026 at 9:09 pm

    The basic code should look like this:

    public class YourClass {
      public static Solution doYourStuff(double startingTemperature, int numberOfIterations, double coolingRate) {
        double t = startingTemperature;
        Solution x = createRandomSolution();
        double ti = t;
    
        for (int i = 0; i < numberOfIterations; i ++) {
          double f = calculateFitness(x);
          Solution mutatedX = mutate(x);
          double newF = calculateFitness(mutatedX);
          if (newF < f) {
            double p = PR(); // no idea what you're talking about here
            if (p > UR(0, 1)) { // likewise
              // then do nothing
            } else {
              x = mutatedX;
            }
            ti = t * coolingRate;
          }
        }
        return x;
      }
    
      static class Solution {
        // no idea what's in here...
      }
    }
    

    Now as far as wanting different versions of smallChange() method – totally doable, but you have to read up on inheritance a little bit

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on a project about social networking, where I have some problems
I'm currently working on project with Haskell, and have found myself some trouble. I'm
I'm currently working on a project that is building a java-based desktop application to
I am currently working on a project where I have several string that may
I am currently working on a project in java. I need to create a
I'm currently working on a project Euler problem (www.projecteuler.net) for fun but have hit
I am currently working on project where I have to match up a large
I'm currently working on a project where some bugs are popping up in our
Iam currently working on a project where i have to read serial port continuously.
I'm currently working on a project in which i need to read some (Latitude,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.