victory 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1ddbe3510c3b4bddd014951aa6aebaac3a702c39b752751270e212583b1abf9
4
- data.tar.gz: b0e3f83beeb1bf0373fbdc1fbfdf3ba76ab1bda526a2cd1537a890c0145765dc
3
+ metadata.gz: 030a0da8ae15c1c576f0420a877f2ad6dbe5bd666b27204a1d7832b77253336e
4
+ data.tar.gz: c056640572922b46768204052095393268fd1e55a00e6119388d41f616637a42
5
5
  SHA512:
6
- metadata.gz: 8aa93ef475b81c961405ebff72d5dca34ebb464425fd5cf842b5b29b2fbef7017032bdc8c92f696b409d9733e690250ec071c7099d1c30df3212b5700e5bc03d
7
- data.tar.gz: 425a03ea2c788e42fdfab0ade46c285635b0072c1cb6d73833e40684e1833f7c2979c46257ffb8729fcd56a031213890022f8a249d03391e13107b90e2817b0f
6
+ metadata.gz: 5157527a3f066468eeab262aa7e22fea7818ac9668c253b2454ecc80ae2dcd1a35fa33f876a3b653bca3f6136440af062ad17eab5adf464504a58298ce5d8292
7
+ data.tar.gz: 6891b77b838db2d460a56cef11472ed69eb0da900b3b423c2bd5f7f58ebcef401c02bef7867314546382937284062be1c7671b161c2ad58ef9b7cd0ecddbf52d
data/.gitignore CHANGED
@@ -101,4 +101,4 @@ fabric.properties
101
101
 
102
102
  Gemfile.lock
103
103
  **/*.gem
104
- *.dylib
104
+ *.dylib
data/USAGE.md CHANGED
@@ -547,6 +547,49 @@ Thread-safe variables:
547
547
  A counting-based locking mechanism that uses permits.
548
548
  * [AtomicMarkableReference](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/AtomicMarkableReference.html)
549
549
 
550
+ # Algorithms
551
+
552
+ * [Greedy](#greedy)
553
+ * [Genetic Algorithm](#genetic)
554
+
555
+ <a name="greedy" />
556
+
557
+ ## Greedy
558
+
559
+ ```ruby
560
+ class TestSolution
561
+ include Algorithms::Greedy::Solution
562
+
563
+ def score; @data; end
564
+
565
+ def next_solutions
566
+ [
567
+ TestSolution.new(@data),
568
+ TestSolution.new(@data + 1),
569
+ TestSolution.new(@data - 1),
570
+ ]
571
+ end
572
+ end
573
+
574
+ initial_solution = TestSolution.new(0)
575
+ g = Algorithms::Greedy.init(initial_solution)
576
+ g.run(10)
577
+ g.best_solution.data
578
+ # => 10
579
+ ```
580
+
581
+ <a name="genetic" />
582
+
583
+ ## Genetic Algorithm
584
+
585
+ ```ruby
586
+ class TestArraySolution < Algorithms::GeneticAlgorithm::ArraySolution; def score; @data.sum; end end
587
+ solution = TestArraySolution.new(Array.new(50, 0), possible_elements: (0..50).to_a)
588
+ genetic_alg = Algorithms::GeneticAlgorithm.init([solution])
589
+ genetic_alg.run(100)
590
+ genetic_alg.best_solution.score
591
+ ```
592
+
550
593
  # Other useful links
551
594
 
552
595
  * https://github.com/kumar91gopi/Algorithms-and-Data-Structures-in-Ruby/
@@ -1,6 +1,11 @@
1
1
  module Algorithms::Greedy
2
2
  module Solution
3
3
  abstract_method :score, :next_solutions
4
+ attr_reader :data
5
+
6
+ def initialize(data)
7
+ @data = data
8
+ end
4
9
  end
5
10
 
6
11
  def self.init(solution)
@@ -1,3 +1,3 @@
1
1
  module Victory
2
- VERSION = '0.4.0'
2
+ VERSION = '0.4.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: victory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arnold Szederjesi