ravensat 0.3.1 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +44 -21
- data/docs/Arcteryx/CNF.html +827 -0
- data/docs/Arcteryx.html +309 -0
- data/docs/Ravensat/AndNode.html +159 -0
- data/docs/Ravensat/Claw.html +338 -0
- data/docs/Ravensat/DimacsDecoder.html +224 -0
- data/docs/Ravensat/DimacsEncoder.html +425 -0
- data/docs/Ravensat/Extension/BooleanVariable.html +229 -0
- data/docs/Ravensat/Extension/Domain.html +319 -0
- data/docs/Ravensat/Extension/IntegerVariable.html +589 -0
- data/docs/Ravensat/Extension/UndefinedVariable.html +236 -0
- data/docs/Ravensat/Extension/Variable.html +443 -0
- data/docs/Ravensat/Extension.html +141 -0
- data/docs/Ravensat/InitialNode.html +267 -0
- data/docs/Ravensat/Node.html +780 -0
- data/docs/Ravensat/NotNode.html +159 -0
- data/docs/Ravensat/OprNode.html +226 -0
- data/docs/Ravensat/OrNode.html +252 -0
- data/docs/Ravensat/Solver.html +373 -0
- data/docs/Ravensat/VarNode.html +488 -0
- data/docs/Ravensat.html +135 -0
- data/docs/_index.html +329 -0
- data/docs/class_list.html +51 -0
- data/docs/css/common.css +1 -0
- data/docs/css/full_list.css +58 -0
- data/docs/css/style.css +497 -0
- data/docs/file.README.html +233 -0
- data/docs/file_list.html +56 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +233 -0
- data/docs/js/app.js +314 -0
- data/docs/js/full_list.js +216 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +523 -0
- data/docs/top-level-namespace.html +110 -0
- data/lib/ravensat/ast/and_node.rb +8 -0
- data/lib/ravensat/ast/node.rb +50 -15
- data/lib/ravensat/ast/not_node.rb +7 -0
- data/lib/ravensat/ast/or_node.rb +9 -0
- data/lib/ravensat/ast/var_node.rb +6 -1
- data/lib/ravensat/claw.rb +45 -0
- data/lib/ravensat/dimacs/dimacs_decoder.rb +6 -12
- data/lib/ravensat/dimacs/dimacs_encoder.rb +10 -13
- data/lib/ravensat/extension/variable/integer_variable.rb +3 -3
- data/lib/ravensat/solver.rb +1 -1
- data/lib/ravensat/version.rb +1 -1
- data/lib/ravensat.rb +1 -1
- metadata +37 -4
- data/Gemfile.lock +0 -45
- data/lib/ravensat/ravenclaw.rb +0 -19
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,23 +1,26 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
[![Ruby](https://github.com/matsuda0528/ravensat/actions/workflows/main.yml/badge.svg)](https://github.com/matsuda0528/ravensat/actions/workflows/main.yml)
|
1
|
+
[![GitHub Actions](https://github.com/matsuda0528/ravensat/actions/workflows/main.yml/badge.svg)](https://github.com/matsuda0528/ravensat/actions/workflows/main.yml)
|
4
2
|
[![Gem Version](https://badge.fury.io/rb/ravensat.svg)](https://badge.fury.io/rb/ravensat)
|
5
3
|
[![LICENSE](https://img.shields.io/github/license/matsuda0528/ravensat)](https://opensource.org/licenses/MIT)
|
6
4
|
|
7
|
-
|
5
|
+
<!-- [![GitHub Pages](https://img.shields.io/badge/GitHub%20Pages--brightgreen.svg?logo=github&style=social)](https://matsuda0528.github.io/ravensat/) -->
|
6
|
+
|
7
|
+
# Ravensat
|
8
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.
|
9
12
|
In order to use Ravensat, you need to install SAT solver.
|
10
13
|
If you do not install SAT solver, it will use the one bundled in the gem.
|
11
14
|
|
12
15
|
About [SAT](https://en.wikipedia.org/wiki/Boolean_satisfiability_problem), [SAT solver](https://en.wikipedia.org/wiki/SAT_solver)
|
13
16
|
|
14
17
|
## Description
|
15
|
-
To solve SAT, we usually use SAT solver.
|
18
|
+
To solve SAT(Boolean Satisfiability Problem), we usually use SAT solver.
|
16
19
|
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
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})$$
|
22
|
+
|
23
|
+
To solve the above SAT, give it to the SAT solver.
|
21
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).
|
22
25
|
Converting the example SAT to DIMACS Format yields the following.
|
23
26
|
|
@@ -27,25 +30,37 @@ p cnf 5 3
|
|
27
30
|
-1 5 3 4 0
|
28
31
|
-3 -4 0
|
29
32
|
```
|
33
|
+
|
30
34
|
DIMACS Format is widely distributed as an I/O format for SAT solver.
|
31
35
|
However, when solving a large SAT, the following problems occur.
|
32
36
|
- Need to create a file with thousands of lines.
|
33
37
|
- Confusion arises because of the inability to name variables meaningfully.
|
34
38
|
|
35
|
-
|
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.
|
36
41
|
Using Ravensat, propositional variables can be defined as local variables in Ruby.
|
42
|
+
|
37
43
|
```ruby
|
38
|
-
|
44
|
+
John_is_a_male = Ravensat::VarNode.new
|
39
45
|
```
|
40
|
-
|
46
|
+
|
47
|
+
In addition, you can write logical expressions intuitively and imperatively.
|
48
|
+
|
41
49
|
```ruby
|
42
50
|
x = Ravensat::VarNode.new
|
43
51
|
y = Ravensat::VarNode.new
|
44
52
|
|
45
|
-
# (x or y) and (not x or y)
|
46
53
|
(x | y) & (~x | y)
|
47
54
|
```
|
48
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
|
+
```
|
49
64
|
|
50
65
|
## Installation
|
51
66
|
|
@@ -66,41 +81,39 @@ Or install it yourself as:
|
|
66
81
|
## Usage
|
67
82
|
### Basic Usage
|
68
83
|
This is a basic usage example of the library.
|
84
|
+
|
69
85
|
```ruby
|
70
86
|
require 'ravensat'
|
71
87
|
|
72
|
-
# Define propositional variables
|
73
88
|
a = Ravensat::VarNode.new
|
74
89
|
b = Ravensat::VarNode.new
|
75
90
|
|
76
91
|
a.result #=> nil
|
77
92
|
b.result #=> nil
|
78
93
|
|
79
|
-
# Generate logical expressions as CNF
|
80
94
|
logic = (a | b) & (~a | b) & (a | ~b)
|
81
95
|
|
82
|
-
# Launch SAT solver
|
83
96
|
solver = Ravensat::Solver.new
|
84
97
|
solver.solve logic #=> true(SAT)
|
85
98
|
|
86
|
-
# Refer to the satisfiability
|
87
99
|
a.result #=> true
|
88
100
|
b.result #=> true
|
89
101
|
```
|
90
102
|
|
91
103
|
If you have SAT solver installed, you can write:
|
104
|
+
|
92
105
|
```ruby
|
93
|
-
# Launch SAT solver
|
94
106
|
solver = Ravensat::Solver.new("<solver_name>")
|
95
107
|
solver.solve logic
|
96
108
|
```
|
109
|
+
|
97
110
|
The available solvers are assumed to be those that can be I/O in the DIMACS Format.
|
98
111
|
At least, we have confirmed that it works properly with [MiniSat](https://github.com/niklasso/minisat).
|
99
112
|
|
100
113
|
If you do not use an external SAT solver, create a SAT solver object without any constructor arguments.
|
101
114
|
In that case, **Arcteryx**(the very simple SAT solver built into Ravensat) will launch.
|
102
115
|
|
103
|
-
### Extension Usage
|
116
|
+
### Extension Usage(prototype)
|
104
117
|
In Ravensat::Extension, C-like variable definitions are available.
|
105
118
|
|
106
119
|
*Note: In Ravensat::Extension, all undefined variables and methods are caught by method_missing method.*
|
@@ -122,8 +135,8 @@ module Ravensat
|
|
122
135
|
end
|
123
136
|
```
|
124
137
|
|
125
|
-
### Extension Usage(CSP; Constraint Satisfaction Problem)
|
126
138
|
It is possible to define integer variables and to describe some integer constraints.
|
139
|
+
|
127
140
|
```ruby
|
128
141
|
require 'ravensat'
|
129
142
|
|
@@ -147,10 +160,20 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
147
160
|
|
148
161
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
149
162
|
|
163
|
+
## License
|
164
|
+
|
165
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
166
|
+
|
150
167
|
## Contributing
|
151
168
|
|
152
169
|
Bug reports and pull requests are welcome on GitHub at https://github.com/matsuda0528/ravensat.
|
153
170
|
|
154
|
-
|
171
|
+
```
|
172
|
+
____ _
|
173
|
+
| _ \ __ ___ _____ _ __ ___ __ _| |_
|
174
|
+
| |_) / _` \ \ / / _ \ '_ \/ __|/ _` | __|
|
175
|
+
| _ < (_| |\ V / __/ | | \__ \ (_| | |_
|
176
|
+
|_| \_\__,_| \_/ \___|_| |_|___/\__,_|\__|
|
177
|
+
|
178
|
+
```
|
155
179
|
|
156
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|