grimoire 0.2.4 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +17 -0
- data/lib/grimoire/solver.rb +30 -1
- data/lib/grimoire/version.rb +1 -1
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 244dbe7852a4c8a6571a1acca74fd4691f2b3b95
|
4
|
+
data.tar.gz: 8885acc391087a2f00aabbd2afc5cff96bcb7da7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53f4a3d269886d731bbe4b624d2fbb5d8111e05dde78bbcc50bfa4d43955ca6f2b3ca6a04f41aef71ba3a0e6e45620c2b29e3465a7c3e72912c7cfd39978e661
|
7
|
+
data.tar.gz: 760312eebe3756cb1f7353dd78020dccbe87fdea4f93ee60cccbcd87e9a86f38fbc11f653faa8a862cf139a771935dd6dd76e22d2c8ca431e127007cf14a2de8
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# v0.2.6
|
2
|
+
* Add support for external constraint set within solver
|
3
|
+
* Allow Solver#requirements to be coerced from Array
|
4
|
+
|
1
5
|
# v0.2.4
|
2
6
|
* No longer force error when no requested units are within system
|
3
7
|
* Discard no solution errors when pruning the world instead of failing
|
data/README.md
CHANGED
@@ -50,6 +50,23 @@ solver = Grimoire::Solver.new(
|
|
50
50
|
)
|
51
51
|
```
|
52
52
|
|
53
|
+
* Create a solver with restrictions (optional)
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
solver = Grimoire::Solver.new(
|
57
|
+
:system => system,
|
58
|
+
:score_keeper => score_keeper,
|
59
|
+
:requirements => [
|
60
|
+
['unit1', '> 2.0.0'],
|
61
|
+
['unit2', '> 1', '< 3']
|
62
|
+
],
|
63
|
+
:restrictions => [
|
64
|
+
['unit1', '< 3'],
|
65
|
+
['unit2', '> 1.2.0']
|
66
|
+
]
|
67
|
+
)
|
68
|
+
```
|
69
|
+
|
53
70
|
* Generate solutions
|
54
71
|
|
55
72
|
```ruby
|
data/lib/grimoire/solver.rb
CHANGED
@@ -10,7 +10,12 @@ module Grimoire
|
|
10
10
|
|
11
11
|
include Bogo::Memoization
|
12
12
|
|
13
|
-
attribute :
|
13
|
+
attribute :restrictions, RequirementList, :coerce => lambda{|x|
|
14
|
+
RequirementList.new(:name => 'restrictions', :requirements => x) if x.is_a?(Array)
|
15
|
+
}
|
16
|
+
attribute :requirements, RequirementList, :required => true, :coerce => lambda{|x|
|
17
|
+
RequirementList.new(:name => 'requirements', :requirements => x) if x.is_a?(Array)
|
18
|
+
}
|
14
19
|
attribute :system, System, :required => true
|
15
20
|
attribute :score_keeper, UnitScoreKeeper
|
16
21
|
attribute :result_limit, Integer, :required => true, :default => 1
|
@@ -25,11 +30,35 @@ module Grimoire
|
|
25
30
|
@world = System.new
|
26
31
|
@new_world = nil
|
27
32
|
@log = []
|
33
|
+
if(restrictions)
|
34
|
+
apply_restrictions!
|
35
|
+
end
|
28
36
|
build_world(requirements.requirements, world, system)
|
29
37
|
@log.clear
|
30
38
|
world.scrub!
|
31
39
|
end
|
32
40
|
|
41
|
+
# Restrictions are simply an implicit expansion of the requirements
|
42
|
+
# that. When restrictions are provided, it serves to further
|
43
|
+
# restrict the valid units available for solutions
|
44
|
+
#
|
45
|
+
# @return [self]
|
46
|
+
def apply_restrictions!
|
47
|
+
restrictions.requirements.each do |rst|
|
48
|
+
req = requirements.requirements.detect do |r|
|
49
|
+
r.name == rst.name
|
50
|
+
end
|
51
|
+
if(req)
|
52
|
+
new_req = req.merge(rst)
|
53
|
+
requirements.requirements.delete(req)
|
54
|
+
requirements.requirements.push(new_req)
|
55
|
+
else
|
56
|
+
requirements.requirements.push(rst)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
self
|
60
|
+
end
|
61
|
+
|
33
62
|
# After the world has been generated extraneous units will
|
34
63
|
# be included as a result of dependency constraints that may
|
35
64
|
# be too loose and are not actually required by any resolution
|
data/lib/grimoire/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grimoire
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Roberts
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bogo
|
@@ -112,4 +112,3 @@ signing_key:
|
|
112
112
|
specification_version: 4
|
113
113
|
summary: Constraint solver
|
114
114
|
test_files: []
|
115
|
-
has_rdoc:
|