vns 0.1.1 → 0.3.0

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: fe1c277a047286ad18e02f1536bc192aa8327444a1d7cf2d6efa3c7d31fcd42e
4
- data.tar.gz: 020472d1dd94083946b4b39a2e82647953e65ff592f3fccdfdf052f10f1e85b6
3
+ metadata.gz: b1128cbe4173ea847fb81d2a84a1155e6a4203b42101eacef121d71018ec823b
4
+ data.tar.gz: 7586d4596737a7ed4e5f46b2b80e596d3d099c44f9b9133cf386aa8f1691c3e8
5
5
  SHA512:
6
- metadata.gz: ae6143e3d7ee45ace9391a20183265ceb1bc89dc4cad7aeeb6620e75556ab88ee990e51c18ac734b565f6ad49b670142ed0fc820da317903100cfd73307b8501
7
- data.tar.gz: f6d70a283e94d1d3eb0e1331ef7d9e07d4b2853923c25c2b9fb075b7c5f3397721654ffa78417f6eb4e5972764d25b8b7b53c39620ee03de72b8247d17aaa416
6
+ metadata.gz: 17ddca60952da55c8e2917a3f11e73305c930950e1b9b35ac9be63686906807b32b1194ca801903fcfcd1d12c0a7a9a8910d50264fcda41ae8e04c13962c4540
7
+ data.tar.gz: 8da56db54249ad9038caadfdfb3daad4a4de8c04f17d9ba78aceecd16b8a7e2f99befbbe3b0bb6d641d083b6cdf8e8ca456c090ccdf3995864d81d17a98aa41b
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vns (0.1.1)
4
+ vns (0.3.0)
5
5
  activesupport
6
6
 
7
7
  GEM
data/lib/vns.rb CHANGED
@@ -4,15 +4,16 @@ 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
8
8
 
9
9
  PERTURBATION_COUNT = 100
10
10
 
11
- def initialize(people, sessions, preferences, &inspection)
11
+ def initialize(people, sessions, preferences, max_allocation, &inspection)
12
12
  @people = people.map.with_index { |person, i| Person.new(i, person) }
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
16
17
  end
17
18
 
18
19
  def run
@@ -71,7 +72,7 @@ module VNS
71
72
  end
72
73
 
73
74
  progress = (counter + 1) * 1.0 / PERTURBATION_COUNT
74
- @inspection.call(progress, target_function(best_solution)) if @inspection
75
+ @inspection&.call(progress, target_function(best_solution), public_format(best_solution))
75
76
  end
76
77
 
77
78
  best_solution
@@ -119,13 +120,13 @@ module VNS
119
120
  def perturbate(solution)
120
121
  2.times do
121
122
  extracted = []
122
- solution.each do |_, people|
123
- extracted << people.delete_at(rand(people.length))
124
- end
123
+ solution.each do |_, people|
124
+ extracted << people.delete_at(rand(people.length))
125
+ end
125
126
 
126
- extracted.shuffle.each_with_index do |person, i|
127
- solution.values[i] << person
128
- end
127
+ extracted.shuffle.each_with_index do |person, i|
128
+ solution.values[i] << person
129
+ end
129
130
  end
130
131
  end
131
132
 
@@ -141,7 +142,7 @@ module VNS
141
142
  end
142
143
 
143
144
  def feasible?(solution)
144
- solution.values.all? { |group| group.size <= Session::MAX_ALLOCATION }
145
+ solution.values.all? { |group| group.size <= max_allocation }
145
146
  end
146
147
 
147
148
  def swap(solution, person1, person2)
@@ -161,5 +162,9 @@ module VNS
161
162
  def find_session(solution, person)
162
163
  sessions.detect { |s| solution[s].include?(person) }
163
164
  end
165
+
166
+ def public_format(solution)
167
+ solution.map { |k, v| [k.name, v.map(&:name)] }.to_h
168
+ end
164
169
  end
165
- end
170
+ end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module VNS
2
- VERSION = '0.1.1'
2
+ VERSION = '0.3.0'
3
3
  end
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.1.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manuel Bustillo