ravensat 1.0.9 → 1.1.1
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 +4 -0
- data/lib/ravensat/ast/node.rb +3 -0
- data/lib/ravensat/ast/not_node.rb +4 -0
- data/lib/ravensat/ast/or_node.rb +4 -0
- data/lib/ravensat/ast/var_node.rb +4 -0
- data/lib/ravensat/claw.rb +47 -15
- 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: 6bfe00570d2de6c7da2dfe2075f99d3372435290235f4f581c82697a19e9e415
|
4
|
+
data.tar.gz: 25e100b47651b0b146e7f392bc793059a0702bb58fe663618d3f2501059c7783
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cdb626e3c97e72cb4b3221a6a89857cc1fe4d8704235f73b504ed3c2e0fcea13d49d3f17f074bf62ea982c64c5663708332ad86494d59c3bc8403a3c2d9c67c
|
7
|
+
data.tar.gz: 152988e5e50542e1bd63c842cee4024144c8154fbf6567383eebfd35dfff530de1342e0f44a3ec30365845aff79e41c964dd8fafb2d626718c94805162b95115
|
data/lib/ravensat/ast/node.rb
CHANGED
data/lib/ravensat/ast/or_node.rb
CHANGED
data/lib/ravensat/claw.rb
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
module Ravensat
|
2
2
|
module Claw
|
3
|
-
def self.
|
3
|
+
def self.at_most_one(bool_vars)
|
4
|
+
return Ravensat::NilNode.new if bool_vars.size == 1
|
5
|
+
bool_vars.combination(2).map do |e|
|
6
|
+
e.map(&:~@).reduce(:|)
|
7
|
+
end.reduce(:&)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.at_least_one(bool_vars)
|
4
11
|
return Ravensat::NilNode.new if bool_vars.size == 1
|
5
12
|
bool_vars.reduce(:|)
|
6
13
|
end
|
@@ -15,19 +22,13 @@ module Ravensat
|
|
15
22
|
def self.at_least_k(bool_vars, k)
|
16
23
|
return Ravensat::NilNode.new if bool_vars.size == 1
|
17
24
|
bool_vars.combination(k-1).map do |e|
|
18
|
-
|
25
|
+
at_least_one(bool_vars - e)
|
19
26
|
end.reduce(:&)
|
20
27
|
end
|
21
28
|
|
22
|
-
def self.pairwise_amo(bool_vars)
|
23
|
-
return Ravensat::NilNode.new if bool_vars.size == 1
|
24
|
-
bool_vars.combination(2).map do |e|
|
25
|
-
e.map(&:~@).reduce(:|)
|
26
|
-
end.reduce(:&)
|
27
|
-
end
|
28
29
|
|
29
30
|
# NOTE: Klieber, W. and Kwon, G.: Efficient CNF Encoding for Selecting 1 from N Objects (2007).
|
30
|
-
def self.
|
31
|
+
def self.commander_at_most_one(bool_vars)
|
31
32
|
return Ravensat::NilNode.new if bool_vars.size == 1
|
32
33
|
# XXX: Operator unknown if bool_vars.size is very small.
|
33
34
|
m = bool_vars.size / 2
|
@@ -36,16 +37,49 @@ module Ravensat
|
|
36
37
|
bool_vars.each_slice(2) do |g|
|
37
38
|
c = Ravensat::VarNode.new
|
38
39
|
subset = g << ~c
|
39
|
-
formula &=
|
40
|
-
formula &=
|
40
|
+
formula &= at_most_one(subset)
|
41
|
+
formula &= at_least_one(subset)
|
41
42
|
commander_variables << c
|
42
43
|
end
|
43
44
|
|
44
45
|
if m < 6
|
45
|
-
formula &=
|
46
|
+
formula &= at_most_one(commander_variables)
|
46
47
|
else
|
47
|
-
formula &=
|
48
|
+
formula &= commander_at_most_one(commander_variables)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.commander_at_most_k(bool_vars, k)
|
53
|
+
return Ravensat::NilNode.new if bool_vars.size == 1
|
54
|
+
return commander_at_most_one(bool_vars) if k == 1
|
55
|
+
group_size = k + 2
|
56
|
+
commander_variables = []
|
57
|
+
formula = Ravensat::InitialNode.new
|
58
|
+
|
59
|
+
bool_vars.each_slice(group_size) do |g|
|
60
|
+
cmds = Array.new(k){Ravensat::VarNode.new}
|
61
|
+
subset = g + cmds.map(&:~)
|
62
|
+
formula &= at_most_k(subset, k)
|
63
|
+
formula &= at_least_k(subset, k)
|
64
|
+
cmds.each_cons(2) do |e1, e2|
|
65
|
+
formula &= ~e1 | e2
|
66
|
+
end
|
67
|
+
commander_variables += cmds
|
48
68
|
end
|
69
|
+
|
70
|
+
formula &= at_most_k(commander_variables, k)
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.exactly_one(bool_vars)
|
74
|
+
formula = Ravensat::InitialNode.new
|
75
|
+
formula &= commander_at_most_one(bool_vars)
|
76
|
+
formula &= at_least_one(bool_vars)
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.exactly_k(bool_vars, k)
|
80
|
+
formula = Ravensat::InitialNode.new
|
81
|
+
formula &= commander_at_most_k(bool_vars, k)
|
82
|
+
formula &= at_least_k(bool_vars, k)
|
49
83
|
end
|
50
84
|
|
51
85
|
def self.all_different(*int_vars)
|
@@ -57,7 +91,5 @@ module Ravensat
|
|
57
91
|
def self.all_only_one(*int_vars)
|
58
92
|
int_vars.map(&:only_one).reduce(:&)
|
59
93
|
end
|
60
|
-
|
61
|
-
# alias :amo :pairwise_amo
|
62
94
|
end
|
63
95
|
end
|
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: 1.
|
4
|
+
version: 1.1.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-
|
11
|
+
date: 2022-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|