victory 0.4.0 → 0.4.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 +4 -4
- data/.gitignore +1 -1
- data/USAGE.md +43 -0
- data/lib/algorithms/greedy.rb +5 -0
- data/lib/victory/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 030a0da8ae15c1c576f0420a877f2ad6dbe5bd666b27204a1d7832b77253336e
|
4
|
+
data.tar.gz: c056640572922b46768204052095393268fd1e55a00e6119388d41f616637a42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5157527a3f066468eeab262aa7e22fea7818ac9668c253b2454ecc80ae2dcd1a35fa33f876a3b653bca3f6136440af062ad17eab5adf464504a58298ce5d8292
|
7
|
+
data.tar.gz: 6891b77b838db2d460a56cef11472ed69eb0da900b3b423c2bd5f7f58ebcef401c02bef7867314546382937284062be1c7671b161c2ad58ef9b7cd0ecddbf52d
|
data/.gitignore
CHANGED
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/
|
data/lib/algorithms/greedy.rb
CHANGED
data/lib/victory/version.rb
CHANGED