rgl 0.5.4 → 0.5.6

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
  SHA256:
3
- metadata.gz: 8756a57ea9c8151eadaa993efee20e2d41ddba102bee5d4106e00c94318d328e
4
- data.tar.gz: c2400afcdcc2d5c8f22ed0da9e48cd843629f57747335265087a7e3e892d55d0
3
+ metadata.gz: 6cc432ed6e3560ca66d241be508defa12cd832a205df40f6f06e50ae187cb35f
4
+ data.tar.gz: 4f31192830a5a78b1d42c1a150a0f5b649750abb440ea06df689fa3dfc4c9621
5
5
  SHA512:
6
- metadata.gz: 83cebc1a0570644f5dc1a48c16a5a38e11d73b9baf095f2627ef91676139c473f8027b608748dfe5d7df1926b17759e07dab85722fa0ced05b1656880fade8da
7
- data.tar.gz: ad2d7ee636584a077313323efacf8c274f25643cc78e85b4f4f0e01dfbbbb522e00b7e50c295ad1e2ff395300c8f4f0551e00bb7b2a514cc179f01b9d327487e
6
+ metadata.gz: 568056f6ad3038dda236d889b09e78007767103692c514d5627a4efe0e610797e91eda827b58880c5714e357d964db7cf2040b238fbf79286108410b35592aeb
7
+ data.tar.gz: 3e1f01edc45fc73f094dd1d89cca164e6a2792cee0e555ab3b330f7c8cb981a5d79d2ec6003a6e9f8a39f6ec8d651b8d3d36645415a7156b6ab8e72cad4d41bb
data/ChangeLog CHANGED
@@ -1,3 +1,10 @@
1
+ 2019-01 Release 0.5.5
2
+
3
+ Artemy Kirienko
4
+ * PR #42 Add method Graph#path?(u, v) to check if a path exists between two vertices
5
+ Horst Duchene
6
+ * Fix #47 set_to_begin for graph iterator (881aa8)
7
+
1
8
  2019-01 Release 0.5.4
2
9
 
3
10
  Lia Skalkos
data/README.md CHANGED
@@ -171,6 +171,12 @@ Add inverse edge (4-2) to directed graph:
171
171
  irb> dg.remove_edge 4,2
172
172
  true
173
173
 
174
+ Check whether a path exists between vertices 1 and 5
175
+
176
+ irb> require 'rgl/path'
177
+ irb> dg.path?(1, 5)
178
+ true
179
+
174
180
  *Topological sort* is implemented as an iterator:
175
181
 
176
182
  require 'rgl/topsort'
@@ -4,7 +4,7 @@
4
4
  # library. The main module is RGL::Graph which defines the abstract behavior of
5
5
  # all graphs in the library.
6
6
 
7
- RGL_VERSION = "0.5.4"
7
+ RGL_VERSION = "0.5.6"
8
8
 
9
9
  module RGL
10
10
  class NotDirectedError < RuntimeError; end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rgl/traversal'
4
+
5
+ module RGL
6
+ module Graph
7
+ # Checks whether a path exists between _source_ and _target_ vertices
8
+ # in the graph.
9
+ #
10
+ def path?(source, target)
11
+ return false unless has_vertex?(source)
12
+
13
+ bfs_iterator = bfs_iterator(source)
14
+ bfs_iterator.include?(target)
15
+ end
16
+ end
17
+ end
@@ -58,9 +58,12 @@ module RGL
58
58
  # Reset the iterator to the initial state (i.e. at_beginning? == true).
59
59
  #
60
60
  def set_to_begin
61
+ # Reset color_map
62
+ @color_map = Hash.new(:WHITE)
61
63
  color_map[@start_vertex] = :GRAY
62
- @waiting = [@start_vertex] # a queue
64
+ @waiting = [@start_vertex] # a queue
63
65
  handle_tree_edge(nil, @start_vertex) # discovers start vertex
66
+ self
64
67
  end
65
68
 
66
69
  def basic_forward # :nodoc:
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ require 'rgl/adjacency'
6
+ require 'rgl/path'
7
+
8
+ class TestPath < Test::Unit::TestCase
9
+ include RGL
10
+
11
+ def setup
12
+ edges = [[1, 2], [2, 3], [2, 4], [4, 5], [6, 4], [1, 6]]
13
+ @directed_graph, @undirected_graph =
14
+ [DirectedAdjacencyGraph, AdjacencyGraph].map do |klass|
15
+ graph = klass.new
16
+ graph.add_edges(*edges)
17
+ graph
18
+ end
19
+ end
20
+
21
+ def test_path_for_directed_graph
22
+ assert(@directed_graph.path?(1, 5))
23
+ end
24
+
25
+ def test_path_for_undirected_graph
26
+ assert(@undirected_graph.path?(1, 5))
27
+ end
28
+
29
+ def test_inverse_path_for_directed_graph
30
+ assert_equal(@directed_graph.path?(3, 1), false)
31
+ end
32
+
33
+ def test_inverse_path_for_undirected_graph
34
+ assert(@undirected_graph.path?(3, 1))
35
+ end
36
+
37
+ def test_path_for_directed_graph_wrong_source
38
+ assert_equal(@directed_graph.path?(0, 1), false)
39
+ end
40
+
41
+ def test_path_for_undirected_graph_wrong_source
42
+ assert_equal(@undirected_graph.path?(0, 1), false)
43
+ end
44
+
45
+ def test_path_for_directed_graph_wrong_target
46
+ assert_equal(@directed_graph.path?(4, 0), false)
47
+ end
48
+
49
+ def test_path_for_undirected_graph_wrong_target
50
+ assert_equal(@undirected_graph.path?(4, 0), false)
51
+ end
52
+ end
@@ -218,4 +218,30 @@ END
218
218
  dg.depth_first_search(vis) { |x| }
219
219
  assert_equal("(1 (2 (3 3)(4 (5 5) 4) 2)(6 6) 1)(10 (11 11) 10)", a)
220
220
  end
221
+
222
+ def test_bfs_stream_protocol
223
+ it = @dg.bfs_iterator(1)
224
+ assert_true(it.at_beginning?)
225
+
226
+ it.set_to_end()
227
+ assert_true(it.at_end?)
228
+
229
+ it.set_to_begin()
230
+ assert_true(it.at_beginning?)
231
+
232
+ assert_equal(it.to_a(), [1, 2, 6, 3, 4, 5])
233
+ end
234
+
235
+ def test_dfs_stream_protocol
236
+ it = @dg.dfs_iterator(1)
237
+ assert_true(it.at_beginning?)
238
+
239
+ it.set_to_end()
240
+ assert_true(it.at_end?)
241
+
242
+ it.set_to_begin()
243
+ assert_true(it.at_beginning?)
244
+
245
+ assert_equal(it.to_a(), [1, 6, 4, 5, 2, 3])
246
+ end
221
247
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Horst Duchene
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire: rgl/base
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-02-06 00:00:00.000000000 Z
12
+ date: 2019-08-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: stream
@@ -183,6 +183,7 @@ files:
183
183
  - lib/rgl/graphxml.rb
184
184
  - lib/rgl/implicit.rb
185
185
  - lib/rgl/mutable.rb
186
+ - lib/rgl/path.rb
186
187
  - lib/rgl/path_builder.rb
187
188
  - lib/rgl/prim.rb
188
189
  - lib/rgl/rdot.rb
@@ -205,6 +206,7 @@ files:
205
206
  - test/graph_test.rb
206
207
  - test/graph_xml_test.rb
207
208
  - test/implicit_test.rb
209
+ - test/path_test.rb
208
210
  - test/prim_test.rb
209
211
  - test/rdot_test.rb
210
212
  - test/test_helper.rb
@@ -234,7 +236,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
234
236
  - !ruby/object:Gem::Version
235
237
  version: '0'
236
238
  requirements: []
237
- rubygems_version: 3.0.2
239
+ rubygems_version: 3.0.6
238
240
  signing_key:
239
241
  specification_version: 4
240
242
  summary: Ruby Graph Library