metaheuristic_algorithms 0.1.0 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1d0f703767effd3bf49ad6f0fdb937e81f4cca0b
4
- data.tar.gz: 2b006e39389d9ab0cf870de9178150f956bd948e
3
+ metadata.gz: bc5353994d45d2635304aa9b75be715238dc7b81
4
+ data.tar.gz: 5e560ac1a8f7d7b7df2f2204fec271b9abd6020d
5
5
  SHA512:
6
- metadata.gz: 3128ccca278336b88d59a1dff1e91f6e087b038693ffc8a7da83a24c64e5afe42aa5a98a809586ccdb0460a35ddebea172254df017757eb7756cbf0ee6dda579
7
- data.tar.gz: 3cc1be0fa3cb7093f7615fc4abfd0b182c0f906f9979d4025bf1370fbf9b290d70973fc6d13d70e1be4505d671782e2526e583d95dba5d8db488e20718727afe
6
+ metadata.gz: 546683c005f556c3e094c54dba1a5f647715f66e7a09216490caf3d216b59409d623831f2339b482fd6132042b03812d4f6159f017ad51ba1c8618fa37d1f03a
7
+ data.tar.gz: 8f4f50276ea362c49369025a6e68c0cd0f2259d2d50360d34f25e7a0b33ea5a6f7a30ab0ba8f2bcba04cecaabc00cd817ba02f7dab11f8ca847fa12490171f1e
data/README.md CHANGED
@@ -20,7 +20,62 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- See examples in RSpec codes under spec directory.
23
+ Step 1. Create a Function Wrapper for your objective function by extending MetaheuristicAlgorithms::FunctionWrappers::AbstractWrapper
24
+
25
+ Example: Rosenbrook's Function: f(x,y) = (1 - x)^2 + 100(y - x^2)^2
26
+
27
+ ```ruby
28
+ require 'metaheuristic_algorithms'
29
+
30
+ class RosenbrookFunctionWrapper < MetaheuristicAlgorithms::FunctionWrappers::AbstractWrapper
31
+
32
+ def maximum_decision_variable_values
33
+ [BigDecimal('5'), BigDecimal('5')]
34
+ end
35
+
36
+ def miminum_decision_variable_values
37
+ [BigDecimal('-5'), BigDecimal('-5')]
38
+ end
39
+
40
+ def objective_function_value(decision_variable_values)
41
+ (BigDecimal('1') - decision_variable_values[0]).power(2) + BigDecimal('100') * (decision_variable_values[1] - decision_variable_values[0].power(2)).power(2)
42
+ end
43
+
44
+ # For the algorithm that requires initial estimate that is depending on the particular objective function:
45
+ def initial_decision_variable_value_estimates
46
+ [BigDecimal('2'), BigDecimal('2')]
47
+ end
48
+
49
+ end
50
+ ```
51
+
52
+ Step 2. Instantiate the created Function Wrapper and pass it as the first argument of the Algorithm instantiation.
53
+ Also specify the number of variables and objective (:maximization or :minimization)
54
+ Then call the search method passing the algorithm specific parameters.
55
+
56
+ Example: Harmony Search for the glocal minimum value for Rosenbrook's Function
57
+
58
+ ```ruby
59
+ require 'metaheuristic_algorithms'
60
+
61
+ rosenbrook_function_wrapper = MetaheuristicAlgorithms::FunctionWrappers::RosenbrookFunctionWrapper.new
62
+
63
+ harmony_search = MetaheuristicAlgorithms::HarmonySearch.new(rosenbrook_function_wrapper, number_of_variables: 2, objective: :minimization)
64
+
65
+ maximum_attempt = 25000
66
+ pitch_adjusting_range = BigDecimal('100')
67
+ harmony_search_size = 20
68
+ harmony_memory_acceping_rate = BigDecimal('0.95')
69
+ pitch_adjusting_rate = BigDecimal('0.7')
70
+
71
+ result = harmony_search.search(maximum_attempt: maximum_attempt, pitch_adjusting_range: pitch_adjusting_range,
72
+ harmony_search_size: harmony_search_size, harmony_memory_acceping_rate: harmony_memory_acceping_rate,
73
+ pitch_adjusting_rate: pitch_adjusting_rate)
74
+
75
+ puts result[:best_decision_variable_values][0] # x value: Example: BigDecimal('1.0112')
76
+ puts result[:best_decision_variable_values][1] # y value: Example: BigDecimal('0.9988')
77
+ puts result[:best_objective_function_value] # f(x,y) value: Example: BigDecimal('0.0563')
78
+ ```
24
79
 
25
80
  ## Development
26
81
 
@@ -1,3 +1,3 @@
1
1
  module MetaheuristicAlgorithms
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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.1.0
4
+ version: 0.1.1
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-08-08 00:00:00.000000000 Z
11
+ date: 2015-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: distribution