Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[Java] Basic implementation of TSP problem
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Sat Oct 02, 2010 6:29 pm    Post subject: [Java] Basic implementation of TSP problem Reply with quote

new version: http://rapidshare.com/files/423238992/TSP.rar


As most people here probably know, there's a tricky problem out there
referred to as the Traveling Salesperson Problem.

@see http://en.wikipedia.org/wiki/Travelling_salesman_problem

I have taken an interest in genetic computation recently so i decided to make a basic GA to "solve" this problem. By solve I mean give the best solution in a given number of evolutions.

A Swap mutation is used as the mutation algorithm.
The genes are filled with alleles referring to an integer represented city.
A vector is filled with Points of these cities.
The fitness is given by 1/distance of tour.

http://rapidshare.com/files/422766857/TSP.rar

I would love to get some discussion to this problem or maybe someone link me to a place with a large input test file and a verified solution so i can run my code against it.

_________________


Last edited by HomerSexual on Tue Oct 05, 2010 7:05 am; edited 1 time in total
Back to top
View user's profile Send private message
Jorg hi
I post too much
Reputation: 7

Joined: 24 Dec 2007
Posts: 2276
Location: Minnesota

PostPosted: Sat Oct 02, 2010 9:28 pm    Post subject: This post has 1 review(s) Reply with quote

Hmm I have an idea.

Why don't you order the locations by the points that are closest to each other. Example
if you have

0,0
10,10
100,100
15,11

You would go this route

0,0
10,10
15,11
100,00


Probably to order them out you could use a loop to test each location to each location.


OR

BRUTE FORCE EVERYTHING until you get the shortest distance...
You could just brute

_________________
CEF will always stay alive.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 204

Joined: 25 Jan 2006
Posts: 8579
Location: 127.0.0.1

PostPosted: Sat Oct 02, 2010 10:31 pm    Post subject: Reply with quote

A* pathing could help with this to determine the shortest route to the given destination.
http://en.wikipedia.org/wiki/A*_search_algorithm

As linked on that wiki article here's a site with a Java applet that has an example showing A*, Dijkstra, and 'Depth First' pathing:
http://www.stackframe.com/software/PathFinder

Getting the best route possible is going to land up requiring some amount of bruteforcing either way you go about doing something like this. Without calculation specific paths ahead of time you have no real method of getting the best possible / shortest route.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Sat Oct 02, 2010 11:03 pm    Post subject: Reply with quote

The problem with the bruteforce is that the TSP is an O(2^x) type problem. It would take a very long time (more time than you will live) to just calculate 30 cities bruteforced.

That is the beauty of this problem, bruteforcing is technically the best way to find the optimal path, but it would take so long and so much computing power for small datasets that it's not possible. Genetic algorithms provide a O(1) efficiency and give a GOOD (usually 2% - 3% difference) path with large datasets

Also going to the closest points does make sense, for CERTAIN datasets, but it is certainly not valid for some datasets, it also requires some form of bruteforce which makes it impractical.

_________________
Back to top
View user's profile Send private message
justa_dude
Grandmaster Cheater
Reputation: 23

Joined: 29 Jun 2010
Posts: 891

PostPosted: Sun Oct 03, 2010 1:20 am    Post subject: Reply with quote

HomerSexual wrote:
That is the beauty of this problem, bruteforcing is technically the best way to find the optimal path, but it would take so long and so much computing power for small datasets that it's not possible. Genetic algorithms provide a O(1) efficiency and give a GOOD (usually 2% - 3% difference) path with large datasets


If you can prove that your algorithm is 95% efficient, I'd really like to see the proof.

Cheers,
adude
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Sun Oct 03, 2010 10:00 am    Post subject: Reply with quote

I said that genetic algorithms are 95% efficient, I can't prove my way because I don't have any way of checking it. Regardless my algorithm tends to find at least a 100% improvement over the stock 1>2>3>4>5>6>etc layout everytime. If the initial distance is 12000 mine will usually find something < 6000.

Like I said I don't have a dataset large enough to test and lets face it, i'm not going to make one

This was my first attempt at the problem and it doesn't have any "smart" mutation like the best GA's do. I also haven't optimized the population, evolutions, mutation %, what gets mutated, etc. For as SIMPLE of an implementation as mine is, it works quite well

_________________
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Sun Oct 03, 2010 4:51 pm    Post subject: Reply with quote

HomerSexual wrote:
Genetic algorithms provide a O(1) efficiency...


Just thought that I should point out that asymptotic notation is a terrible measure of efficiency. It is for modeling growth rates based on the size of the input provided.
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Sun Oct 03, 2010 4:57 pm    Post subject: Reply with quote

Flyte wrote:
Just thought that I should point out that asymptotic notation is a terrible measure of efficiency. It is for modeling growth rates based on the size of the input provided.

Sorry for my noobishness here, but can you explain that? The growth rates based on the size of the input is almost the same as efficiency right? The more efficient the algorithm, the less growth rate at bigger input? What's the difference?
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Sun Oct 03, 2010 7:09 pm    Post subject: Reply with quote

Flyte wrote:
HomerSexual wrote:
Genetic algorithms provide a O(1) efficiency...


Just thought that I should point out that asymptotic notation is a terrible measure of efficiency. It is for modeling growth rates based on the size of the input provided.


But i'm correct in saying that the size of the input doesn't have any effect on the efficiency of the genetic algorithm, correct? The efficiency comes from population and evolutions instead, which are mostly constant

The reason i say that it's O(1) is because bruteforcing becomes very inefficient based on input size, so i'm just comparing efficiency as input grows larger, which is what the notation is used for, and therefore it's used correctly. Right?

_________________
Back to top
View user's profile Send private message
justa_dude
Grandmaster Cheater
Reputation: 23

Joined: 29 Jun 2010
Posts: 891

PostPosted: Sun Oct 03, 2010 8:34 pm    Post subject: Reply with quote

tombana wrote:
Flyte wrote:
Just thought that I should point out that asymptotic notation is a terrible measure of efficiency. It is for modeling growth rates based on the size of the input provided.

Sorry for my noobishness here, but can you explain that? The growth rates based on the size of the input is almost the same as efficiency right? The more efficient the algorithm, the less growth rate at bigger input? What's the difference?


You're (Tombana) quite right, of course. The salesman problem is famous because there's no way to solve it in polynomial time (relative to the input, of course). I can only guess that Flyte meant that it would be more meaningful to look at the correctness of the approximations in this case, since the OP is not going to actually be solving the problem. That is, his O(1) algorithm might simply return the inputs as a solution.
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Sun Oct 03, 2010 8:57 pm    Post subject: Reply with quote

justa_dude wrote:
tombana wrote:
Flyte wrote:
Just thought that I should point out that asymptotic notation is a terrible measure of efficiency. It is for modeling growth rates based on the size of the input provided.

Sorry for my noobishness here, but can you explain that? The growth rates based on the size of the input is almost the same as efficiency right? The more efficient the algorithm, the less growth rate at bigger input? What's the difference?


You're (Tombana) quite right, of course. The salesman problem is famous because there's no way to solve it in polynomial time (relative to the input, of course). I can only guess that Flyte meant that it would be more meaningful to look at the correctness of the approximations in this case, since the OP is not going to actually be solving the problem. That is, his O(1) algorithm might simply return the inputs as a solution.


It is theoretically impossible to return the inputs as a solution, since there's 1500 evolutions of mutation occuring, along with selection and removal. But you're right that it's not "solving" the problem but offering an approximation.

I would also like to add that this was simply my first attempt at an independently written GA program.

_________________
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Mon Oct 04, 2010 8:21 pm    Post subject: Reply with quote

http://rapidshare.com/files/423166758/TSP.rar

New version uploaded which generates a graph of the tour

_________________
Back to top
View user's profile Send private message
justa_dude
Grandmaster Cheater
Reputation: 23

Joined: 29 Jun 2010
Posts: 891

PostPosted: Mon Oct 04, 2010 10:51 pm    Post subject: Reply with quote

FYI, I just looked at the code and the nested loops that check for duplicate cities mean that your algorithm runs slower than n^2, definitely slower than O(1) (constant). You can trade space for speed and store data in a search tree instead.

Cheers,
adude
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Tue Oct 05, 2010 6:59 am    Post subject: Reply with quote

uh no part in my code searchs for duplicate cities...it doesn't have to. The algorithm is filled up with value from 0->citylen and a swap mutation is applied therefore it's impossible to have duplicates. Any of the inefficiencies probably happen outside of the main algorithm and are only run once...just sayin

Edit: I just looked at the code for the problem area and there's no nested for loops in my code lawl...editedit. I see what you mean now and that function sholud have been removed. My oringal algorithm wasn't using a swap and therefore two cities could occur twice. I just removed it without any side effect to output.

Thanks for pointing that out but realize it shouldn't have been used so i removed it Razz

http://rapidshare.com/files/423238992/TSP.rar

Edit again: Another improvement i just added is the fintess is 1/ 5*distance instead of 1 / distance. This puts more pressure on the population to evolve and i noticed lower distances immediately

_________________
Back to top
View user's profile Send private message
Jorg hi
I post too much
Reputation: 7

Joined: 24 Dec 2007
Posts: 2276
Location: Minnesota

PostPosted: Tue Oct 12, 2010 8:51 pm    Post subject: Reply with quote

Mathematical intervention should not be creating solutions based of problems, but creating solutions based upon reason.
_________________
CEF will always stay alive.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites