ravensat 0.3.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +18 -0
- data/README.md +90 -13
- 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/exe/ravensat +1 -5
- data/lib/ravensat/ast/and_node.rb +8 -0
- data/lib/ravensat/ast/node.rb +84 -20
- 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 +10 -1
- data/lib/ravensat/claw.rb +44 -0
- data/lib/ravensat/dimacs/dimacs_decoder.rb +9 -6
- data/lib/ravensat/dimacs/dimacs_encoder.rb +10 -13
- data/lib/ravensat/extension/domain.rb +0 -1
- data/lib/ravensat/extension/variable/integer_variable.rb +3 -3
- data/lib/ravensat/solver.rb +1 -8
- data/lib/ravensat/version.rb +1 -1
- data/lib/ravensat.rb +1 -1
- metadata +38 -3
- 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: bd6bb73a8f6668c36675461d24272ae8e02632c5b2d3f768b5a81347ad29956a
|
4
|
+
data.tar.gz: 48e4f44fa76bd1716b32ed98ddaa82d198cb83064e944269ecfd57ab21645860
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5365bfdf37eeb55b5a7ccab53f0ecca8cf8c73ecdfcac2eb9c92ce843aa6fa2e77f711f14a9b00f37cb9a37bfade19c65ea38cbd3f7478398b0d1ef8a5cf416a
|
7
|
+
data.tar.gz: abf648c3097425241ae106e7ed42876f9c9a33e55bf4615cefc16c77943aedf62b0bd99fc6b9c2062147dbaf6c9b690b13f5a28204771e03934e4c59bdf98a9e
|
@@ -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,54 @@
|
|
1
1
|
# Ravensat
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
(
|
3
|
+
[![GitHub Actions](https://github.com/matsuda0528/ravensat/actions/workflows/main.yml/badge.svg)](https://github.com/matsuda0528/ravensat/actions/workflows/main.yml)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/ravensat.svg)](https://badge.fury.io/rb/ravensat)
|
5
|
+
[![LICENSE](https://img.shields.io/github/license/matsuda0528/ravensat)](https://opensource.org/licenses/MIT)
|
6
|
+
|
7
|
+
[![GitHub Pages](https://img.shields.io/badge/GitHub%20Pages--brightgreen.svg?logo=github&style=social)](https://matsuda0528.github.io/ravensat/)
|
8
|
+
|
9
|
+
Ravensat is an interface to SAT solver in Ruby.
|
10
|
+
|
11
|
+
In order to use Ravensat, you need to install SAT solver.
|
12
|
+
If you do not install SAT solver, it will use the one bundled in the gem.
|
13
|
+
|
14
|
+
About [SAT](https://en.wikipedia.org/wiki/Boolean_satisfiability_problem), [SAT solver](https://en.wikipedia.org/wiki/SAT_solver)
|
15
|
+
|
16
|
+
## Description
|
17
|
+
To solve SAT, we usually use SAT solver.
|
18
|
+
Now, let's solve the following SAT with SAT solver.
|
19
|
+
|
20
|
+
$$(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
|
+
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
|
+
Converting the example SAT to DIMACS Format yields the following.
|
24
|
+
|
25
|
+
```DIMACS Format
|
26
|
+
p cnf 5 3
|
27
|
+
1 -5 4 0
|
28
|
+
-1 5 3 4 0
|
29
|
+
-3 -4 0
|
30
|
+
```
|
31
|
+
|
32
|
+
DIMACS Format is widely distributed as an I/O format for SAT solver.
|
33
|
+
However, when solving a large SAT, the following problems occur.
|
34
|
+
- Need to create a file with thousands of lines.
|
35
|
+
- Confusion arises because of the inability to name variables meaningfully.
|
36
|
+
|
37
|
+
To solve these problems, Ravensat can be used.
|
38
|
+
Using Ravensat, propositional variables can be defined as local variables in Ruby.
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
fuji_is_the_highest_mountain_in_japan = Ravensat::VarNode.new
|
42
|
+
```
|
43
|
+
|
44
|
+
In addition, you can write logical expressions intuitively.
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
x = Ravensat::VarNode.new
|
48
|
+
y = Ravensat::VarNode.new
|
49
|
+
|
50
|
+
(x | y) & (~x | y) # (x or y) and (not x or y)
|
51
|
+
```
|
6
52
|
|
7
53
|
|
8
54
|
## Installation
|
@@ -22,26 +68,45 @@ Or install it yourself as:
|
|
22
68
|
$ gem install ravensat
|
23
69
|
|
24
70
|
## Usage
|
25
|
-
###
|
71
|
+
### Basic Usage
|
72
|
+
This is a basic usage example of the library.
|
73
|
+
|
26
74
|
```ruby
|
27
75
|
require 'ravensat'
|
28
76
|
|
29
77
|
a = Ravensat::VarNode.new
|
30
78
|
b = Ravensat::VarNode.new
|
31
79
|
|
32
|
-
a.
|
33
|
-
b.
|
80
|
+
a.result #=> nil
|
81
|
+
b.result #=> nil
|
34
82
|
|
35
83
|
logic = (a | b) & (~a | b) & (a | ~b)
|
36
84
|
|
37
85
|
solver = Ravensat::Solver.new
|
38
86
|
solver.solve logic #=> true(SAT)
|
39
87
|
|
40
|
-
a.
|
41
|
-
b.
|
88
|
+
a.result #=> true
|
89
|
+
b.result #=> true
|
90
|
+
```
|
91
|
+
|
92
|
+
If you have SAT solver installed, you can write:
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
solver = Ravensat::Solver.new("<solver_name>")
|
96
|
+
solver.solve logic
|
42
97
|
```
|
43
98
|
|
44
|
-
|
99
|
+
The available solvers are assumed to be those that can be I/O in the DIMACS Format.
|
100
|
+
At least, we have confirmed that it works properly with [MiniSat](https://github.com/niklasso/minisat).
|
101
|
+
|
102
|
+
If you do not use an external SAT solver, create a SAT solver object without any constructor arguments.
|
103
|
+
In that case, **Arcteryx**(the very simple SAT solver built into Ravensat) will launch.
|
104
|
+
|
105
|
+
### Extension Usage
|
106
|
+
In Ravensat::Extension, C-like variable definitions are available.
|
107
|
+
|
108
|
+
*Note: In Ravensat::Extension, all undefined variables and methods are caught by method_missing method.*
|
109
|
+
|
45
110
|
```ruby
|
46
111
|
require 'ravensat'
|
47
112
|
|
@@ -53,13 +118,15 @@ module Ravensat
|
|
53
118
|
solver = Ravensat::Solver.new
|
54
119
|
solver.solve logic #=> true
|
55
120
|
|
56
|
-
a.
|
57
|
-
b.
|
121
|
+
a.result #=> true
|
122
|
+
b.result #=> true
|
58
123
|
end
|
59
124
|
end
|
60
125
|
```
|
61
126
|
|
62
127
|
### Extension Usage(CSP; Constraint Satisfaction Problem)
|
128
|
+
It is possible to define integer variables and to describe some integer constraints.
|
129
|
+
|
63
130
|
```ruby
|
64
131
|
require 'ravensat'
|
65
132
|
|
@@ -83,10 +150,20 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
83
150
|
|
84
151
|
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).
|
85
152
|
|
153
|
+
## License
|
154
|
+
|
155
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
156
|
+
|
86
157
|
## Contributing
|
87
158
|
|
88
159
|
Bug reports and pull requests are welcome on GitHub at https://github.com/matsuda0528/ravensat.
|
89
160
|
|
90
|
-
|
161
|
+
```
|
162
|
+
____ _
|
163
|
+
| _ \ __ ___ _____ _ __ ___ __ _| |_
|
164
|
+
| |_) / _` \ \ / / _ \ '_ \/ __|/ _` | __|
|
165
|
+
| _ < (_| |\ V / __/ | | \__ \ (_| | |_
|
166
|
+
|_| \_\__,_| \_/ \___|_| |_|___/\__,_|\__|
|
167
|
+
|
168
|
+
```
|
91
169
|
|
92
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|