vns 0.2.0.pre.rc.2 → 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 +4 -4
- data/Gemfile.lock +6 -6
- data/lib/vns/person.rb +4 -3
- data/lib/vns/session.rb +1 -2
- data/lib/vns/version.rb +1 -1
- data/lib/vns.rb +19 -9
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f8eacfde3fd497f7317f610995db9fc16942bec62eb40602da5286b94593b448
|
|
4
|
+
data.tar.gz: '08103a631dc376473929349c08ad35801478a9d865c33235fa86109d6ce37c65'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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 (
|
|
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.
|
|
19
|
-
i18n (1.
|
|
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.
|
|
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
|
|
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
data/lib/vns/version.rb
CHANGED
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,19 @@ 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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
|
48
58
|
end
|
|
49
59
|
|
|
50
60
|
private
|
|
@@ -141,7 +151,7 @@ module VNS
|
|
|
141
151
|
end
|
|
142
152
|
|
|
143
153
|
def feasible?(solution)
|
|
144
|
-
solution.values.all? { |group| group.size <=
|
|
154
|
+
solution.values.all? { |group| group.size <= max_allocation }
|
|
145
155
|
end
|
|
146
156
|
|
|
147
157
|
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:
|
|
4
|
+
version: 1.0.pre.rc.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Manuel Bustillo
|
|
@@ -116,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
116
116
|
- !ruby/object:Gem::Version
|
|
117
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
|