ravensat 0.3.0 → 0.3.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/.github/workflows/main.yml +18 -0
- data/README.md +75 -11
- data/exe/ravensat +1 -5
- data/lib/ravensat/ast/node.rb +0 -6
- data/lib/ravensat/ast/var_node.rb +4 -0
- data/lib/ravensat/extension/domain.rb +0 -1
- data/lib/ravensat/solver.rb +0 -7
- data/lib/ravensat/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47afc062227efddad35ed4643e28c4eea8957ecb32c8aa34d3c69a9ff52d3a88
|
4
|
+
data.tar.gz: a39c4f15fb17321ded803e79b702c55150197b3a613a340ca4a728e0a6a27402
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f29375d0971be0c3a721e9932fec0b69ad9db5b6df089e9d07fad557a82fac176faf7b71eea0ca73b8ee76ba60b413bfc799fd2de798c0b0fc513e39c8c0388d
|
7
|
+
data.tar.gz: a596fa29bfb55341a016ddde64b2e7d788a4877d4504cd5921cee81e486ee28207fd14027c81c0e113c8485edd0cc9bd5921beac75728da85e3390c1eab4d23f
|
@@ -0,0 +1,18 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: [push,pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- uses: actions/checkout@v2
|
10
|
+
- name: Set up Ruby
|
11
|
+
uses: ruby/setup-ruby@v1
|
12
|
+
with:
|
13
|
+
ruby-version: 3.0.0
|
14
|
+
- name: Run the default task
|
15
|
+
run: |
|
16
|
+
gem install bundler -v 2.2.3
|
17
|
+
bundle install
|
18
|
+
bundle exec rake
|
data/README.md
CHANGED
@@ -1,8 +1,50 @@
|
|
1
1
|
# Ravensat
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
(
|
3
|
+
[](https://github.com/matsuda0528/ravensat/actions/workflows/main.yml)
|
4
|
+
[](https://badge.fury.io/rb/ravensat)
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
6
|
+
|
7
|
+
Ravensat is an interface to SAT solver in Ruby.
|
8
|
+
|
9
|
+
In order to use Ravensat, you need to install SAT solver.
|
10
|
+
If you do not install SAT solver, it will use the one bundled in the gem.
|
11
|
+
|
12
|
+
About [SAT](https://en.wikipedia.org/wiki/Boolean_satisfiability_problem), [SAT solver](https://en.wikipedia.org/wiki/SAT_solver)
|
13
|
+
|
14
|
+
## Description
|
15
|
+
To solve SAT, we usually use SAT solver.
|
16
|
+
Now, let's solve the following SAT with SAT solver.
|
17
|
+
<p align="center">
|
18
|
+
<img src="https://latex.codecogs.com/svg.image?\inline&space;\large&space;\bg{white}(1&space;\lor&space;\lnot&space;5&space;\lor&space;4)&space;\land&space;(\lnot&space;1&space;\lor&space;5&space;\lor&space;3&space;\lor&space;4)&space;\land&space;(\lnot&space;3&space;\lor&space;\lnot&space;4)" style="background-color:white;"/>
|
19
|
+
</p>
|
20
|
+
|
21
|
+
Most SAT solvers are input in [DIMACS Format](https://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/index-seo.php/SATLINK____DIMACS).
|
22
|
+
Converting the example SAT to DIMACS Format yields the following.
|
23
|
+
|
24
|
+
```DIMACS Format
|
25
|
+
p cnf 5 3
|
26
|
+
1 -5 4 0
|
27
|
+
-1 5 3 4 0
|
28
|
+
-3 -4 0
|
29
|
+
```
|
30
|
+
DIMACS Format is widely distributed as an I/O format for SAT solver.
|
31
|
+
However, when solving a large SAT, the following problems occur.
|
32
|
+
- Need to create a file with thousands of lines.
|
33
|
+
- Confusion arises because of the inability to name variables meaningfully.
|
34
|
+
|
35
|
+
To solve these problems, Ravensat can be used.
|
36
|
+
Using Ravensat, propositional variables can be defined as local variables in Ruby.
|
37
|
+
```ruby
|
38
|
+
fuji_is_the_highest_mountain_in_japan = Ravensat::VarNode.new
|
39
|
+
```
|
40
|
+
In addition, you can write logical expressions intuitively.
|
41
|
+
```ruby
|
42
|
+
x = Ravensat::VarNode.new
|
43
|
+
y = Ravensat::VarNode.new
|
44
|
+
|
45
|
+
# (x or y) and (not x or y)
|
46
|
+
(x | y) & (~x | y)
|
47
|
+
```
|
6
48
|
|
7
49
|
|
8
50
|
## Installation
|
@@ -22,26 +64,47 @@ Or install it yourself as:
|
|
22
64
|
$ gem install ravensat
|
23
65
|
|
24
66
|
## Usage
|
25
|
-
###
|
67
|
+
### Basic Usage
|
68
|
+
This is a basic usage example of the library.
|
26
69
|
```ruby
|
27
70
|
require 'ravensat'
|
28
71
|
|
72
|
+
# Define propositional variables
|
29
73
|
a = Ravensat::VarNode.new
|
30
74
|
b = Ravensat::VarNode.new
|
31
75
|
|
32
|
-
a.
|
33
|
-
b.
|
76
|
+
a.result #=> nil
|
77
|
+
b.result #=> nil
|
34
78
|
|
79
|
+
# Generate logical expressions as CNF
|
35
80
|
logic = (a | b) & (~a | b) & (a | ~b)
|
36
81
|
|
82
|
+
# Launch SAT solver
|
37
83
|
solver = Ravensat::Solver.new
|
38
84
|
solver.solve logic #=> true(SAT)
|
39
85
|
|
40
|
-
|
41
|
-
|
86
|
+
# Refer to the satisfiability
|
87
|
+
a.result #=> true
|
88
|
+
b.result #=> true
|
42
89
|
```
|
43
90
|
|
44
|
-
|
91
|
+
If you have SAT solver installed, you can write:
|
92
|
+
```ruby
|
93
|
+
# Launch SAT solver
|
94
|
+
solver = Ravensat::Solver.new("<solver_name>")
|
95
|
+
solver.solve logic
|
96
|
+
```
|
97
|
+
The available solvers are assumed to be those that can be I/O in the DIMACS Format.
|
98
|
+
At least, we have confirmed that it works properly with [MiniSat](https://github.com/niklasso/minisat).
|
99
|
+
|
100
|
+
If you do not use an external SAT solver, create a SAT solver object without any constructor arguments.
|
101
|
+
In that case, **Arcteryx**(the very simple SAT solver built into Ravensat) will launch.
|
102
|
+
|
103
|
+
### Extension Usage
|
104
|
+
In Ravensat::Extension, C-like variable definitions are available.
|
105
|
+
|
106
|
+
*Note: In Ravensat::Extension, all undefined variables and methods are caught by method_missing method.*
|
107
|
+
|
45
108
|
```ruby
|
46
109
|
require 'ravensat'
|
47
110
|
|
@@ -53,13 +116,14 @@ module Ravensat
|
|
53
116
|
solver = Ravensat::Solver.new
|
54
117
|
solver.solve logic #=> true
|
55
118
|
|
56
|
-
a.
|
57
|
-
b.
|
119
|
+
a.result #=> true
|
120
|
+
b.result #=> true
|
58
121
|
end
|
59
122
|
end
|
60
123
|
```
|
61
124
|
|
62
125
|
### Extension Usage(CSP; Constraint Satisfaction Problem)
|
126
|
+
It is possible to define integer variables and to describe some integer constraints.
|
63
127
|
```ruby
|
64
128
|
require 'ravensat'
|
65
129
|
|
data/exe/ravensat
CHANGED
data/lib/ravensat/ast/node.rb
CHANGED
data/lib/ravensat/solver.rb
CHANGED
@@ -5,15 +5,8 @@ module Ravensat
|
|
5
5
|
attr_accessor :name
|
6
6
|
def initialize( default_solver_name = "arcteryx" )
|
7
7
|
@name = default_solver_name
|
8
|
-
# @cnf = Array.new
|
9
|
-
# @nr_vars
|
10
|
-
# @nr_clses
|
11
8
|
end
|
12
9
|
|
13
|
-
# def <<( clause )
|
14
|
-
# 'this is << method'
|
15
|
-
# end
|
16
|
-
|
17
10
|
def solve( cnf )
|
18
11
|
encoder = DimacsEncoder.new
|
19
12
|
@input_file = Tempfile.open(["ravensat",".cnf"])
|
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: 0.3.
|
4
|
+
version: 0.3.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-05-
|
11
|
+
date: 2022-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -18,6 +18,7 @@ executables:
|
|
18
18
|
extensions: []
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
|
+
- ".github/workflows/main.yml"
|
21
22
|
- ".gitignore"
|
22
23
|
- ".rspec"
|
23
24
|
- ".ruby-version"
|