mpath_graph 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe98d3cf16c7b1260eec6fe214e67be4bb03581f
4
- data.tar.gz: 6b63b914bbe6d13531b690b22379326bd2d854a8
3
+ metadata.gz: 7f3784e16dd4d77ac7d5807f57e3cb23576160ae
4
+ data.tar.gz: a19ca64b2b62264a83492640588e33969c57f75e
5
5
  SHA512:
6
- metadata.gz: ea44cc2381b1af9bd296ae35d0071fa7de78bbf55d1c3cb054aff0bc285e8728c4d88d04592943f0be8744d01606cfc61367bfe49302bc0ce59786f0288526c9
7
- data.tar.gz: 2c29f85da657ec31887bcb8eef9afa7679b1f5484037c8ee641e985f57f07fdfb61a5d7981786f83ed7fe458c8cb872a1c43c6584f63977ac1cd839fc583de6c
6
+ metadata.gz: 81b8e837bc5b616e12699bf0d63f3e201ac23a5e153cf3ba77db478106a8bd47f972998a629fa2a63b6267ac378b68271b8cd118b3a8542f0d1779f7f128583f
7
+ data.tar.gz: 528876979ca88371ddee480494b4590fbbf623b072ed65a8b11b3de54a04f96ab1d43762909a378af8fa9b453b78f7250d293d8aed4e9f350b55fc1acce92e8c
data/lib/mpath_graph.rb CHANGED
@@ -190,6 +190,35 @@ module MPathGraph
190
190
  paths
191
191
  end
192
192
 
193
+ def self.share_inner_vertices?(path_a, path_b)
194
+ raise ArgumentError, "Path must have same lenght" if path_a.size != path_b.size
195
+
196
+ path_a[1..-2].each { |a| path_b.each { |b| return true if a == b } }
197
+ path_b[1..-2].each { |b| return true if b == path_a[0] || b == path_a[-1] }
198
+ false
199
+ end
200
+
201
+ def self.gen_mpath_graph_from_paths(paths)
202
+ mp_graph_edges = []
203
+
204
+ pbar = ProgressBar.create(
205
+ title: "Computing mPath graph",
206
+ output: STDERR,
207
+ format: "%t [%B] [%c/%C - %P%%]",
208
+ total: paths.size-1)
209
+
210
+ (0..paths.size-2).each do |i|
211
+ ((i+1)...paths.size).each do |j|
212
+ share = MPathGraph::share_inner_vertices?(paths[i],paths[j])
213
+ mp_graph_edges << [i,j] if share
214
+ end
215
+ pbar.increment
216
+ end
217
+ pbar.finish
218
+
219
+ mp_graph_edges
220
+ end
221
+
193
222
  module OddHole
194
223
  def self.equivalents(hole)
195
224
  perms = [hole.reverse]
@@ -1,3 +1,3 @@
1
1
  module MPathGraph
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -0,0 +1,26 @@
1
+ require 'mpath_graph'
2
+ require 'minitest/autorun'
3
+ require 'minitest/unit'
4
+
5
+ # Author:: Israel Buitron (mailto:ibuitron@computacion.cs.cinvestav.mx)
6
+ class TestMPathGraph < MiniTest::Unit::TestCase
7
+
8
+ def setup
9
+ end
10
+
11
+ def test_gen_mpath_graph_from_paths
12
+ paths = [[1,2,3,4],[5,6,7,8],[0,1,8,4]]
13
+
14
+ assert_equal [[0,2],[1,2]], MPathGraph::gen_mpath_graph_from_paths(paths)
15
+ end
16
+
17
+ def test_share_inner_vertices
18
+ assert_raises(ArgumentError) {MPathGraph::share_inner_vertices?([],[1])}
19
+
20
+ refute MPathGraph::share_inner_vertices?([1,2,3,4,5,6],[0,7,8,9,10,11])
21
+ refute MPathGraph::share_inner_vertices?([1,2,3,4,5,6],[1,7,8,9,10,11])
22
+ assert MPathGraph::share_inner_vertices?([1,2,3,4,5,6],[0,1,8,9,10,11])
23
+ assert MPathGraph::share_inner_vertices?([1,2,3,4,5,6],[2,7,8,9,10,11])
24
+ assert MPathGraph::share_inner_vertices?([1,2,3,4,5,6],[6,7,8,4,9,0])
25
+ end
26
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mpath_graph
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Israel Buitron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-14 00:00:00.000000000 Z
11
+ date: 2014-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-progressbar
@@ -83,6 +83,7 @@ files:
83
83
  - lib/mpath_graph.rb
84
84
  - lib/mpath_graph/version.rb
85
85
  - mpath_graph.gemspec
86
+ - test/test_mpath_graph.rb
86
87
  - test/test_mpath_graph_odd_hole.rb
87
88
  homepage: ''
88
89
  licenses:
@@ -109,4 +110,5 @@ signing_key:
109
110
  specification_version: 4
110
111
  summary: m-Path graphs library
111
112
  test_files:
113
+ - test/test_mpath_graph.rb
112
114
  - test/test_mpath_graph_odd_hole.rb