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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6803a4b304a1a963f6c0656fb7ba2a4587d52ecd
4
- data.tar.gz: da773a35044ca0777473b689d8af68734f0b1d9c
3
+ metadata.gz: bf4090c12a830fe79fd2e9a82b0a9e0ff88c13d9
4
+ data.tar.gz: 706cf5a6414bcb35d01bc75e099b469e38eaee50
5
5
  SHA512:
6
- metadata.gz: fcb51d63d7f89d52b103495da244d9635b7ac1b4d3c1165f1c3bbcc9905e028571670a34d328608dfe9bd69be3b0f369924e9fdec5c6dc03a323605b9ee0d67e
7
- data.tar.gz: 3e1252e32d8eb405b7aec43cc2b699b961a84b2ef447b759e699fe7f36e96d8c12d7a625a5fad2a1c18c718ebdc2d5d06fd21c385b43bc5aeda20378c69a0851
6
+ metadata.gz: 4a300c0e167977749282c0c29eca872927aa8d13124c0dfac27b2c439f35b7aaeef9338f0c31d9a94405cae8a0269d2b7c3d9a8e6b8b1063e6535afdf6302821
7
+ data.tar.gz: 1c08980250baf23168ace07c0bad0a13cf6bc67fb0130554d9125fd835f39d75df33246dba700241f53c9f8bb73ff0e28519baae6b0405b67ee3b86715add9e6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- group_mixer (0.4.1)
4
+ group_mixer (0.4.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -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
- if is_separate_reminders
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(group_size, max_group_size, min_member_size)
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 make_separate_groups(group_size, people_size)
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
- past_pheromone = Hash.new(0)
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
- if people.include?(pair[0]) && people.include?(pair[1])
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
- end
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) do |person, hash|
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
- end
61
+ }
65
62
  end
66
63
 
67
64
  def select_group(groups, person, links)
68
- group_relevance = get_group_relevance(groups, person, links)
69
- min_relevence = group_relevance.min{ |x, y| x[1] <=> y[1] }[1]
70
- min_relevence_groups = group_relevance.select { |g, v| v == min_relevence }.keys
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 get_group_relevance(groups, person, links)
74
+ def group_relevance(groups, person, links)
78
75
  groups.each_with_object(Hash.new) { |g, hash|
79
- if g.full?
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
@@ -1,3 +1,3 @@
1
1
  module GroupMixer
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
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.1
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-04 00:00:00.000000000 Z
11
+ date: 2018-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler