annealing 0.1.0 → 0.2.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 +4 -4
- data/README.md +2 -1
- data/lib/annealing/pool.rb +5 -5
- data/lib/annealing/simulator.rb +2 -2
- data/lib/annealing/version.rb +1 -1
- 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: 53e5900add60de36b8e3bb441be9bce450f6dcb3cbd67552913684745e90a0c1
|
4
|
+
data.tar.gz: 00347f761988a73951ed950317c1fc6ebf6d1add2d2ab1889bf8cbe6eebabe36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef3653ce209af0a76189157cdecbbac58613aa86845b0e8476a22407fc17b9edb75e879f1676497eb7f1d8b4f86549719f67825f7c48db134603ed784d2d5ef1
|
7
|
+
data.tar.gz: 022accd062db4cc155e50606d22ea7e51db7603a61ef9b40512625110d528975de275b1abbb5ea6604fa98162122ef8b5e143f474593536af4291089e4d3f229
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# Annealing
|
2
|
+
[](https://badge.fury.io/rb/annealing)
|
2
3
|
|
3
4
|
Find the optimal solution in a complex problem through a simulated annealing implementation for enumerable objects. Where the energy of each object can be measured by a distance method between two elements or a lambda function where the total energy is calculated in the objects.
|
4
5
|
|
@@ -97,7 +98,7 @@ or in the simulator as a parameter
|
|
97
98
|
calc = lambda do |enumerable|
|
98
99
|
enumerable.each_cons(2).sum { |a, b| a.distance(b) }
|
99
100
|
end
|
100
|
-
solution = simulator.run(locations,
|
101
|
+
solution = simulator.run(locations, calc).collection
|
101
102
|
[(20,40), (40,120), (100,120), (60,200), (180,200)]
|
102
103
|
```
|
103
104
|
|
data/lib/annealing/pool.rb
CHANGED
@@ -5,7 +5,7 @@ module Annealing
|
|
5
5
|
class Pool
|
6
6
|
attr_reader :collection
|
7
7
|
|
8
|
-
def initialize(collection, energy_calculator
|
8
|
+
def initialize(collection, energy_calculator = nil)
|
9
9
|
@collection = collection.dup
|
10
10
|
@energy_calculator = energy_calculator || Annealing.configuration.total_energy_calculator
|
11
11
|
end
|
@@ -32,14 +32,14 @@ module Annealing
|
|
32
32
|
format('%<energy>.4f:%<value>s', energy: energy, value: collection)
|
33
33
|
end
|
34
34
|
|
35
|
+
def next
|
36
|
+
Pool.new(swap_collection, energy_calculator)
|
37
|
+
end
|
38
|
+
|
35
39
|
private
|
36
40
|
|
37
41
|
attr_reader :energy_calculator
|
38
42
|
|
39
|
-
def next
|
40
|
-
Pool.new(swap_collection, energy_calculator: energy_calculator)
|
41
|
-
end
|
42
|
-
|
43
43
|
def swap_collection
|
44
44
|
swapped = collection.dup
|
45
45
|
idx_a = rand(size)
|
data/lib/annealing/simulator.rb
CHANGED
@@ -14,8 +14,8 @@ module Annealing
|
|
14
14
|
normalize_cooling_rate
|
15
15
|
end
|
16
16
|
|
17
|
-
def run(collection,
|
18
|
-
best = current = Pool.new(collection.shuffle,
|
17
|
+
def run(collection, calculator = nil)
|
18
|
+
best = current = Pool.new(collection.shuffle, calculator)
|
19
19
|
Annealing.logger.debug(" Original: #{current}")
|
20
20
|
cool_down do |temp|
|
21
21
|
current = current.solution_at(temp)
|
data/lib/annealing/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: annealing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luis Ezcurdia Razo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-06-
|
11
|
+
date: 2020-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Simulated Annealing algoritm implementation.
|
14
14
|
email:
|