File Coverage

blib/lib/Algorithm/SAT/Backtracking/DPLLProb.pm
Criterion Covered Total %
statement 18 18 100.0
branch 2 2 100.0
condition n/a
subroutine 4 4 100.0
pod n/a
total 24 24 100.0


line stmt bran cond sub pod time code
1             package Algorithm::SAT::Backtracking::DPLLProb;
2 2     2   1157 use base 'Algorithm::SAT::Backtracking::DPLL';
  2         11  
  2         456  
3 2     2   11 use List::Util qw(shuffle);
  2         2  
  2         169  
4 2     2   11 use Storable qw(dclone);
  2         2  
  2         229  
5             our $VERSION = "0.11";
6              
7             sub _choice {
8 19     19   15 my $self = shift;
9 19         14 my $variables = shift;
10 19         17 my $model = shift;
11 19         13 my $choice;
12 19         17 foreach my $variable ( shuffle( @{$variables} ) ) {
  19         82  
13 37         27 $choice = $variable;
14 37 100       61 last if ( !exists $model->{$variable} );
15             }
16 19         34 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"); #Uses Algorithm::SAT::Backtracking by default, you can use "with()" to specify other implementations
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