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
data/lib/ravensat/ast/node.rb
CHANGED
@@ -7,10 +7,24 @@ module Ravensat
|
|
7
7
|
@children = []
|
8
8
|
end
|
9
9
|
|
10
|
+
# def each
|
11
|
+
# yield(self)
|
12
|
+
# @children.each do |child|
|
13
|
+
# child.each {|c| yield(c)}
|
14
|
+
# end
|
15
|
+
# end
|
16
|
+
|
10
17
|
def each
|
11
|
-
|
12
|
-
|
13
|
-
|
18
|
+
case self
|
19
|
+
when AndNode, OrNode
|
20
|
+
@children.first.each{|c| yield(c)}
|
21
|
+
yield(self)
|
22
|
+
@children.last.each{|c| yield(c)}
|
23
|
+
when NotNode
|
24
|
+
yield(self)
|
25
|
+
@children.first.each{|c| yield(c)}
|
26
|
+
when VarNode
|
27
|
+
yield(self)
|
14
28
|
end
|
15
29
|
end
|
16
30
|
|
@@ -22,12 +36,6 @@ module Ravensat
|
|
22
36
|
OrNode.new(self, object)
|
23
37
|
end
|
24
38
|
|
25
|
-
# def tree_text
|
26
|
-
# self.each do |child|
|
27
|
-
# child.to_s
|
28
|
-
# end
|
29
|
-
# end
|
30
|
-
|
31
39
|
def to_s
|
32
40
|
self.class.name
|
33
41
|
end
|
data/lib/ravensat/ast.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
module Ravensat
|
2
|
+
dir = File.dirname(__FILE__) + '/ast'
|
3
|
+
|
4
|
+
autoload :Node, dir + '/node.rb'
|
5
|
+
autoload :VarNode, dir + '/var_node.rb'
|
6
|
+
autoload :OprNode, dir + '/opr_node.rb'
|
7
|
+
autoload :AndNode, dir + '/and_node.rb'
|
8
|
+
autoload :OrNode, dir + '/or_node.rb'
|
9
|
+
autoload :NotNode, dir + '/not_node.rb'
|
10
|
+
autoload :InitialNode, dir + '/initial_node.rb'
|
11
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Ravensat
|
2
|
+
module Claw
|
3
|
+
def self.alo(bool_vars)
|
4
|
+
bool_vars.reduce(:|)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.pairwise_amo(bool_vars)
|
8
|
+
bool_vars.combination(2).map do |e|
|
9
|
+
e.map(&:~@).reduce(:|)
|
10
|
+
end.reduce(:&)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.commander_amo(bool_vars)
|
14
|
+
m = bool_vars.size / 2
|
15
|
+
introductory_variables = []
|
16
|
+
formula = Ravensat::InitialNode.new
|
17
|
+
bool_vars.each_slice(2) do |e|
|
18
|
+
c = Ravensat::VarNode.new
|
19
|
+
subset = e << ~c
|
20
|
+
formula &= pairwise_amo(subset)
|
21
|
+
formula &= alo(subset)
|
22
|
+
introductory_variables << c
|
23
|
+
end
|
24
|
+
|
25
|
+
if m < 6
|
26
|
+
formula &= pairwise_amo(introductory_variables)
|
27
|
+
else
|
28
|
+
formula &= commander_amo(introductory_variables)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.all_different(*int_vars)
|
33
|
+
int_vars.combination(2).map do |int_var|
|
34
|
+
int_var.reduce(:!=)
|
35
|
+
end.reduce(:&)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.all_only_one(*int_vars)
|
39
|
+
int_vars.map(&:only_one).reduce(:&)
|
40
|
+
end
|
41
|
+
|
42
|
+
# alias :amo :pairwise_amo
|
43
|
+
end
|
44
|
+
end
|
File without changes
|
@@ -13,16 +13,13 @@ module Ravensat
|
|
13
13
|
create_table(formula)
|
14
14
|
formula.each do |node|
|
15
15
|
case node
|
16
|
-
when AndNode
|
17
|
-
when OrNode then dimacs_body << "
|
16
|
+
when AndNode then dimacs_body << " 0\n"
|
17
|
+
when OrNode then dimacs_body << " "
|
18
18
|
when NotNode then dimacs_body << "-"
|
19
|
-
when VarNode then dimacs_body << @name_table[node]
|
19
|
+
when VarNode then dimacs_body << @name_table[node]
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
23
|
-
# dimacs_body formatting
|
24
|
-
dimacs_body.strip! << ' '
|
25
|
-
dimacs_body.gsub!(/\n{2,}/, "\n").gsub!(/\n/, "0\n") << '0'
|
22
|
+
dimacs_body << " 0\n"
|
26
23
|
|
27
24
|
dimacs_header + dimacs_body
|
28
25
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Ravensat
|
2
|
+
module Extension
|
3
|
+
module Domain
|
4
|
+
LOCAL_VARIABLE_TABLE = {}
|
5
|
+
def int(*vars)
|
6
|
+
vars.each do |var|
|
7
|
+
next if var.is_defined?
|
8
|
+
LOCAL_VARIABLE_TABLE[var.name] = Ravensat::Extension::IntegerVariable.new(var.name, var.args)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def bool(*vars)
|
13
|
+
vars.each do |var|
|
14
|
+
next if var.is_defined?
|
15
|
+
LOCAL_VARIABLE_TABLE[var.name] = Ravensat::Extension::BooleanVariable.new(var.name, var.args)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def method_missing(name, *args)
|
20
|
+
LOCAL_VARIABLE_TABLE[name] || UndefinedVariable.new(name, args)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module Ravensat
|
4
|
+
module Extension
|
5
|
+
class BooleanVariable < Variable
|
6
|
+
extend Forwardable
|
7
|
+
delegate Node.public_instance_methods(false) => :@var_node
|
8
|
+
delegate OprNode.public_instance_methods(false) => :@var_node
|
9
|
+
delegate VarNode.public_instance_methods(false) => :@var_node
|
10
|
+
|
11
|
+
def initialize(name, args)
|
12
|
+
super
|
13
|
+
@var_node = VarNode.new
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Ravensat
|
2
|
+
module Extension
|
3
|
+
class IntegerVariable < Variable
|
4
|
+
|
5
|
+
attr_reader :var_nodes
|
6
|
+
def initialize(name, args)
|
7
|
+
super
|
8
|
+
return unless args.first.is_a? Range
|
9
|
+
@var_nodes = args.first.zip(Array.new(args.first.size){Ravensat::VarNode.new}).to_h
|
10
|
+
end
|
11
|
+
|
12
|
+
def ==(object)
|
13
|
+
case object
|
14
|
+
when Integer
|
15
|
+
return @var_nodes[object]
|
16
|
+
when IntegerVariable
|
17
|
+
result_formula = Ravensat::InitialNode.new
|
18
|
+
duplicated_keys = self.var_nodes.keys & object.var_nodes.keys
|
19
|
+
|
20
|
+
[self.var_nodes, object.var_nodes].repeated_permutation(duplicated_keys.size) do |var_nodes|
|
21
|
+
result_formula &= Ravensat::Claw.alo(var_nodes.zip(duplicated_keys).map{|arr| arr.first[arr.last]})
|
22
|
+
end
|
23
|
+
return result_formula
|
24
|
+
else
|
25
|
+
raise ArgumentError
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def !=(object)
|
30
|
+
case object
|
31
|
+
when Integer
|
32
|
+
return ~(@var_nodes[object])
|
33
|
+
when IntegerVariable
|
34
|
+
result_formula = Ravensat::InitialNode.new
|
35
|
+
duplicated_keys = self.var_nodes.keys & object.var_nodes.keys
|
36
|
+
|
37
|
+
duplicated_keys.each do |index|
|
38
|
+
result_formula &= ~(self.var_nodes[index]) | ~(object.var_nodes[index])
|
39
|
+
end
|
40
|
+
return result_formula
|
41
|
+
else
|
42
|
+
raise ArgumentError
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def only_one
|
47
|
+
result_formula = Ravensat::InitialNode.new
|
48
|
+
result_formula &= Ravensat::Claw.alo @var_nodes.values
|
49
|
+
result_formula &= Ravensat::Claw.amo @var_nodes.values
|
50
|
+
result_formula
|
51
|
+
end
|
52
|
+
|
53
|
+
def result
|
54
|
+
result = @var_nodes.select{|key, var_node| var_node.value}.keys
|
55
|
+
if result.one?
|
56
|
+
result.first
|
57
|
+
else
|
58
|
+
result
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Ravensat
|
2
|
+
module Extension
|
3
|
+
dir = File.dirname(__FILE__) + '/extension'
|
4
|
+
|
5
|
+
autoload :Domain, dir + '/domain.rb'
|
6
|
+
autoload :Variable, dir + '/variable/variable.rb'
|
7
|
+
autoload :BooleanVariable, dir + '/variable/boolean_variable.rb'
|
8
|
+
autoload :IntegerVariable, dir + '/variable/integer_variable.rb'
|
9
|
+
autoload :UndefinedVariable, dir + '/variable/undefined_variable.rb'
|
10
|
+
|
11
|
+
extend Domain
|
12
|
+
end
|
13
|
+
end
|
data/lib/ravensat/solver.rb
CHANGED
@@ -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"])
|
data/lib/ravensat/version.rb
CHANGED
data/lib/ravensat.rb
CHANGED
@@ -7,17 +7,12 @@ module Ravensat
|
|
7
7
|
ast = File.dirname(__FILE__) + '/ravensat/ast'
|
8
8
|
arcteryx = File.dirname(__FILE__) + '/arcteryx'
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
autoload :DimacsDecoder, ravensat + '/dimacs_decoder.rb'
|
13
|
-
autoload :RavenClaw, ravensat + '/ravenclaw.rb'
|
10
|
+
require_relative ravensat + "/ast.rb"
|
11
|
+
require_relative ravensat + "/dimacs.rb"
|
14
12
|
|
15
|
-
autoload :
|
16
|
-
autoload :
|
17
|
-
autoload :
|
18
|
-
autoload :AndNode, ast + '/and_node.rb'
|
19
|
-
autoload :OrNode, ast + '/or_node.rb'
|
20
|
-
autoload :NotNode, ast + '/not_node.rb'
|
13
|
+
autoload :Solver, ravensat + '/solver.rb'
|
14
|
+
autoload :Claw, ravensat + '/claw.rb'
|
15
|
+
autoload :Extension, ravensat + '/extension.rb'
|
21
16
|
|
22
17
|
autoload :Arcteryx, arcteryx + '/arcteryx.rb'
|
23
18
|
end
|
metadata
CHANGED
@@ -1,22 +1,24 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ravensat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.2
|
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-
|
11
|
+
date: 2022-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
15
15
|
- p99y92og@s.okayama-u.ac.jp
|
16
|
-
executables:
|
16
|
+
executables:
|
17
|
+
- ravensat
|
17
18
|
extensions: []
|
18
19
|
extra_rdoc_files: []
|
19
20
|
files:
|
21
|
+
- ".github/workflows/main.yml"
|
20
22
|
- ".gitignore"
|
21
23
|
- ".rspec"
|
22
24
|
- ".ruby-version"
|
@@ -27,19 +29,63 @@ files:
|
|
27
29
|
- Rakefile
|
28
30
|
- bin/console
|
29
31
|
- bin/setup
|
32
|
+
- docs/Arcteryx.html
|
33
|
+
- docs/Arcteryx/CNF.html
|
34
|
+
- docs/Ravensat.html
|
35
|
+
- docs/Ravensat/AndNode.html
|
36
|
+
- docs/Ravensat/Claw.html
|
37
|
+
- docs/Ravensat/DimacsDecoder.html
|
38
|
+
- docs/Ravensat/DimacsEncoder.html
|
39
|
+
- docs/Ravensat/Extension.html
|
40
|
+
- docs/Ravensat/Extension/BooleanVariable.html
|
41
|
+
- docs/Ravensat/Extension/Domain.html
|
42
|
+
- docs/Ravensat/Extension/IntegerVariable.html
|
43
|
+
- docs/Ravensat/Extension/UndefinedVariable.html
|
44
|
+
- docs/Ravensat/Extension/Variable.html
|
45
|
+
- docs/Ravensat/InitialNode.html
|
46
|
+
- docs/Ravensat/Node.html
|
47
|
+
- docs/Ravensat/NotNode.html
|
48
|
+
- docs/Ravensat/OprNode.html
|
49
|
+
- docs/Ravensat/OrNode.html
|
50
|
+
- docs/Ravensat/Solver.html
|
51
|
+
- docs/Ravensat/VarNode.html
|
52
|
+
- docs/_index.html
|
53
|
+
- docs/class_list.html
|
54
|
+
- docs/css/common.css
|
55
|
+
- docs/css/full_list.css
|
56
|
+
- docs/css/style.css
|
57
|
+
- docs/file.README.html
|
58
|
+
- docs/file_list.html
|
59
|
+
- docs/frames.html
|
60
|
+
- docs/index.html
|
61
|
+
- docs/js/app.js
|
62
|
+
- docs/js/full_list.js
|
63
|
+
- docs/js/jquery.js
|
64
|
+
- docs/method_list.html
|
65
|
+
- docs/top-level-namespace.html
|
30
66
|
- example/magic_square_3x3.rb
|
67
|
+
- exe/ravensat
|
31
68
|
- lib/arcteryx/arcteryx.rb
|
32
69
|
- lib/arcteryx/cnf.rb
|
33
70
|
- lib/ravensat.rb
|
71
|
+
- lib/ravensat/ast.rb
|
34
72
|
- lib/ravensat/ast/and_node.rb
|
73
|
+
- lib/ravensat/ast/initial_node.rb
|
35
74
|
- lib/ravensat/ast/node.rb
|
36
75
|
- lib/ravensat/ast/not_node.rb
|
37
76
|
- lib/ravensat/ast/opr_node.rb
|
38
77
|
- lib/ravensat/ast/or_node.rb
|
39
78
|
- lib/ravensat/ast/var_node.rb
|
40
|
-
- lib/ravensat/
|
41
|
-
- lib/ravensat/
|
42
|
-
- lib/ravensat/
|
79
|
+
- lib/ravensat/claw.rb
|
80
|
+
- lib/ravensat/dimacs.rb
|
81
|
+
- lib/ravensat/dimacs/dimacs_decoder.rb
|
82
|
+
- lib/ravensat/dimacs/dimacs_encoder.rb
|
83
|
+
- lib/ravensat/extension.rb
|
84
|
+
- lib/ravensat/extension/domain.rb
|
85
|
+
- lib/ravensat/extension/variable/boolean_variable.rb
|
86
|
+
- lib/ravensat/extension/variable/integer_variable.rb
|
87
|
+
- lib/ravensat/extension/variable/undefined_variable.rb
|
88
|
+
- lib/ravensat/extension/variable/variable.rb
|
43
89
|
- lib/ravensat/solver.rb
|
44
90
|
- lib/ravensat/version.rb
|
45
91
|
- ravensat.gemspec
|
data/lib/ravensat/ravenclaw.rb
DELETED