<?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>Wyatt Baldwin &#187; dijkstra</title>
	<atom:link href="http://wyattbaldwin.com/tag/dijkstra/feed/" rel="self" type="application/rss+xml" />
	<link>http://wyattbaldwin.com</link>
	<description></description>
	<lastBuildDate>Tue, 20 Jul 2010 17:43:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Implementation of Dijkstra&#8217;s Single-Source Shortest-Paths in JavaScript</title>
		<link>http://wyattbaldwin.com/2008/08/19/implementation-of-dijkstras-single-source-shortest-paths-in-javascript/</link>
		<comments>http://wyattbaldwin.com/2008/08/19/implementation-of-dijkstras-single-source-shortest-paths-in-javascript/#comments</comments>
		<pubDate>Tue, 19 Aug 2008 23:52:03 +0000</pubDate>
		<dc:creator>Wyatt</dc:creator>
				<category><![CDATA[planet python]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[dijkstra]]></category>
		<category><![CDATA[geek-fun]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://wyattbaldwin.com/?p=223</guid>
		<description><![CDATA[I&#8217;m working on a project where the client wants a cool sliding navigation effect. We&#8217;re implementing this with JavaScript/AJAX/DHTML. One of the constraints is that pages can only be reached via certain other pages. For example, if you&#8217;re on the &#8230; <a href="http://wyattbaldwin.com/2008/08/19/implementation-of-dijkstras-single-source-shortest-paths-in-javascript/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on a project where the client wants a cool sliding navigation effect. We&#8217;re implementing this with JavaScript/AJAX/DHTML.</p>
<p>One of the constraints is that pages can only be reached via certain other pages. For example, if you&#8217;re on the /portland/contact page and want to go to the /seattle/contact page, you&#8217;ll first slide up to /portland, then over to /seattle, then finally down to /seattle/contact.</p>
<p>After a while, it occurred to me that there were some similarities with another project I&#8217;ve been working on off and on for the last few years, byCycle.org, which is a bicycle trip planner ala Google Maps.</p>
<p>I had written a Python version of Dijkstra&#8217;s Single-Source Shortest-Paths (SSSP) for byCycle.org. That&#8217;s available on <a title="Dijkstar on PyPi" href="http://pypi.python.org/pypi/Dijkstar">PyPi as Dijkstar</a> (so named because it also <span style="text-decoration: line-through;">does</span> has the potential to do A*). I figured it wouldn&#8217;t be too hard to port the Python version to JavaScript, and it wasn&#8217;t.</p>
<p>There were a few snags, though. Most of it was just syntactic and semantic differences between the two languages. The biggest issue was that I use &#8220;heapq&#8220; in the Python version to maintain the costs to previously visited nodes in sorted order. JavaScript has no priority queue implementation that I could find, so I came up with a different solution that involves updating an Object (AKA &#8220;dict&#8220;) with costs to newly visited nodes and sorting the keys to pick the next node to visit. I&#8217;m assuming/hoping the underlying sort implementation is highly optimized.</p>
<p>Interestingly, I think I found at least one bug in the Python version, although I&#8217;ve been using that version for a couple years now with no known problems, so it must only be applicable in certain edge (no pun intended) cases (or maybe it&#8217;s due to some difference in the languages&#8211;need to take a closer look). I think the JS version came out cleaner, too.</p>
<p>If anyone&#8217;s interested, I&#8217;m releasing this under an MIT license. For now, you can <a title="Dijkstra in JavaScript" href="http://wyattbaldwin.com/code/dijkstra.js">get it from here</a>. Note that it depends on the util module that you can <a title="Namespaces and classes in JavaScript" href="http://wyattbaldwin.com/code/util.js">get from here</a>. The util module contains some other Python-inspired JavaScript, in particular a couple of functions for generating namespaces and classes. I might write another post about that at some point.</p>
]]></content:encoded>
			<wfw:commentRss>http://wyattbaldwin.com/2008/08/19/implementation-of-dijkstras-single-source-shortest-paths-in-javascript/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
