group_mixer 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/group_mixer/mixer.rb +19 -26
- data/lib/group_mixer/version.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: bf4090c12a830fe79fd2e9a82b0a9e0ff88c13d9
|
4
|
+
data.tar.gz: 706cf5a6414bcb35d01bc75e099b469e38eaee50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a300c0e167977749282c0c29eca872927aa8d13124c0dfac27b2c439f35b7aaeef9338f0c31d9a94405cae8a0269d2b7c3d9a8e6b8b1063e6535afdf6302821
|
7
|
+
data.tar.gz: 1c08980250baf23168ace07c0bad0a13cf6bc67fb0130554d9125fd835f39d75df33246dba700241f53c9f8bb73ff0e28519baae6b0405b67ee3b86715add9e6
|
data/Gemfile.lock
CHANGED
data/lib/group_mixer/mixer.rb
CHANGED
@@ -12,12 +12,7 @@ module GroupMixer
|
|
12
12
|
if group_size.zero?
|
13
13
|
raise ZeroGroupSize, 'group_size must be a number greater than 1'
|
14
14
|
end
|
15
|
-
|
16
|
-
@groups = make_separate_groups(group_size, @people.size)
|
17
|
-
else
|
18
|
-
min_member_size, max_group_size = people.size.divmod group_size
|
19
|
-
@groups = make_groups(group_size, max_group_size, min_member_size)
|
20
|
-
end
|
15
|
+
@groups = make_groups(is_separate_reminders, group_size)
|
21
16
|
end
|
22
17
|
|
23
18
|
def execute
|
@@ -33,54 +28,52 @@ module GroupMixer
|
|
33
28
|
|
34
29
|
private
|
35
30
|
|
36
|
-
def make_groups(
|
31
|
+
def make_groups(is_separate_reminders, group_size)
|
32
|
+
ps = @people.size
|
33
|
+
is_separate_reminders ? separate_groups(group_size, ps) : flatting_groups(group_size, ps)
|
34
|
+
end
|
35
|
+
|
36
|
+
def flatting_groups(group_size, people_size)
|
37
|
+
min_member_size, max_group_size = people_size.divmod group_size
|
37
38
|
max_group_size.times.map { |n| Group.new(min_member_size + 1) } +
|
38
39
|
(group_size - max_group_size).times.map { |n| Group.new(min_member_size) }
|
39
40
|
end
|
40
41
|
|
41
|
-
def
|
42
|
+
def separate_groups(group_size, people_size)
|
42
43
|
member_size = people_size / (group_size - 1)
|
43
44
|
(group_size - 1).times.map { Group.new(member_size) } +
|
44
45
|
[Group.new(people_size % (group_size - 1))]
|
45
46
|
end
|
46
47
|
|
47
48
|
def make_heuristic_from_past(people, past_set)
|
48
|
-
|
49
|
-
past_set.each do |past|
|
49
|
+
past_set.each_with_object(Hash.new(0)) { |past, pheromone|
|
50
50
|
past.members.to_a.combination(2).each do |pair|
|
51
|
-
|
52
|
-
past_pheromone[Set.new(pair)] += past.weight
|
53
|
-
end
|
51
|
+
pheromone[Set.new(pair)] += past.weight if (people & pair).size > 1
|
54
52
|
end
|
55
|
-
|
56
|
-
past_pheromone
|
53
|
+
}
|
57
54
|
end
|
58
55
|
|
59
56
|
def make_link_amount_hash(people, links)
|
60
|
-
people.each_with_object(Hash.new)
|
57
|
+
people.each_with_object(Hash.new) { |person, hash|
|
61
58
|
hash[person] = links.select { |pair, value| pair.member? person }
|
62
59
|
.map { |pair, value| value }
|
63
60
|
.inject(0) { |sum, value| sum += value }
|
64
|
-
|
61
|
+
}
|
65
62
|
end
|
66
63
|
|
67
64
|
def select_group(groups, person, links)
|
68
|
-
|
69
|
-
min_relevence =
|
70
|
-
min_relevence_groups =
|
65
|
+
relevances = group_relevance(groups, person, links)
|
66
|
+
min_relevence = relevances.min{ |x, y| x[1] <=> y[1] }[1]
|
67
|
+
min_relevence_groups = relevances.select { |g, v| v == min_relevence }.keys
|
71
68
|
max_relevence_group_size = min_relevence_groups.max{ |x, y|
|
72
69
|
x.members.size <=> y.members.size
|
73
70
|
}.members.size
|
74
71
|
min_relevence_groups.select { |g| g.members.size == max_relevence_group_size }.sample
|
75
72
|
end
|
76
73
|
|
77
|
-
def
|
74
|
+
def group_relevance(groups, person, links)
|
78
75
|
groups.each_with_object(Hash.new) { |g, hash|
|
79
|
-
|
80
|
-
hash[g] = MAX_AMOUNT
|
81
|
-
else
|
82
|
-
hash[g] = g.inject(0) { |sum, m| sum += links[Set[m, person]].to_i }
|
83
|
-
end
|
76
|
+
hash[g] = g.full? ? MAX_AMOUNT : g.inject(0) { |sum, m| sum += links[Set[m, person]].to_i }
|
84
77
|
}
|
85
78
|
end
|
86
79
|
end
|
data/lib/group_mixer/version.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.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- iwtn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|