ravensat 0.2.2 → 0.3.2
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 +122 -9
- 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 +7 -0
- data/lib/ravensat/ast/initial_node.rb +11 -0
- data/lib/ravensat/ast/node.rb +17 -9
- data/lib/ravensat/ast/not_node.rb +3 -0
- data/lib/ravensat/ast/var_node.rb +4 -0
- data/lib/ravensat/ast.rb +11 -0
- data/lib/ravensat/claw.rb +44 -0
- data/lib/ravensat/{dimacs_decoder.rb → dimacs/dimacs_decoder.rb} +0 -0
- data/lib/ravensat/{dimacs_encoder.rb → dimacs/dimacs_encoder.rb} +4 -7
- data/lib/ravensat/dimacs.rb +6 -0
- data/lib/ravensat/extension/domain.rb +24 -0
- data/lib/ravensat/extension/variable/boolean_variable.rb +17 -0
- data/lib/ravensat/extension/variable/integer_variable.rb +63 -0
- data/lib/ravensat/extension/variable/undefined_variable.rb +9 -0
- data/lib/ravensat/extension/variable/variable.rb +16 -0
- data/lib/ravensat/extension.rb +13 -0
- data/lib/ravensat/solver.rb +0 -7
- data/lib/ravensat/version.rb +1 -1
- data/lib/ravensat.rb +5 -10
- metadata +52 -6
- data/lib/ravensat/ravenclaw.rb +0 -15
@@ -0,0 +1,233 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
File: README
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.27
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" />
|
16
|
+
|
17
|
+
<script type="text/javascript">
|
18
|
+
pathId = "README";
|
19
|
+
relpath = '';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="file_list.html?1"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="_index.html">Index</a> »
|
40
|
+
<span class="title">File: README</span>
|
41
|
+
|
42
|
+
</div>
|
43
|
+
|
44
|
+
<div id="search">
|
45
|
+
|
46
|
+
<a class="full_list_link" id="class_list_link"
|
47
|
+
href="class_list.html">
|
48
|
+
|
49
|
+
<svg width="24" height="24">
|
50
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
51
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
52
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
</svg>
|
54
|
+
</a>
|
55
|
+
|
56
|
+
</div>
|
57
|
+
<div class="clear"></div>
|
58
|
+
</div>
|
59
|
+
|
60
|
+
<div id="content"><div id='filecontents'><h1 id="ravensat">Ravensat</h1>
|
61
|
+
|
62
|
+
<p><a href="https://github.com/matsuda0528/ravensat/actions/workflows/main.yml"><img src="https://github.com/matsuda0528/ravensat/actions/workflows/main.yml/badge.svg" alt="Ruby" /></a>
|
63
|
+
<a href="https://badge.fury.io/rb/ravensat"><img src="https://badge.fury.io/rb/ravensat.svg" alt="Gem Version" /></a>
|
64
|
+
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/github/license/matsuda0528/ravensat" alt="LICENSE" /></a></p>
|
65
|
+
|
66
|
+
<p>Ravensat is an interface to SAT solver in Ruby.</p>
|
67
|
+
|
68
|
+
<p>In order to use Ravensat, you need to install SAT solver.
|
69
|
+
If you do not install SAT solver, it will use the one bundled in the gem.</p>
|
70
|
+
|
71
|
+
<p>About <a href="https://en.wikipedia.org/wiki/Boolean_satisfiability_problem">SAT</a>, <a href="https://en.wikipedia.org/wiki/SAT_solver">SAT solver</a></p>
|
72
|
+
|
73
|
+
<h2 id="description">Description</h2>
|
74
|
+
<p>To solve SAT, we usually use SAT solver.
|
75
|
+
Now, let’s solve the following SAT with SAT solver.</p>
|
76
|
+
|
77
|
+
\[(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)\]
|
78
|
+
|
79
|
+
<p>Most SAT solvers are input in <a href="https://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/index-seo.php/SATLINK____DIMACS">DIMACS Format</a>.
|
80
|
+
Converting the example SAT to DIMACS Format yields the following.</p>
|
81
|
+
|
82
|
+
<p><code>DIMACS Format
|
83
|
+
p cnf 5 3
|
84
|
+
1 -5 4 0
|
85
|
+
-1 5 3 4 0
|
86
|
+
-3 -4 0
|
87
|
+
</code></p>
|
88
|
+
|
89
|
+
<p>DIMACS Format is widely distributed as an I/O format for SAT solver.
|
90
|
+
However, when solving a large SAT, the following problems occur.
|
91
|
+
- Need to create a file with thousands of lines.
|
92
|
+
- Confusion arises because of the inability to name variables meaningfully.</p>
|
93
|
+
|
94
|
+
<p>To solve these problems, Ravensat can be used.
|
95
|
+
Using Ravensat, propositional variables can be defined as local variables in Ruby.</p>
|
96
|
+
|
97
|
+
<p><code>ruby
|
98
|
+
fuji_is_the_highest_mountain_in_japan = Ravensat::VarNode.new
|
99
|
+
</code></p>
|
100
|
+
|
101
|
+
<p>In addition, you can write logical expressions intuitively.</p>
|
102
|
+
|
103
|
+
<p>```ruby
|
104
|
+
x = Ravensat::VarNode.new
|
105
|
+
y = Ravensat::VarNode.new</p>
|
106
|
+
|
107
|
+
<p>(x | y) & (~x | y) # (x or y) and (not x or y)
|
108
|
+
```</p>
|
109
|
+
|
110
|
+
<h2 id="installation">Installation</h2>
|
111
|
+
|
112
|
+
<p>Add this line to your application’s Gemfile:</p>
|
113
|
+
|
114
|
+
<p><code>ruby
|
115
|
+
gem 'ravensat'
|
116
|
+
</code></p>
|
117
|
+
|
118
|
+
<p>And then execute:</p>
|
119
|
+
|
120
|
+
<pre class="code ruby"><code class="ruby">$ bundle install
|
121
|
+
</code></pre>
|
122
|
+
|
123
|
+
<p>Or install it yourself as:</p>
|
124
|
+
|
125
|
+
<pre class="code ruby"><code class="ruby">$ gem install ravensat
|
126
|
+
</code></pre>
|
127
|
+
|
128
|
+
<h2 id="usage">Usage</h2>
|
129
|
+
<p>### Basic Usage
|
130
|
+
This is a basic usage example of the library.</p>
|
131
|
+
|
132
|
+
<p>```ruby
|
133
|
+
require ‘ravensat’</p>
|
134
|
+
|
135
|
+
<p>a = Ravensat::VarNode.new
|
136
|
+
b = Ravensat::VarNode.new</p>
|
137
|
+
|
138
|
+
<p>a.result #=> nil
|
139
|
+
b.result #=> nil</p>
|
140
|
+
|
141
|
+
<table>
|
142
|
+
<tbody>
|
143
|
+
<tr>
|
144
|
+
<td>logic = (a</td>
|
145
|
+
<td>b) & (~a</td>
|
146
|
+
<td>b) & (a</td>
|
147
|
+
<td>~b)</td>
|
148
|
+
</tr>
|
149
|
+
</tbody>
|
150
|
+
</table>
|
151
|
+
|
152
|
+
<p>solver = Ravensat::Solver.new
|
153
|
+
solver.solve logic #=> true(SAT)</p>
|
154
|
+
|
155
|
+
<p>a.result #=> true
|
156
|
+
b.result #=> true
|
157
|
+
```</p>
|
158
|
+
|
159
|
+
<p>If you have SAT solver installed, you can write:</p>
|
160
|
+
|
161
|
+
<p><code>ruby
|
162
|
+
solver = Ravensat::Solver.new("<solver_name>")
|
163
|
+
solver.solve logic
|
164
|
+
</code></p>
|
165
|
+
|
166
|
+
<p>The available solvers are assumed to be those that can be I/O in the DIMACS Format.
|
167
|
+
At least, we have confirmed that it works properly with <a href="https://github.com/niklasso/minisat">MiniSat</a>.</p>
|
168
|
+
|
169
|
+
<p>If you do not use an external SAT solver, create a SAT solver object without any constructor arguments.
|
170
|
+
In that case, <strong>Arcteryx</strong>(the very simple SAT solver built into Ravensat) will launch.</p>
|
171
|
+
|
172
|
+
<h3 id="extension-usage">Extension Usage</h3>
|
173
|
+
<p>In Ravensat::Extension, C-like variable definitions are available.</p>
|
174
|
+
|
175
|
+
<p><em>Note: In Ravensat::Extension, all undefined variables and methods are caught by method_missing method.</em></p>
|
176
|
+
|
177
|
+
<p>```ruby
|
178
|
+
require ‘ravensat’</p>
|
179
|
+
|
180
|
+
<p>module Ravensat
|
181
|
+
module Extension
|
182
|
+
bool a, b
|
183
|
+
logic = (a | b) & (~a | b) & (a | ~b)</p>
|
184
|
+
|
185
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_solver'>solver</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Ravensat.html" title="Ravensat (module)">Ravensat</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Ravensat/Solver.html" title="Ravensat::Solver (class)">Solver</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Ravensat/Solver.html#initialize-instance_method" title="Ravensat::Solver#initialize (method)">new</a></span></span>
|
186
|
+
<span class='id identifier rubyid_solver'>solver</span><span class='period'>.</span><span class='id identifier rubyid_solve'>solve</span> <span class='id identifier rubyid_logic'>logic</span> <span class='comment'>#=> true
|
187
|
+
</span>
|
188
|
+
<span class='id identifier rubyid_a'>a</span><span class='period'>.</span><span class='id identifier rubyid_result'>result</span> <span class='comment'>#=> true
|
189
|
+
</span><span class='id identifier rubyid_b'>b</span><span class='period'>.</span><span class='id identifier rubyid_result'>result</span> <span class='comment'>#=> true end end ```
|
190
|
+
</span></code></pre>
|
191
|
+
|
192
|
+
<h3 id="extension-usagecsp-constraint-satisfaction-problem">Extension Usage(CSP; Constraint Satisfaction Problem)</h3>
|
193
|
+
<p>It is possible to define integer variables and to describe some integer constraints.</p>
|
194
|
+
|
195
|
+
<p>```ruby
|
196
|
+
require ‘ravensat’</p>
|
197
|
+
|
198
|
+
<p>module Ravensat
|
199
|
+
module Extension
|
200
|
+
int a(1..10), b(1..10)
|
201
|
+
constraint = (a.only_one & b.only_one & (a != b))</p>
|
202
|
+
|
203
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_solver'>solver</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Ravensat.html" title="Ravensat (module)">Ravensat</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Ravensat/Solver.html" title="Ravensat::Solver (class)">Solver</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Ravensat/Solver.html#initialize-instance_method" title="Ravensat::Solver#initialize (method)">new</a></span></span>
|
204
|
+
<span class='id identifier rubyid_solver'>solver</span><span class='period'>.</span><span class='id identifier rubyid_solve'>solve</span> <span class='id identifier rubyid_constraint'>constraint</span> <span class='comment'>#=> true
|
205
|
+
</span>
|
206
|
+
<span class='id identifier rubyid_a'>a</span><span class='period'>.</span><span class='id identifier rubyid_result'>result</span> <span class='comment'>#=> 1
|
207
|
+
</span><span class='id identifier rubyid_b'>b</span><span class='period'>.</span><span class='id identifier rubyid_result'>result</span> <span class='comment'>#=> 2 end end ```
|
208
|
+
</span></code></pre>
|
209
|
+
|
210
|
+
<h2 id="development">Development</h2>
|
211
|
+
|
212
|
+
<p>After checking out the repo, run <code>bin/setup</code> to install dependencies. Then, run <code>rake spec</code> to run the tests. You can also run <code>bin/console</code> for an interactive prompt that will allow you to experiment.</p>
|
213
|
+
|
214
|
+
<p>To install this gem onto your local machine, run <code>bundle exec rake install</code>. To release a new version, update the version number in <code>version.rb</code>, and then run <code>bundle exec rake release</code>, which will create a git tag for the version, push git commits and the created tag, and push the <code>.gem</code> file to <a href="https://rubygems.org">rubygems.org</a>.</p>
|
215
|
+
|
216
|
+
<h2 id="contributing">Contributing</h2>
|
217
|
+
|
218
|
+
<p>Bug reports and pull requests are welcome on GitHub at https://github.com/matsuda0528/ravensat.</p>
|
219
|
+
|
220
|
+
<h2 id="license">License</h2>
|
221
|
+
|
222
|
+
<p>The gem is available as open source under the terms of the <a href="https://opensource.org/licenses/MIT">MIT License</a>.</p>
|
223
|
+
</div></div>
|
224
|
+
|
225
|
+
<div id="footer">
|
226
|
+
Generated on Wed May 25 14:42:45 2022 by
|
227
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
228
|
+
0.9.27 (ruby-3.0.0).
|
229
|
+
</div>
|
230
|
+
|
231
|
+
</div>
|
232
|
+
</body>
|
233
|
+
</html>
|
data/docs/file_list.html
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
5
|
+
<meta charset="utf-8" />
|
6
|
+
|
7
|
+
<link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen" />
|
8
|
+
|
9
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" />
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
14
|
+
|
15
|
+
<script type="text/javascript" charset="utf-8" src="js/full_list.js"></script>
|
16
|
+
|
17
|
+
|
18
|
+
<title>File List</title>
|
19
|
+
<base id="base_target" target="_parent" />
|
20
|
+
</head>
|
21
|
+
<body>
|
22
|
+
<div id="content">
|
23
|
+
<div class="fixed_header">
|
24
|
+
<h1 id="full_list_header">File List</h1>
|
25
|
+
<div id="full_list_nav">
|
26
|
+
|
27
|
+
<span><a target="_self" href="class_list.html">
|
28
|
+
Classes
|
29
|
+
</a></span>
|
30
|
+
|
31
|
+
<span><a target="_self" href="method_list.html">
|
32
|
+
Methods
|
33
|
+
</a></span>
|
34
|
+
|
35
|
+
<span><a target="_self" href="file_list.html">
|
36
|
+
Files
|
37
|
+
</a></span>
|
38
|
+
|
39
|
+
</div>
|
40
|
+
|
41
|
+
<div id="search">Search: <input type="text" /></div>
|
42
|
+
</div>
|
43
|
+
|
44
|
+
<ul id="full_list" class="file">
|
45
|
+
|
46
|
+
|
47
|
+
<li id="object_README" class="odd">
|
48
|
+
<div class="item"><span class="object_link"><a href="index.html" title="README">README</a></span></div>
|
49
|
+
</li>
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
</ul>
|
54
|
+
</div>
|
55
|
+
</body>
|
56
|
+
</html>
|
data/docs/frames.html
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<title>Documentation by YARD 0.9.27</title>
|
6
|
+
</head>
|
7
|
+
<script type="text/javascript">
|
8
|
+
var match = unescape(window.location.hash).match(/^#!(.+)/);
|
9
|
+
var name = match ? match[1] : 'index.html';
|
10
|
+
name = name.replace(/^(\w+):\/\//, '').replace(/^\/\//, '');
|
11
|
+
window.top.location = name;
|
12
|
+
</script>
|
13
|
+
<noscript>
|
14
|
+
<h1>Oops!</h1>
|
15
|
+
<h2>YARD requires JavaScript!</h2>
|
16
|
+
</noscript>
|
17
|
+
</html>
|
data/docs/index.html
ADDED
@@ -0,0 +1,233 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
File: README
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.27
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" />
|
16
|
+
|
17
|
+
<script type="text/javascript">
|
18
|
+
pathId = "README";
|
19
|
+
relpath = '';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="class_list.html?1"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="_index.html">Index</a> »
|
40
|
+
<span class="title">File: README</span>
|
41
|
+
|
42
|
+
</div>
|
43
|
+
|
44
|
+
<div id="search">
|
45
|
+
|
46
|
+
<a class="full_list_link" id="class_list_link"
|
47
|
+
href="class_list.html">
|
48
|
+
|
49
|
+
<svg width="24" height="24">
|
50
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
51
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
52
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
</svg>
|
54
|
+
</a>
|
55
|
+
|
56
|
+
</div>
|
57
|
+
<div class="clear"></div>
|
58
|
+
</div>
|
59
|
+
|
60
|
+
<div id="content"><div id='filecontents'><h1 id="ravensat">Ravensat</h1>
|
61
|
+
|
62
|
+
<p><a href="https://github.com/matsuda0528/ravensat/actions/workflows/main.yml"><img src="https://github.com/matsuda0528/ravensat/actions/workflows/main.yml/badge.svg" alt="Ruby" /></a>
|
63
|
+
<a href="https://badge.fury.io/rb/ravensat"><img src="https://badge.fury.io/rb/ravensat.svg" alt="Gem Version" /></a>
|
64
|
+
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/github/license/matsuda0528/ravensat" alt="LICENSE" /></a></p>
|
65
|
+
|
66
|
+
<p>Ravensat is an interface to SAT solver in Ruby.</p>
|
67
|
+
|
68
|
+
<p>In order to use Ravensat, you need to install SAT solver.
|
69
|
+
If you do not install SAT solver, it will use the one bundled in the gem.</p>
|
70
|
+
|
71
|
+
<p>About <a href="https://en.wikipedia.org/wiki/Boolean_satisfiability_problem">SAT</a>, <a href="https://en.wikipedia.org/wiki/SAT_solver">SAT solver</a></p>
|
72
|
+
|
73
|
+
<h2 id="description">Description</h2>
|
74
|
+
<p>To solve SAT, we usually use SAT solver.
|
75
|
+
Now, let’s solve the following SAT with SAT solver.</p>
|
76
|
+
|
77
|
+
\[(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)\]
|
78
|
+
|
79
|
+
<p>Most SAT solvers are input in <a href="https://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/index-seo.php/SATLINK____DIMACS">DIMACS Format</a>.
|
80
|
+
Converting the example SAT to DIMACS Format yields the following.</p>
|
81
|
+
|
82
|
+
<p><code>DIMACS Format
|
83
|
+
p cnf 5 3
|
84
|
+
1 -5 4 0
|
85
|
+
-1 5 3 4 0
|
86
|
+
-3 -4 0
|
87
|
+
</code></p>
|
88
|
+
|
89
|
+
<p>DIMACS Format is widely distributed as an I/O format for SAT solver.
|
90
|
+
However, when solving a large SAT, the following problems occur.
|
91
|
+
- Need to create a file with thousands of lines.
|
92
|
+
- Confusion arises because of the inability to name variables meaningfully.</p>
|
93
|
+
|
94
|
+
<p>To solve these problems, Ravensat can be used.
|
95
|
+
Using Ravensat, propositional variables can be defined as local variables in Ruby.</p>
|
96
|
+
|
97
|
+
<p><code>ruby
|
98
|
+
fuji_is_the_highest_mountain_in_japan = Ravensat::VarNode.new
|
99
|
+
</code></p>
|
100
|
+
|
101
|
+
<p>In addition, you can write logical expressions intuitively.</p>
|
102
|
+
|
103
|
+
<p>```ruby
|
104
|
+
x = Ravensat::VarNode.new
|
105
|
+
y = Ravensat::VarNode.new</p>
|
106
|
+
|
107
|
+
<p>(x | y) & (~x | y) # (x or y) and (not x or y)
|
108
|
+
```</p>
|
109
|
+
|
110
|
+
<h2 id="installation">Installation</h2>
|
111
|
+
|
112
|
+
<p>Add this line to your application’s Gemfile:</p>
|
113
|
+
|
114
|
+
<p><code>ruby
|
115
|
+
gem 'ravensat'
|
116
|
+
</code></p>
|
117
|
+
|
118
|
+
<p>And then execute:</p>
|
119
|
+
|
120
|
+
<pre class="code ruby"><code class="ruby">$ bundle install
|
121
|
+
</code></pre>
|
122
|
+
|
123
|
+
<p>Or install it yourself as:</p>
|
124
|
+
|
125
|
+
<pre class="code ruby"><code class="ruby">$ gem install ravensat
|
126
|
+
</code></pre>
|
127
|
+
|
128
|
+
<h2 id="usage">Usage</h2>
|
129
|
+
<p>### Basic Usage
|
130
|
+
This is a basic usage example of the library.</p>
|
131
|
+
|
132
|
+
<p>```ruby
|
133
|
+
require ‘ravensat’</p>
|
134
|
+
|
135
|
+
<p>a = Ravensat::VarNode.new
|
136
|
+
b = Ravensat::VarNode.new</p>
|
137
|
+
|
138
|
+
<p>a.result #=> nil
|
139
|
+
b.result #=> nil</p>
|
140
|
+
|
141
|
+
<table>
|
142
|
+
<tbody>
|
143
|
+
<tr>
|
144
|
+
<td>logic = (a</td>
|
145
|
+
<td>b) & (~a</td>
|
146
|
+
<td>b) & (a</td>
|
147
|
+
<td>~b)</td>
|
148
|
+
</tr>
|
149
|
+
</tbody>
|
150
|
+
</table>
|
151
|
+
|
152
|
+
<p>solver = Ravensat::Solver.new
|
153
|
+
solver.solve logic #=> true(SAT)</p>
|
154
|
+
|
155
|
+
<p>a.result #=> true
|
156
|
+
b.result #=> true
|
157
|
+
```</p>
|
158
|
+
|
159
|
+
<p>If you have SAT solver installed, you can write:</p>
|
160
|
+
|
161
|
+
<p><code>ruby
|
162
|
+
solver = Ravensat::Solver.new("<solver_name>")
|
163
|
+
solver.solve logic
|
164
|
+
</code></p>
|
165
|
+
|
166
|
+
<p>The available solvers are assumed to be those that can be I/O in the DIMACS Format.
|
167
|
+
At least, we have confirmed that it works properly with <a href="https://github.com/niklasso/minisat">MiniSat</a>.</p>
|
168
|
+
|
169
|
+
<p>If you do not use an external SAT solver, create a SAT solver object without any constructor arguments.
|
170
|
+
In that case, <strong>Arcteryx</strong>(the very simple SAT solver built into Ravensat) will launch.</p>
|
171
|
+
|
172
|
+
<h3 id="extension-usage">Extension Usage</h3>
|
173
|
+
<p>In Ravensat::Extension, C-like variable definitions are available.</p>
|
174
|
+
|
175
|
+
<p><em>Note: In Ravensat::Extension, all undefined variables and methods are caught by method_missing method.</em></p>
|
176
|
+
|
177
|
+
<p>```ruby
|
178
|
+
require ‘ravensat’</p>
|
179
|
+
|
180
|
+
<p>module Ravensat
|
181
|
+
module Extension
|
182
|
+
bool a, b
|
183
|
+
logic = (a | b) & (~a | b) & (a | ~b)</p>
|
184
|
+
|
185
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_solver'>solver</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Ravensat.html" title="Ravensat (module)">Ravensat</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Ravensat/Solver.html" title="Ravensat::Solver (class)">Solver</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Ravensat/Solver.html#initialize-instance_method" title="Ravensat::Solver#initialize (method)">new</a></span></span>
|
186
|
+
<span class='id identifier rubyid_solver'>solver</span><span class='period'>.</span><span class='id identifier rubyid_solve'>solve</span> <span class='id identifier rubyid_logic'>logic</span> <span class='comment'>#=> true
|
187
|
+
</span>
|
188
|
+
<span class='id identifier rubyid_a'>a</span><span class='period'>.</span><span class='id identifier rubyid_result'>result</span> <span class='comment'>#=> true
|
189
|
+
</span><span class='id identifier rubyid_b'>b</span><span class='period'>.</span><span class='id identifier rubyid_result'>result</span> <span class='comment'>#=> true end end ```
|
190
|
+
</span></code></pre>
|
191
|
+
|
192
|
+
<h3 id="extension-usagecsp-constraint-satisfaction-problem">Extension Usage(CSP; Constraint Satisfaction Problem)</h3>
|
193
|
+
<p>It is possible to define integer variables and to describe some integer constraints.</p>
|
194
|
+
|
195
|
+
<p>```ruby
|
196
|
+
require ‘ravensat’</p>
|
197
|
+
|
198
|
+
<p>module Ravensat
|
199
|
+
module Extension
|
200
|
+
int a(1..10), b(1..10)
|
201
|
+
constraint = (a.only_one & b.only_one & (a != b))</p>
|
202
|
+
|
203
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_solver'>solver</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Ravensat.html" title="Ravensat (module)">Ravensat</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Ravensat/Solver.html" title="Ravensat::Solver (class)">Solver</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Ravensat/Solver.html#initialize-instance_method" title="Ravensat::Solver#initialize (method)">new</a></span></span>
|
204
|
+
<span class='id identifier rubyid_solver'>solver</span><span class='period'>.</span><span class='id identifier rubyid_solve'>solve</span> <span class='id identifier rubyid_constraint'>constraint</span> <span class='comment'>#=> true
|
205
|
+
</span>
|
206
|
+
<span class='id identifier rubyid_a'>a</span><span class='period'>.</span><span class='id identifier rubyid_result'>result</span> <span class='comment'>#=> 1
|
207
|
+
</span><span class='id identifier rubyid_b'>b</span><span class='period'>.</span><span class='id identifier rubyid_result'>result</span> <span class='comment'>#=> 2 end end ```
|
208
|
+
</span></code></pre>
|
209
|
+
|
210
|
+
<h2 id="development">Development</h2>
|
211
|
+
|
212
|
+
<p>After checking out the repo, run <code>bin/setup</code> to install dependencies. Then, run <code>rake spec</code> to run the tests. You can also run <code>bin/console</code> for an interactive prompt that will allow you to experiment.</p>
|
213
|
+
|
214
|
+
<p>To install this gem onto your local machine, run <code>bundle exec rake install</code>. To release a new version, update the version number in <code>version.rb</code>, and then run <code>bundle exec rake release</code>, which will create a git tag for the version, push git commits and the created tag, and push the <code>.gem</code> file to <a href="https://rubygems.org">rubygems.org</a>.</p>
|
215
|
+
|
216
|
+
<h2 id="contributing">Contributing</h2>
|
217
|
+
|
218
|
+
<p>Bug reports and pull requests are welcome on GitHub at https://github.com/matsuda0528/ravensat.</p>
|
219
|
+
|
220
|
+
<h2 id="license">License</h2>
|
221
|
+
|
222
|
+
<p>The gem is available as open source under the terms of the <a href="https://opensource.org/licenses/MIT">MIT License</a>.</p>
|
223
|
+
</div></div>
|
224
|
+
|
225
|
+
<div id="footer">
|
226
|
+
Generated on Wed May 25 14:42:45 2022 by
|
227
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
228
|
+
0.9.27 (ruby-3.0.0).
|
229
|
+
</div>
|
230
|
+
|
231
|
+
</div>
|
232
|
+
</body>
|
233
|
+
</html>
|