<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jeroens blog &#187; WPF</title>
	<atom:link href="http://blog.bn2vs.com/tag/wpf/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.bn2vs.com</link>
	<description>Blog of Jeroen De Dauw. The latest news on my open source work and interests.</description>
	<lastBuildDate>Fri, 23 Dec 2011 14:44:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>GALib with TSP implementation</title>
		<link>http://blog.bn2vs.com/2010/01/10/galib-with-tsp-implementation/</link>
		<comments>http://blog.bn2vs.com/2010/01/10/galib-with-tsp-implementation/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 01:21:03 +0000</pubDate>
		<dc:creator>Jeroen De Dauw</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 4.0]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[GA]]></category>
		<category><![CDATA[GALib]]></category>
		<category><![CDATA[Genetic Algorithm]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Skynet]]></category>
		<category><![CDATA[TSP]]></category>
		<category><![CDATA[Ttravelling Salesman Problem]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://blog.bn2vs.com/?p=650</guid>
		<description><![CDATA[Over the last week, I&#8217;ve been rewriting my Genetic Algorithm (GA) implementation of the Travelling Salesman Problem (TSP). I&#8217;ve rewritten pretty much everything, but the two most notable changes are: 1. I split the code into 2 projects: one holding the general GA code, which is now called GALib, and one holding the code specific [...]]]></description>
			<content:encoded><![CDATA[<p>Over the last week, I&#8217;ve been rewriting my Genetic Algorithm (<a href="http://en.wikipedia.org/wiki/Genetic_algorithm">GA</a>) implementation of the Travelling Salesman Problem (<a href="http://en.wikipedia.org/wiki/Travelling_salesman_problem" target="_blank">TSP</a>). I&#8217;ve rewritten pretty much everything, but the two most notable changes are:</p>
<p>1. I split the code into 2 projects: one holding the general GA code, which is now called GALib, and one holding the code specific to the TSP, now called <a href="http://en.wikipedia.org/wiki/Skynet_%28Terminator%29" target="_blank">Skynet</a> (lol <img src='http://blog.bn2vs.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> ). This allows for making any other GA implementation using GALib, even in .Net languages different from C#. The underneath diagram should give you a good idea of how the who thing works. The 4 most left classes are of Skynet, all remaining classes and interfaces are of GALib.</p>
<p><a href="http://blog.bn2vs.com/wp-content/uploads/2010/01/GALib-TSP-dependencyDiagram.png.gif"><img class="alignnone size-full wp-image-651" title="Dependency diagram of a Visual Studio solution containing the GALib and TSP app (Skynet)" src="http://blog.bn2vs.com/wp-content/uploads/2010/01/GALib-TSP-dependencyDiagram.png.gif" alt="Dependency diagram of a Visual Studio solution containing the GALib and TSP app (Skynet)" width="603" height="333" /></a></p>
<p>2. I rewrote the genotype of the Route individual type, the core of the TSP implementation. Instead of having a list of integers, referring to cities, I now have a list of Connection, each containing 2 instances of Location. I&#8217;ve done this to allow smarter <a href="http://en.wikipedia.org/wiki/Crossover_%28genetic_algorithm%29">crossover</a>, decreasing the chance of not finding a better solution while it&#8217;s still in the converged search space significantly. As a result of this change, I also had to rewrite pretty much everything else of the Route class, including random initialization, mutation and fitness assessment. The biggest challenge here was preventing the creation of multiple loops in the crossover algorithm.</p>
<p>The interface of the TSP app (now called Skynet) also has seen quite some work. I figured out quite a lot of <a href="http://en.wikipedia.org/wiki/Windows_Presentation_Foundation">WPF</a> stuff by further creating it. Some extra controls and progress indicators still need to be added though, and I also haven&#8217;t created the Cancel/Stop functionality.</p>
<p><a href="http://blog.bn2vs.com/wp-content/uploads/2010/01/GALib-TSP.png"><img class="alignnone size-full wp-image-652" title="Skynet interface showing 42 cities arranged in a circle" src="http://blog.bn2vs.com/wp-content/uploads/2010/01/GALib-TSP.png" alt="Skynet interface showing 42 cities arranged in a circle" width="592" height="662" /></a></p>
<p>Although the algorithm is efficient in the way that it takes relatively few generations to find a close to optimal solution, there remain a few mayor performance issues. If I compare the speed of evolution (measured in generations) with similar applications tackling the TSP, there are those performing up to 3 orders of magnitude faster. Although the fastest of those are written in C++ or C, I should be able to significantly speed up my application. Tracking down resource eating parts of code will be one of my next steps in developing this app. Another possible issue is diversity of the population. I have the suspicion that the diversity shrinks pretty fast, resulting into evolution driven only by mutation. I&#8217;m not sure of this though, and also have to investigate how I can prevent this from happening.</p>
<p>Here you have a few screenshots of the app in action <img src='http://blog.bn2vs.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a href="http://blog.bn2vs.com/wp-content/uploads/2010/01/GALib-TSP-gen41.png"><img class="alignnone size-full wp-image-653" title="Skynet interface showing the evolved route between 42 cities after 41 generations." src="http://blog.bn2vs.com/wp-content/uploads/2010/01/GALib-TSP-gen41.png" alt="Skynet interface showing the evolved route between 42 cities after 41 generations." width="594" height="662" /></a></p>
<p><a href="http://blog.bn2vs.com/wp-content/uploads/2010/01/GALib-TSP-gen2-1470.png"><img class="alignnone size-full wp-image-654" title="Skynet interface showing the evolved route between 42 cities after 1470 generations." src="http://blog.bn2vs.com/wp-content/uploads/2010/01/GALib-TSP-gen2-1470.png" alt="Skynet interface showing the evolved route between 42 cities after 1470 generations." width="592" height="660" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bn2vs.com/2010/01/10/galib-with-tsp-implementation/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>My first genetic algorithm</title>
		<link>http://blog.bn2vs.com/2010/01/03/my-first-genetic-algorithm/</link>
		<comments>http://blog.bn2vs.com/2010/01/03/my-first-genetic-algorithm/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 06:04:36 +0000</pubDate>
		<dc:creator>Jeroen De Dauw</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 4.0]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[GA]]></category>
		<category><![CDATA[Genetic Algorithm]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[SourceForge]]></category>
		<category><![CDATA[TSP]]></category>
		<category><![CDATA[Ttravelling Salesman Problem]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://blog.bn2vs.com/?p=644</guid>
		<description><![CDATA[To practice some AI methods I&#8217;ve been reading about, I created a genetic algorithm (GA) implementation to tackle the travelling salesman problem (TSP). I decided to do this in C#, to practice myself in some more advanced aspects of the language, and mess some more around with the new stuff of .Net 4.0, and with [...]]]></description>
			<content:encoded><![CDATA[<p>To practice some AI methods I&#8217;ve been reading about, I created a <a href="http://en.wikipedia.org/wiki/Genetic_algorithm" target="_blank">genetic algorithm</a> (GA) implementation to tackle the <a href="http://en.wikipedia.org/wiki/Travelling_salesman_problem" target="_blank">travelling salesman problem</a> (TSP). I decided to do this in C#, to practice myself in some more advanced aspects of the language, and mess some more around with the new stuff of .Net 4.0, and with WPF as interface to get a better grip on the basics of <a href="http://en.wikipedia.org/wiki/Windows_Presentation_Foundation" target="_blank">WPF</a> and <a href="http://en.wikipedia.org/wiki/XAML" target="_blank">XAML</a>.</p>
<p>I started with creating a general data structure for any GA algorithm (Classes Population and Individual, interface IIndividual and some others), and then added handling for the TSP problem by creating a Route class. This class holds the crossover, mutation and random initialization methods for routes. Each instance of Route, which derives from Individual and implements IIndividual, contains it&#8217;s own genotype, which is a List&lt;Int64&gt;. This list contains the numbers of the &#8216;cities&#8217; the &#8216;salesman&#8217; travels along. In the code behind my main window, I then create an instance of a Population&lt;Route&gt;, and do a calculation of the distances between all points, which is then stored in a static field of Route.</p>
<p>I&#8217;m going to put the complete project on <a href="http://sourceforge.net/" target="_blank">SourceForge</a> when it&#8217;s a little more finished. Although the algorithm is working it can still be optimized a lot (especially the genetic operations). Also, the interface is far from ready, and I&#8217;d like to do another simple implementation with the general GA structure to tackle some other problem.</p>
<p>In any case, here are some nice sceenshots <img src='http://blog.bn2vs.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div id="attachment_646" class="wp-caption alignnone" style="width: 529px"><a href="http://blog.bn2vs.com/wp-content/uploads/2010/01/tsp-genetic-algorithm-cities.gif"><img class="size-full wp-image-646" title="The travelling salesman problem - the dots represent cities." src="http://blog.bn2vs.com/wp-content/uploads/2010/01/tsp-genetic-algorithm-cities.gif" alt="" width="519" height="209" /></a><p class="wp-caption-text">The dots represent cities.</p></div>
<div id="attachment_647" class="wp-caption alignnone" style="width: 529px"><a href="http://blog.bn2vs.com/wp-content/uploads/2010/01/tsp-genetic-algorithm-evolution.gif"><img class="size-full wp-image-647" title="The travelling salesman problem - evolution of the route." src="http://blog.bn2vs.com/wp-content/uploads/2010/01/tsp-genetic-algorithm-evolution.gif" alt="The travelling salesman problem - evolution of the route." width="519" height="240" /></a><p class="wp-caption-text">The shortest route after several generations. The gray line represents an attempted, but failed, mutation or combination.</p></div>
<div id="attachment_648" class="wp-caption alignnone" style="width: 531px"><a href="http://blog.bn2vs.com/wp-content/uploads/2010/01/tsp-genetic-algorithm-shortest-path.gif"><img class="size-full wp-image-648" title="The travelling salesman problem - the shortest route." src="http://blog.bn2vs.com/wp-content/uploads/2010/01/tsp-genetic-algorithm-shortest-path.gif" alt="The travelling salesman problem - the shortest route." width="521" height="244" /></a><p class="wp-caption-text">After a while the shortest route, or at least one that&#39;s very close, is found.</p></div>
<p>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bn2vs.com/2010/01/03/my-first-genetic-algorithm/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

