rgraph 0.0.8 → 0.0.9
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.
- data/lib/rgraph/graph.rb +11 -2
- data/lib/rgraph/version.rb +1 -1
- data/spec/rgraph/graph_spec.rb +4 -1
- metadata +2 -2
data/lib/rgraph/graph.rb
CHANGED
@@ -125,14 +125,23 @@ class Graph
|
|
125
125
|
n / m
|
126
126
|
end
|
127
127
|
|
128
|
-
def betweenness(
|
128
|
+
def betweenness(args = {})
|
129
|
+
cumulative = args[:cumulative] || false
|
130
|
+
|
131
|
+
#If we ask cumulative, normalized must be true
|
132
|
+
normalized = args[:normalized] || cumulative || false
|
133
|
+
|
129
134
|
bts = 0.upto(@nodes.size - 1).map { |i| between(i) }
|
130
135
|
|
131
136
|
if normalized
|
132
137
|
max = bts.max
|
133
138
|
min = bts.min
|
134
139
|
|
135
|
-
bts.map{|bt| (bt - min) / (max - min)}
|
140
|
+
bts.map!{|bt| (bt - min) / (max - min)}
|
141
|
+
end
|
142
|
+
|
143
|
+
if cumulative
|
144
|
+
bts.uniq.sort.map{ |bt1| [bts.select{|bt2| bt2 >= bt1}.count, bt1] }
|
136
145
|
else
|
137
146
|
bts
|
138
147
|
end
|
data/lib/rgraph/version.rb
CHANGED
data/spec/rgraph/graph_spec.rb
CHANGED
@@ -140,11 +140,14 @@ describe Graph do
|
|
140
140
|
0 / 15.0])
|
141
141
|
end
|
142
142
|
it "calculates all betweenness normalized" do
|
143
|
-
expect(subject.betweenness(true)).to eq(
|
143
|
+
expect(subject.betweenness(normalized: true)).to eq(
|
144
144
|
[0.0, 0.5, 0.5, 1.0, 0.5, 0.0])
|
145
145
|
end
|
146
146
|
it "calculates diameter" do
|
147
147
|
expect(subject.diameter).to eq(3)
|
148
148
|
end
|
149
|
+
it "calculates cumulative betweenness" do
|
150
|
+
expect(subject.betweenness(cumulative: true)).to eq([[6, 0.0], [4, 0.5], [1, 1.0]])
|
151
|
+
end
|
149
152
|
end
|
150
153
|
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.
|
4
|
+
version: 0.0.9
|
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-08-
|
13
|
+
date: 2013-08-30 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|