z3 0.0.20220630 → 0.0.20220828

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: a9289c94f0a177c8e59d2c18c65775344414bb3558151ac58fc02e932b3a7eb1
4
- data.tar.gz: 3171e750dc3a36d1534ffc0c069274ff8bc7bc4d59d15e6792add5c4ab5f90b6
3
+ metadata.gz: 94779e8d2fdaee7a213640164c8113fee96135e5247d9dc161d02dae87da6e94
4
+ data.tar.gz: d11a1326c693216fe857b436460d63176b466cc8b9927378940fc5543506a02e
5
5
  SHA512:
6
- metadata.gz: d19511280987279176db440a5c5f3764d9029b49c74185c32cbf3dd01e6f02bcefa92b5800b24d4e872f052cb40a8daddf756783c81f3fdb63055d1be950b119
7
- data.tar.gz: '09eedf827d3dfae3c56fd6d1c165160cdb5e3aeab0e2faae429dd81da91b7eaafd6640a6f28ed2a1b45e8a3a3c3e12a03d38327e86ac497b69e974e5f431cee6'
6
+ metadata.gz: 5282dc961ae5f4f9dbe08c3f0e225ad3e8849522d5f0f7de7deaa233463479197498c91327dc8e6455478ee4469cbec660f6c278a45b09218a45e3d3d8f5736d
7
+ data.tar.gz: b884d26fb02ec6714d5ff54e862cbe5dccec2853b4ebcdda84410ccda65fc7693428e163b390a7d71b741a538d5ef9e0c5aac365d8709ff301e0344bb7bd8880
data/lib/z3/optimize.rb CHANGED
@@ -23,9 +23,9 @@ module Z3
23
23
  LowLevel.optimize_assert(self, ast)
24
24
  end
25
25
 
26
- def assert_soft(ast)
26
+ def assert_soft(ast, weight = "1", id = nil)
27
27
  reset_model!
28
- LowLevel.optimize_assert_soft(self, ast)
28
+ LowLevel.optimize_assert_soft(self, ast, weight, id)
29
29
  end
30
30
 
31
31
  def check(*args)
@@ -1,21 +1,5 @@
1
- # There are multiple solutions, so this test is nondeterministic
2
- # This is what Z3 4.8.13 returns
3
1
  describe "ABC Path" do
4
2
  it do
5
- expect("abc_path").to have_output <<'EOF'
6
- C O R D F B U
7
-
8
- N o-n l-k-j L
9
- | |/ |
10
- G p m g-f i I
11
- | x /
12
- Q q-r e h a H
13
- / | |
14
- V s v d-c-b S
15
- x \
16
- T u-t w-x-y X
17
-
18
- J P M W K Y E
19
- EOF
3
+ expect("abc_path").to have_output_matching_saved_example
20
4
  end
21
5
  end
@@ -0,0 +1,13 @@
1
+ C O R D F B U
2
+
3
+ N o-n l-k-j L
4
+ | |/ |
5
+ G p m g-f i I
6
+ | x /
7
+ Q q-r e h a H
8
+ / | |
9
+ V s v d-c-b S
10
+ x \
11
+ T u-t w-x-y X
12
+
13
+ J P M W K Y E
@@ -0,0 +1,13 @@
1
+ C O R D F B U
2
+
3
+ N o-n l-k-j L
4
+ | |/ |
5
+ G p m g-f i I
6
+ | x /
7
+ Q q-r e h b H
8
+ / | /|
9
+ V s v d-c a S
10
+ x \
11
+ T u-t w-x-y X
12
+
13
+ J P M W K Y E
@@ -0,0 +1,17 @@
1
+ 2 5 3 4 1 7 6<9 8
2
+
3
+ 1 9 7 2 8 5 3<4<6
4
+ _
5
+ 7<8 2 5>3>1 4<6 9
6
+ ^
7
+ 8 1<5<9 7 6 2 3 4
8
+ ^
9
+ 4 7>6>1 9 2 5 8 3
10
+ ^ ^ ^
11
+ 6 4 1 8 2 3 9 5 7
12
+ _ _ ^ _ _
13
+ 9 3 4 6>5 8 7 1 2
14
+ _
15
+ 5 2 9>3 6>4 8>7 1
16
+ _
17
+ 3 6 8>7>4 9 1<2 5
@@ -0,0 +1,17 @@
1
+ 2 5 3 4 1 7 6<9 8
2
+
3
+ 1 9 7 2 8 5 3<4<6
4
+ _
5
+ 7<8 2 5>3>1 4<6 9
6
+ ^
7
+ 8 3<5<9 7 6 2 1 4
8
+ ^
9
+ 4 7>6>1 9 2 5 8 3
10
+ ^ ^ ^
11
+ 6 4 1 8 2 3 9 5 7
12
+ _ _ ^ _ _
13
+ 9 1 4 6>5 8 7 3 2
14
+ _
15
+ 5 2 9>3 6>4 8>7 1
16
+ _
17
+ 3 6 8>7>4 9 1<2 5
@@ -0,0 +1,90 @@
1
+ Solved
2
+ State 0:
3
+ bbb.
4
+ xbxw
5
+ ..ww
6
+ x.xw
7
+ w: 2,2 -> 3,0
8
+
9
+ State 1:
10
+ bbbw
11
+ xbxw
12
+ ...w
13
+ x.xw
14
+ b: 1,0 -> 2,2
15
+
16
+ State 2:
17
+ b.bw
18
+ xbxw
19
+ ..bw
20
+ x.xw
21
+ w: 3,1 -> 1,0
22
+
23
+ State 3:
24
+ bwbw
25
+ xbx.
26
+ ..bw
27
+ x.xw
28
+ b: 0,0 -> 1,2
29
+
30
+ State 4:
31
+ .wbw
32
+ xbx.
33
+ .bbw
34
+ x.xw
35
+ b: 1,2 -> 3,1
36
+
37
+ State 5:
38
+ .wbw
39
+ xbxb
40
+ ..bw
41
+ x.xw
42
+ w: 3,3 -> 1,2
43
+
44
+ State 6:
45
+ .wbw
46
+ xbxb
47
+ .wbw
48
+ x.x.
49
+ w: 1,2 -> 0,0
50
+
51
+ State 7:
52
+ wwbw
53
+ xbxb
54
+ ..bw
55
+ x.x.
56
+ b: 2,0 -> 1,2
57
+
58
+ State 8:
59
+ ww.w
60
+ xbxb
61
+ .bbw
62
+ x.x.
63
+ w: 3,2 -> 2,0
64
+
65
+ State 9:
66
+ wwww
67
+ xbxb
68
+ .bb.
69
+ x.x.
70
+ b: 1,1 -> 3,2
71
+
72
+ State 10:
73
+ wwww
74
+ x.xb
75
+ .bbb
76
+ x.x.
77
+ b: 1,2 -> 3,3
78
+
79
+ State 11:
80
+ wwww
81
+ x.xb
82
+ ..bb
83
+ x.xb
84
+ w: 3,0 -> 1,1
85
+
86
+ State 12:
87
+ www.
88
+ xwxb
89
+ ..bb
90
+ x.xb
@@ -0,0 +1,90 @@
1
+ Solved
2
+ State 0:
3
+ bbb.
4
+ xbxw
5
+ ..ww
6
+ x.xw
7
+ w: 2,2 -> 3,0
8
+
9
+ State 1:
10
+ bbbw
11
+ xbxw
12
+ ...w
13
+ x.xw
14
+ b: 1,0 -> 2,2
15
+
16
+ State 2:
17
+ b.bw
18
+ xbxw
19
+ ..bw
20
+ x.xw
21
+ w: 3,1 -> 1,0
22
+
23
+ State 3:
24
+ bwbw
25
+ xbx.
26
+ ..bw
27
+ x.xw
28
+ b: 0,0 -> 1,2
29
+
30
+ State 4:
31
+ .wbw
32
+ xbx.
33
+ .bbw
34
+ x.xw
35
+ b: 1,2 -> 3,1
36
+
37
+ State 5:
38
+ .wbw
39
+ xbxb
40
+ ..bw
41
+ x.xw
42
+ w: 3,3 -> 1,2
43
+
44
+ State 6:
45
+ .wbw
46
+ xbxb
47
+ .wbw
48
+ x.x.
49
+ w: 1,2 -> 0,0
50
+
51
+ State 7:
52
+ wwbw
53
+ xbxb
54
+ ..bw
55
+ x.x.
56
+ b: 2,0 -> 1,2
57
+
58
+ State 8:
59
+ ww.w
60
+ xbxb
61
+ .bbw
62
+ x.x.
63
+ b: 1,2 -> 3,3
64
+
65
+ State 9:
66
+ ww.w
67
+ xbxb
68
+ ..bw
69
+ x.xb
70
+ w: 3,2 -> 2,0
71
+
72
+ State 10:
73
+ wwww
74
+ xbxb
75
+ ..b.
76
+ x.xb
77
+ b: 1,1 -> 3,2
78
+
79
+ State 11:
80
+ wwww
81
+ x.xb
82
+ ..bb
83
+ x.xb
84
+ w: 3,0 -> 1,1
85
+
86
+ State 12:
87
+ www.
88
+ xwxb
89
+ ..bb
90
+ x.xb
@@ -0,0 +1,90 @@
1
+ Solved
2
+ State 0:
3
+ bbb.
4
+ xbxw
5
+ ..ww
6
+ x.xw
7
+ w: 2,2 -> 3,0
8
+
9
+ State 1:
10
+ bbbw
11
+ xbxw
12
+ ...w
13
+ x.xw
14
+ b: 1,0 -> 2,2
15
+
16
+ State 2:
17
+ b.bw
18
+ xbxw
19
+ ..bw
20
+ x.xw
21
+ b: 0,0 -> 1,2
22
+
23
+ State 3:
24
+ ..bw
25
+ xbxw
26
+ .bbw
27
+ x.xw
28
+ w: 3,1 -> 1,0
29
+
30
+ State 4:
31
+ .wbw
32
+ xbx.
33
+ .bbw
34
+ x.xw
35
+ b: 1,2 -> 3,1
36
+
37
+ State 5:
38
+ .wbw
39
+ xbxb
40
+ ..bw
41
+ x.xw
42
+ w: 3,3 -> 1,2
43
+
44
+ State 6:
45
+ .wbw
46
+ xbxb
47
+ .wbw
48
+ x.x.
49
+ w: 1,2 -> 0,0
50
+
51
+ State 7:
52
+ wwbw
53
+ xbxb
54
+ ..bw
55
+ x.x.
56
+ b: 2,0 -> 1,2
57
+
58
+ State 8:
59
+ ww.w
60
+ xbxb
61
+ .bbw
62
+ x.x.
63
+ b: 1,2 -> 3,3
64
+
65
+ State 9:
66
+ ww.w
67
+ xbxb
68
+ ..bw
69
+ x.xb
70
+ w: 3,2 -> 2,0
71
+
72
+ State 10:
73
+ wwww
74
+ xbxb
75
+ ..b.
76
+ x.xb
77
+ b: 1,1 -> 3,2
78
+
79
+ State 11:
80
+ wwww
81
+ x.xb
82
+ ..bb
83
+ x.xb
84
+ w: 3,0 -> 1,1
85
+
86
+ State 12:
87
+ www.
88
+ xwxb
89
+ ..bb
90
+ x.xb
@@ -1,23 +1,5 @@
1
1
  describe "Futoshiki" do
2
2
  it do
3
- expect("futoshiki").to have_output <<EOF
4
- 2 5 3 4 1 7 6<9 8
5
-
6
- 1 9 7 2 8 5 3<4<6
7
- _
8
- 7<8 2 5>3>1 4<6 9
9
- ^
10
- 8 1<5<9 7 6 2 3 4
11
- ^
12
- 4 7>6>1 9 2 5 8 3
13
- ^ ^ ^
14
- 6 4 1 8 2 3 9 5 7
15
- _ _ ^ _ _
16
- 9 3 4 6>5 8 7 1 2
17
- _
18
- 5 2 9>3 6>4 8>7 1
19
- _
20
- 3 6 8>7>4 9 1<2 5
21
- EOF
3
+ expect("futoshiki").to have_output_matching_saved_example
22
4
  end
23
5
  end
@@ -1,98 +1,5 @@
1
- # There are multiple solutions, so this test is nondeterministic
2
- # This is what Z3 4.8.13 returns
3
1
  describe "Knights Swap Puzzle" do
4
2
  it do
5
- expect("knights_puzzle").to have_output <<EOF
6
- Solved
7
- State 0:
8
- bbb.
9
- xbxw
10
- ..ww
11
- x.xw
12
- w: 2,2 -> 3,0
13
-
14
- State 1:
15
- bbbw
16
- xbxw
17
- ...w
18
- x.xw
19
- b: 1,0 -> 2,2
20
-
21
- State 2:
22
- b.bw
23
- xbxw
24
- ..bw
25
- x.xw
26
- w: 3,1 -> 1,0
27
-
28
- State 3:
29
- bwbw
30
- xbx.
31
- ..bw
32
- x.xw
33
- b: 0,0 -> 1,2
34
-
35
- State 4:
36
- .wbw
37
- xbx.
38
- .bbw
39
- x.xw
40
- b: 1,2 -> 3,1
41
-
42
- State 5:
43
- .wbw
44
- xbxb
45
- ..bw
46
- x.xw
47
- w: 3,3 -> 1,2
48
-
49
- State 6:
50
- .wbw
51
- xbxb
52
- .wbw
53
- x.x.
54
- w: 1,2 -> 0,0
55
-
56
- State 7:
57
- wwbw
58
- xbxb
59
- ..bw
60
- x.x.
61
- b: 2,0 -> 1,2
62
-
63
- State 8:
64
- ww.w
65
- xbxb
66
- .bbw
67
- x.x.
68
- w: 3,2 -> 2,0
69
-
70
- State 9:
71
- wwww
72
- xbxb
73
- .bb.
74
- x.x.
75
- b: 1,1 -> 3,2
76
-
77
- State 10:
78
- wwww
79
- x.xb
80
- .bbb
81
- x.x.
82
- b: 1,2 -> 3,3
83
-
84
- State 11:
85
- wwww
86
- x.xb
87
- ..bb
88
- x.xb
89
- w: 3,0 -> 1,1
90
-
91
- State 12:
92
- www.
93
- xwxb
94
- ..bb
95
- x.xb
96
- EOF
3
+ expect("knights_puzzle").to have_output_matching_saved_example
97
4
  end
98
5
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Disabled as it crashes on Z3 4.8.13
4
4
  module Z3
5
- xdescribe Optimize do
5
+ describe Optimize do
6
6
  let(:optimize) { Optimize.new }
7
7
  let(:a) { Z3.Int("a") }
8
8
  let(:b) { Z3.Int("b") }
@@ -34,6 +34,15 @@ module Z3
34
34
  ])
35
35
  end
36
36
 
37
+ it "#assert_soft" do
38
+ optimize.assert_soft a > 0
39
+ optimize.assert_soft a < 0
40
+ optimize.assert_soft a < 10
41
+ optimize.maximize a
42
+ expect(optimize).to be_satisfiable
43
+ expect(optimize.model[a].to_i).to eq 9
44
+ end
45
+
37
46
  it "#statistics" do
38
47
  optimize.assert a + b == 4
39
48
  optimize.assert b >= 2
@@ -42,16 +51,6 @@ module Z3
42
51
  expect(stats.keys).to match_array(["rlimit count", "max memory", "memory", "num allocs"])
43
52
  end
44
53
 
45
- # This is a very simple example of unknown satisfiablity
46
- # so we might need more complex one in the future
47
- # Unlike Z3::Solver, this is unknown even 4.6.0
48
- it "unknown satisfiability" do
49
- optimize.assert a**3 == a
50
- expect(optimize.check).to eq(:unknown)
51
- expect{optimize.satisfiable?}.to raise_error("Satisfiability unknown")
52
- expect{optimize.unsatisfiable?}.to raise_error("Satisfiability unknown")
53
- end
54
-
55
54
  it "unknown satisfiability" do
56
55
  optimize.assert a**a == a
57
56
  expect(optimize.check).to eq(:unknown)
data/spec/spec_helper.rb CHANGED
@@ -38,6 +38,20 @@ RSpec::Matchers.define :have_output do |expected|
38
38
  end
39
39
  end
40
40
 
41
+ RSpec::Matchers.define :have_output_matching_saved_example do
42
+ match do |file_name|
43
+ executable_path = "#{__dir__}/../examples/#{file_name}"
44
+ actual = IO.popen("ruby -r./spec/coverage_helper #{executable_path}").read
45
+ @actual = actual.gsub(/ *$/, "")
46
+ @expected = Pathname("spec/integration/examples").glob("#{file_name}-*.txt").map(&:read).map{|o| o.gsub(/ *$/, "")}
47
+ @expected.include?(@actual)
48
+ end
49
+
50
+ failure_message do |actual|
51
+ "Expected one of saved examples, but got:\n#{@actual}"
52
+ end
53
+ end
54
+
41
55
  RSpec::Matchers.define :have_output_no_color do |expected|
42
56
  match do |file_name|
43
57
  executable_path = "#{__dir__}/../examples/#{file_name}"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: z3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.20220630
4
+ version: 0.0.20220828
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomasz Wegrzanowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-30 00:00:00.000000000 Z
11
+ date: 2022-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -280,6 +280,13 @@ files:
280
280
  - spec/integration/dominion_spec.rb
281
281
  - spec/integration/dominosa_spec.rb
282
282
  - spec/integration/eulero_spec.rb
283
+ - spec/integration/examples/abc_path-1.txt
284
+ - spec/integration/examples/abc_path-2.txt
285
+ - spec/integration/examples/futoshiki-1.txt
286
+ - spec/integration/examples/futoshiki-2.txt
287
+ - spec/integration/examples/knights_puzzle-1.txt
288
+ - spec/integration/examples/knights_puzzle-2.txt
289
+ - spec/integration/examples/knights_puzzle-3.txt
283
290
  - spec/integration/four_hackers_puzzle_spec.rb
284
291
  - spec/integration/futoshiki_spec.rb
285
292
  - spec/integration/geometry_problem_spec.rb