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