ravensat 0.3.2 → 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/lib/ravensat/ast/and_node.rb +8 -0
- data/lib/ravensat/ast/node.rb +80 -10
- data/lib/ravensat/ast/not_node.rb +4 -0
- data/lib/ravensat/ast/or_node.rb +9 -0
- data/lib/ravensat/ast/var_node.rb +6 -1
- data/lib/ravensat/claw.rb +6 -6
- data/lib/ravensat/dimacs/dimacs_decoder.rb +9 -6
- data/lib/ravensat/dimacs/dimacs_encoder.rb +10 -13
- data/lib/ravensat/solver.rb +1 -1
- data/lib/ravensat/version.rb +1 -1
- metadata +2 -2
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
|
data/lib/ravensat/ast/node.rb
CHANGED
@@ -14,17 +14,84 @@ module Ravensat
|
|
14
14
|
# end
|
15
15
|
# end
|
16
16
|
|
17
|
+
# def each
|
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)
|
28
|
+
# end
|
29
|
+
# end
|
30
|
+
|
31
|
+
def each_DP
|
32
|
+
node_stack = [[self, self.children.clone]] #[[parent, children], ...]
|
33
|
+
|
34
|
+
until node_stack.empty?
|
35
|
+
current_parent, current_children = node_stack.pop
|
36
|
+
current_node = current_children.shift
|
37
|
+
|
38
|
+
# puts 'loop'
|
39
|
+
# puts "node_stack.size:#{node_stack.size}"
|
40
|
+
# puts "current_parent:#{current_parent.class}"
|
41
|
+
# puts "current_children.size:#{current_children.size}"
|
42
|
+
# puts "current_node:#{current_node.class}"
|
43
|
+
|
44
|
+
case current_node
|
45
|
+
when AndNode
|
46
|
+
node_stack.push [current_parent, current_children.clone]
|
47
|
+
node_stack.push [current_node, current_node.children.clone]
|
48
|
+
when OrNode
|
49
|
+
node_stack.push [current_parent, current_children.clone]
|
50
|
+
node_stack.push [current_node, current_node.children.clone]
|
51
|
+
when NotNode
|
52
|
+
yield(current_node)
|
53
|
+
yield(current_node.children.first)
|
54
|
+
|
55
|
+
if current_children.empty?
|
56
|
+
yield(node_stack.last.first)
|
57
|
+
else
|
58
|
+
yield(current_parent)
|
59
|
+
node_stack.push [current_parent, current_children.clone]
|
60
|
+
end
|
61
|
+
when VarNode, Extension::BooleanVariable
|
62
|
+
yield(current_node)
|
63
|
+
|
64
|
+
if current_children.empty?
|
65
|
+
yield(node_stack.last.first)
|
66
|
+
else
|
67
|
+
yield(current_parent)
|
68
|
+
node_stack.push [current_parent, current_children.clone]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
17
75
|
def each
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
76
|
+
return to_enum unless block_given?
|
77
|
+
node_stack = [self]
|
78
|
+
|
79
|
+
until node_stack.empty?
|
80
|
+
current_node = node_stack.shift
|
81
|
+
next unless current_node
|
82
|
+
|
83
|
+
yield current_node
|
84
|
+
|
85
|
+
node_stack = node_stack.concat(current_node.children)
|
86
|
+
end
|
87
|
+
|
88
|
+
self if block_given?
|
89
|
+
end
|
90
|
+
|
91
|
+
def each_naive
|
92
|
+
yield(self)
|
93
|
+
@children.each do |child|
|
94
|
+
child.each {|c| yield(c)}
|
28
95
|
end
|
29
96
|
end
|
30
97
|
|
@@ -40,6 +107,9 @@ module Ravensat
|
|
40
107
|
self.class.name
|
41
108
|
end
|
42
109
|
|
110
|
+
def to_dimacs
|
111
|
+
end
|
112
|
+
|
43
113
|
def cnf?
|
44
114
|
@children.map(&:cnf?).reduce(:&)
|
45
115
|
end
|
data/lib/ravensat/ast/or_node.rb
CHANGED
@@ -1,8 +1,17 @@
|
|
1
1
|
module Ravensat
|
2
2
|
class OrNode < OprNode
|
3
|
+
def |(object)
|
4
|
+
@children.append object
|
5
|
+
self
|
6
|
+
end
|
7
|
+
|
3
8
|
def cnf?
|
4
9
|
return false if @children.any?{|node| node.is_a? AndNode}
|
5
10
|
@children.map(&:cnf?).reduce(:&)
|
6
11
|
end
|
12
|
+
|
13
|
+
def to_dimacs
|
14
|
+
" "
|
15
|
+
end
|
7
16
|
end
|
8
17
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module Ravensat
|
2
2
|
class VarNode < Node
|
3
|
-
attr_accessor :value
|
3
|
+
attr_accessor :value, :dimacs_name
|
4
4
|
def initialize
|
5
5
|
@value
|
6
6
|
@children = []
|
7
|
+
@dimacs_name
|
7
8
|
end
|
8
9
|
|
9
10
|
def ~@
|
@@ -17,5 +18,9 @@ module Ravensat
|
|
17
18
|
def result
|
18
19
|
@value
|
19
20
|
end
|
21
|
+
|
22
|
+
def to_dimacs
|
23
|
+
@dimacs_name
|
24
|
+
end
|
20
25
|
end
|
21
26
|
end
|
data/lib/ravensat/claw.rb
CHANGED
@@ -12,20 +12,20 @@ module Ravensat
|
|
12
12
|
|
13
13
|
def self.commander_amo(bool_vars)
|
14
14
|
m = bool_vars.size / 2
|
15
|
-
|
15
|
+
commander_variables = []
|
16
16
|
formula = Ravensat::InitialNode.new
|
17
|
-
bool_vars.each_slice(2) do |
|
17
|
+
bool_vars.each_slice(2) do |g|
|
18
18
|
c = Ravensat::VarNode.new
|
19
|
-
subset =
|
19
|
+
subset = g << ~c
|
20
20
|
formula &= pairwise_amo(subset)
|
21
21
|
formula &= alo(subset)
|
22
|
-
|
22
|
+
commander_variables << c
|
23
23
|
end
|
24
24
|
|
25
25
|
if m < 6
|
26
|
-
formula &= pairwise_amo(
|
26
|
+
formula &= pairwise_amo(commander_variables)
|
27
27
|
else
|
28
|
-
formula &= commander_amo(
|
28
|
+
formula &= commander_amo(commander_variables)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -1,18 +1,21 @@
|
|
1
1
|
module Ravensat
|
2
2
|
class DimacsDecoder
|
3
|
-
def decode(model,
|
4
|
-
inverted_name_table = name_table.invert
|
3
|
+
def decode(model, cnf)
|
4
|
+
# inverted_name_table = name_table.invert
|
5
|
+
prop_vars = cnf.vars
|
5
6
|
case model.first
|
6
7
|
when "SAT"
|
7
8
|
model.last.split.each do |e|
|
8
9
|
if e == '0'
|
9
10
|
next
|
10
11
|
elsif e[0] == "-"
|
11
|
-
|
12
|
-
|
12
|
+
dimacs_name = e.slice(1..-1)
|
13
|
+
var = prop_vars.find{|i| i.dimacs_name == dimacs_name}
|
14
|
+
var.value = false
|
13
15
|
else
|
14
|
-
|
15
|
-
|
16
|
+
dimacs_name = e
|
17
|
+
var = prop_vars.find{|i| i.dimacs_name == dimacs_name}
|
18
|
+
var.value = true
|
16
19
|
end
|
17
20
|
end
|
18
21
|
true
|
@@ -6,26 +6,23 @@ module Ravensat
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def to_dimacs(formula)
|
9
|
-
return nil unless formula.cnf?
|
10
|
-
|
11
9
|
dimacs_header = "p cnf #{formula.vars_size} #{formula.clauses_size}\n"
|
12
10
|
dimacs_body = ""
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
when VarNode then dimacs_body << @name_table[node]
|
20
|
-
end
|
11
|
+
return nil unless formula.cnf?
|
12
|
+
|
13
|
+
set_dimacs_name(formula)
|
14
|
+
|
15
|
+
formula.each_DP do |node|
|
16
|
+
dimacs_body << node.to_dimacs
|
21
17
|
end
|
22
|
-
dimacs_body << " 0\n"
|
23
18
|
|
24
19
|
dimacs_header + dimacs_body
|
25
20
|
end
|
26
21
|
|
27
|
-
def
|
28
|
-
|
22
|
+
def set_dimacs_name(formula)
|
23
|
+
formula.vars.each_with_index do |node, i|
|
24
|
+
node.dimacs_name = (i+1).to_s
|
25
|
+
end
|
29
26
|
end
|
30
27
|
end
|
31
28
|
end
|
data/lib/ravensat/solver.rb
CHANGED
data/lib/ravensat/version.rb
CHANGED
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.
|
4
|
+
version: 1.0.0
|
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-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|