-1

通过使用 ruby​​ 中的 RGL 库,如何在图中找到子图的存在。

4

1 回答 1

0

你可以看看这里set

这是一个提示代码:

p RUBY_VERSION
require 'set'


arr = [ [1,2], [1,3], [3,4], [3,5], [4,6], [6,5], [5,7],[7,8]]
arr1 = [[1,3],[3,4]]
arr2 = [[10,11],[4,5]]
dirgraph = Set.new()
subgraph = Set.new()
subgraph1 = Set.new()

arr.each{|x|
dirgraph.add(x)
}

p dirgraph

arr1.each{|x|
subgraph.add(x)
}

p subgraph

arr2.each{|x|
subgraph1.add(x)
}

p subgraph1

p subgraph.subset?(dirgraph)
p subgraph1.subset?(dirgraph)

输出:

"2.0.0"
#<Set: {[1, 2], [1, 3], [3, 4], [3, 5], [4, 6], [6, 5], [5, 7], [7, 8]}>
#<Set: {[1, 3], [3,4]}>
#<Set: {[10, 11], [4, 5]}>
true
false
于 2013-03-20T07:58:33.160 回答