ravensat 1.0.0 → 1.0.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/README.md +21 -11
- data/lib/ravensat/ast/node.rb +1 -36
- data/lib/ravensat/claw.rb +1 -0
- data/lib/ravensat/dimacs/dimacs_decoder.rb +4 -13
- data/lib/ravensat/dimacs/dimacs_encoder.rb +1 -1
- data/lib/ravensat/version.rb +1 -1
- metadata +2 -3
- data/Gemfile.lock +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fe48515db2ce222168fac2854fcab5b2057c84336195e129e6c532ab519082e
|
4
|
+
data.tar.gz: bc265a79298a55684d1bb1c83a196e0530b4670515c22d4388f65bdf7b872c67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d715763470fe222f0ba71c998e27a43f8e40c04ae50cadceae48b324a962eaa75ceef92f02154cc74f9e04edbae47de1f36eb6e3c655019c0f3fedd72aae448
|
7
|
+
data.tar.gz: d2178778880fa55127ef5bd0b2b5d76fa5431452d20f06b0672374a99f9a718a881c01c1c055b11579c86e063decc607416c0f3450213f460dac756e28cc201c
|
data/README.md
CHANGED
@@ -1,24 +1,26 @@
|
|
1
|
-
# Ravensat
|
2
|
-
|
3
1
|
[](https://github.com/matsuda0528/ravensat/actions/workflows/main.yml)
|
4
2
|
[](https://badge.fury.io/rb/ravensat)
|
5
3
|
[](https://opensource.org/licenses/MIT)
|
6
4
|
|
7
|
-
[](https://matsuda0528.github.io/ravensat/)
|
5
|
+
<!-- [](https://matsuda0528.github.io/ravensat/) -->
|
8
6
|
|
9
|
-
Ravensat
|
7
|
+
# Ravensat
|
10
8
|
|
9
|
+
Ravensat provides an intuitive interface for working with SAT solver.
|
10
|
+
SAT solver is a useful tool for solving various problems, but it is not user-friendly.
|
11
|
+
Ravensat wraps the SAT solver and makes it easier to use.
|
11
12
|
In order to use Ravensat, you need to install SAT solver.
|
12
13
|
If you do not install SAT solver, it will use the one bundled in the gem.
|
13
14
|
|
14
15
|
About [SAT](https://en.wikipedia.org/wiki/Boolean_satisfiability_problem), [SAT solver](https://en.wikipedia.org/wiki/SAT_solver)
|
15
16
|
|
16
17
|
## Description
|
17
|
-
To solve SAT, we usually use SAT solver.
|
18
|
+
To solve SAT(Boolean Satisfiability Problem), we usually use SAT solver.
|
18
19
|
Now, let's solve the following SAT with SAT solver.
|
19
20
|
|
20
21
|
$$(p_{1} \lor \lnot p_{5} \lor p_{4}) \land (\lnot p_{1} \lor p_{5} \lor p_{3} \lor p_{4}) \land (\lnot p_{3} \lor \lnot p_{4})$$
|
21
22
|
|
23
|
+
To solve the above SAT, give it to the SAT solver.
|
22
24
|
Most SAT solvers are input in [DIMACS Format](https://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/index-seo.php/SATLINK____DIMACS).
|
23
25
|
Converting the example SAT to DIMACS Format yields the following.
|
24
26
|
|
@@ -34,22 +36,31 @@ However, when solving a large SAT, the following problems occur.
|
|
34
36
|
- Need to create a file with thousands of lines.
|
35
37
|
- Confusion arises because of the inability to name variables meaningfully.
|
36
38
|
|
37
|
-
|
39
|
+
Therefore, we need an interface that can flexibly determine the names of variables and imperatively write loginal expressions.
|
40
|
+
To achieve these requirements, we are developing Ravensat.
|
38
41
|
Using Ravensat, propositional variables can be defined as local variables in Ruby.
|
39
42
|
|
40
43
|
```ruby
|
41
|
-
|
44
|
+
John_is_a_male = Ravensat::VarNode.new
|
42
45
|
```
|
43
46
|
|
44
|
-
In addition, you can write logical expressions intuitively.
|
47
|
+
In addition, you can write logical expressions intuitively and imperatively.
|
45
48
|
|
46
49
|
```ruby
|
47
50
|
x = Ravensat::VarNode.new
|
48
51
|
y = Ravensat::VarNode.new
|
49
52
|
|
50
|
-
(x | y) & (~x | y)
|
53
|
+
(x | y) & (~x | y)
|
51
54
|
```
|
52
55
|
|
56
|
+
```ruby
|
57
|
+
x = Ravensat::VarNode.new
|
58
|
+
y = Ravensat::VarNode.new
|
59
|
+
z = Ravensat::VarNode.new
|
60
|
+
|
61
|
+
# (~x | ~y) & (~x | ~z) & (~y | ~z)
|
62
|
+
Ravensat::Claw.pairwise_amo [x,y,z]
|
63
|
+
```
|
53
64
|
|
54
65
|
## Installation
|
55
66
|
|
@@ -102,7 +113,7 @@ At least, we have confirmed that it works properly with [MiniSat](https://github
|
|
102
113
|
If you do not use an external SAT solver, create a SAT solver object without any constructor arguments.
|
103
114
|
In that case, **Arcteryx**(the very simple SAT solver built into Ravensat) will launch.
|
104
115
|
|
105
|
-
### Extension Usage
|
116
|
+
### Extension Usage(prototype)
|
106
117
|
In Ravensat::Extension, C-like variable definitions are available.
|
107
118
|
|
108
119
|
*Note: In Ravensat::Extension, all undefined variables and methods are caught by method_missing method.*
|
@@ -124,7 +135,6 @@ module Ravensat
|
|
124
135
|
end
|
125
136
|
```
|
126
137
|
|
127
|
-
### Extension Usage(CSP; Constraint Satisfaction Problem)
|
128
138
|
It is possible to define integer variables and to describe some integer constraints.
|
129
139
|
|
130
140
|
```ruby
|
data/lib/ravensat/ast/node.rb
CHANGED
@@ -7,40 +7,13 @@ module Ravensat
|
|
7
7
|
@children = []
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
# yield(self)
|
12
|
-
# @children.each do |child|
|
13
|
-
# child.each {|c| yield(c)}
|
14
|
-
# end
|
15
|
-
# end
|
16
|
-
|
17
|
-
# def each
|
18
|
-
# case self
|
19
|
-
# when AndNode, OrNode
|
20
|
-
# @children.first.each{|c| yield(c)}
|
21
|
-
# yield(self)
|
22
|
-
# @children.last.each{|c| yield(c)}
|
23
|
-
# when NotNode
|
24
|
-
# yield(self)
|
25
|
-
# @children.first.each{|c| yield(c)}
|
26
|
-
# when VarNode
|
27
|
-
# yield(self)
|
28
|
-
# end
|
29
|
-
# end
|
30
|
-
|
31
|
-
def each_DP
|
10
|
+
def each_by_descriptive
|
32
11
|
node_stack = [[self, self.children.clone]] #[[parent, children], ...]
|
33
12
|
|
34
13
|
until node_stack.empty?
|
35
14
|
current_parent, current_children = node_stack.pop
|
36
15
|
current_node = current_children.shift
|
37
16
|
|
38
|
-
# puts 'loop'
|
39
|
-
# puts "node_stack.size:#{node_stack.size}"
|
40
|
-
# puts "current_parent:#{current_parent.class}"
|
41
|
-
# puts "current_children.size:#{current_children.size}"
|
42
|
-
# puts "current_node:#{current_node.class}"
|
43
|
-
|
44
17
|
case current_node
|
45
18
|
when AndNode
|
46
19
|
node_stack.push [current_parent, current_children.clone]
|
@@ -68,7 +41,6 @@ module Ravensat
|
|
68
41
|
node_stack.push [current_parent, current_children.clone]
|
69
42
|
end
|
70
43
|
end
|
71
|
-
|
72
44
|
end
|
73
45
|
end
|
74
46
|
|
@@ -88,13 +60,6 @@ module Ravensat
|
|
88
60
|
self if block_given?
|
89
61
|
end
|
90
62
|
|
91
|
-
def each_naive
|
92
|
-
yield(self)
|
93
|
-
@children.each do |child|
|
94
|
-
child.each {|c| yield(c)}
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
63
|
def &(object)
|
99
64
|
AndNode.new(self, object)
|
100
65
|
end
|
data/lib/ravensat/claw.rb
CHANGED
@@ -1,22 +1,13 @@
|
|
1
1
|
module Ravensat
|
2
2
|
class DimacsDecoder
|
3
3
|
def decode(model, cnf)
|
4
|
-
# inverted_name_table = name_table.invert
|
5
4
|
prop_vars = cnf.vars
|
6
5
|
case model.first
|
7
6
|
when "SAT"
|
8
|
-
model.last.split.
|
9
|
-
if e == '0'
|
10
|
-
|
11
|
-
|
12
|
-
dimacs_name = e.slice(1..-1)
|
13
|
-
var = prop_vars.find{|i| i.dimacs_name == dimacs_name}
|
14
|
-
var.value = false
|
15
|
-
else
|
16
|
-
dimacs_name = e
|
17
|
-
var = prop_vars.find{|i| i.dimacs_name == dimacs_name}
|
18
|
-
var.value = true
|
19
|
-
end
|
7
|
+
model.last.split.each_with_index do |e,i|
|
8
|
+
break if e == '0'
|
9
|
+
var = prop_vars[i]
|
10
|
+
var.value = !(e[0] == '-')
|
20
11
|
end
|
21
12
|
true
|
22
13
|
when "UNSAT"
|
data/lib/ravensat/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ravensat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rikuto matsuda
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-07-
|
11
|
+
date: 2022-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -23,7 +23,6 @@ files:
|
|
23
23
|
- ".rspec"
|
24
24
|
- ".ruby-version"
|
25
25
|
- Gemfile
|
26
|
-
- Gemfile.lock
|
27
26
|
- LICENSE.txt
|
28
27
|
- README.md
|
29
28
|
- Rakefile
|
data/Gemfile.lock
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
ravensat (0.1.1)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
byebug (11.1.3)
|
10
|
-
coderay (1.1.3)
|
11
|
-
diff-lcs (1.4.4)
|
12
|
-
method_source (1.0.0)
|
13
|
-
pry (0.14.0)
|
14
|
-
coderay (~> 1.1)
|
15
|
-
method_source (~> 1.0)
|
16
|
-
pry-byebug (3.8.0)
|
17
|
-
byebug (~> 11.0)
|
18
|
-
pry (~> 0.10)
|
19
|
-
rake (13.0.3)
|
20
|
-
rspec (3.10.0)
|
21
|
-
rspec-core (~> 3.10.0)
|
22
|
-
rspec-expectations (~> 3.10.0)
|
23
|
-
rspec-mocks (~> 3.10.0)
|
24
|
-
rspec-core (3.10.1)
|
25
|
-
rspec-support (~> 3.10.0)
|
26
|
-
rspec-expectations (3.10.1)
|
27
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
-
rspec-support (~> 3.10.0)
|
29
|
-
rspec-mocks (3.10.2)
|
30
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
-
rspec-support (~> 3.10.0)
|
32
|
-
rspec-support (3.10.2)
|
33
|
-
|
34
|
-
PLATFORMS
|
35
|
-
x86_64-linux
|
36
|
-
|
37
|
-
DEPENDENCIES
|
38
|
-
pry
|
39
|
-
pry-byebug
|
40
|
-
rake (~> 13.0)
|
41
|
-
ravensat!
|
42
|
-
rspec (~> 3.0)
|
43
|
-
|
44
|
-
BUNDLED WITH
|
45
|
-
2.2.24
|