• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
QuinnJohns

Genetic Algorithms for TSP

12 posts in this topic

I'm trying to code a GA for the Travelling Salesman Problem, would there be any chance someone could give me basic pseudocode? I've looked over a ton of online documentations, but I'm still confused on the basic flow of a system like that? Thanks.
0

Share this post


Link to post
Share on other sites
For a GA, all you need to do is make each variable a "gene" in a long line of genes. (Think an array, basically.) You simply use the values in the array to solve your problem and measure the results. The swapping of genes is as simple as swapping values from one array to another (not between array locations, mind you.) So, after our passes and grading, we might say "swap AgentA[17..20] with AgentB[17..20]". You now have two, slightly modified versions of Agents A and B.

Was there a reason that you chose GA for TSP?
0

Share this post


Link to post
Share on other sites
You can Gtranslate the following (French <-> English generally works great): [url="http://khayyam.developpez.com/articles/algo/voyageur-de-commerce/genetique/"]http://khayyam.developpez.com/articles/algo/voyageur-de-commerce/genetique/[/url]
1

Share this post


Link to post
Share on other sites
[quote name='Franck Dernoncourt' timestamp='1318052395' post='4870391']
You can Gtranslate the following (French <-> English generally works great): [url="http://khayyam.developpez.com/articles/algo/voyageur-de-commerce/genetique/"]http://khayyam.devel...erce/genetique/[/url]
[/quote]
Well done!

Incidentally, they have been able to solve 16-node TSP in screaming fast time using swarm theory (think ants that report back on their adventures). Read [i]The Perfect Swarm [/i]by Fisher for more info.

0

Share this post


Link to post
Share on other sites
[quote name='IADaveMark' timestamp='1318024048' post='4870273']
Was there a reason that you chose GA for TSP?
[/quote]

I think I'm with IADaveMark on this one, GAs doesn't strike me as particularly useful for this... it's much less likely to give you the optimal solution (unless it gets really lucky).

Unless there's some kind of hidden logic to the layout of the locations in the kind of environment you're solving that you don't know about and could be teased out by by the GA and applied across many problems, the advantages aren't really very apparent.

Sometimes I'm sure there is such a logic (and in that case, a really good genetic algorithm may be able to figure it out and probably proceed much faster than a random system)... but if this is a more or less random level we're talking about, there may not be anything of the sort that would give a GA an advantage here.

That said, genetic algorithms are just plain fun... so, that could factor in.
0

Share this post


Link to post
Share on other sites
[font="arial, verdana, tahoma, sans-serif"][size="2"][quote name='IADaveMark' timestamp='1318053460' post='4870394']they have been able to solve 16-node TSP in screaming fast time using swarm theory (think ants that report back on their adventures). Read [i]The Perfect Swarm [/i]by Fisher for more info.[/quote]
A nice tutorial explaining the implementation of an ant colony algorithm to the traveling salesman problem: [url="http://khayyam.developpez.com/articles/algo/voyageur-de-commerce/colonies-de-fourmis/"]http://khayyam.devel...ies-de-fourmis/[/url] (sorry, you'll have to Gtranslate it again)

[/size][/font][quote name='driftingSpaceMan' timestamp='1318064427' post='4870424']
[quote name='IADaveMark' timestamp='1318024048' post='4870273']
Was there a reason that you chose GA for TSP?
[/quote]
I think I'm with IADaveMark on this one, GAs doesn't strike me as particularly useful for this... it's much less likely to give you the optimal solution (unless it gets really lucky).
[/quote]

Even though a GA only approach might be inefficient compared to classical heuristics, it can always be combined with these later if needed (that's the advantage of a metaheuristic method). Crossovers might turn out to be useful. That said, I have never looked closely at TSP but there seem to be myriads of papers on TSP + GA, which tends to make me think the OP's goal isn't too quixotic.
0

Share this post


Link to post
Share on other sites
Thanks for the help! I've been toying around with different algorithms, to gain a better understanding. I've written so far, Depth First, Bread First, Best First, Insertion Heuristic, and now I'm trying a GA. Using a GA would be pointless for me on a small dataset, but i'm playing with about 100 "city" data points. Thanks again for the help!

Regards,
Quinn
0

Share this post


Link to post
Share on other sites
This document may interest you: [url="https://louisville.edu/speed/faculty/sheragu/Research/Intelligent/tsp.PDF"]https://louisville.e...lligent/tsp.PDF[/url] (mirror: [url="http://www.scribd.com/doc/68045235/Comparison-of-TSP-Algorithms-1998"]http://www.scribd.co...Algorithms-1998[/url])

[quote]Our purpose in this term project is to implement heuristic algorithms and compare and evaluate their respective computational efficiency. Included in this model are greedy, 2-opt, greedy 2-opt, 3-opt, greedy 3-opt, genetic algorithm, simulated annealing, and neural network approach and their improvement versions. The problem size can be adjusted from 2-node up to 10,000-node. Therefore, these algorithms can be evaluated in a wide spectrum of situations[/quote]

[img]http://img197.imageshack.us/img197/9681/comparisonoftspalgorith.png[/img]
1

Share this post


Link to post
Share on other sites
GAs are terrible local search solvers for TSPs. State of the art solvers use hand-crafted meta-heuristics to direct the search toward promising solutions. These are usually combined with some kind of edge-swapping move operator like Lin-Kernighan or Stem-and-Cycle.

Check out [url="http://www.akira.ruc.dk/~keld/research/LKH/"]LKH[/url] for example; winner of the DIMACS challenge for TSPs.
1

Share this post


Link to post
Share on other sites
[quote name='pithlit' timestamp='1318381291' post='4871679']Check out [url="http://www.akira.ruc.dk/~keld/research/LKH/"]LKH[/url] for example; winner of the DIMACS challenge for TSPs.
[/quote]

Interesting, thanks pithlit!

[quote][url="http://www.akira.ruc.dk/~keld/research/LKH/"]http://www.akira.ruc.dk/~keld/research/LKH/[/url] :
A simple genetic algorithm has been added. New keyword: POPULATION_SIZE. Tours found by the first POPULATION_SIZE runs constitute an initial population of tours. In each of the remaining runs two tours (parents) from the current population is recombined into a new tour (child) using a variant of the Edge Recombination Crossover (ERX). The parents are chosen with random linear bias towards the best members of the population. The child is used as initial tour for the next run. If this run produces a tour better than the worst tour of the population, then the resulting tour replaces the worst tour. Premature convergence is avoided by requiring that all tours in the population have different costs.[/quote]


[color="#1C2837"][size="2"]So crossovers turned out to be useful and diversity is used in the fitness function in order to avoid premature convergence (=[i] genetic drift[/i] in GA terminology), such as illustrated below:[/size][/color]

[color="#1C2837"][size="2"][img]http://img3.imageshack.us/img3/3582/eatypicalprogressofanea.png[/img]
[/size][/color]
0

Share this post


Link to post
Share on other sites
I did a project for college a few years back, it has an option to solve TSP using a GA.

Here are the binaries and the source, I hope it helps:
http://www.mediafire.com/file/jc0yka96f63b05x/TSP-Genetic.rar

UI is in Croatian but it shouldn't be too hard to figure out. Code is in English.

I didn't find GA too useful for TSP, it was mostly included as a proof of concept.
0

Share this post


Link to post
Share on other sites
[quote name='Franck Dernoncourt' timestamp='1318406659' post='4871766']
[size="2"][color=#1C2837]So crossovers turned out to be useful and diversity is used in the fitness function in order to avoid premature convergence (=[i] genetic drift[/i] in GA terminology), such as illustrated below:[/color][/size]
[size="2"][color="#1c2837"][/color][/size][/quote]

I think the GA is just used as a diversification mechanism here: an alternative meta-heuristic that picks new neighbourhoods to search in. IIRC the local search itself is using an exchange operator that ranks edges based on how close they are to being part of the Minimum Spanning Tree of all cities.
0

Share this post


Link to post
Share on other sites
[quote name='pithlit' timestamp='1318460708' post='4872030']
[quote name='Franck Dernoncourt' timestamp='1318406659' post='4871766']
[size="2"][color="#1C2837"]So crossovers turned out to be useful and diversity is used in the fitness function in order to avoid premature convergence (=[i] genetic drift[/i] in GA terminology), such as illustrated below:[/color][/size]
[size="2"] [/size][/quote]

I think the GA is just used as a diversification mechanism here: an alternative meta-heuristic that picks new neighbourhoods to search in. IIRC the local search itself is using an exchange operator that ranks edges based on how close they are to being part of the Minimum Spanning Tree of all cities.
[/quote]

Anyways, it took me a little less than two days to write the GA, mutations, crossovers, etc. Pretty excited about the results. Thanks for the input everyone.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0