ravensat 0.2.2 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/main.yml +18 -0
  3. data/README.md +122 -9
  4. data/docs/Arcteryx/CNF.html +827 -0
  5. data/docs/Arcteryx.html +309 -0
  6. data/docs/Ravensat/AndNode.html +159 -0
  7. data/docs/Ravensat/Claw.html +338 -0
  8. data/docs/Ravensat/DimacsDecoder.html +224 -0
  9. data/docs/Ravensat/DimacsEncoder.html +425 -0
  10. data/docs/Ravensat/Extension/BooleanVariable.html +229 -0
  11. data/docs/Ravensat/Extension/Domain.html +319 -0
  12. data/docs/Ravensat/Extension/IntegerVariable.html +589 -0
  13. data/docs/Ravensat/Extension/UndefinedVariable.html +236 -0
  14. data/docs/Ravensat/Extension/Variable.html +443 -0
  15. data/docs/Ravensat/Extension.html +141 -0
  16. data/docs/Ravensat/InitialNode.html +267 -0
  17. data/docs/Ravensat/Node.html +780 -0
  18. data/docs/Ravensat/NotNode.html +159 -0
  19. data/docs/Ravensat/OprNode.html +226 -0
  20. data/docs/Ravensat/OrNode.html +252 -0
  21. data/docs/Ravensat/Solver.html +373 -0
  22. data/docs/Ravensat/VarNode.html +488 -0
  23. data/docs/Ravensat.html +135 -0
  24. data/docs/_index.html +329 -0
  25. data/docs/class_list.html +51 -0
  26. data/docs/css/common.css +1 -0
  27. data/docs/css/full_list.css +58 -0
  28. data/docs/css/style.css +497 -0
  29. data/docs/file.README.html +233 -0
  30. data/docs/file_list.html +56 -0
  31. data/docs/frames.html +17 -0
  32. data/docs/index.html +233 -0
  33. data/docs/js/app.js +314 -0
  34. data/docs/js/full_list.js +216 -0
  35. data/docs/js/jquery.js +4 -0
  36. data/docs/method_list.html +523 -0
  37. data/docs/top-level-namespace.html +110 -0
  38. data/exe/ravensat +7 -0
  39. data/lib/ravensat/ast/initial_node.rb +11 -0
  40. data/lib/ravensat/ast/node.rb +17 -9
  41. data/lib/ravensat/ast/not_node.rb +3 -0
  42. data/lib/ravensat/ast/var_node.rb +4 -0
  43. data/lib/ravensat/ast.rb +11 -0
  44. data/lib/ravensat/claw.rb +44 -0
  45. data/lib/ravensat/{dimacs_decoder.rb → dimacs/dimacs_decoder.rb} +0 -0
  46. data/lib/ravensat/{dimacs_encoder.rb → dimacs/dimacs_encoder.rb} +4 -7
  47. data/lib/ravensat/dimacs.rb +6 -0
  48. data/lib/ravensat/extension/domain.rb +24 -0
  49. data/lib/ravensat/extension/variable/boolean_variable.rb +17 -0
  50. data/lib/ravensat/extension/variable/integer_variable.rb +63 -0
  51. data/lib/ravensat/extension/variable/undefined_variable.rb +9 -0
  52. data/lib/ravensat/extension/variable/variable.rb +16 -0
  53. data/lib/ravensat/extension.rb +13 -0
  54. data/lib/ravensat/solver.rb +0 -7
  55. data/lib/ravensat/version.rb +1 -1
  56. data/lib/ravensat.rb +5 -10
  57. metadata +52 -6
  58. data/lib/ravensat/ravenclaw.rb +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2206c8010f299d713c19b74682a2c46470d0c4cc7e27ade7e429ee0de09622de
4
- data.tar.gz: 14b05657764ab053b091da8f0ddb339201ea2cd469d2828eccc04fd0b3c4e49e
3
+ metadata.gz: f369c1036cde3ea2ff754109809d5b4ce62f826a2ab409e9ec19fdd07ff341dc
4
+ data.tar.gz: 76df72fb98e5140fcd1b2b394643f23de5218ea47f4ec03f450dc0a05074f801
5
5
  SHA512:
6
- metadata.gz: ba52ce15498089d710d8e7ded3b8f35da11364a74a6f72241482ceb794cec83164423142e5b3d3feb90b0a444d8ec62327d7be830cac6d4390844fb9ce10cb6e
7
- data.tar.gz: 83509b606c6693373ce2918fe4ae9feda5aafbd241bca5510ed795cc52aae6dc0120cfc0e0294dd76a53004dbb825c1a9b0aa27664c47ff04a5e311ebf7bb167
6
+ metadata.gz: b59a47f2b7a899e49d506f839c892178523ea3920e611278e0f31399dc1c0e5c868bb8f8a74adab5a848f26f2d2efb8779f6391a20ec566ec177a1fdacfb4565
7
+ data.tar.gz: 9ed85ceb8abc589197c9241679bb5c5486ce525e427d91f84568dcc4b4ab7a58b0d110688cba999d78dacc9fd0e067d6e4f3908ef87d2d3851ed7c30331d22ca
@@ -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
- Ravensat is an interface to SAT Solver .
4
- In order to use Ravensat, you need to install SAT Solver and specify the name of the Solver .
5
- (If you do not specify SAT Solver, it will use the one bundled in the gem .)
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,6 +68,8 @@ Or install it yourself as:
22
68
  $ gem install ravensat
23
69
 
24
70
  ## Usage
71
+ ### Basic Usage
72
+ This is a basic usage example of the library.
25
73
 
26
74
  ```ruby
27
75
  require 'ravensat'
@@ -29,16 +77,71 @@ require 'ravensat'
29
77
  a = Ravensat::VarNode.new
30
78
  b = Ravensat::VarNode.new
31
79
 
32
- a.value #=> nil
33
- b.value #=> nil
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.value #=> true
41
- b.value #=> true
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
97
+ ```
98
+
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
+
110
+ ```ruby
111
+ require 'ravensat'
112
+
113
+ module Ravensat
114
+ module Extension
115
+ bool a, b
116
+ logic = (a | b) & (~a | b) & (a | ~b)
117
+
118
+ solver = Ravensat::Solver.new
119
+ solver.solve logic #=> true
120
+
121
+ a.result #=> true
122
+ b.result #=> true
123
+ end
124
+ end
125
+ ```
126
+
127
+ ### Extension Usage(CSP; Constraint Satisfaction Problem)
128
+ It is possible to define integer variables and to describe some integer constraints.
129
+
130
+ ```ruby
131
+ require 'ravensat'
132
+
133
+ module Ravensat
134
+ module Extension
135
+ int a(1..10), b(1..10)
136
+ constraint = (a.only_one & b.only_one & (a != b))
137
+
138
+ solver = Ravensat::Solver.new
139
+ solver.solve constraint #=> true
140
+
141
+ a.result #=> 1
142
+ b.result #=> 2
143
+ end
144
+ end
42
145
  ```
43
146
 
44
147
  ## Development
@@ -47,10 +150,20 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
47
150
 
48
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).
49
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
+
50
157
  ## Contributing
51
158
 
52
159
  Bug reports and pull requests are welcome on GitHub at https://github.com/matsuda0528/ravensat.
53
160
 
54
- ## License
161
+ ```
162
+ ____ _
163
+ | _ \ __ ___ _____ _ __ ___ __ _| |_
164
+ | |_) / _` \ \ / / _ \ '_ \/ __|/ _` | __|
165
+ | _ < (_| |\ V / __/ | | \__ \ (_| | |_
166
+ |_| \_\__,_| \_/ \___|_| |_|___/\__,_|\__|
167
+
168
+ ```
55
169
 
56
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).