weighted_graph 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -3
- data/lib/weighted_graph.rb +2 -1
- data/lib/weighted_graph/positive_weighted_graph.rb +24 -0
- data/lib/weighted_graph/version.rb +1 -1
- data/weighted_graph.gemspec +2 -4
- metadata +2 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2aeaa497d98a2ce3127350c971b0a95ca8b439d7
|
4
|
+
data.tar.gz: 2d738d658bff3b8e81f7d6c4cef2d22d4cf8dea0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f78b0f3725d12cc951db351850131c772cce8f9f4abed144bcc09f3e0bfbe2528274f7e30226626b3905940e942ec6451b4ab599962b099c35c4dbb0190a8224
|
7
|
+
data.tar.gz: bf24cb04fe31638d191f2926a32cc0a142b264121ce8f0d33f04383e4da257f95b709a22954cd9a07ba03ec80b36a0053a4d7a06ca0efbb0797fb4e69676d9a8
|
data/README.md
CHANGED
@@ -28,7 +28,20 @@ get_edge_weight(source, destination)
|
|
28
28
|
get_adjacent_vertices(source)
|
29
29
|
```
|
30
30
|
|
31
|
-
|
31
|
+
## WeightedGraph::PositiveWeightedGraph API
|
32
|
+
|
33
|
+
WeightedGraph::PositiveWeightedGraph extends WeightedGraph::Graph and shares its behaviour, with the following differences:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
# Add directed edge (source, destination) to the graph with given weight
|
37
|
+
# Requires that weight is a positive number
|
38
|
+
add_edge(source, destination, weight)
|
39
|
+
|
40
|
+
# Add undirected edge (vertex_a, vertex_b) to the graph with given weight
|
41
|
+
# Requires that weight is a positive number
|
42
|
+
add_undirected_edge(vertex_a, vertex_b, weight)
|
43
|
+
```
|
44
|
+
|
32
45
|
## Installation
|
33
46
|
|
34
47
|
Add this line to your application's Gemfile:
|
@@ -37,9 +50,17 @@ Add this line to your application's Gemfile:
|
|
37
50
|
gem 'weighted_graph'
|
38
51
|
```
|
39
52
|
|
40
|
-
|
53
|
+
Then you can require the gem in Ruby programs:
|
41
54
|
|
42
|
-
|
55
|
+
```ruby
|
56
|
+
require 'weighted_graph'
|
57
|
+
|
58
|
+
def myMethod()
|
59
|
+
graph = WeightedGraph::Graph.new
|
60
|
+
graph.add_edge('Vancouver', 'Port Coquitlam', 28)
|
61
|
+
# ...
|
62
|
+
end
|
63
|
+
```
|
43
64
|
|
44
65
|
## Development
|
45
66
|
|
data/lib/weighted_graph.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative './graph'
|
2
|
+
|
3
|
+
# A simple graph with weighted edges
|
4
|
+
module WeightedGraph
|
5
|
+
# API for a graph that requires positive edge weights
|
6
|
+
class PositiveWeightedGraph < WeightedGraph::Graph
|
7
|
+
# Initialize an empty adjacency list for edges
|
8
|
+
def initialize
|
9
|
+
super(Hash.new(0))
|
10
|
+
end
|
11
|
+
|
12
|
+
# Add directed edge (source, destination) to the graph with given weight
|
13
|
+
# Requires that weight is a positive number
|
14
|
+
def add_edge(source, destination, weight)
|
15
|
+
super(source, destination, weight) if weight > 0
|
16
|
+
end
|
17
|
+
|
18
|
+
# Add undirected edge (vertex_a, vertex_b) to the graph with given weight
|
19
|
+
# Requires that weight is a positive number
|
20
|
+
def add_undirected_edge(vertex_a, vertex_b, weight)
|
21
|
+
super(vertex_a, vertex_b, weight) if weight > 0
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/weighted_graph.gemspec
CHANGED
@@ -16,9 +16,7 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.homepage = 'https://github.com/msayson/weighted_graph'
|
17
17
|
spec.license = 'MIT'
|
18
18
|
|
19
|
-
#
|
20
|
-
# To allow pushes either set the 'allowed_push_host' to allow pushing to
|
21
|
-
# a single host or delete this section to allow pushing to any host.
|
19
|
+
# Specify hosts this gem may be pushed to.
|
22
20
|
if spec.respond_to?(:metadata)
|
23
21
|
spec.metadata['allowed_push_host'] = 'https://rubygems.org/gems/weighted_graph'
|
24
22
|
else
|
@@ -34,7 +32,7 @@ Gem::Specification.new do |spec|
|
|
34
32
|
spec.require_paths = ['lib']
|
35
33
|
|
36
34
|
spec.add_development_dependency 'bundler', '~> 1.14'
|
37
|
-
spec.add_development_dependency 'pry', '~> 0.10'
|
35
|
+
# spec.add_development_dependency 'pry', '~> 0.10' # Local debugging utility
|
38
36
|
spec.add_development_dependency 'rake', '~> 10.0'
|
39
37
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
40
38
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: weighted_graph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Sayson
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.14'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: pry
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0.10'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0.10'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: rake
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -87,6 +73,7 @@ files:
|
|
87
73
|
- bin/setup
|
88
74
|
- lib/weighted_graph.rb
|
89
75
|
- lib/weighted_graph/graph.rb
|
76
|
+
- lib/weighted_graph/positive_weighted_graph.rb
|
90
77
|
- lib/weighted_graph/version.rb
|
91
78
|
- weighted_graph.gemspec
|
92
79
|
homepage: https://github.com/msayson/weighted_graph
|