git-svn-id: http://igraph.rubyforge.org/svn/trunk@50 71f48855-0bbf-4aa5-930d-4df415e86613

This commit is contained in:
alexgutteridge 2007-09-28 07:49:58 +00:00
parent 9a93da3491
commit e61bb75550
5 changed files with 108 additions and 0 deletions

View File

@ -0,0 +1,24 @@
require 'igraph'
g = IGraph.new(['A','B','A','C','A','D','C','D'],false)
adj = g.get_adjacency(2)
g.vcount.times do |k|
adj[k][k] = 1
end
dis = Array.new(4){|i| Array.new(4)}
dis.each_with_index do |row,i|
row.each_with_index do |cell,j|
cij = 0
g.vcount.times do |k|
puts "#{i} #{j} #{k}"
cij += adj[i][k] * adj[j][k]
end
dis[i][j] = 10 - cij
end
end
p adj
p dis

11
test/tc_dijkstra.rb Normal file
View File

@ -0,0 +1,11 @@
require 'test/unit'
require 'igraph'
Infinity = 1.0/0
class TestGraph < Test::Unit::TestCase
def test_dijkstra
g = IGraph.new([1,2,3,4],false)
assert_equal [[0,1.5,Infinity,Infinity]], g.dijkstra_shortest_paths([1],[1.5,2.5],IGraph::OUT)
end
end

View File

@ -0,0 +1,21 @@
require 'test/unit'
require 'igraph'
class TestGraph < Test::Unit::TestCase
def test_independent_vertex_sets
g = IGraph.new([1,2,3,4],true)
assert_equal [[1,3],[1,4],[2,3],[2,4]], g.independent_vertex_sets(2,0)
end
def test_largest_independent_vertex_sets
g = IGraph.new([1,2,3,4,1,5],true)
assert_equal [[2,3,5],[2,4,5]], g.largest_independent_vertex_sets
end
def test_maximal_independent_vertex_sets
g = IGraph.new([1,2,3,4],true)
assert_equal [[1,3],[1,4],[2,3],[2,4]], g.maximal_independent_vertex_sets
end
def test_independence_number
g = IGraph.new([1,2,3,4],true)
assert_equal 2, g.independence_number
end
end

33
test/tc_isomorphic.rb Normal file
View File

@ -0,0 +1,33 @@
require 'test/unit'
require 'igraph'
class TestGraph < Test::Unit::TestCase
def test_isomorphic
g = IGraph.new([1,2,3,4],false)
h = IGraph.new([5,6,7,8],false)
assert_equal true, g.isomorphic(h)
assert_equal true, h.isomorphic(g)
end
def test_isomorphic_vf2
g = IGraph.new([1,2,3,4],false)
h = IGraph.new([5,6,7,8],false)
assert_equal true, g.isomorphic_vf2(h)
assert_equal true, h.isomorphic_vf2(g)
end
def test_isoclass
g = IGraph.new([1,2,3,4],false)
h = IGraph.new([5,6,7,8],false)
assert g.isoclass >= 0 and g.isoclass <= 11
assert_equal h.isoclass, g.isoclass
end
def test_isoclass_subgraph
g = IGraph.new([1,2,3,4],false)
assert g.isoclass_subgraph([1,2,3]) >= 0 and g.isoclass <= 4
assert_equal g.isoclass_subgraph([1,2,3]), g.isoclass_subgraph([2,3,4])
end
def test_igraph_isoclass_create
g = IGraph.new([1,2,3,4],false)
h = IGraph.isoclass_create(4,g.isoclass,false)
assert_equal g.isoclass, h.isoclass
end
end

19
test/tc_motif.rb Normal file
View File

@ -0,0 +1,19 @@
require 'test/unit'
require 'igraph'
class TestGraph < Test::Unit::TestCase
def test_motifs_randesu
g = IGraph.new(['A','B','C','D','A','C'],false)
hist = g.motifs_randesu(3,[0,0,0])
assert_equal [0,0,2,0], hist
end
def test_motifs_randesu_no
g = IGraph.new(['A','B','C','D','A','C'],false)
assert_equal 2, g.motifs_randesu_no(3,[0,0,0])
end
def test_motifs_randesu_estimate
g = IGraph.new(['A','B','C','D','A','C'],false)
assert_equal 2, g.motifs_randesu_estimate(3,[0,0,0],4,nil)
assert_equal 2, g.motifs_randesu_estimate(3,[0,0,0],0,['A','B','C','D'])
end
end