metaheuristic_algorithms 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +1 -1
- data/lib/metaheuristic_algorithms/base_algorithm_module.rb +4 -4
- data/lib/metaheuristic_algorithms/firefly_algorithm.rb +5 -5
- data/lib/metaheuristic_algorithms/function_wrappers/abstract_wrapper.rb +2 -2
- data/lib/metaheuristic_algorithms/function_wrappers/easom_function_wrapper.rb +1 -1
- data/lib/metaheuristic_algorithms/function_wrappers/michaelwicz_function_wrapper.rb +1 -1
- data/lib/metaheuristic_algorithms/function_wrappers/nonsmooth_multipeak_function_wrapper.rb +1 -1
- data/lib/metaheuristic_algorithms/function_wrappers/rosenbrook_function_wrapper.rb +1 -1
- data/lib/metaheuristic_algorithms/genetic_algorithm.rb +5 -5
- data/lib/metaheuristic_algorithms/harmony_search.rb +3 -3
- data/lib/metaheuristic_algorithms/simplified_particle_swarm_optimization.rb +4 -4
- data/lib/metaheuristic_algorithms/simulated_annealing.rb +6 -6
- data/lib/metaheuristic_algorithms/version.rb +1 -1
- data/lib/metaheuristic_algorithms/virtual_bee_algorithm.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71ab576a4800485d9359feeeee21831e1e8cad8b
|
4
|
+
data.tar.gz: 8cb7ecfb7825b3a4ab998360605bc205a88756cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3a418400c47d95fe4d9f2fceb1a7bd0ad8854d8ce00de8a34c04d39045748c52adc5a1837b1143607388d6224ebf924d57868b0db2d15f3c65cdd9c0c5f37b5
|
7
|
+
data.tar.gz: 11b6e91e6215f1f4fcea3498aa5db60475e46fe1a8e9bde5d11e62c6ba013d9caa5c975fad4a1f871b9414712fe747e1a6b75b28daa383209a44f0bf9a8223c5
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
## metaheuristic_algorithms 0.2.4 (November 9, 2015) ##
|
2
|
+
|
3
|
+
* Fixed a typo in method name minimum_decision_variable_values in FunctionWrapper's.
|
4
|
+
|
5
|
+
* Converts the values from methods in FunctionWrapper to Float, so that the algorithms codes work even when FunctionWrapper methods return values in BigDecimal.
|
6
|
+
|
7
|
+
Note: This can be considered to be incompatible API change. However, at this point, it is not yet considered to be a stable public API. Hence, the MAJOR version is kept to be 0. (See, [Semantic Versioning](http://semver.org/))
|
data/README.md
CHANGED
@@ -3,10 +3,10 @@ module MetaheuristicAlgorithms
|
|
3
3
|
module BaseAlgorithmModule
|
4
4
|
|
5
5
|
def get_decision_variable_value_by_randomization(decision_variable_index)
|
6
|
-
# @function_wrapper.
|
7
|
-
# + (@function_wrapper.maximum_decision_variable_values[decision_variable_index] - @function_wrapper.
|
8
|
-
@function_wrapper.
|
9
|
-
+ (@function_wrapper.maximum_decision_variable_values[decision_variable_index] - @function_wrapper.
|
6
|
+
# @function_wrapper.minimum_decision_variable_values[decision_variable_index]
|
7
|
+
# + (@function_wrapper.maximum_decision_variable_values[decision_variable_index] - @function_wrapper.minimum_decision_variable_values[decision_variable_index]) * bigdecimal_rand
|
8
|
+
@function_wrapper.minimum_decision_variable_values[decision_variable_index].to_f
|
9
|
+
+ (@function_wrapper.maximum_decision_variable_values[decision_variable_index].to_f - @function_wrapper.minimum_decision_variable_values[decision_variable_index].to_f) * rand
|
10
10
|
end
|
11
11
|
|
12
12
|
# Based on the code by antonakos on http://stackoverflow.com/questions/5825680/code-to-generate-gaussian-normally-distributed-random-numbers-in-ruby
|
@@ -20,7 +20,7 @@ module MetaheuristicAlgorithms
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def update_light_intensity
|
23
|
-
@light_intensity = @function_wrapper.objective_function_value(@location_coordinates)
|
23
|
+
@light_intensity = @function_wrapper.objective_function_value(@location_coordinates).to_f
|
24
24
|
end
|
25
25
|
|
26
26
|
def deep_clone
|
@@ -126,10 +126,10 @@ module MetaheuristicAlgorithms
|
|
126
126
|
end
|
127
127
|
|
128
128
|
def constrain_within_range(location_coordinate, variable_index)
|
129
|
-
if location_coordinate < @function_wrapper.
|
130
|
-
|
131
|
-
elsif location_coordinate > @function_wrapper.maximum_decision_variable_values[variable_index]
|
132
|
-
|
129
|
+
if location_coordinate < (minimum_decision_variable_values = @function_wrapper.minimum_decision_variable_values[variable_index].to_f)
|
130
|
+
minimum_decision_variable_values
|
131
|
+
elsif location_coordinate > (maximum_decision_variable_values = @function_wrapper.maximum_decision_variable_values[variable_index].to_f)
|
132
|
+
maximum_decision_variable_values
|
133
133
|
else
|
134
134
|
location_coordinate
|
135
135
|
end
|
@@ -10,9 +10,9 @@ module MetaheuristicAlgorithms
|
|
10
10
|
end
|
11
11
|
|
12
12
|
# Return value: Array
|
13
|
-
def
|
13
|
+
def minimum_decision_variable_values
|
14
14
|
raise "#{__method__} method must be implemented in the subclass"
|
15
|
-
end
|
15
|
+
end
|
16
16
|
|
17
17
|
# Input value: Array
|
18
18
|
def objective_function_value(decision_variable_values)
|
@@ -82,7 +82,7 @@ module MetaheuristicAlgorithms
|
|
82
82
|
get_decision_variable_value_by_randomization(variable_index)
|
83
83
|
end
|
84
84
|
@population << decision_variable_values
|
85
|
-
@population_fitness << @function_wrapper.objective_function_value(decision_variable_values)
|
85
|
+
@population_fitness << @function_wrapper.objective_function_value(decision_variable_values).to_f
|
86
86
|
end
|
87
87
|
|
88
88
|
end
|
@@ -126,8 +126,8 @@ module MetaheuristicAlgorithms
|
|
126
126
|
|
127
127
|
end
|
128
128
|
|
129
|
-
new_crossover_pair_1_fitness = @function_wrapper.objective_function_value(crossover_pair_1_decimal_values)
|
130
|
-
new_crossover_pair_2_fitness = @function_wrapper.objective_function_value(crossover_pair_2_decimal_values)
|
129
|
+
new_crossover_pair_1_fitness = @function_wrapper.objective_function_value(crossover_pair_1_decimal_values).to_f
|
130
|
+
new_crossover_pair_2_fitness = @function_wrapper.objective_function_value(crossover_pair_2_decimal_values).to_f
|
131
131
|
|
132
132
|
if new_crossover_pair_1_fitness > @population_fitness[crossover_pair_1_index] &&
|
133
133
|
new_crossover_pair_2_fitness > @population_fitness[crossover_pair_2_index]
|
@@ -176,7 +176,7 @@ module MetaheuristicAlgorithms
|
|
176
176
|
|
177
177
|
end
|
178
178
|
|
179
|
-
new_individual_fitness = @function_wrapper.objective_function_value(decimal_values)
|
179
|
+
new_individual_fitness = @function_wrapper.objective_function_value(decimal_values).to_f
|
180
180
|
|
181
181
|
if new_individual_fitness > @population_fitness[individual_index]
|
182
182
|
|
@@ -193,7 +193,7 @@ module MetaheuristicAlgorithms
|
|
193
193
|
end
|
194
194
|
|
195
195
|
def in_the_range?(decimal_value, variable_index)
|
196
|
-
decimal_value >= @function_wrapper.
|
196
|
+
decimal_value >= @function_wrapper.minimum_decision_variable_values[variable_index].to_f && decimal_value <= @function_wrapper.maximum_decision_variable_values[variable_index].to_f
|
197
197
|
end
|
198
198
|
|
199
199
|
def deep_clone_population
|
@@ -50,7 +50,7 @@ module MetaheuristicAlgorithms
|
|
50
50
|
|
51
51
|
# if bigdecimal_rand < pitch_adjusting_rate
|
52
52
|
if rand < pitch_adjusting_rate
|
53
|
-
pitch_adjusting = (@function_wrapper.maximum_decision_variable_values[variable_index] - @function_wrapper.
|
53
|
+
pitch_adjusting = (@function_wrapper.maximum_decision_variable_values[variable_index].to_f - @function_wrapper.minimum_decision_variable_values[variable_index].to_f) / pitch_adjusting_range
|
54
54
|
# decision_variable_value = decision_variable_value + pitch_adjusting * (bigdecimal_rand - BigDecimal('0.5'))
|
55
55
|
decision_variable_value = decision_variable_value + pitch_adjusting * (rand -0.5)
|
56
56
|
end
|
@@ -60,7 +60,7 @@ module MetaheuristicAlgorithms
|
|
60
60
|
|
61
61
|
end
|
62
62
|
|
63
|
-
best_function_value = @function_wrapper.objective_function_value(decision_variable_values)
|
63
|
+
best_function_value = @function_wrapper.objective_function_value(decision_variable_values).to_f
|
64
64
|
|
65
65
|
# TODO: Evaluate this logic. It appears that best_function_value_harmony_memory only needs to store the max best_function_value and the corresponding harmony_memory_random_index of harmony_memory.
|
66
66
|
# The simpler implementation for MatLab doesn't seem to be a good implementation in Ruby here.
|
@@ -96,7 +96,7 @@ module MetaheuristicAlgorithms
|
|
96
96
|
end
|
97
97
|
|
98
98
|
@harmony_memory << decision_variable_values
|
99
|
-
@best_function_value_harmony_memory << @function_wrapper.objective_function_value(decision_variable_values)
|
99
|
+
@best_function_value_harmony_memory << @function_wrapper.objective_function_value(decision_variable_values).to_f
|
100
100
|
|
101
101
|
end
|
102
102
|
|
@@ -33,7 +33,7 @@ module MetaheuristicAlgorithms
|
|
33
33
|
number_of_iterations.times do |iteration|
|
34
34
|
|
35
35
|
function_values = @particle_locations.map do |particle_location|
|
36
|
-
@function_wrapper.objective_function_value(particle_location)
|
36
|
+
@function_wrapper.objective_function_value(particle_location).to_f
|
37
37
|
end
|
38
38
|
|
39
39
|
best_function_value = function_values.send(@objective_method_name)
|
@@ -69,10 +69,10 @@ module MetaheuristicAlgorithms
|
|
69
69
|
(0...@number_of_variables).map do |variable_index|
|
70
70
|
|
71
71
|
# The value out-of-range in order to enter while loop
|
72
|
-
# new_particle_location_coordinate = @function_wrapper.
|
73
|
-
new_particle_location_coordinate = @function_wrapper.
|
72
|
+
# new_particle_location_coordinate = @function_wrapper.minimum_decision_variable_values[variable_index] - BigDecimal('1')
|
73
|
+
new_particle_location_coordinate = @function_wrapper.minimum_decision_variable_values[variable_index].to_f - 1
|
74
74
|
|
75
|
-
while new_particle_location_coordinate < @function_wrapper.
|
75
|
+
while new_particle_location_coordinate < @function_wrapper.minimum_decision_variable_values[variable_index].to_f || new_particle_location_coordinate > @function_wrapper.maximum_decision_variable_values[variable_index].to_f
|
76
76
|
# new_particle_location_coordinate = (BigDecimal('1') - social_coefficient) * particle_location[variable_index] + social_coefficient * global_best_position[variable_index] + random_variable_coefficient * (bigdecimal_rand - BigDecimal('0.5'))
|
77
77
|
new_particle_location_coordinate = (1 - social_coefficient) * particle_location[variable_index] + social_coefficient * global_best_position[variable_index] + random_variable_coefficient * (rand - 0.5)
|
78
78
|
end
|
@@ -51,9 +51,9 @@ module MetaheuristicAlgorithms
|
|
51
51
|
number_of_acceptances = 0
|
52
52
|
total_evaluations = 0
|
53
53
|
|
54
|
-
initial_estimates = @function_wrapper.initial_decision_variable_value_estimates
|
54
|
+
initial_estimates = @function_wrapper.initial_decision_variable_value_estimates.map(&:to_f)
|
55
55
|
|
56
|
-
best_evaluation = @function_wrapper.objective_function_value(initial_estimates)
|
56
|
+
best_evaluation = @function_wrapper.objective_function_value(initial_estimates).to_f
|
57
57
|
|
58
58
|
best_solution = initial_estimates
|
59
59
|
|
@@ -72,7 +72,7 @@ module MetaheuristicAlgorithms
|
|
72
72
|
end
|
73
73
|
|
74
74
|
new_estimates = estimate_solution(initial_estimates, standard_diviation_for_estimation)
|
75
|
-
new_evaluation = @function_wrapper.objective_function_value(new_estimates)
|
75
|
+
new_evaluation = @function_wrapper.objective_function_value(new_estimates).to_f
|
76
76
|
|
77
77
|
evaluation_delta = ratio_of_energy_delta_over_evaluation_delta * (new_evaluation - best_evaluation)
|
78
78
|
|
@@ -107,10 +107,10 @@ module MetaheuristicAlgorithms
|
|
107
107
|
(0...@number_of_variables).map do |variable_index|
|
108
108
|
|
109
109
|
# The value out-of-range in order to enter while loop
|
110
|
-
# new_estimate = @function_wrapper.
|
111
|
-
new_estimate = @function_wrapper.
|
110
|
+
# new_estimate = @function_wrapper.minimum_decision_variable_values[variable_index] - BigDecimal('1')
|
111
|
+
new_estimate = @function_wrapper.minimum_decision_variable_values[variable_index].to_f - 1
|
112
112
|
|
113
|
-
while new_estimate < @function_wrapper.
|
113
|
+
while new_estimate < @function_wrapper.minimum_decision_variable_values[variable_index].to_f || new_estimate > @function_wrapper.maximum_decision_variable_values[variable_index].to_f
|
114
114
|
|
115
115
|
# MatLab example code uses newGuess = initialGuess + rand(1,2) * randn;
|
116
116
|
# But in our case, the value range is different.
|
@@ -16,7 +16,7 @@ module MetaheuristicAlgorithms
|
|
16
16
|
number_of_virtual_bees = number_of_virtual_bees.to_i unless number_of_virtual_bees.kind_of?(Integer)
|
17
17
|
number_of_foraging_explorations = number_of_foraging_explorations.to_i unless number_of_foraging_explorations.kind_of?(Integer)
|
18
18
|
|
19
|
-
solution_estimates = @function_wrapper.initial_decision_variable_value_estimates
|
19
|
+
solution_estimates = @function_wrapper.initial_decision_variable_value_estimates.map(&:to_f)
|
20
20
|
|
21
21
|
|
22
22
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metaheuristic_algorithms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tadatoshi Takahashi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -64,6 +64,7 @@ files:
|
|
64
64
|
- ".ruby-gemset"
|
65
65
|
- ".ruby-version"
|
66
66
|
- ".travis.yml"
|
67
|
+
- CHANGELOG.md
|
67
68
|
- CODE_OF_CONDUCT.md
|
68
69
|
- Gemfile
|
69
70
|
- LICENSE.txt
|