vns 0.3.0 → 1.0.pre.rc.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b1128cbe4173ea847fb81d2a84a1155e6a4203b42101eacef121d71018ec823b
4
- data.tar.gz: 7586d4596737a7ed4e5f46b2b80e596d3d099c44f9b9133cf386aa8f1691c3e8
3
+ metadata.gz: f8eacfde3fd497f7317f610995db9fc16942bec62eb40602da5286b94593b448
4
+ data.tar.gz: '08103a631dc376473929349c08ad35801478a9d865c33235fa86109d6ce37c65'
5
5
  SHA512:
6
- metadata.gz: 17ddca60952da55c8e2917a3f11e73305c930950e1b9b35ac9be63686906807b32b1194ca801903fcfcd1d12c0a7a9a8910d50264fcda41ae8e04c13962c4540
7
- data.tar.gz: 8da56db54249ad9038caadfdfb3daad4a4de8c04f17d9ba78aceecd16b8a7e2f99befbbe3b0bb6d641d083b6cdf8e8ca456c090ccdf3995864d81d17a98aa41b
6
+ metadata.gz: 6f265e1ff335f4aac537957c1c989d15679cafa3b987d87eb4e514abf590ff0711d89fe3541ceda044be8e1684314f6ba220309d545bf6abb259985a6392d2f3
7
+ data.tar.gz: 780e7f9cf043f89059dc3809852c5a6ff6c6911d6983a57e3b9f6ccd87c6694dd88c8086a76409199f8839bf47be26a5eba9cee5a99af6db980ca8b9c4bc4b8b
data/Gemfile.lock CHANGED
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vns (0.3.0)
4
+ vns (1.0.pre.rc.1)
5
5
  activesupport
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activesupport (6.1.1)
10
+ activesupport (6.1.4.1)
11
11
  concurrent-ruby (~> 1.0, >= 1.0.2)
12
12
  i18n (>= 1.6, < 2)
13
13
  minitest (>= 5.1)
@@ -15,11 +15,11 @@ GEM
15
15
  zeitwerk (~> 2.3)
16
16
  ast (2.4.1)
17
17
  coderay (1.1.3)
18
- concurrent-ruby (1.1.8)
19
- i18n (1.8.7)
18
+ concurrent-ruby (1.1.9)
19
+ i18n (1.9.1)
20
20
  concurrent-ruby (~> 1.0)
21
21
  method_source (0.9.2)
22
- minitest (5.14.3)
22
+ minitest (5.15.0)
23
23
  parallel (1.20.1)
24
24
  parser (2.7.2.0)
25
25
  ast (~> 2.4.1)
@@ -45,7 +45,7 @@ GEM
45
45
  tzinfo (2.0.4)
46
46
  concurrent-ruby (~> 1.0)
47
47
  unicode-display_width (1.7.0)
48
- zeitwerk (2.4.2)
48
+ zeitwerk (2.5.4)
49
49
 
50
50
  PLATFORMS
51
51
  ruby
data/lib/vns/person.rb CHANGED
@@ -1,13 +1,14 @@
1
1
  module VNS
2
2
  class Person
3
- attr_reader :id, :name
4
- def initialize(id, name)
3
+ attr_reader :id, :name, :group
4
+ def initialize(id, name, group)
5
5
  @id = id
6
6
  @name = name
7
+ @group = group
7
8
  end
8
9
 
9
10
  def to_s
10
- "#{id}\t#{name}"
11
+ "#{id}\t#{name} (#{group})"
11
12
  end
12
13
  end
13
14
  end
data/lib/vns/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module VNS
2
- VERSION = '0.3.0'
2
+ VERSION = '1.0-rc.1'
3
3
  end
data/lib/vns.rb CHANGED
@@ -4,16 +4,17 @@ module VNS
4
4
  require 'active_support/all'
5
5
 
6
6
  class VNS
7
- attr_reader :people, :sessions, :preferences, :max_allocation
7
+ attr_reader :people, :sessions, :preferences, :max_allocation, :group_duplication_factor
8
8
 
9
9
  PERTURBATION_COUNT = 100
10
10
 
11
- def initialize(people, sessions, preferences, max_allocation, &inspection)
12
- @people = people.map.with_index { |person, i| Person.new(i, person) }
11
+ def initialize(people, groups, sessions, preferences, max_allocation, group_duplication_factor, &inspection)
12
+ @people = people.map.with_index { |person, i| Person.new(i, person, groups[i]) }
13
13
  @sessions = sessions.map.with_index { |session, i| Session.new(i, session) }
14
14
  @preferences = preferences
15
15
  @inspection = inspection
16
16
  @max_allocation = max_allocation
17
+ @group_duplication_factor = group_duplication_factor
17
18
  end
18
19
 
19
20
  def run
@@ -41,11 +42,19 @@ module VNS
41
42
  def target_function(solution = @solution)
42
43
  return Float::INFINITY unless solution
43
44
 
44
- solution.map do |session, people|
45
- people.map do |person|
46
- preferences[person.id][session.id]
47
- end
48
- end.flatten.inject(:+)
45
+ individual_penalty = solution.map do |session, people|
46
+ people.map do |person|
47
+ preferences[person.id][session.id]
48
+ end
49
+ end.flatten.inject(:+)
50
+
51
+ group_penalty = solution.map do |session, people|
52
+ people.group_by(&:group).map{|group, people| people.count - 1 }.sum
53
+ end.inject(:+)
54
+
55
+ Rails.logger.info "Penalty: #{individual_penalty} + #{group_penalty}"
56
+
57
+ individual_penalty + group_duplication_factor * group_penalty
49
58
  end
50
59
 
51
60
  private
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vns
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.pre.rc.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manuel Bustillo
@@ -112,11 +112,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
112
  version: '0'
113
113
  required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">="
115
+ - - ">"
116
116
  - !ruby/object:Gem::Version
117
- version: '0'
117
+ version: 1.3.1
118
118
  requirements: []
119
- rubygems_version: 3.0.3
119
+ rubygems_version: 3.0.3.1
120
120
  signing_key:
121
121
  specification_version: 4
122
122
  summary: VNS