line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Algorithm::SAT::Backtracking::DPLLProb; |
2
|
2
|
|
|
2
|
|
1148
|
use base 'Algorithm::SAT::Backtracking::DPLL'; |
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
541
|
|
3
|
2
|
|
|
2
|
|
9
|
use List::Util qw(shuffle); |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
174
|
|
4
|
2
|
|
|
2
|
|
9
|
use Storable qw(dclone); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
62
|
|
5
|
2
|
|
|
2
|
|
7
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
40
|
|
6
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
215
|
|
7
|
|
|
|
|
|
|
our $VERSION = "0.12"; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub _choice { |
10
|
16
|
|
|
16
|
|
12
|
my $self = shift; |
11
|
16
|
|
|
|
|
14
|
my $variables = shift; |
12
|
16
|
|
|
|
|
16
|
my $model = shift; |
13
|
16
|
|
|
|
|
11
|
my $choice; |
14
|
16
|
|
|
|
|
12
|
foreach my $variable ( shuffle( @{$variables} ) ) { |
|
16
|
|
|
|
|
78
|
|
15
|
27
|
|
|
|
|
25
|
$choice = $variable; |
16
|
27
|
100
|
|
|
|
47
|
last if ( !exists $model->{$variable} ); |
17
|
|
|
|
|
|
|
} |
18
|
16
|
|
|
|
|
34
|
return $choice; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
1; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=encoding utf-8 |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 NAME |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Algorithm::SAT::Backtracking::DPLLProb - A DPLL Probabilistic Backtracking SAT solver written in pure Perl |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 SYNOPSIS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# You can use it with Algorithm::SAT::Expression |
33
|
|
|
|
|
|
|
use Algorithm::SAT::Expression; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $expr = Algorithm::SAT::Expression->new->with("Algorithm::SAT::Backtracking::DPLLProb"); #Uses Algorithm::SAT::Backtracking by default, you can use "with()" to specify other implementations |
36
|
|
|
|
|
|
|
$expr->or( '-foo@2.1', 'bar@2.2' ); |
37
|
|
|
|
|
|
|
$expr->or( '-foo@2.3', 'bar@2.2' ); |
38
|
|
|
|
|
|
|
$expr->or( '-baz@2.3', 'bar@2.3' ); |
39
|
|
|
|
|
|
|
$expr->or( '-baz@1.2', 'bar@2.2' ); |
40
|
|
|
|
|
|
|
my $model = $exp->solve(); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Or you can use it directly: |
43
|
|
|
|
|
|
|
use Algorithm::SAT::BacktrackingDPLLProb; |
44
|
|
|
|
|
|
|
my $solver = Algorithm::SAT::Backtracking::DPLLProb->new; |
45
|
|
|
|
|
|
|
my $variables = [ 'blue', 'green', 'yellow', 'pink', 'purple' ]; |
46
|
|
|
|
|
|
|
my $clauses = [ |
47
|
|
|
|
|
|
|
[ 'blue', 'green', '-yellow' ], |
48
|
|
|
|
|
|
|
[ '-blue', '-green', 'yellow' ], |
49
|
|
|
|
|
|
|
[ 'pink', 'purple', 'green', 'blue', '-yellow' ] |
50
|
|
|
|
|
|
|
]; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my $model = $solver->solve( $variables, $clauses ); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 DESCRIPTION |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Algorithm::SAT::Backtracking::DPLLProb is a pure Perl implementation of a SAT Backtracking solver. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Look at L for a theory description. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
L use this module to solve Boolean expressions. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 METHODS |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Inherits all the methods from L and in this variant C<_choice()> it's overrided to choose a random literal. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 LICENSE |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Copyright (C) mudler. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
71
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 AUTHOR |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
mudler Emudler@dark-lab.netE |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 SEE ALSO |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
L, L,L, L, L |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |