<?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>SQL in the Wild &#187; Personal</title>
	<atom:link href="http://sqlinthewild.co.za/index.php/category/personal/feed/" rel="self" type="application/rss+xml" />
	<link>http://sqlinthewild.co.za</link>
	<description>A discussion on SQL Server</description>
	<lastBuildDate>Sun, 01 Jan 2012 14:30:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>2011 Book review</title>
		<link>http://sqlinthewild.co.za/index.php/2012/01/01/2011-book-review/</link>
		<comments>http://sqlinthewild.co.za/index.php/2012/01/01/2011-book-review/#comments</comments>
		<pubDate>Sun, 01 Jan 2012 14:30:00 +0000</pubDate>
		<dc:creator>Gail</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://sqlinthewild.co.za/?p=1370</guid>
		<description><![CDATA[Another year over and much as I did last year, I&#8217;m going to briefly go over the books I read this last year. I will freely admit, very few of these could be considered &#8216;classic literature&#8217;, most is a mix of sci-fi, fantasy or adventure fiction. That&#8217;s just what I like to read. Book total [...]]]></description>
			<content:encoded><![CDATA[<p>Another year over and much as I did last year, I&#8217;m going to briefly go over the books I read this last year.</p>
<p>I will freely admit, very few of these could be considered &#8216;classic literature&#8217;, most is a mix of sci-fi, fantasy or adventure fiction. That&#8217;s just what I like to read.</p>
<p>Book total this year was 53, up from the 45 I managed in 2010 and above the 50 that I aimed for. Part of this is that I travelled more (and hence had time with nothing to do but read), part is because I took a couple of small vacations (and spent time reading) and part is due to getting an iPad and loading a couple of book apps on there.</p>
<p>The iPad is never going to replace real, physical, paper books for me. I love the smell of new books, the feel of the book (and you can&#8217;t read an iPad in the bath without significant risk). That said, it is convenient when travelling and for carrying a few books easily. It&#8217;s especially nice when getting books from Amazon. 6 week shipping vs immediate delivery. No contest there.</p>
<p>My choice for best books of the year:</p>
<ol>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=jim-butcher&amp;now_reading_title=first-lords-fury-codex-alera">First Lord’s Fury (Codex Alera)</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=jim-butcher">Jim Butcher</a>. This is the climax of the Alera series and definitely the best of the bunch. Fast moving, tense, full of action and altogether an excellent ending for an excellent series. One thing I really like about this one: It doesn&#8217;t end with &#8216;happily ever after&#8217;.</li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=brandon-sanderson&amp;now_reading_title=elantris">Elantris</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=brandon-sanderson">Brandon Sanderson</a>. This is a bit of a surprise. I got this on sale without too much in the way of expectations. Not to say I don&#8217;t like Brandon Sanderson, I&#8217;ve enjoyed everything of his that I&#8217;ve read, but this was his first published book and so I was willing to give it a little leeway. Not necessary. Good characters (though I&#8217;m sure I recognise that headstrong princess from a few places), good plot without too many holes and an intriguing mystery that all comes together logically in a way that leaves you saying &#8216;But, of course that&#8217;s the problem&#8217;. Definitely recommend and looking forward to more of his work.</li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=david-mack&amp;now_reading_title=star-trek-destiny-gods-of-night">Star Trek: Destiny</a></strong> (trilogy). Yes, I&#8217;m recommending Star Trek novels. The world has not ended. I find most Star Trek novels are quickly churned out, mediocre novels. Average writing, average plotting (at best) and usually a reset button to return the universe to the way it was at the end. This trilogy is none of those. The plot works, it&#8217;s intertwined over three books and about four time-periods and the crew of at least four ships, and it works. It also leaves the universe dramatically changed (in a way that I did not foresee coming). Finally it&#8217;s one of the few time travel tales I&#8217;ve read that doesn&#8217;t leave me cringing.</li>
</ol>
<p>Sooo… books per month.</p>
<p><a href="http://sqlinthewild.co.za/wp-content/uploads/2012/01/BookList.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="BookList" src="http://sqlinthewild.co.za/wp-content/uploads/2012/01/BookList_thumb.png" alt="BookList" width="480" height="244" border="0" /></a></p>
<p>You can almost see from that which months I was travelling or on holiday. June – trip to UK and a few days at leisure. Oct – trip to Pass and lots of time to read while travelling. Nov – Week away in the middle of nowhere.</p>
<p>Lastly, books per genre. Yes, I read a lot of fantasy. (note, these links go to the library pages on this blog, there&#8217;s a link to the Amazon page from there)</p>
<p>Science Fiction</p>
<ol>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=peter-david&amp;now_reading_title=the-long-night-of-centauri-prime-babylon-5-legions-of-fire-book-1">The Long Night of Centauri Prime (Babylon 5: Legions of Fire, Book 1)</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=peter-david">Peter David</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=arthur-c-clarke&amp;now_reading_title=the-light-of-other-days">The Light of Other Days</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=arthur-c-clarke">Arthur C. Clarke</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=david-mack&amp;now_reading_title=star-trek-destiny-3-lost-souls">Star Trek: Destiny #3: Lost Souls</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=david-mack">David Mack</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=david-mack&amp;now_reading_title=star-trek-destiny-2-mere-mortals">Star Trek: Destiny #2: Mere Mortals</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=david-mack">David Mack</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=tanya-huff&amp;now_reading_title=a-confederation-of-valor-omnibus">A Confederation of Valor (omnibus)</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=tanya-huff">Tanya Huff</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=david-mack&amp;now_reading_title=star-trek-destiny-gods-of-night">Star Trek: Destiny #1: Gods of Night</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=david-mack">David Mack</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=orson-scott-card&amp;now_reading_title=earthfall-homecoming">Earthfall (Homecoming)</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=orson-scott-card">Orson Scott Card</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=simon-r-green&amp;now_reading_title=deathstalker">Deathstalker</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=simon-r-green">Simon R. Green</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=arthur-c-clarke&amp;now_reading_title=childhoods-end-del-rey-impact">Childhood’s End </a></strong>by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=arthur-c-clarke">Arthur C. Clarke</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=arthur-c-clarke&amp;now_reading_title=songs-of-distant-earth">Songs of Distant Earth</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=arthur-c-clarke">Arthur C. Clarke</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=h-g-wells&amp;now_reading_title=the-time-machine-sf-masterworks">The Time Machine (SF Masterworks)</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=h-g-wells">H. G. Wells</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=orson-scott-card&amp;now_reading_title=the-call-of-earth">The Call of Earth</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=orson-scott-card">Orson Scott Card</a></li>
</ol>
<p>Fantasy</p>
<ol>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=mercedes-lackey-james-mallory&amp;now_reading_title=the-phoenix-transformed-the-enduring-flame">The Phoenix Transformed (The Enduring Flame)</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=mercedes-lackey-james-mallory">Mercedes Lackey, James Mallory</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=simon-r-green&amp;now_reading_title=nightingales-lament-nightside-book-3">Nightingale’s Lament (Nightside, Book 3)</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=simon-r-green">Simon R. Green</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=brandon-sanderson&amp;now_reading_title=elantris">Elantris</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=brandon-sanderson">Brandon Sanderson</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=stephen-king&amp;now_reading_title=the-gunslinger-the-dark-tower">The Gunslinger (The Dark Tower)</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=stephen-king">Stephen King</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=simon-r-green&amp;now_reading_title=agents-of-light-and-darkness-nightside-book-2">Agents of Light and Darkness (Nightside, Book 2)</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=simon-r-green">Simon R. Green</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=melanie-rawn&amp;now_reading_title=the-dragon-token-dragon-star-book-2">The Dragon Token (Dragon Star, Book 2)</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=melanie-rawn">Melanie Rawn</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=simon-r-green&amp;now_reading_title=something-from-the-nightside-nightside-book-1">Something from the Nightside (Nightside, Book 1)</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=simon-r-green">Simon R. Green</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=j-gregory-keyes&amp;now_reading_title=a-calculus-of-angels-the-age-of-unreason-book-2">A Calculus of Angels (The Age of Unreason, Book 2)</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=j-gregory-keyes">J. Gregory Keyes</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=melanie-rawn&amp;now_reading_title=stronghold-dragon-star-book-1">Stronghold (Dragon Star, Book 1)</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=melanie-rawn">Melanie Rawn</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=orson-scott-card&amp;now_reading_title=the-crystal-city-the-tales-of-alvin-maker-book-6">The Crystal City (The Tales of Alvin Maker, Book 6)</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=orson-scott-card">Orson Scott Card</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=simon-r-green&amp;now_reading_title=guards-of-haven-the-adventures-of-hawk-and-fisher">Guards of Haven: The Adventures of Hawk and Fisher</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=simon-r-green">Simon R. Green</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=rick-riordan&amp;now_reading_title=the-last-olympian-percy-jackson-and-the-olympians-book-5">The Last Olympian (Percy Jackson and the Olympians, Book 5)</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=rick-riordan">Rick Riordan</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=rick-riordan&amp;now_reading_title=the-battle-of-the-labyrinth-percy-jackson-and-the-olympians-book-4">The Battle of the Labyrinth (Percy Jackson and the Olympians, Book 4)</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=rick-riordan">Rick Riordan</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=rick-riordan&amp;now_reading_title=the-titans-curse-percy-jackson-and-the-olympians-book-3">The Titan’s Curse (Percy Jackson and the Olympians, Book 3)</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=rick-riordan">Rick Riordan</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=rick-riordan&amp;now_reading_title=the-sea-of-monsters-percy-jackson-and-the-olympians-book-2">The Sea Of Monsters (Percy Jackson and the Olympians, Book 2)</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=rick-riordan">Rick Riordan</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=rick-riordan&amp;now_reading_title=the-lightning-thief-percy-jackson-and-the-olympians-book-1">The Lightning Thief (Percy Jackson and the Olympians, Book 1)</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=rick-riordan">Rick Riordan</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=orson-scott-card&amp;now_reading_title=heartfire-the-tales-of-alvin-maker-book-5">Heartfire (The Tales of Alvin Maker, Book 5)</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=orson-scott-card">Orson Scott Card</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=orson-scott-card&amp;now_reading_title=alvin-journeyman-tales-of-alvin-maker-book-4">Alvin Journeyman (Tales of Alvin Maker, Book 4)</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=orson-scott-card">Orson Scott Card</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=orson-scott-card&amp;now_reading_title=prentice-alvin-the-tales-of-alvin-maker-book-3">Prentice Alvin (The Tales of Alvin Maker, Book 3)</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=orson-scott-card">Orson Scott Card</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=orson-scott-card&amp;now_reading_title=red-prophet-tales-of-alvin-maker-book-2">Red Prophet (Tales of Alvin Maker, Book 2)</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=orson-scott-card">Orson Scott Card</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=orson-scott-card&amp;now_reading_title=seventh-son-tales-of-alvin-maker-book-1">Seventh Son (Tales of Alvin Maker, Book 1)</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=orson-scott-card">Orson Scott Card</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=raymond-e-feist&amp;now_reading_title=rides-a-dread-legion-book-one-of-the-demonwar-saga">Rides a Dread Legion: Book One of the Demonwar Saga</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=raymond-e-feist">Raymond E. Feist</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=jim-butcher&amp;now_reading_title=first-lords-fury-codex-alera">First Lord’s Fury (Codex Alera)</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=jim-butcher">Jim Butcher</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=steven-brust&amp;now_reading_title=issola-vlad-taltos">Issola (Vlad Taltos)</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=steven-brust">Steven Brust</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=jim-butcher&amp;now_reading_title=turn-coat-the-dresden-files-book-11">Turn Coat (The Dresden Files, Book 11)</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=jim-butcher">Jim Butcher</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=simon-r-green&amp;now_reading_title=hawk">Hawk </a></strong>by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=simon-r-green">Simon R. Green</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=stephen-r-lawhead&amp;now_reading_title=taliesin">Taliesin</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=stephen-r-lawhead">Stephen R. Lawhead</a></li>
</ol>
<p>Other Fiction</p>
<ol>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=robert-ludlum-patrick-larkin&amp;now_reading_title=robert-ludlums-the-lazarus-vendetta-a-covert-one-novel">Robert Ludlum’s The Lazarus Vendetta: A Covert-One Novel</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=robert-ludlum-patrick-larkin">Robert Ludlum, Patrick Larkin</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=robert-ludlum-gayle-lynds&amp;now_reading_title=robert-ludlums-the-altman-code-a-covert-one-novel">Robert Ludlum’s The Altman Code: A Covert-One Novel</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=robert-ludlum-gayle-lynds">Robert Ludlum, Gayle Lynds</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=robert-ludlum&amp;now_reading_title=the-bourne-identity-a-novel">The Bourne Identity: A Novel</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=robert-ludlum">Robert Ludlum</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=jasper-fforde&amp;now_reading_title=the-eyre-affair-a-thursday-next-novel-thursday-next-novels-penguin-books">The Eyre Affair: A Thursday Next Novel (Thursday Next Novels (Penguin Books))</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=jasper-fforde">Jasper Fforde</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=conn-iggulden&amp;now_reading_title=lords-of-the-bow">Lords of the Bow</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=conn-iggulden">Conn Iggulden</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=robert-ludlum-philip-shelby&amp;now_reading_title=robert-ludlums-the-cassandra-compact-a-covert-one-novel">Robert Ludlum’s The Cassandra Compact: A Covert-One Novel</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=robert-ludlum-philip-shelby">Robert Ludlum, Philip Shelby</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=robert-ludlum&amp;now_reading_title=robert-ludlums-the-hades-factor-a-covert-one-novel">Robert Ludlum’s The Hades Factor: A Covert-One Novel</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=robert-ludlum">Robert Ludlum</a></li>
</ol>
<p>Non-fiction</p>
<ol>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=lee-smolin&amp;now_reading_title=three-roads-to-quantum-gravity">Three Roads to Quantum Gravity</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=lee-smolin">Lee Smolin</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=adam-machanic-hugo-kornelis-lara-rubbelke&amp;now_reading_title=expert-sql-server-2005-development">Expert SQL Server 2005 Development</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=adam-machanic-hugo-kornelis-lara-rubbelke">Adam Machanic, Hugo Kornelis, Lara Rubbelke</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=bill-bryson&amp;now_reading_title=notes-from-a-small-island">Notes From a Small Island</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=bill-bryson">Bill Bryson</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=michael-howard-david-leblanc-john-viega&amp;now_reading_title=19-deadly-sins-of-software-security-programming-flaws-and-how-to-fix-them-security-one-off">19 Deadly Sins of Software Security: Programming Flaws and How to Fix Them (Security One-off)</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=michael-howard-david-leblanc-john-viega">Michael Howard, David LeBlanc, John Viega</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=frederick-p-brooks&amp;now_reading_title=the-mythical-man-month-essays-on-software-engineering-anniversary-edition-2nd-edition">The Mythical Man-Month: Essays on Software Engineering, Anniversary Edition (2nd Edition)</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=frederick-p-brooks">Frederick P. Brooks</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=joseph-silk&amp;now_reading_title=on-the-shores-of-the-unknown-a-short-history-of-the-universe">On the Shores of the Unknown: A Short History of the Universe</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=joseph-silk">Joseph Silk</a></li>
<li><strong><a href="http://sqlinthewild.co.za/index.php?now_reading_author=chuck-pfarrer&amp;now_reading_title=warrior-soul-the-memoir-of-a-navy-seal">Warrior Soul: The Memoir of a Navy Seal</a></strong> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=chuck-pfarrer">Chuck Pfarrer</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://sqlinthewild.co.za/index.php/2012/01/01/2011-book-review/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Tourist time, Amsterdam and Vancouver</title>
		<link>http://sqlinthewild.co.za/index.php/2011/02/27/tourist-time-amsterdam-and-vancouver/</link>
		<comments>http://sqlinthewild.co.za/index.php/2011/02/27/tourist-time-amsterdam-and-vancouver/#comments</comments>
		<pubDate>Sun, 27 Feb 2011 17:47:58 +0000</pubDate>
		<dc:creator>Gail</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://sqlinthewild.co.za/index.php/2011/02/27/tourist-time-amsterdam-and-vancouver/</guid>
		<description><![CDATA[Nothing fancy here, just some of the photos that I took in Amsterdam and Vancouver. Taken with my phone, as I forgot to check the camera battery before I left, and I forgot to pack the charger. Amsterdam Amsterdam Central train station One of the canals downtown Amsterdam Vancouver The steam-powered clock One of the [...]]]></description>
			<content:encoded><![CDATA[<p>Nothing fancy here, just some of the photos that I took in Amsterdam and Vancouver. Taken with my phone, as I forgot to check the camera battery before I left, and I forgot to pack the charger.</p>
<h2>Amsterdam</h2>
<p>Amsterdam Central train station    </p>
<h2><a href="http://sqlinthewild.co.za/wp-content/uploads/2011/02/2011-02-23-12.06.48.jpg"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="2011-02-23 12.06.48" border="0" alt="2011-02-23 12.06.48" src="http://sqlinthewild.co.za/wp-content/uploads/2011/02/2011-02-23-12.06.48_thumb.jpg" width="244" height="184" /></a></h2>
<p>One of the canals downtown Amsterdam    <br /><a href="http://sqlinthewild.co.za/wp-content/uploads/2011/02/2011-02-23-12.25.04.jpg"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="2011-02-23 12.25.04" border="0" alt="2011-02-23 12.25.04" src="http://sqlinthewild.co.za/wp-content/uploads/2011/02/2011-02-23-12.25.04_thumb.jpg" width="184" height="244" /></a></p>
<p><a href="http://sqlinthewild.co.za/wp-content/uploads/2011/02/2011-02-23-12.21.16.jpg"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="2011-02-23 12.21.16" border="0" alt="2011-02-23 12.21.16" src="http://sqlinthewild.co.za/wp-content/uploads/2011/02/2011-02-23-12.21.16_thumb.jpg" width="244" height="184" /></a></p>
<p><a href="http://sqlinthewild.co.za/wp-content/uploads/2011/02/2011-02-23-13.03.43.jpg"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="2011-02-23 13.03.43" border="0" alt="2011-02-23 13.03.43" src="http://sqlinthewild.co.za/wp-content/uploads/2011/02/2011-02-23-13.03.43_thumb.jpg" width="184" height="244" /></a></p>
<h2>Vancouver</h2>
<p>The steam-powered clock    <br /><a href="http://sqlinthewild.co.za/wp-content/uploads/2011/02/2011-02-24-12.47.03.jpg"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="2011-02-24 12.47.03" border="0" alt="2011-02-24 12.47.03" src="http://sqlinthewild.co.za/wp-content/uploads/2011/02/2011-02-24-12.47.03_thumb.jpg" width="184" height="244" /></a></p>
<p>One of the parks around the city.   <br /><a href="http://sqlinthewild.co.za/wp-content/uploads/2011/02/2011-02-24-13.54.18.jpg"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="2011-02-24 13.54.18" border="0" alt="2011-02-24 13.54.18" src="http://sqlinthewild.co.za/wp-content/uploads/2011/02/2011-02-24-13.54.18_thumb.jpg" width="244" height="184" /></a></p>
<p>Entrance to Chinatown   <br /><a href="http://sqlinthewild.co.za/wp-content/uploads/2011/02/2011-02-24-13.59.59.jpg"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="2011-02-24 13.59.59" border="0" alt="2011-02-24 13.59.59" src="http://sqlinthewild.co.za/wp-content/uploads/2011/02/2011-02-24-13.59.59_thumb.jpg" width="244" height="184" /></a></p>
<p>Taken from near the ScienceWorld   <br /><a href="http://sqlinthewild.co.za/wp-content/uploads/2011/02/2011-02-25-12.14.48.jpg"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="2011-02-25 12.14.48" border="0" alt="2011-02-25 12.14.48" src="http://sqlinthewild.co.za/wp-content/uploads/2011/02/2011-02-25-12.14.48_thumb.jpg" width="244" height="184" /></a></p>
<p>Half-frozen fountains Friday afternoon   <br /><a href="http://sqlinthewild.co.za/wp-content/uploads/2011/02/2011-02-25-16.13.17.jpg"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="2011-02-25 16.13.17" border="0" alt="2011-02-25 16.13.17" src="http://sqlinthewild.co.za/wp-content/uploads/2011/02/2011-02-25-16.13.17_thumb.jpg" width="244" height="184" /></a></p>
<p>And snow on Saturday.   <br /><a href="http://sqlinthewild.co.za/wp-content/uploads/2011/02/2011-02-27-04.41.23.jpg"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="2011-02-27 04.41.23" border="0" alt="2011-02-27 04.41.23" src="http://sqlinthewild.co.za/wp-content/uploads/2011/02/2011-02-27-04.41.23_thumb.jpg" width="244" height="184" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://sqlinthewild.co.za/index.php/2011/02/27/tourist-time-amsterdam-and-vancouver/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>And now for a completely inappropriate use of SQL Server</title>
		<link>http://sqlinthewild.co.za/index.php/2011/02/22/and-now-for-a-completely-inappropriate-use-of-sql-server/</link>
		<comments>http://sqlinthewild.co.za/index.php/2011/02/22/and-now-for-a-completely-inappropriate-use-of-sql-server/#comments</comments>
		<pubDate>Tue, 22 Feb 2011 14:30:41 +0000</pubDate>
		<dc:creator>Gail</dc:creator>
				<category><![CDATA[Artificial Intelligence]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Syndication]]></category>

		<guid isPermaLink="false">http://sqlinthewild.co.za/?p=885</guid>
		<description><![CDATA[A while back I wrote up a short introductory overview of Genetic Algorithms. Just for the shear, absolute fun of it, I thought I&#8217;d implement a basic genetic algorithm within SQL Server and use it to solve a form of the knapsack problem. Now first a few comments on this. As the title states, this [...]]]></description>
			<content:encoded><![CDATA[<p>A while back I wrote up a short introductory overview of <a href="http://sqlinthewild.co.za/index.php/2010/01/28/genetic-algorithms/">Genetic Algorithms</a>. Just for the shear, absolute fun of it, I thought I&#8217;d implement a basic genetic algorithm within SQL Server and use it to solve a form of the <a href="http://en.wikipedia.org/wiki/Knapsack_problem">knapsack problem</a>.</p>
<p>Now first a few comments on this. As the title states, this is not really an appropriate use of SQL Server. Genetic algorithms are generally implemented in languages like Java, C++, C#, etc; languages that are good at complex mathematics, string manipulation and have complex data types. I&#8217;m not necessarily using efficient, well-performing methods here, UDFa abound. This is not an article on best practices and well-performing code. I&#8217;m also doing no error handling, which I would if this were a real system (in a more suitable language)</p>
<p>Still, doing just for the sake of seeing if it&#8217;s possible is all sorts of fun. So, without further ado, the knapsack problem, an approximate solution with genetic algorithms in SQL Server. (For the record, this is a multi-constrained, bounded knapsack problem)</p>
<h3>The scenario</h3>
<p><img class="alignright" title="Treasure" src="http://sqlinthewild.co.za/wp-content/uploads/2011/02/Treasure-300x211.jpg" alt="" width="300" height="211" align="right" />There&#8217;s a bag that has a maximum volume that it can hold and a maximum mass that it can hold (and we assume that we can pack perfectly with no wasted space). There are eight items, all with different masses, different volumes and different values. The goal here is to maximise the total value of all the items contained within the bag.</p>
<pre class="brush: sql; title: ; notranslate">CREATE TABLE ObjectStatistics (
  ObjectNumber TINYINT NOT NULL,
  Mass NUMERIC(4,2) NOT NULL,
  Volume NUMERIC(4,2) NOT NULL,
  Value NUMERIC(4,2) NOT NULL,
  NumberAvailable TINYINT NOT NULL,
  CONSTRAINT pk_ObjectStats PRIMARY KEY CLUSTERED (ObjectNumber)
);

CREATE TABLE BagStatistics (
  MaxMass NUMERIC(5,2),
  MaxVolume NUMERIC(5,2)
);

INSERT INTO dbo.ObjectStatistics (ObjectNumber, Mass, Volume, Value, NumberAvailable)
VALUES
  (1,0.5,0.45,2,50),
  (2,1.5,0.25,20,10),
  (3,0.1,1.25,8,150),
  (4,0.25,0.1,1,250),
  (5,0.67,0.3,6,100),
  (6,0.34,0.75,18,5),
  (7,1.25,0.25,5,40),
  (8,1.1,0.8,10,25);

INSERT INTO dbo.BagStatistics (MaxMass, MaxVolume)
VALUES  (100, 75);</pre>
<p>Those two tables set up the constraints for the scenario, the maximum mass and volume for the bag and the mass, volume, value and maximum number available for each of the items.</p>
<p><span id="more-885"></span></p>
<h3>The setup</h3>
<p>Next we need a way to store the potential solutions (referred to as &#8216;individuals&#8217;). I decided on two tables (pretending to be doing proper DB design here). Keeping everything in one table would also have worked, it would just have required a different implementation later on.</p>
<pre class="brush: sql; title: ; notranslate">CREATE TABLE Individuals (
  Generation SMALLINT,
  IndividualID SMALLINT,
  CONSTRAINT pk_Individuals PRIMARY KEY CLUSTERED (Generation, IndividualID)
);

CREATE TABLE IndividualDetails (
  Generation SMALLINT,
  IndividualID SMALLINT,
  ObjectNumber TINYINT,
  Quantity TINYINT,
  CONSTRAINT pk_IndividualDetails PRIMARY KEY CLUSTERED (Generation, IndividualID, ObjectNumber),
  CONSTRAINT fk_IndividualDetails_Individuals FOREIGN KEY (Generation, IndividualID) REFERENCES dbo.Individuals (Generation, IndividualID)
);</pre>
<p>I&#8217;m going to add two more tables, one to make the processing easier (it&#8217;ll become clear later where this is used) and one to store some results. Also a view to get around the &#8216;cannot use RAND inside a UDF&#8217; limitation.</p>
<pre class="brush: sql; title: ; notranslate">CREATE TABLE Numbers (
  Value TINYINT PRIMARY KEY,
  BinaryRepresentation CHAR(8) UNIQUE
);

CREATE TABLE GenerationStatistics (
  Generation SMALLINT,
  MaxFitness NUMERIC(8,2),
  AvgFitness NUMERIC(8,2)
);
GO

CREATE VIEW RandomNumber
AS
  SELECT RAND(CHECKSUM(NEWID())) AS Random;
GO</pre>
<p>That&#8217;s the basics out of the way. There are two important things I need to decide on straightaway.</p>
<p>The first is an encoding of the individual&#8217;s properties (in this case object quantities) so that the genetic algorithm can manipulate them. I&#8217;m going to use a binary representation &#8211; convert the quantity for each object into binary and concatenate the strings together. 8 bits per object.</p>
<p>The second is a fitness function, a way to tell which individuals are the best. In this case it&#8217;ll be a simple sum of the values of all the items, taking into account the max mass, max volume and max quantity for each.</p>
<p>I decided to implement both of these as scalar UDFs (yes, shock and horror, I&#8217;m using data-accessing scalar UDFs) and make them calculated columns of the Individuals table.</p>
<p>The integer-to-binary uses a slightly modified version of a function written by <a href="http://mitch-wheat.blogspot.com/">Mitch Wheat</a>, available on his blog &#8211; <a title="http://mitch-wheat.blogspot.com/2006/10/t-sql-way-converting-integers-to.html" href="http://mitch-wheat.blogspot.com/2006/10/t-sql-way-converting-integers-to.html">http://mitch-wheat.blogspot.com/2006/10/t-sql-way-converting-integers-to.html</a>. Thanks Mitch</p>
<pre class="brush: sql; title: ; notranslate">-- Originally from http://mitch-wheat.blogspot.com/2006/10/t-sql-way-converting-integers-to.html
CREATE FUNCTION IntegerToBinary(@intval int)
RETURNS char(8)
AS
BEGIN
 DECLARE @bincode char(64);

 SET @bincode = '0000000100100011010001010110011110001001101010111100110111101111';

 RETURN (
   SUBSTRING( @bincode, ((@IntVal / 16) &amp; 15) * 4 + 1 , 4 ) +
   SUBSTRING( @bincode, (@IntVal &amp; 15) * 4 + 1 , 4 )
 );
END
GO

CREATE FUNCTION dbo.ComputeBinaryString(@Generation SMALLINT, @Individual SMALLINT)
RETURNS CHAR(64)
AS
BEGIN
 DECLARE @BinaryString VARCHAR(64) = '';

 SELECT @BinaryString = @BinaryString + dbo.IntegerToBinary(Quantity)
   FROM dbo.IndividualDetails
   WHERE Generation = @Generation AND IndividualID = @Individual
   ORDER BY ObjectNumber;

 RETURN @BinaryString;
END;
GO

CREATE FUNCTION dbo.Fitness(@Generation SMALLINT, @Individual SMALLINT)
RETURNS NUMERIC(6,2)
AS
BEGIN
 DECLARE @MaxMass NUMERIC(5,2), @MaxVolume NUMERIC(5,2);
 SELECT @MaxMass = MaxMass, @MaxVolume = MaxVolume
   FROM dbo.BagStatistics;

 DECLARE @TotalValue NUMERIC(6,2) = 0;

 SELECT @TotalValue = SUM(id.Quantity*os.Value)
   FROM dbo.IndividualDetails id
   INNER JOIN dbo.ObjectStatistics os ON id.ObjectNumber = os.ObjectNumber
   WHERE Generation = @Generation AND IndividualID = @Individual
   HAVING SUM(id.Quantity*os.Mass) &lt;= @MaxMass
     AND SUM(id.Quantity*os.Volume) &lt;= @MaxVolume
     AND SUM(CASE WHEN id.Quantity&gt;os.NumberAvailable THEN 1 ELSE 0 END) = 0;

 RETURN @TotalValue;
END;
GO

ALTER TABLE dbo.Individuals
ADD BinaryString AS dbo.ComputeBinaryString (Generation, IndividualID),
    Fitness AS dbo.Fitness(Generation, IndividualID);
GO</pre>
<p>At this point I have a way to store the individual in each generation, a way to represent them in order for the genetic algorithm to process them and a way to calculate the fitness. Good to go.</p>
<h3>The framework</h3>
<p>I now need to implement the genetic algorithm itself. The main components that I need to implement are the crossover and the mutation and then an evolution procedure to generate new individuals from the current ones.</p>
<p>I&#8217;m going to again use functions for the crossover and mutation, for convenience and easy coding. A multi-statement table-valued UDF for the crossover and a scalar UDF for the mutation. (Performance? What performance?)</p>
<p>The crossover&#8217;s fairly simple. Take 2 binary strings as parameters. Pick a random point along the string and cut the two strings at that point. Create two new strings from the first part of the first input string concatenated with the second part of the second input string and from the first part of the second input string concatenated with the second part of the first input string.</p>
<p>If I started with &#8217;00000000&#8242; and &#8217;11111111&#8242; and picked 5 as the crossover point, afterwards I&#8217;d get &#8217;00000111&#8242; and &#8217;11111000&#8242;</p>
<pre class="brush: sql; title: ; notranslate">CREATE FUNCTION dbo.Crossover(@BinaryString1 CHAR(64), @BinaryString2 CHAR(64))
  RETURNS @NewIndividuals TABLE (CrossoverPoint TINYINT, BinaryString CHAR(64))
AS
BEGIN

 -- where in the string is the crossover
 DECLARE @CrossoverPoint TINYINT;
 SELECT @CrossoverPoint = FLOOR(Random*64)+1
   FROM RandomNumber;

 INSERT INTO @NewIndividuals
 SELECT @CrossoverPoint, SUBSTRING(@BinaryString1,0,@CrossoverPoint) + SUBSTRING(@BinaryString2,@CrossoverPoint, 64-@CrossoverPoint+1)
 UNION ALL
 SELECT @CrossoverPoint, SUBSTRING(@BinaryString2,0,@CrossoverPoint) + SUBSTRING(@BinaryString1,@CrossoverPoint, 64-@CrossoverPoint+1);

 RETURN;

END
GO</pre>
<p>The mutation&#8217;s not much more complex. Take a single binary string as input. Pick a random position along the string. Flip that bit (0-&gt;1; 1-&gt;0). Return the modified string</p>
<pre class="brush: sql; title: ; notranslate">CREATE FUNCTION dbo.ApplyMutation(@BinaryString CHAR(64))
RETURNS CHAR(64)
AS
BEGIN

DECLARE @MutationLocation TINYINT, @SwappedBit CHAR(1);

-- Which bit are we toggling?
SELECT @MutationLocation = FLOOR(Random*64)+1
  FROM RandomNumber;

-- simple toggle for the chosen bit
SET @SwappedBit = 1 - CAST(SUBSTRING(@BinaryString, @MutationLocation,1) AS BIT);

-- and stuff it back in
SET @BinaryString = STUFF(@BinaryString,@MutationLocation,1,@SwappedBit);

RETURN @BinaryString;
END
GO</pre>
<p>One thing to note at this point is that neither the crossover nor the mutation has any dependency on the details of the problem being solved. This is intentional, and is generally how genetic algorithms work. With the details encoded properly (in this case into a binary string), the crossover and mutation should be able to work just on the encoded string without needing any knowledge of the actual problem.</p>
<p>Last thing needed here is something that will take the existing individuals, apply the crossover and mutation and return new individuals. This time I think a stored procedure would be best.</p>
<pre class="brush: sql; title: ; notranslate">CREATE PROCEDURE Evolve (@CurrentGeneration INT)
AS
BEGIN

CREATE TABLE #SelectedIndividuals (
  BinaryString CHAR(64),
  CrossoverGroup TINYINT
);

-- use the fittest half of the current population to evolve the next generation
-- ensures that the low fitness individuals are eliminated (survival of the fittest FTW)
INSERT INTO #SelectedIndividuals (BinaryString, CrossoverGroup)
SELECT BinaryString, NTILE(2) OVER (ORDER BY (SELECT NEWID())) AS CrossoverGroup
  FROM (
    SELECT TOP (50) PERCENT BinaryString
      FROM Individuals
      ORDER BY Fitness DESC
  ) sub;

-- Join so that I have the two binary strings I'm crossing over in the same row.
-- The function then does the cross over and the mutation applies to the result
SELECT @CurrentGeneration AS Generation, ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS IndividualID, dbo.ApplyMutation(co.BinaryString) AS NewIndividual
 FROM (
    SELECT BinaryString, ROW_NUMBER() OVER (ORDER BY (SELECT NEWID())) AS PartnerNo
      FROM #SelectedIndividuals
      WHERE CrossoverGroup = 1
    ) AS Group1
  INNER JOIN (
    SELECT BinaryString, ROW_NUMBER() OVER (ORDER BY (SELECT NEWID())) AS PartnerNo
      FROM #SelectedIndividuals
      WHERE CrossoverGroup = 2
    ) AS Group2
    ON Group1.PartnerNo = Group2.PartnerNo
   CROSS APPLY dbo.CrossOver(Group1.BinaryString, Group2.BinaryString) co;
END;
GO</pre>
<p>That&#8217;s all that&#8217;s needed for the GA framework.</p>
<h3>The solution</h3>
<p>What&#8217;s needed for the solution is a loop to run through the generations one by one, a way to decode the individual returned by the Evolve procedure and some housekeeping.</p>
<p>First off, I need to fill the Numbers table.</p>
<pre class="brush: sql; title: ; notranslate">INSERT INTO dbo.Numbers (Value, BinaryRepresentation)
SELECT Value, dbo.IntegerToBinary(Value)
  FROM (
    SELECT TOP (256) Row_Number() OVER (ORDER BY column_id)-1 AS Value FROM sys.columns
  ) sub;
GO</pre>
<p>The setup for the execution loop involves declaring a few variable, a temp table and setting up the initial generation (randomly).</p>
<pre class="brush: sql; title: ; notranslate">SET NOCOUNT ON
DECLARE @CurrentGeneration SMALLINT = 0;
DECLARE @TotalGenerations SMALLINT = 50;
DECLARE @GenerationSize SMALLINT = 64; -- keep to powers of 2, and everything will work...

-- Create initial generation
-- First the individuals
INSERT INTO Individuals (Generation, IndividualID)
SELECT TOP(@GenerationSize) @CurrentGeneration AS Generation, ROW_NUMBER() OVER (ORDER BY column_id) AS IndividualID
  FROM sys.columns;

-- Now the details
INSERT INTO IndividualDetails (Generation, IndividualID, ObjectNumber, Quantity)
SELECT Generation, IndividualID, ObjectNumber, CEILING(RAND(CHECKSUM(NEWID()))*NumberAvailable/4)
  FROM Individuals
    CROSS JOIN ObjectStatistics;

-- Initial generation statistics
INSERT INTO GenerationStatistics (Generation, MaxFitness, AvgFitness)
SELECT @CurrentGeneration, MAX(Fitness), AVG(Fitness)
FROM Individuals;

-- placeholder table for new generations
CREATE TABLE #NewIndividuals (
  Generation SMALLINT,
  IndividualID SmallINT,
  BinaryString CHAR(64)
);</pre>
<p>The processing loop itself is nothing complex. Insert the results of the Evolve procedure into a temp table. From the temp table insert into the Individuals, decode the binary string and insert into IndividualDetails, then delete the lower-fitness individuals so that the population remains at a constant size.</p>
<p>In this case I&#8217;ve decided just to run for a fixed number of iterations. Often genetic algorithms would terminate after a certain number of iterations or if the max fitness didn&#8217;t improve by more than a certain threshold. For simplicity I&#8217;ll leave that out. It&#8217;s trivial to implement if anyone wants to experiment further.</p>
<pre class="brush: sql; title: ; notranslate">WHILE (@CurrentGeneration&lt;@TotalGenerations)
 BEGIN

   SET @CurrentGeneration+=1;

 -- Generate the new generation
   INSERT INTO #NewIndividuals (Generation, IndividualID, BinaryString)
   EXEC Evolve @CurrentGeneration;

 -- store the new individuals
   INSERT INTO Individuals (Generation, IndividualID)
   SELECT Generation, IndividualID
     FROM #NewIndividuals;

 -- chop binary string, insert into details table.
   INSERT INTO IndividualDetails (Generation, IndividualID, ObjectNumber, Quantity)
   SELECT Generation, IndividualID, Allele, Value
     FROM (
       SELECT Generation, IndividualID, Value+1 AS Allele, SUBSTRING(BinaryString, 1 + (Value * 8), 8 ) AS BinaryString
         FROM #NewIndividuals
           CROSS JOIN Numbers
         WHERE Value &lt; 8
     ) sub
       INNER JOIN Numbers ON sub.BinaryString = Numbers.BinaryRepresentation;

 -- delete all but the top (@GenerationSize) fittest individuals. Keep fixed population size.
   DELETE FROM IndividualDetails
     FROM IndividualDetails LEFT OUTER JOIN (
       SELECT TOP (@GenerationSize) Generation, IndividualID
         FROM Individuals
         ORDER BY fitness DESC
     ) Chosen ON IndividualDetails.Generation = Chosen.Generation AND IndividualDetails.IndividualID = Chosen.IndividualID
     WHERE Chosen.IndividualID IS NULL;

   DELETE FROM Individuals WHERE BinaryString = ''; -- only possible when there are no details

 -- Compute current max fitness and current avg fitness
   INSERT INTO GenerationStatistics (Generation, MaxFitness, AvgFitness)
   SELECT @CurrentGeneration, MAX(Fitness), AVG(Fitness)
     FROM Individuals;

 -- cleanup
 TRUNCATE TABLE #NewIndividuals;
 END -- while
DROP TABLE #NewIndividuals
</pre>
<p>And that&#8217;s pretty much all there is to it. All that&#8217;s left is to see how well the genetic algorithm did and how good the best solution it found really is.</p>
<p>Please note that this entire solution is driven by random numbers, if you run it you will get different results to what I did.</p>
<pre class="brush: sql; title: ; notranslate">SELECT TOP (1) i.Generation, i.IndividualID, TotalMass, TotalVolume, TotalValue
  FROM dbo.Individuals AS i
    INNER JOIN (
      SELECT Generation, IndividualID, SUM(Quantity*Value) AS TotalValue,  SUM(Quantity*Mass) AS TotalMass, SUM(Quantity*Volume) AS TotalVolume
        FROM dbo.IndividualDetails d INNER JOIN dbo.ObjectStatistics AS os ON d.ObjectNumber = os.ObjectNumber
        GROUP BY Generation, IndividualID
    ) id ON i.Generation = id.Generation AND i.IndividualID = id.IndividualID
  ORDER BY Fitness DESC;</pre>
<p><a href="http://sqlinthewild.co.za/wp-content/uploads/2011/02/GA-Results.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="GA Results" src="http://sqlinthewild.co.za/wp-content/uploads/2011/02/GA-Results_thumb.png" border="0" alt="GA Results" width="388" height="52" /></a></p>
<p>Not half bad.Is it the absolute best? Probably not. Genetic algorithms do not guarantee that they will find the best solution, just that they will find good ones</p>
<p>If we look at how the fitness (total value) improved over the generations it shows a massive initial increase in fitness then slow refinements. I could have run only 10 generations and still had a reasonably good result.</p>
<p><a href="http://sqlinthewild.co.za/wp-content/uploads/2011/02/GA-Graph.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="GA Graph" src="http://sqlinthewild.co.za/wp-content/uploads/2011/02/GA-Graph_thumb.png" border="0" alt="GA Graph" width="484" height="297" /></a></p>
<p>I think that&#8217;s enough playing with AI for now. While I doubt there&#8217;s any real practical use, I hope it was at least entertaining.</p>
<p>Full code: <a href="http://sqlinthewild.co.za/wp-content/uploads/2011/02/GeneticAlgorithms.zip">GeneticAlgorithms</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sqlinthewild.co.za/index.php/2011/02/22/and-now-for-a-completely-inappropriate-use-of-sql-server/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>The books of the year</title>
		<link>http://sqlinthewild.co.za/index.php/2011/01/01/the-books-of-the-year/</link>
		<comments>http://sqlinthewild.co.za/index.php/2011/01/01/the-books-of-the-year/#comments</comments>
		<pubDate>Fri, 31 Dec 2010 23:35:02 +0000</pubDate>
		<dc:creator>Gail</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://sqlinthewild.co.za/index.php/2011/01/01/the-books-of-the-year/</guid>
		<description><![CDATA[At the beginning of the year I set myself a goal of 50 books. I managed 45, which isn&#8217;t bad considering there were a couple of months where I was re-reading old favourites only. I&#8217;m not going to go into the level of detail Paul Randal did, rather I&#8217;m just list the books read, the [...]]]></description>
			<content:encoded><![CDATA[<p>At the beginning of the year I set myself a goal of 50 books. I managed 45, which isn&#8217;t bad considering there were a couple of months where I was re-reading old favourites only.</p>
<p>I&#8217;m not going to go into the level of detail <a href="http://www.sqlskills.com/BLOGS/PAUL/post/2010-the-year-in-books.aspx">Paul Randal</a> did, rather I&#8217;m just list the books read, the genre and give my top 3 of the year.</p>
<p>Top 3:</p>
<ol>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=jim-butcher&amp;now_reading_title=princeps-fury-book-five-of-the-codex-alera">Princeps’ Fury: Book Five of the Codex Alera</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=jim-butcher">Jim Butcher</a>&#160; I&#8217;m adoring the entire Codex Alara series. Well written, strong character, interesting form of magic and looks like a climactic ending. The last book should be in my post box in a couple of weeks.</li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=garth-nix&amp;now_reading_title=sabriel-abhorsen">Sabriel (Abhorsen)</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=garth-nix">Garth Nix</a> Actually the entire series belongs here. They&#8217;re apparently teenage books, but they&#8217;re complex and deal with adult themes. </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=john-gribbin&amp;now_reading_title=in-search-of-schrodingers-cat-quantum-physics-and-reality">In Search of Schrödinger’s Cat: Quantum Physics and Reality</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=john-gribbin">John Gribbin</a> Exceptional take on the birth of quantum physics, minimal to no maths skills required. It&#8217;s written for the layman and is part history, part physics.</li>
</ol>
<p><strong>Complete list:</strong></p>
<p>Fantasy: </p>
<ul>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=david-eddings-leigh-eddings&amp;now_reading_title=the-elder-gods">The Elder Gods</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=david-eddings-leigh-eddings">David Eddings, Leigh Eddings</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=cecilia-dart-thornton&amp;now_reading_title=the-lady-of-the-sorrows-the-bitterbynde-book-2">The Lady of the Sorrows (The Bitterbynde, Book 2)</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=cecilia-dart-thornton">Cecilia Dart-Thornton</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=cecilia-dart-thornton&amp;now_reading_title=the-battle-of-evernight-the-bitterbynde-trilogy">The Battle of Evernight (The Bitterbynde, Book 3)</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=cecilia-dart-thornton">Cecilia Dart-Thornton</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=jim-butcher&amp;now_reading_title=princeps-fury-book-five-of-the-codex-alera">Princeps’ Fury: Book Five of the Codex Alera</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=jim-butcher">Jim Butcher</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=christopher-paolini&amp;now_reading_title=brisingr">Brisingr</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=christopher-paolini">Christopher Paolini</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=china-mieville&amp;now_reading_title=looking-for-jake-and-other-stories">Looking for Jake and Other Stories</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=china-mieville">China Mieville</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=michael-crichton&amp;now_reading_title=the-13th-warrior">The 13th Warrior </a>by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=michael-crichton">Michael Crichton</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=umberto-eco&amp;now_reading_title=foucaults-pendulum">Foucault’s Pendulum</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=umberto-eco">Umberto Eco</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=garth-nix&amp;now_reading_title=sabriel-abhorsen">Sabriel (Abhorsen)</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=garth-nix">Garth Nix</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=patrick-rothfuss&amp;now_reading_title=the-name-of-the-wind-kingkiller-chronicles-day-1">The Name of the Wind (Kingkiller Chronicles, Day 1)</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=patrick-rothfuss">Patrick Rothfuss</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=ed-greenwood&amp;now_reading_title=silverfall-stories-of-the-seven-sisters-forgotten-realms-stand-alone-novel">Silverfall: Stories of the Seven Sisters (Forgotten Realms: Stand-Alone Novel)</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=ed-greenwood">Ed Greenwood</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=garth-nix&amp;now_reading_title=lirael-abhorsen-trilogy">Lirael (Abhorsen Trilogy)</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=garth-nix">Garth Nix</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=stephen-r-lawhead&amp;now_reading_title=the-paradise-war-the-song-of-albion">The Paradise War (The Song of Albion)</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=stephen-r-lawhead">Stephen R. Lawhead</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=stephen-r-lawhead&amp;now_reading_title=in-the-hall-of-the-dragon-king-the-dragon-king-trilogy-book-1">In the Hall of the Dragon King (The Dragon King Trilogy, Book 1)</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=stephen-r-lawhead">Stephen R. Lawhead</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=stephen-r-lawhead&amp;now_reading_title=the-warlords-of-nin-the-dragon-king-trilogy-book-2">The Warlords of Nin (The Dragon King Trilogy, Book 2)</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=stephen-r-lawhead">Stephen R. Lawhead</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=marcus-sedgwick&amp;now_reading_title=my-swordhand-is-singing">My Swordhand Is Singing</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=marcus-sedgwick">Marcus Sedgwick</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=garth-nix&amp;now_reading_title=abhorsen-abhorsen-trilogy">Abhorsen (Abhorsen Trilogy)</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=garth-nix">Garth Nix</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=patricia-bray&amp;now_reading_title=devlins-justice-sword-of-change-book-3">Devlin’s Justice (Sword of Change, Book 3)</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=patricia-bray">Patricia Bray</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=garth-nix&amp;now_reading_title=mister-monday-keys-to-the-kingdom-book-1">Mister Monday (Keys to the Kingdom, Book 1)</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=garth-nix">Garth Nix</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=janny-wurts&amp;now_reading_title=that-way-lies-camelot">That Way Lies Camelot</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=janny-wurts">Janny Wurts</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=mercedes-lackey-james-mallory&amp;now_reading_title=the-phoenix-endangered-book-two-of-the-enduring-flame">The Phoenix Endangered: Book Two of The Enduring Flame</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=mercedes-lackey-james-mallory">Mercedes Lackey, James Mallory</a> </li>
</ul>
<p>Science Fiction</p>
<ul>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=timothy-zahn&amp;now_reading_title=the-icarus-hunt">The Icarus Hunt</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=timothy-zahn">Timothy Zahn</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=ken-macleod&amp;now_reading_title=the-sky-road">The Sky Road</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=ken-macleod">Ken MacLeod</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=assorted&amp;now_reading_title=the-mammoth-book-of-mind-blowing-sf">The Mammoth Book of Mind-Blowing SF</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=assorted">Assorted</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=orson-scott-card&amp;now_reading_title=the-call-of-earth">The Call of Earth</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=orson-scott-card">Orson Scott Card</a> </li>
</ul>
<p>Other fiction</p>
<ul>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=steve-berry&amp;now_reading_title=the-templar-legacy">The Templar Legacy</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=steve-berry">Steve Berry</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=a-n-wilson&amp;now_reading_title=stray">Stray</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=a-n-wilson">A.N. Wilson</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=tom-clancy&amp;now_reading_title=rainbow-six">Rainbow Six</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=tom-clancy">Tom Clancy</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=tom-clancy&amp;now_reading_title=the-teeth-of-the-tiger-jack-ryan">The Teeth Of The Tiger (Jack Ryan)</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=tom-clancy">Tom Clancy</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=conn-iggulden&amp;now_reading_title=wolf-of-the-plains">Wolf of the Plains</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=conn-iggulden">Conn Iggulden</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=clive-cussler&amp;now_reading_title=night-probe">Night Probe!</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=clive-cussler">Clive Cussler</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=clive-cussler&amp;now_reading_title=valhalla-rising-dirk-pitt-adventure">Valhalla Rising (Dirk Pitt Adventure)</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=clive-cussler">Clive Cussler</a> </li>
</ul>
<p>Non-fiction</p>
<ul>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=daniel-wade&amp;now_reading_title=expose-5-finest-digital-art-in-the-known-universe">Expose 5: Finest Digital Art in the Known Universe</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=daniel-wade">Daniel Wade</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=bill-bryson&amp;now_reading_title=a-walk-in-the-woods-rediscovering-america-along-the-appalachian-trail">A Walk in the Woods: Rediscovering America Along the Appalachian Trail</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=bill-bryson">Bill Bryson</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=jonathan-i-katz&amp;now_reading_title=the-biggest-bangs-the-mystery-of-gamma-ray-bursts-the-most-violent-explosions-in-the-universe">The Biggest Bangs: The Mystery of Gamma-Ray Bursts, the Most Violent Explosions in the Universe</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=jonathan-i-katz">Jonathan I. Katz</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=stuart-russell-eric-h-wefald&amp;now_reading_title=do-the-right-thing-studies-in-limited-rationality-artificial-intelligence">Do the Right Thing: Studies in Limited Rationality (Artificial Intelligence)</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=stuart-russell-eric-h-wefald">Stuart Russell, Eric H. Wefald</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=lynne-truss&amp;now_reading_title=eats-shoots-and-leaves">Eats, Shoots and leaves</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=lynne-truss">Lynne Truss</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=stephen-hawking&amp;now_reading_title=a-brief-history-of-time">A Brief History of Time</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=stephen-hawking">Stephen Hawking</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=steven-m-lavalle&amp;now_reading_title=planning-algorithms">Planning Algorithms</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=steven-m-lavalle">Steven M. LaValle</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=james-allen-james-hendler&amp;now_reading_title=readings-in-planning-morgan-kaufmann-series-in-representation-and-reasoning">Readings in Planning (Morgan Kaufmann Series in Representation and Reasoning)</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=james-allen-james-hendler">James Allen, James Hendler</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=stephen-w-hawking&amp;now_reading_title=black-holes-and-baby-universes-and-other-essays">Black Holes and Baby Universes and Other Essays</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=stephen-w-hawking">Stephen W. Hawking</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=john-gribbin&amp;now_reading_title=in-search-of-schrodingers-cat-quantum-physics-and-reality">In Search of Schrödinger’s Cat: Quantum Physics and Reality</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=john-gribbin">John Gribbin</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=robert-l-glass&amp;now_reading_title=facts-and-fallacies-of-software-engineering">Facts and Fallacies of Software Engineering</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=robert-l-glass">Robert L. Glass</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=david-e-goldberg&amp;now_reading_title=genetic-algorithms-in-search-optimization-and-machine-learning">Genetic Algorithms in Search, Optimization, and Machine Learning</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=david-e-goldberg">David E. Goldberg</a> </li>
<li><a href="http://sqlinthewild.co.za/index.php?now_reading_author=bill-bryson&amp;now_reading_title=down-under">Down Under</a> by <a href="http://sqlinthewild.co.za/index.php?now_reading_author=bill-bryson">Bill Bryson</a> </li>
</ul>
<p>Goal for 2011… 50 books.</p>
]]></content:encoded>
			<wfw:commentRss>http://sqlinthewild.co.za/index.php/2011/01/01/the-books-of-the-year/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Looking back</title>
		<link>http://sqlinthewild.co.za/index.php/2011/01/01/looking-back/</link>
		<comments>http://sqlinthewild.co.za/index.php/2011/01/01/looking-back/#comments</comments>
		<pubDate>Fri, 31 Dec 2010 22:46:12 +0000</pubDate>
		<dc:creator>Gail</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://sqlinthewild.co.za/index.php/2011/01/01/looking-back/</guid>
		<description><![CDATA[2010 has been an &#8216;interesting&#8217; year. Interesting in the Chinese curse sense of the word mostly. I set a bunch of goals back at the end of 2009, but to be quite honest I&#8217;m not even going to look at them. If I achieved even one it was more chance than anything. Still there have [...]]]></description>
			<content:encoded><![CDATA[<p>2010 has been an &#8216;interesting&#8217; year. Interesting in the Chinese curse sense of the word mostly.</p>
<p>I set a bunch of goals back at the end of 2009, but to be quite honest I&#8217;m not even going to look at them. If I achieved even one it was more chance than anything. Still there have been a couple of positive aspects to the year.</p>
<ul>
<li>Enthusiasm for SQL-related stuff (and pretty much everything else) was finally relocated. I wrote 3 blog posts this last week, and it didn&#8217;t feel like a chore for the first time in many months. </li>
<li>For the first time since I moved to consulting, my income comfortably exceeds my expenses. Moving to consulting at the start of an economic downturn was probably a stupid thing to do, but I never do things the easy way. </li>
<li>Got the hardest part of my Masters thesis out of the way, all that&#8217;s really left is a bit more data collection and writing up. </li>
</ul>
<p>So, some goals for the new year…</p>
<ul>
<li>Finish the thesis. This isn&#8217;t optional. I&#8217;ve committed to handing it in by June. </li>
<li>Aikido at least once a week and archery at least one Saturday a month. I&#8217;ve skipped far too many classes and practices these last few months. </li>
<li>Attempt the first MCM test. This probably won&#8217;t be until the latter part of the year. The Master&#8217;s thesis comes first </li>
<li>Get back into computer graphics. Old hobby that&#8217;s been mostly neglected, but that I still enjoy </li>
</ul>
<p>No blog-related goals or article quotas. I intend to write a fair bit, but I don&#8217;t want to set requirements.</p>
<p>One last thing, for anyone wondering about the computer graphics, these are some work-in-progress or finished pieces.</p>
<p><a href="http://sqlinthewild.co.za/wp-content/uploads/2011/01/LadyOfTheLake.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="LadyOfTheLake" border="0" alt="LadyOfTheLake" src="http://sqlinthewild.co.za/wp-content/uploads/2011/01/LadyOfTheLake_thumb.png" width="184" height="244" /></a> </p>
<p><a href="http://sqlinthewild.co.za/wp-content/uploads/2011/01/BridgeFull.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="BridgeFull" border="0" alt="BridgeFull" src="http://sqlinthewild.co.za/wp-content/uploads/2011/01/BridgeFull_thumb.png" width="364" height="184" /></a></p>
<p><a href="http://sqlinthewild.co.za/wp-content/uploads/2011/01/Castles.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Castles" border="0" alt="Castles" src="http://sqlinthewild.co.za/wp-content/uploads/2011/01/Castles_thumb.png" width="364" height="184" /></a></p>
<p><a href="http://sqlinthewild.co.za/wp-content/uploads/2011/01/Orbs.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Orbs" border="0" alt="Orbs" src="http://sqlinthewild.co.za/wp-content/uploads/2011/01/Orbs_thumb.png" width="244" height="184" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://sqlinthewild.co.za/index.php/2011/01/01/looking-back/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>On burnout and recovery</title>
		<link>http://sqlinthewild.co.za/index.php/2010/12/09/on-burnout-and-recovery/</link>
		<comments>http://sqlinthewild.co.za/index.php/2010/12/09/on-burnout-and-recovery/#comments</comments>
		<pubDate>Thu, 09 Dec 2010 14:00:07 +0000</pubDate>
		<dc:creator>Gail</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://sqlinthewild.co.za/?p=755</guid>
		<description><![CDATA[I suspect for a fair number burnout is something that they believe happens to others. People with less fulfilling jobs, people who don’t love their work, people in poorly managed companies. Other people. i certainly didn’t consider myself at risk for burnout. I loved my work, I had a great manager prior to moving to [...]]]></description>
			<content:encoded><![CDATA[<p>I suspect for a fair number burnout is something that they believe happens to others. People with less fulfilling jobs, people who don’t love their work, people in poorly managed companies. Other people.</p>
<p>i certainly didn’t consider myself at risk for burnout. I loved my work, I had a great manager prior to moving to consulting and was pretty much my own manager afterwards. I had a hobby (or 5), practiced a sport, took time to play games and relax. At risk? Never!</p>
<p>At least that’s what I thought until sometime around May last year when I realised I had absolutely no enthusiasm for anything related to IT. Blogging was a chore, books held no interest and many a day I opened management studio intending to do some development or investigation and then several hours later I&#8217;d close it without a line of code having being written.</p>
<p>The biggest mistake (I think) was in how I handled it. Instead of taking a break (and work was quiet around that time so I could), I took on more commitments, thinking that it would help motivate. Exceptional DBA Awards. SSC Articles. Tech-Ed presentations. PASS Summit presentations. SQL Exams. Hell I even started discussing and planning to write a book.</p>
<p>Bad idea.</p>
<p>Far from acting as motivation, the long list of things to do just made things worse. Far worse. I now had hard deadlines, people chasing me and still no motivation or enthusiasm. Naturally everything came to a head at the worst possible time and place – the PASS summit in Seattle that year. It&#8217;s really hard to write and deliver speeches, prep and deliver presentations and generally act friendly and enthusiastic when the only thing that you want to do is get on the next flight and go home. Fortunately I think only a couple of people noticed.</p>
<p>It&#8217;s only in the last couple of months (October/November 2010) that the enthusiasm for writing, blogging, researching (and in fact anything other than sitting and watching the world go by) has partially returned. Is the burnout past? No, definitely not, I still have days (weeks) where I can&#8217;t summon the enthusiasm to care, but it is getting better.</p>
<p>But this isn&#8217;t just a post on history or a poor attempt at sympathy. The point is how I handled it (badly). Looking back, what I should have done was</p>
<ul>
<li>Take a break (work was quiet at the time). Not a weekend crashed in front of the TV, but a proper break – out of town for a week or so.</li>
<li>Get some help from friends, rather than pushing them away and pretending everything was fine.</li>
<li>Try a new technology rather than piling on SQL stuff. WCF, Ruby, F#, anything as long as it was different.</li>
</ul>
<p>I&#8217;m far from qualified to offer advice on this issue, but I would suggest to anyone feeling the same way, don&#8217;t ignore it, don&#8217;t try to work through it and don&#8217;t hide it. Few problems go away by themselves, burnout certainly doesn&#8217;t.</p>
]]></content:encoded>
			<wfw:commentRss>http://sqlinthewild.co.za/index.php/2010/12/09/on-burnout-and-recovery/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Genetic Algorithms</title>
		<link>http://sqlinthewild.co.za/index.php/2010/01/28/genetic-algorithms/</link>
		<comments>http://sqlinthewild.co.za/index.php/2010/01/28/genetic-algorithms/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 14:00:59 +0000</pubDate>
		<dc:creator>Gail</dc:creator>
				<category><![CDATA[Artificial Intelligence]]></category>
		<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://sqlinthewild.co.za/?p=531</guid>
		<description><![CDATA[Warning. This post has absolutely nothing to do with SQL Server. What are Genetic Algorithms? Genetic algorithms are a form of evolutionary computation, a branch of artificial intelligence that focuses on evolving effective or optimal solutions to difficult problems, based on the biological theory of evolution. Genetic algorithms are, at their core, a search/optimisation technique. [...]]]></description>
			<content:encoded><![CDATA[<p>Warning. This post has absolutely nothing to do with SQL Server.</p>
<h3>What are Genetic Algorithms?</h3>
<p>Genetic algorithms are a form of evolutionary computation, a branch of artificial intelligence that focuses on evolving effective or optimal solutions to difficult problems, based on the biological theory of evolution.</p>
<p>Genetic algorithms are, at their core, a search/optimisation technique. They are a way of finding maximum/minimum solutions to problems and, can be effective when there is no algorithmic solution to the problem. An example here would be the ‘Travelling Salesman’ problem.</p>
<p>Genetic algorithms work by taking an initial population of potential solutions (referred to as individuals), selecting a subset of the population that has the highest fitness then using that subset to generate a second generation. From the second generation again a subset with the highest fitness is selected and used to generate a third generation. This repeats until either the &#8216;fittest’ individual is considered a good enough solution, or until a certain number of generations have passed.</p>
<p>There are advantage to using genetic algorithms to solve problems over more traditional methods like <a href="http://en.wikipedia.org/wiki/Hill_climbing">hill climbing</a>.</p>
<ul>
<li>Genetic algorithms can quickly produce good solutions though they may take a lot of time to find the best solution. This is a benefit when the problem is such that the absolute best solution is not necessary, just one that is ‘good enough’</li>
<li>They are not susceptible to getting trapped by local maxima.</li>
<li>They do not work on the entire search space one potential solution at a time, but rather work on populations of potential solutions, focusing towards more optimal areas of the search space.</li>
</ul>
<p>A genetic algorithm will almost always find an optimal solution, given enough time. The main downside is that they may take a lot of time to find that optimal solution.</p>
<p><span id="more-531"></span></p>
<h3>Components of a Genetic Algorithm</h3>
<p>There are two main critical parts in setting up a genetic algorithm for a problem.</p>
<ul>
<li>The encoding of the potential solutions into a form where they can be operated on.</li>
<li>The fitness function which defines which individuals are better than others, which are closer to the maximum that is being searched for.</li>
</ul>
<p>Most of the design work when using genetic algorithms goes into those two problems.</p>
<h4>Encoding</h4>
<p>Encoding is the process of taking all the values that make up a potential solution and turning them into a form that the genetic algorithm can operate on.</p>
<p>The selection of an encoding is of utmost importance to the effectiveness of the entire process and a poor representation can make the entire problem much harder than it should. Unfortunately there has been little academic work done on the process of designing representations.</p>
<p>Often for genetic algorithms, the end result of the encoding will be a binary string. There are other variations of evolutionary computation that use other representations, from the arrays of real numbers used by evolutionary strategies to the code trees used by genetic programming.</p>
<h4>Fitness function</h4>
<p>Depending on the problem, the fitness function can be trivial to write or near-impossible. The design of the fitness function is completely based on the problem that is being solved.</p>
<p>There are two important considerations for a fitness function.</p>
<ul>
<li>It must be deterministic.</li>
<li>It must be fast</li>
</ul>
<p>If the fitness of an individual is assessed twice, it must come to the same value<sup>1</sup>. If the fitness function could return different values for the same individual, then it is of no use in determining the fittest individuals in the population and hence the genetic algorithm will not be able to identify the best solution to the problem.</p>
<p>The fitness of each individual is assessed at least once in each generation. The calculation of the fitness function is usually the most time consuming part of the entire process and the longer the fitness function takes to run, the longer the entire process is run</p>
<p>(1) There are cases where the fitness of an individual may depend on external factors which change over time. Hence a fitness function may give different values for one individual if calculated at different times. Genetic algorithms in a changing environment are a little beyond the scope of this entry.</p>
<h3>Evolution Process</h3>
<p>In order to create a new generation, the fittest individuals from the previous generation are taken and used to generate the next generation. There are two main operators that are used to generate a generation from the previous one. Crossover and mutation.</p>
<h4>Crossover</h4>
<p>Crossover involved taking two individuals, splitting each one’s encoded string and swapping parts to generate two new individuals.</p>
<p>Say we had two individuals with the following encoded strings (spaces added for clarity)<br />
0000 0001 1111 1110<br />
0101 1010 1100 0011<br />
and we chose the splitting point for the crossover after the 4th bit, the resulting strings after the crossover will be<br />
0000 1010 1100 0011<br />
0101 0001 1111 1110</p>
<p>In genetic algorithms crossover is the primary operator used. What I described here was a single crossover. There are a number of other variations that can be used.</p>
<h4>Mutation</h4>
<p>Mutation is an operator applied to a single individual. It’s usually applied after crossover has generated new individuals. Mutation involves flipping a single bit somewhere in the encoded string.</p>
<p>Let’s take the two individuals that were generates by the crossover earlier and apply a random mutation to each<br />
0000 1010 1100 0011<br />
0101 0001 1111 1110<br />
After<br />
0000 1010 1101 0011<br />
0101 0001 1011 1110</p>
<p>In genetic algorithms mutation is very seldom applied and only a small percentage of individuals in a generation will be affected by the mutation operator.</p>
<h3>Example</h3>
<p>As a quick example let’s manually evolve a simple function to see how the whole thing works.</p>
<p>Let’s say I have an array of 4 numbers (call it num) between 0 and 15. I want to know what values give me the best value for the following.</p>
<p>num[1]-num[2]-num[3]+num[4]</p>
<p>I know, that’s simple enough that we could work out the optimal solution just by eye. Not the point. This is enough to do a quick and effective demo with.</p>
<p>I’m going to encode that by simply converting the numbers in the array to binary and concatenating the binary representations of the 4 numbers (spaces just added for clarity). The fitness function is already defined. I’m going to start with an initial population of eight individuals.</p>
<p>1111 1111 1100 1110 – fitness = (15-15-12+14) = 2<br />
0101 1010 1100 0011 – fitness = (9-10-12+3) = –10<br />
1011 0111 0011 1111 – fitness = (11-7-3+15) = 16<br />
1111 1001 1010 0011 – fitness = (15-9-10+3) = -1<br />
1010 1010 1010 1010 – fitness = (10-10-10+10) = 0<br />
1000 0010 0111 0110 – fitness = (8-2-7+6) = 5<br />
0000 0001 1111 1110 – fitness = (0-1-15+14) = -2<br />
1010 0101 0010 0101 – fitness = (10-5-2+5) = 8</p>
<p>From this I’m going to take the 4 individuals with the highest fitness, use crossover operations (with the crossover point exactly in the middle) between them until I have 8 individuals for the 2nd generation and then apply a single bit mutation to one of the individuals (detailed steps left as an exercise for the reader)</p>
<p>1111 1111 0011 1111 – fitness = (15-15-3+15) = 12<br />
1011 0111 1100 1110 – fitness = (11-7-12+14) = 6<br />
1111 1011 0010 0101 – fitness = (15-11-2+5) = 7<br />
1010 0101 1100 1110 – fitness = (10-5-7+6) = 4<br />
1011 0111 0111 0110 – fitness = (11-7-7+6) = 3<br />
1000 0010 0011 1111 – fitness = (8-2-3+15) = 18<br />
1010 0101 0111 0110 – fitness = (10-5-7+6) = 4<br />
1000 0010 0010 0101 – fitness = (8-2-2+5) = 9</p>
<p>We can already see an improvement. The average and maximum fitness is much higher than for the first generation. I’ll do one more generation in this example, again taking the 4 fittest individuals, crossing over to generate 8 new individuals and then applying a single bit mutation to two individuals. This time however, the crossover point will between the 4th and 5th bit.</p>
<p>1000 1111 0011 1111 &#8211; fitness = (8-15-3+15) = 5<br />
1111 0010 0011 1111 &#8211; fitness = (15-2-3+15) = 25<br />
1000 1011 0010 0101 &#8211; fitness = (8-11-2+5) = 0<br />
1111 0010 0011 1111 &#8211; fitness = (15-2-3+15) = 25<br />
1111 0010 1010 0101 &#8211; fitness = (15-2-10+5) = 8<br />
1000 0111 0011 1111 &#8211; fitness = (8-7-3+15) = 13<br />
1111 0010 0010 0101 &#8211; fitness = (15-2-2+5) = 16<br />
1000 1011 0010 0101 &#8211; fitness = (8-11-2+5) = 0</p>
<p>I think that’s enough for this example. We’re getting fairly close to the best possible solution (15,0,0,15), close enough to see how this works. The population size was very low, that’s why there are duplicates appearing in the results of the crossover. With a larger search space there would be a lot more diversity.</p>
<p>I hope that anyone still reading found this brief diversion into the realms of AI interesting. The regular SQL-related posts will return soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://sqlinthewild.co.za/index.php/2010/01/28/genetic-algorithms/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Great start to the new year. Not!</title>
		<link>http://sqlinthewild.co.za/index.php/2009/01/04/great-start-to-the-new-year-not/</link>
		<comments>http://sqlinthewild.co.za/index.php/2009/01/04/great-start-to-the-new-year-not/#comments</comments>
		<pubDate>Sun, 04 Jan 2009 10:32:20 +0000</pubDate>
		<dc:creator>Gail</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://sqlinthewild.co.za/?p=190</guid>
		<description><![CDATA[My flat got broken into last night. Cell phone, laptop, camera and wallet all gone. Yay. Not! Edit: And my iPod. And an ornamental knife I bought in Scotland a few year back.]]></description>
			<content:encoded><![CDATA[<p>My flat got broken into last night. Cell phone, laptop, camera and wallet all gone.</p>
<p>Yay. Not!</p>
<p>Edit: And my iPod. And an ornamental knife I bought in Scotland a few year back.</p>
]]></content:encoded>
			<wfw:commentRss>http://sqlinthewild.co.za/index.php/2009/01/04/great-start-to-the-new-year-not/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Stepping down</title>
		<link>http://sqlinthewild.co.za/index.php/2008/06/03/stepping-down/</link>
		<comments>http://sqlinthewild.co.za/index.php/2008/06/03/stepping-down/#comments</comments>
		<pubDate>Tue, 03 Jun 2008 21:35:55 +0000</pubDate>
		<dc:creator>Gail</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Roleplaying]]></category>

		<guid isPermaLink="false">http://sqlinthewild.co.za/?p=75</guid>
		<description><![CDATA[Sunday saw the last game (for now) of the d20 Modern campaign I&#8217;m running. I&#8217;m going to miss DMing, but it was for the best. I&#8217;m struggling with a bit of burnout and a lack of free time. The campaign went quite well. The players seemed to enjoy it and that&#8217;s the only real measure [...]]]></description>
			<content:encoded><![CDATA[<p>Sunday saw the last game (for now) of the d20 Modern campaign I&#8217;m running. I&#8217;m going to miss DMing, but it was for the best. I&#8217;m struggling with a bit of burnout and a lack of free time.</p>
<p>The campaign went quite well. The players seemed to enjoy it and that&#8217;s the only real measure of any importance. We didn&#8217;t get quite as far as I had hoped, but a lot of hints and clues were dropped during the various adventures and I think that all the players have a better idea of the &#8216;big picture&#8217;. They&#8217;ve also managed to disrupt the big bad guy&#8217;s plans often enough to be irritating.</p>
<p>For the next few months at least, we&#8217;ll be playing high-fantasy D&amp;D as we return to the world of Per-rune. Currently our characters are about to disembark ship after a rather exciting trip to the Elven kingdom. All we need is to do some shopping for winter gear and then head inland back to the small town of Kurat, where the whole thing started. Easy, right?</p>
]]></content:encoded>
			<wfw:commentRss>http://sqlinthewild.co.za/index.php/2008/06/03/stepping-down/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Birthday musings</title>
		<link>http://sqlinthewild.co.za/index.php/2007/12/07/birthday-musings/</link>
		<comments>http://sqlinthewild.co.za/index.php/2007/12/07/birthday-musings/#comments</comments>
		<pubDate>Fri, 07 Dec 2007 19:45:11 +0000</pubDate>
		<dc:creator>Gail</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://sqlinthewild.co.za/index.php/2007/12/07/birthday-musings/</guid>
		<description><![CDATA[Another year gone, another year older. It&#8217;s been an interesting year. Professionally, I&#8217;m very happy with the past year. I&#8217;ve achieved several goals, got to know some interesting people in the SQL community and, of course, started this blog. I&#8217;ve also made some fairly important decisions about the future. Academically, I&#8217;m not so happy. My [...]]]></description>
			<content:encoded><![CDATA[<p>Another year gone, another year older. It&#8217;s been an interesting year.</p>
<p>Professionally, I&#8217;m very happy with the past year. I&#8217;ve achieved several goals, got to know some interesting people in the SQL community and, of course, started this blog. I&#8217;ve also made some fairly important decisions about the future.</p>
<p>Academically, I&#8217;m not so happy. My masters thesis is behind where it should be. (a fact I&#8217;m sure my supervisor would agree with.) Most of the initial reading is done and I know what I need to do. I need to sit down and get busy. This is going to have to take a higher priority in the next few months.</p>
<p>On more personal matters, a good friend moved up to JHB. It&#8217;s very good to see her again. The roleplaying campaign is going well and from the feedback I&#8217;ve been having, the players are all enjoying themselves.</p>
<p>Overall, it&#8217;s been a good year. Here&#8217;s to the next one.</p>
]]></content:encoded>
			<wfw:commentRss>http://sqlinthewild.co.za/index.php/2007/12/07/birthday-musings/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

