Top Level Namespace

Defined Under Namespace

Modules: Enumerable, Errno, FileOperations, GRATR, HookScriptAPI, PriorityQueueTest Classes: CPriorityQueueTest, ConfigTable, Installer, Node, PoorPriorityQueue, PoorPriorityQueueTest, RubyPriorityQueueTest, SetupError, ToplevelInstaller, ToplevelInstallerMulti

Constant Summary collapse

GRATR_VERSION =

– Copyright © 2006 Shawn Patrick Garbett Copyright © 2002,2004,2005 by Horst Duchene

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice(s),
  this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.
* Neither the name of the Shawn Garbett nor the names of its contributors
  may be used to endorse or promote products derived from this software
  without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ++

"0.4.3"
Arc =

Pull all GRATR classes up into the current namespace

GRATR::Arc
Edge =
GRATR::Edge
MultiArc =
GRATR::MultiArc
MultiEdge =
GRATR::MultiEdge
Graph =
GRATR::Graph
Digraph =
GRATR::Digraph
DirectedGraph =
GRATR::DirectedGraph
DirectedPseudoGraph =
GRATR::DirectedPseudoGraph
DirectedMultiGraph =
GRATR::DirectedMultiGraph
UndirectedGraph =
GRATR::UndirectedGraph
UndirectedPseudoGraph =
GRATR::UndirectedPseudoGraph
UndirectedMultiGraph =
GRATR::UndirectedMultiGraph
Complete =
GRATR::Complete

Instance Method Summary collapse

Instance Method Details

#dijkstra(start_node, queue_klass) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/priority-queue/benchmark/dijkstra.rb', line 53

def dijkstra(start_node, queue_klass)
  # Priority Queue with unfinished nodes
  active = queue_klass.new
  # Distances for all nodes
  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
end

#draw_graph(nodes, out) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/priority-queue/benchmark/dijkstra.rb', line 39

def draw_graph(nodes, out)
  dot = [] << "graph g {"
  nodes.each do | n1 |
    dot << "N#{n1.id} [label='#{n1.id}'];"
    n1.neighbours.each do | n2 |
      dot << "N#{n1.id} -- N#{n2.id};" if n1.id <= n2.id
    end
  end
  dot << "}"

  #  system "echo '#{dot}' | neato -Gepsilon=0.001 -Goverlap=scale -Gsplines=true -Gsep=.4 -Tps -o #{out}"
  system "echo '#{dot}' | neato -Gepsilon=0.05 -Goverlap=scale -Gsep=.4 -Tps -o #{out}"
end

#make_graph(nodes, degree) ⇒ Object

Return a random graph with an average degree of degree



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/priority-queue/benchmark/dijkstra.rb', line 27

def make_graph(nodes, degree)
  nodes = Array.new(nodes) { | i | Node.new(i.to_s) }
  nodes.each do | n |
    (degree / 2).times do 
      true while (n1 = nodes[rand(nodes.length)]) == n
      n.neighbours << nodes[rand(nodes.length)]
      n1.neighbours << n
      n.neighbours << n1
    end
  end
end

#setup_rb_error(msg) ⇒ Object

Raises:



1538
1539
1540
# File 'lib/priority-queue/setup.rb', line 1538

def setup_rb_error(msg)
  raise SetupError, msg
end