Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
priority-queue 0.1.2
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Brian Schröder  
View profile  
 More options Oct 27 2005, 5:56 pm
Newsgroups: comp.lang.ruby
From: Brian Schröder <ruby.br...@gmail.com>
Date: Fri, 28 Oct 2005 06:56:31 +0900
Local: Thurs, Oct 27 2005 5:56 pm
Subject: [ANN] priority-queue 0.1.2
Hello Group,

I finally released a polished up version of my priority queue extension.
A priority-queue is usefull for algorithms like "dijkstras shortest
path algorithm" that finds shortest paths in a graph.

The extension now includes a pure ruby and a c extension. The runtime
behaviour can be seen at

  http://ruby.brian-schroeder.de/priority-queue/

which happens to be the project homepage.

I also added a rubyforge project and packed up the extension using
setup.rb and as a gem, so you should be able to do:

  gem install PriorityQueue

and have it working. But that is not reality as only version 0.1.0 has
found its way into the gem lists. I have asked tom what I did wrong,
so please be patient.

I would be very interested in feedback from people testing the
extension under exotic systems like aix and windows that I do not have
available at home.

I hope this will be usefull,

Brian

# Links:

  http://ruby.brian-schroeder.de/priority-queue/
  http://rubyforge.org/projects/priority-queue/

# Usage:

## Use it like a hash
require 'priority_queue'

q = PriorityQueue.new
q["node1"] = 0
q["node2"] = 1
q.min #=> "node1"
q[q.min] #=> 0
q.min_value #=> 0

q["node2"] = -1
q.delete_min #=> "node2", 1
q["node2"] #= nil
q["node3"] = 1

q.delete("node3") #=> "node3", 1
q.delete("node2") #=> nil

## Dijkstras shortest path algorithm:
def dijkstra(start_node)
  # Nodes that may have neighbours wich can be relaxed further
  active = PriorityQueue.new
  # Best distances found so far
  distances = Hash.new { 1.0 / 0.0 }
  # Parent pointers describing shortest paths for all nodes
  parents = Hash.new

  # Initialize with start node
  active[start_node] = 0
  until active.empty?
    u, distance = active.delete_min
    distances[u] = distance
    d = distance + 1
    u.neighbours.each do | v |
      next unless d < distances[v] # we can't relax this one
      active[v] = distances[v] = d
      parents[v] = u
    end
  end
  parents
end

PS: The raa entry is not updated as I have forgotten my password. I
already asked the admins to reset it, so I hope this will reflect
correct information soon. On a sidenote, what became of the plans to
synchronize rubyforge entries to raa?

--
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tom Copeland  
View profile  
 More options Oct 28 2005, 9:30 am
Newsgroups: comp.lang.ruby
From: Tom Copeland <t...@infoether.com>
Date: Fri, 28 Oct 2005 22:30:08 +0900
Local: Fri, Oct 28 2005 9:30 am
Subject: Re: [ANN] priority-queue 0.1.2

On Fri, 2005-10-28 at 06:56 +0900, Brian Schröder wrote:
> On a sidenote, what became of the plans to
> synchronize rubyforge entries to raa?

Haven't looked at that in a while... but any updates will be posted
here:

http://rubyforge.org/tracker/index.php?func=detail&aid=196&group_id=5...

if/when they occur...

Yours,

Tom


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Amelang  
View profile  
 More options Oct 28 2005, 9:22 pm
Newsgroups: comp.lang.ruby
From: Daniel Amelang <daniel.amel...@gmail.com>
Date: Sat, 29 Oct 2005 10:22:49 +0900
Local: Fri, Oct 28 2005 9:22 pm
Subject: Re: [ANN] priority-queue 0.1.2

Cool Brian! So, from what I can tell, you're providing (or could provide)
some of the same functionality as rbtree. How does your creation compare?

Dan Amelang


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Brian Schröder  
View profile  
 More options Oct 29 2005, 9:22 am
Newsgroups: comp.lang.ruby
From: Brian Schröder <ruby.br...@gmail.com>
Date: Sat, 29 Oct 2005 22:22:59 +0900
Local: Sat, Oct 29 2005 9:22 am
Subject: Re: [ANN] priority-queue 0.1.2
On 29/10/05, Daniel Amelang <daniel.amel...@gmail.com> wrote:

> Cool Brian! So, from what I can tell, you're providing (or could provide)
> some of the same functionality as rbtree. How does your creation compare?

> Dan Amelang

Hello Dan,

I have not looked very deep into rbtree. Maybe it is possible to
implement a priority queue on top of rbtree. But generally it seems
inverse to a priority queue. It orders by key, while a priority queue
orders by priority (value in hash terms).

A priority queue offers another (not a real subset) set of functions
than an rbtree. The complexity of the operations available in both
datastructures differs.

From the rbtree homepage:

"... the complexity for insert, search and delete is O(log N) in
expected and worst case."

while the complexities for the interesting operations in this priority
queue implementation are

insert O(1)
delete O(1) average
delete_min O(log n) average
change priority O(1) average

These properties allow for example to create an O(m + n log n)
shortest path algorithm where m is the number of edges and n the
number of nodes in the graph.

So to summerize, theses datastructures are different and are usefull
for different algorithms.

best regards,

Brian
--
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Joel VanderWerf  
View profile  
 More options Oct 29 2005, 4:14 pm
Newsgroups: comp.lang.ruby
From: Joel VanderWerf <vj...@path.berkeley.edu>
Date: Sun, 30 Oct 2005 05:14:47 +0900
Local: Sat, Oct 29 2005 4:14 pm
Subject: Re: [ANN] priority-queue 0.1.2

Brian Schröder wrote:
> I have not looked very deep into rbtree. Maybe it is possible to
> implement a priority queue on top of rbtree. But generally it seems
> inverse to a priority queue. It orders by key, while a priority queue
> orders by priority (value in hash terms).

I've been using this PriorityQueue based on rbtree:

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/133202

but, Brian, your implementation sounds like it is better suited to being
a priority queue. Also, I think you said there is a pure ruby as well as
extension version of it, which is useful in some situations. I will
check it out when I get a chance, and maybe do some benchmarks.

--
      vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Brian Schröder  
View profile  
 More options Oct 29 2005, 6:14 pm
Newsgroups: comp.lang.ruby
From: Brian Schröder <ruby.br...@gmail.com>
Date: Sun, 30 Oct 2005 07:14:06 +0900
Local: Sat, Oct 29 2005 6:14 pm
Subject: Re: [ANN] priority-queue 0.1.2
On 29/10/05, Joel VanderWerf <vj...@path.berkeley.edu> wrote:

That would be great. Please feed back your experiences with the queue.

cheers,

Brian

--
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google