grimoire 0.2.4 → 0.2.6

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: 80076e8f01f36c012ab6dfb0fd3e28002828f06b
4
- data.tar.gz: 8a44a15ea9dc630a83937e8a765af8801784163d
3
+ metadata.gz: 244dbe7852a4c8a6571a1acca74fd4691f2b3b95
4
+ data.tar.gz: 8885acc391087a2f00aabbd2afc5cff96bcb7da7
5
5
  SHA512:
6
- metadata.gz: a8d92eb9fcf4c38ae1fd67d5c30472cdcbf7e9775afc7b51129530cf16f9e37edd42269007d82e3ef32c397d9b2be26659f813f751a7f47dd4c436a0e5bab887
7
- data.tar.gz: c980efe5d8a72b2ea50fe3b19169662939de2a711076aa4c2de3ce032e0be58dac1ffcc51b881bc7076b85d11e4b45adceb05268fdb8c15ca23b9c71c9a600ed
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
@@ -10,7 +10,12 @@ module Grimoire
10
10
 
11
11
  include Bogo::Memoization
12
12
 
13
- attribute :requirements, RequirementList, :required => true
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
@@ -1,4 +1,4 @@
1
1
  module Grimoire
2
2
  # Current library version
3
- VERSION = Gem::Version.new('0.2.4')
3
+ VERSION = Gem::Version.new('0.2.6')
4
4
  end
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
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-04-27 00:00:00.000000000 Z
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: