group_mixer 0.1.0 → 0.1.1
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/group_mixer/group.rb +1 -0
- data/lib/group_mixer/mixer.rb +15 -33
- data/lib/group_mixer/version.rb +1 -1
- data/lib/group_mixer.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96f7557c79b022995704b2bc75254edf5d42107c
|
4
|
+
data.tar.gz: 18afffdc0fbeddf1df63dea8eb2ef3f3a9e2255a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9ab635121d010486477f7e446123cf9f9758c210e4a7337cc3fccdea39cfa34e3994322a4c57a2a53ec803ebd5a1a6f60beeae6fa8936d68d81df49ca3ff4ec
|
7
|
+
data.tar.gz: 38d73ebc47c003fce25efefcc0f1107ac1cfcdc74fe9d45b0770ff2593d1e8c6dda0598e910534a09035dc733ffb7130d09d2f2b52615761dd47baf65ace12aa
|
data/Gemfile.lock
CHANGED
data/lib/group_mixer/group.rb
CHANGED
data/lib/group_mixer/mixer.rb
CHANGED
@@ -1,15 +1,5 @@
|
|
1
1
|
require "group_mixer/group"
|
2
2
|
|
3
|
-
class Set
|
4
|
-
def pairs
|
5
|
-
Set.new(self.map do |i1|
|
6
|
-
self.map do |i2|
|
7
|
-
Set[i1, i2] if i1 != i2
|
8
|
-
end.compact
|
9
|
-
end.flatten)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
3
|
class Mixer
|
14
4
|
MAX_AMOUNT = 2 ** ([42].pack('i').size * 16 - 2) - 1
|
15
5
|
|
@@ -21,10 +11,10 @@ class Mixer
|
|
21
11
|
end
|
22
12
|
|
23
13
|
def execute
|
24
|
-
links = make_heuristic_from_past(@past_set)
|
14
|
+
links = make_heuristic_from_past(@people, @past_set)
|
25
15
|
link_amount_hash = make_link_amount_hash(@people, links)
|
26
16
|
|
27
|
-
link_amount_hash.sort {|a, b| b[1]<=>a[1]
|
17
|
+
link_amount_hash.sort { |a, b| b[1]<=>a[1] }.each do |person, amount|
|
28
18
|
select_group(@groups, person, links).add person
|
29
19
|
end
|
30
20
|
|
@@ -38,41 +28,33 @@ class Mixer
|
|
38
28
|
(group_size - max_group_size).times.map { |n| GroupMixer::Group.new(min_member_size) }
|
39
29
|
end
|
40
30
|
|
41
|
-
def make_heuristic_from_past(past_set)
|
31
|
+
def make_heuristic_from_past(people, past_set)
|
42
32
|
past_pheromone = Hash.new(0)
|
43
33
|
past_set.each do |past|
|
44
|
-
|
45
|
-
|
34
|
+
past.combination(2).each do |pair|
|
35
|
+
if people.include?(pair[0]) && people.include?(pair[1])
|
36
|
+
past_pheromone[Set.new(pair)] += 1
|
37
|
+
end
|
46
38
|
end
|
47
39
|
end
|
48
40
|
past_pheromone
|
49
41
|
end
|
50
42
|
|
51
43
|
def make_link_amount_hash(people, links)
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
amount += value if pair.member? person
|
57
|
-
end
|
58
|
-
hash[person] = amount
|
44
|
+
people.each_with_object(Hash.new) do |person, hash|
|
45
|
+
hash[person] = links.select { |pair, value| pair.member? person }
|
46
|
+
.map { |pair, value| value }
|
47
|
+
.inject(0) { |sum, value| sum += value }
|
59
48
|
end
|
60
|
-
hash
|
61
49
|
end
|
62
50
|
|
63
51
|
def select_group(groups, person, links)
|
64
|
-
|
65
|
-
groups.each do |g|
|
52
|
+
groups.each_with_object(Hash.new) { |g, hash|
|
66
53
|
if g.full?
|
67
|
-
|
54
|
+
hash[g] = MAX_AMOUNT
|
68
55
|
else
|
69
|
-
|
70
|
-
g.each do |member|
|
71
|
-
amount += links[Set[member, person]].to_i
|
72
|
-
end
|
73
|
-
group_amounts[g] = amount
|
56
|
+
hash[g] = g.inject(0) { |sum, m| sum += links[Set[m, person]].to_i }
|
74
57
|
end
|
75
|
-
|
76
|
-
group_amounts.min{ |x, y| x[1] <=> y[1] }[0]
|
58
|
+
}.min{ |x, y| x[1] <=> y[1] }[0]
|
77
59
|
end
|
78
60
|
end
|
data/lib/group_mixer/version.rb
CHANGED
data/lib/group_mixer.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: group_mixer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- iwtn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|