rgraph 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
data/lib/rgraph/graph.rb CHANGED
@@ -168,6 +168,16 @@ class Graph
168
168
  (distances.flatten - [@infinity]).max
169
169
  end
170
170
 
171
+ def farness
172
+ distances unless @distance
173
+
174
+ @distance.map{ |line| line.select{|l| l != @infinity }.inject(:+) }
175
+ end
176
+
177
+ def closeness
178
+ farness.map{|f| 1.0 / f }
179
+ end
180
+
171
181
  def single_clustering(node)
172
182
  possible = possible_connections(node)
173
183
  return 0 if possible == 0
@@ -1,3 +1,3 @@
1
1
  module Rgraph
2
- VERSION = '0.0.11'
2
+ VERSION = '0.0.12'
3
3
  end
@@ -175,6 +175,12 @@ describe Graph do
175
175
  it "calculates diameter" do
176
176
  expect(subject.diameter).to eq(3)
177
177
  end
178
+ it "calculates farness" do
179
+ expect(subject.farness).to eq([9,8,8,7,7,11])
180
+ end
181
+ it "calculates closeness" do
182
+ expect(subject.closeness).to eq([1/9.0,1/8.0,1/8.0,1/7.0,1/7.0,1/11.0])
183
+ end
178
184
  it "calculates cumulative betweenness" do
179
185
  expect(subject.betweenness(cumulative: true)).to eq([[6, 0.0], [4, 0.5], [1, 1.0]])
180
186
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgraph
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-09-12 00:00:00.000000000 Z
13
+ date: 2013-09-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler