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 7419465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:04:31+00:00 2026-05-29T08:04:31+00:00

I built a GA algorithm to solve the TSP. It’s in an exercise in

  • 0

I built a GA algorithm to solve the TSP.

It’s in an exercise in Norvig’s book (AIAMA). He suggested we read the Larrañaga’s view on the problem for representations and such. I learned the some cross over operators and mutations there and tried out a few of them to see which suited me better. I also elaborated a fitness function based on the cost of each path.

Well, despite all that I have a question about my algorithm design, I had never worked with AI before so I don’t know if my approach is a valid one for GAs.

Here’s what I did:

I took a vector of paths (my initial population)

and then at each loop I organized this vector by increasing cost order and took the best X paths in this vector and deleted the other paths.

I then apply XOver and Mutation (at a certain rate) and put them at the position of the old deleted values of the vector.

I then do the same (order vector – extract best etc)

and keep doing it until it stabilizes.

Is it a good approach ? If it isn’t give me some north. Cause when I selected the best and didn’t keep them (just created a whole new pop from them, via Xover and mutation) I didn’t get good results. This way (keeping the best ones – in some experiments I kept only THE best one) I have better results and the result always converges and well fast

State representation : For state representation I chose to use the Path Representation (I was already using it from start and decided to stick with it after I read Larrañaga et all),
it is as follows: if we have, let’s say, 5 cities and visit the first city, then the second, then the third … our path representation would be (1, 2, 3, 4, 5)

Initial population generation : Actually I’m generation random points to representing the cities (that’s what the book asked me to do, generate random points in a closed square) – but for the sake of comparison I generated a population and stick with it when comparing the results – I think if I didn’t stick with one particular population I wouldn’t have much to know about my improvements

Best Fit Individuals : The best fit individuals are the one’s that have the best traveling cost. (I don’t know if I should have – in this problem – used something else as a parameter

crossover : I tried some crossover operators and compared my reuslts with the one presented in the book and ended up using one of the Order CrossOvers ( Larrañaga et al(1999) ):
this crossover takes tow random cuts (forming a sub-path) fromboth parent paths and then copies the rest of the path (the cities not yet visited inside that sub-path) from the other parent (starting at the second cut, not at the position ‘0’) – adding the cities they appear in the other parent.

example: paths (1 2 3 4 5) (3 4 2 1 5) choosing the sub-paths (234) and (421)
we would have as offsprings (5 |2 3 4| 1) (5 |4 2 1| 3) <- the part inside the | | came from one parent and the other part from the other parent

mutation : For mutation I chose IVM (Inversion Mutation) approach. it takes a sub-path from the original path and inserts it back (inverted) at a random point.

example: path (1 2 3 4 5) sub path ( 2 3 4 )and random insertion after 5

generate : ( 1 5 | 4 3 2 )

  • 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-29T08:04:32+00:00Added an answer on May 29, 2026 at 8:04 am

    First of all, avoid all these abbreviations (GA, TSP, XOver). It is hard to read and some people may have no idea what you are talking about.
    The first problem with genetic algorithm is How you choose the initial population, How you perform the crossover, How you perform the mutation. The second problem is that the naive understanding of the description may be a terrible one.

    For you the best fit individuals are the ones which have already better cost. You can argue that it will be better to take the most diverse individuals, ie the ones which are more likely to explore different part of the problem space. Describe how do you make the following operations:

    • State representation : just to make sure
    • Initial population generation : Really important. Maybe there are materials available for this step, as it is common with local search algorithms.
    • best fit individuals : I suggest you to try to play more here. Try different strategies. You are looking for the best fitted for reproduction, not for the overall solution of the problem.
    • crossover : How do you do it?
    • mutation : The goal of mutation is to evade the current region of the problem space, and you can create an individual with a really high cost. With your current algorithm at the next step he would be ditched out when you sort

    You also need to evaluate how is your solution improved with running time. For example, rather than n iterations your provide 100n, does the solution get better, how much? How similar to each other are the individuals of the last generation when the algorithm stops, etc.

    Another question, do you try to solve it for a fixed topology or a variable topology??

    EDIT :
    You are using published algorithms so it doesn’t seems the problem is on specific operations. For the fitness you are right stick with the path cost. You say

    Cause when I selected the best and didn’t keep them (just created a whole new pop from them, via Xover and mutation) I didn’t get good results. This way (keeping the best ones – in some experiments I kept only THE best one) I have better results and the result always converges and well fast.

    You should keep the best fit individuals and their children. It follow a wicked principle of the nature, Only the best have the right to reproduce. The one which have to be replaced are the least fit individuals.

    There are 3 parameters you can tune : The proportion of best fit individual which have children (also the number of individual will be ditched out), the mutation probability, and the number of runs.

    To test how your algorithm perform you can sample the best solution by iteration, ie each t iteration you save the lower cost. Once plotted it should look like :

    x = iterations ; f(x) = cost

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

Sidebar

Related Questions

This Code is a code I built from the algorithm design manual book but
Is there a better way (built-in function, better algorithm) to normalize the case of
Possible Duplicate: Built in .Net algorithm to round value up to the nearest 10
I've built my system in c-sharp (winforms) and I've run into a problem. In
I've never built an algorithm for matching before and don't really know where to
What algorithm is the built in sort() method in Python using? Is it possible
I coded a Huffman Algorithm. I read a file into a String and then
TLDR version: Most important issue is, that in a TSP problem, instead of finding
I have a bit of a problem with the algorithm proposed as homework by
I build a parsing algorithm using NSXMLParser. Im having doubt as to what is

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.