lahcuby 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.md +25 -0
- data/lib/lahcuby/problem/solution.rb +15 -0
- data/lib/lahcuby/solver.rb +43 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bb55379aa210fc8be83a9c04e8beaf35c81c29a1
|
4
|
+
data.tar.gz: fefaa5bfeec6f8dde392ae6a3af0fa71b85ecb9e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 12fe0322bdcae4c48c0becbc59be6bdffea73cc96458e7f37a8b84483bc646eda88ce79c9741364e3fb526e3290ae3cb85ee4c7568e5b20b51e97efee70e5e0b
|
7
|
+
data.tar.gz: dadd8b61b309e41b2acc2f0d0f1333985be7b35f159e22602d31204d889d2bd5c3fe5441c9b9429292d4d6de8e2ab5f2058a2583a6e653dac912755debf7c205
|
data/LICENSE.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
The MIT License
|
2
|
+
===============
|
3
|
+
|
4
|
+
Copyright © 2020 Fräntz Miccoli
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
7
|
+
this software and associated documentation files (the "Software"), to deal in
|
8
|
+
the Software without restriction, including without limitation the rights to
|
9
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
10
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
11
|
+
so, subject to the following conditions:
|
12
|
+
|
13
|
+
Except as contained in this notice, the name(s) of the above copyright holders
|
14
|
+
shall not be used in advertising or otherwise to promote the sale, use or other
|
15
|
+
dealings in this Software without prior written authorization.
|
16
|
+
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
18
|
+
copies or substantial portions of the Software.
|
19
|
+
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
22
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
23
|
+
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
24
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
25
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Lahcuby
|
2
|
+
class Solver
|
3
|
+
|
4
|
+
def initialize(initial_solution, maximum_number_of_iterations, memory_size)
|
5
|
+
@current_solution = initial_solution
|
6
|
+
@maximum_number_of_iterations = maximum_number_of_iterations
|
7
|
+
@memory_size = memory_size
|
8
|
+
end
|
9
|
+
|
10
|
+
def solve()
|
11
|
+
costs_memory = []
|
12
|
+
@memory_size.times do |_|
|
13
|
+
costs_memory.push(@current_solution.get_cost)
|
14
|
+
end
|
15
|
+
best_solution = @current_solution
|
16
|
+
|
17
|
+
@maximum_number_of_iterations.times do |iteration|
|
18
|
+
memory_index = iteration % @memory_size
|
19
|
+
new_solution = @current_solution.get_variation
|
20
|
+
|
21
|
+
beats_current_solution =
|
22
|
+
new_solution.get_cost < @current_solution.get_cost
|
23
|
+
memory_cost = costs_memory[memory_index]
|
24
|
+
beats_memory_cost = new_solution.get_cost < memory_cost
|
25
|
+
|
26
|
+
if beats_current_solution || beats_memory_cost
|
27
|
+
@current_solution = new_solution
|
28
|
+
end
|
29
|
+
|
30
|
+
if beats_memory_cost
|
31
|
+
costs_memory[memory_index] = new_solution.get_cost
|
32
|
+
end
|
33
|
+
|
34
|
+
if @current_solution.get_cost < best_solution.get_cost
|
35
|
+
best_solution = @current_solution
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
best_solution
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lahcuby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Fräntz Miccoli
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-05-01 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Simple implementation late acceptance hill climbing (LAHC) in Ruby
|
14
|
+
email:
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- LICENSE.md
|
20
|
+
- lib/lahcuby/problem/solution.rb
|
21
|
+
- lib/lahcuby/solver.rb
|
22
|
+
homepage: https://frantzmiccoli.github.io/Lahcuby
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '2.3'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.5.2.3
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: 'Lachuby: late acceptance hill climbing for Ruby'
|
46
|
+
test_files: []
|