ravensat 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d0f5a2e88e6b17130dc2101a9c2e85d0e401fba9bcba081299cf14ded1c683b
4
- data.tar.gz: ee09cdeb7da7fd0cd04a80a5017ae351b836cf9a6d63ab92fddaa9181f36dff2
3
+ metadata.gz: 47afc062227efddad35ed4643e28c4eea8957ecb32c8aa34d3c69a9ff52d3a88
4
+ data.tar.gz: a39c4f15fb17321ded803e79b702c55150197b3a613a340ca4a728e0a6a27402
5
5
  SHA512:
6
- metadata.gz: d763bab0b969a710ef42cae2e1aed39161e4b49488c1d898f8665b14a4763df09a881508875576f6505fc25c75daed694b805cb82ca081c95ac61d31bb49c12d
7
- data.tar.gz: d5ff19dd7503194401664bba22b12bbe16a7ce8b6f1ff8cb54d19d1fcfde0d8912ad25d9762549d19f50dcc0d9d82161f020fae1c1207bd015ce530178eb8b62
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
- 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
+ [![Ruby](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
+ 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
- ### General Usage
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.value #=> nil
33
- b.value #=> nil
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
- a.value #=> true
41
- b.value #=> true
86
+ # Refer to the satisfiability
87
+ a.result #=> true
88
+ b.result #=> true
42
89
  ```
43
90
 
44
- ### Extension Usage(SAT)
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.value #=> true
57
- b.value #=> true
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
@@ -4,8 +4,4 @@ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
4
  require 'ravensat'
5
5
  require 'pry'
6
6
 
7
- module Ravensat
8
- module Extension
9
- binding.pry
10
- end
11
- end
7
+ Pry.start(Ravensat::Extension)
@@ -36,12 +36,6 @@ module Ravensat
36
36
  OrNode.new(self, object)
37
37
  end
38
38
 
39
- # def tree_text
40
- # self.each do |child|
41
- # child.to_s
42
- # end
43
- # end
44
-
45
39
  def to_s
46
40
  self.class.name
47
41
  end
@@ -13,5 +13,9 @@ module Ravensat
13
13
  def cnf?
14
14
  true
15
15
  end
16
+
17
+ def result
18
+ @value
19
+ end
16
20
  end
17
21
  end
@@ -12,7 +12,6 @@ module Ravensat
12
12
  def bool(*vars)
13
13
  vars.each do |var|
14
14
  next if var.is_defined?
15
- # LOCAL_VARIABLE_TABLE[var.name] = Ravensat::VarNode.new
16
15
  LOCAL_VARIABLE_TABLE[var.name] = Ravensat::Extension::BooleanVariable.new(var.name, var.args)
17
16
  end
18
17
  end
@@ -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"])
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ravensat
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.1"
5
5
  end
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.0
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-18 00:00:00.000000000 Z
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"