vns 0.2.0 → 1.0.pre.rc.2

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: aabc4061fa4c01eebf965ce36dda299b11b35d49906eb5815bde21a3d4647703
4
- data.tar.gz: 273f309115f63a6ccfa5bf4497bbe940a31c8d5bdf4e8046d9b23115c48f6971
3
+ metadata.gz: 0b4ff50c222a84989a4a3ef027795ad4e10607605755eae0a511cd36c351c7e3
4
+ data.tar.gz: 5cf1261af73b72f49cf453098029ac2482fc149e46ab869bd19ffeb938e614e3
5
5
  SHA512:
6
- metadata.gz: bf5aec1de3b5c24b83c48acdfa4c895f7d01391be41d6cc5689b1ddf5a1b946105d022b286c7ea408f538c081c73e1da5dac3714f405e27054c2bce89c6840c5
7
- data.tar.gz: 0b3370fa91a444e225ed7462acc19dacba4b0cb1428111c93801822f673a8581142a2d920c509157bd146cfc13ebd775994eada3ae9d822f6417668acd118e8f
6
+ metadata.gz: 133f330f6a0ab768e1e3cbcc3d198668450ca1af04331b57da4b2a02f97ec786ca236f785356acc75ad072d8df5044c42f2d5803401b49ef761761b2700b2def
7
+ data.tar.gz: 07c681af54608712f69df1992f377d977b6001f297399dc7bbb43e4831cf08886241dd31cfeadcf2c8de1407bfaae1a98c90e9532a251c1e1c9fdf9170d8e03a
data/Gemfile.lock CHANGED
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vns (0.2.0)
4
+ vns (1.0.pre.rc.2)
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.10.0)
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/session.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  module VNS
2
2
  class Session
3
- MAX_ALLOCATION = 25
4
3
  attr_reader :id, :name
5
4
 
6
5
  def initialize(id, name)
@@ -12,4 +11,4 @@ module VNS
12
11
  "#{id}\t#{name}"
13
12
  end
14
13
  end
15
- end
14
+ end
data/lib/vns/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module VNS
2
- VERSION = '0.2.0'
2
+ VERSION = '1.0-rc.2'
3
3
  end
data/lib/vns.rb CHANGED
@@ -4,15 +4,17 @@ module VNS
4
4
  require 'active_support/all'
5
5
 
6
6
  class VNS
7
- attr_reader :people, :sessions, :preferences
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, &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
+ @max_allocation = max_allocation
17
+ @group_duplication_factor = group_duplication_factor
16
18
  end
17
19
 
18
20
  def run
@@ -40,11 +42,17 @@ module VNS
40
42
  def target_function(solution = @solution)
41
43
  return Float::INFINITY unless solution
42
44
 
43
- solution.map do |session, people|
44
- people.map do |person|
45
- preferences[person.id][session.id]
46
- end
47
- 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
+ individual_penalty + group_duplication_factor * group_penalty
48
56
  end
49
57
 
50
58
  private
@@ -141,7 +149,7 @@ module VNS
141
149
  end
142
150
 
143
151
  def feasible?(solution)
144
- solution.values.all? { |group| group.size <= Session::MAX_ALLOCATION }
152
+ solution.values.all? { |group| group.size <= max_allocation }
145
153
  end
146
154
 
147
155
  def swap(solution, person1, person2)
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.2.0
4
+ version: 1.0.pre.rc.2
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