prop_logic 0.2.2 → 0.2.3
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 +7 -0
- data/lib/prop_logic/hash_cache.rb +8 -0
- data/lib/prop_logic/term.rb +19 -7
- data/lib/prop_logic/variable.rb +11 -0
- data/lib/prop_logic/version.rb +1 -1
- metadata +16 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1dfd97019313a0cf9368c49fc535084abe18637b
|
4
|
+
data.tar.gz: 2679c35cd7dbf22235bd92b670077c3f57a64e98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78b0d8ad6a92ec447534f42eb6a6ceee63778f74a7d4466079f9f35f0efe2824e26421b8b0000a98473f9209147956381ff4e8a1de753d964c2d895f14017c3a
|
7
|
+
data.tar.gz: d6c09dce76e172d687c5420b5aa4847ec789282fc40b5daf9f775cfbbf3410bca8723ea0ca549bc55df6aff0f0da3adbb3c1d00f15031a3cad889d4414bd5cae
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -54,6 +54,11 @@ diff = (~a | ~b).equiv?(~(a & b)) # true
|
|
54
54
|
(a & b).assign_true(a).assign_false(b).reduce # PropLogic::False
|
55
55
|
```
|
56
56
|
|
57
|
+
### Using normal Hash for caching
|
58
|
+
By default, `prop_logic` uses weak reference for caching terms, allowing garbage collection.
|
59
|
+
|
60
|
+
If this is inappropriate (overhead or unstability), use `require 'prop_logic/hash_cache'` to use `Hash` for caching.
|
61
|
+
|
57
62
|
## Restriction
|
58
63
|
SAT solver bundled with this gem is brute-force solver (intended only for testing), so it is inappropriate to use for
|
59
64
|
real-scale problems.
|
@@ -61,6 +66,8 @@ real-scale problems.
|
|
61
66
|
In CRuby and Rubinius, bindings to MiniSat ([jkr2255/prop_logic-minisat](https://github.com/jkr2255/prop_logic-minisat)) is available.
|
62
67
|
It is a plugin for this gem, so no code (except require and Gemfile) needs to be changed to use `prop_logic-minisat`.
|
63
68
|
|
69
|
+
In JRuby binding to Sat4j ([jkr2255/prop_logic-sat4j](https://github.com/jkr2255/prop_logic-sat4j)) is available.
|
70
|
+
|
64
71
|
## References
|
65
72
|
`PropLogic::Term` is immutable, meaning that all calculations return new Terms.
|
66
73
|
### `PropLogic::Term` instance methods
|
data/lib/prop_logic/term.rb
CHANGED
@@ -102,13 +102,14 @@ module PropLogic
|
|
102
102
|
|
103
103
|
private_class_method :validate_terms
|
104
104
|
|
105
|
-
def self.
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
105
|
+
def self.generate_cache
|
106
|
+
Ref::WeakValueMap.new
|
107
|
+
end
|
108
|
+
|
109
|
+
private_class_method :generate_cache
|
110
|
+
|
111
|
+
def self.cached(klass, *terms)
|
112
|
+
@table ||= generate_cache
|
112
113
|
key = klass.name + terms.map(&:object_id).join(',')
|
113
114
|
return @table[key] if @table[key]
|
114
115
|
ret = klass.__send__ :new, *terms
|
@@ -118,6 +119,17 @@ module PropLogic
|
|
118
119
|
ret.freeze
|
119
120
|
end
|
120
121
|
|
122
|
+
private_class_method :cached
|
123
|
+
|
124
|
+
def self.get(klass, *terms)
|
125
|
+
terms = validate_terms(*terms)
|
126
|
+
if klass == AndTerm || klass == OrTerm
|
127
|
+
terms = terms.map { |t| t.is_a?(klass) ? t.terms : t }.flatten
|
128
|
+
return terms[0] if terms.length == 1
|
129
|
+
end
|
130
|
+
cached klass, *terms
|
131
|
+
end
|
132
|
+
|
121
133
|
# check if this term is a cnf term.
|
122
134
|
# @return [Boolean] false unless overridden.
|
123
135
|
def cnf?
|
data/lib/prop_logic/variable.rb
CHANGED
data/lib/prop_logic/version.rb
CHANGED
metadata
CHANGED
@@ -1,66 +1,66 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prop_logic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jkr2255
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: ref
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
16
15
|
requirements:
|
17
16
|
- - "~>"
|
18
17
|
- !ruby/object:Gem::Version
|
19
18
|
version: '2.0'
|
20
|
-
|
19
|
+
name: ref
|
21
20
|
prerelease: false
|
21
|
+
type: :runtime
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: bundler
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
30
29
|
requirements:
|
31
30
|
- - "~>"
|
32
31
|
- !ruby/object:Gem::Version
|
33
32
|
version: '1.7'
|
34
|
-
|
33
|
+
name: bundler
|
35
34
|
prerelease: false
|
35
|
+
type: :development
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.7'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
42
|
requirement: !ruby/object:Gem::Requirement
|
44
43
|
requirements:
|
45
44
|
- - "~>"
|
46
45
|
- !ruby/object:Gem::Version
|
47
46
|
version: '10.0'
|
48
|
-
|
47
|
+
name: rake
|
49
48
|
prerelease: false
|
49
|
+
type: :development
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '10.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name: rspec
|
57
56
|
requirement: !ruby/object:Gem::Requirement
|
58
57
|
requirements:
|
59
58
|
- - "~>"
|
60
59
|
- !ruby/object:Gem::Version
|
61
60
|
version: '3.0'
|
62
|
-
|
61
|
+
name: rspec
|
63
62
|
prerelease: false
|
63
|
+
type: :development
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
@@ -89,6 +89,7 @@ files:
|
|
89
89
|
- lib/prop_logic/constants.rb
|
90
90
|
- lib/prop_logic/default_incremental_solver.rb
|
91
91
|
- lib/prop_logic/functions.rb
|
92
|
+
- lib/prop_logic/hash_cache.rb
|
92
93
|
- lib/prop_logic/not_term.rb
|
93
94
|
- lib/prop_logic/or_term.rb
|
94
95
|
- lib/prop_logic/sat_solver.rb
|
@@ -101,7 +102,7 @@ homepage: https://github.com/jkr2255/prop_logic
|
|
101
102
|
licenses:
|
102
103
|
- MIT
|
103
104
|
metadata: {}
|
104
|
-
post_install_message:
|
105
|
+
post_install_message:
|
105
106
|
rdoc_options: []
|
106
107
|
require_paths:
|
107
108
|
- lib
|
@@ -116,9 +117,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
117
|
- !ruby/object:Gem::Version
|
117
118
|
version: '0'
|
118
119
|
requirements: []
|
119
|
-
rubyforge_project:
|
120
|
-
rubygems_version: 2.4.
|
121
|
-
signing_key:
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.4.8
|
122
|
+
signing_key:
|
122
123
|
specification_version: 4
|
123
124
|
summary: Propositional logic for Ruby
|
124
125
|
test_files: []
|