Algorithm-SAT-Backtracking
view release on metacpan or search on metacpan
lib/Algorithm/SAT/Backtracking/Ordered.pm view on Meta::CPAN
foreach my $variable ( @{$variables} ) {
$choice = $variable and last if ( !$model->exists($variable) );
}
return $choice;
}
sub solve {
my ( $self, $variables, $clauses, $model ) = @_;
$model = Hash::Ordered->new if !defined $model;
return $self->SUPER::solve( $variables, $clauses, $model );
}
# ### update
# Copies the model, then sets `choice` = `value` in the model, and returns it, keeping the order of keys.
sub update {
my ( $self, $copy, $choice, $value ) = @_;
$copy = $copy->clone;
$copy->set( $choice => $value );
return $copy;
lib/Algorithm/SAT/Backtracking/Ordered/DPLL.pm view on Meta::CPAN
use Algorithm::SAT::Backtracking::DPLL
"Algorithm::SAT::Backtracking::Ordered";
use strict;
use warnings;
our $VERSION = "0.13";
##Ordered implementation, of course has its costs
sub solve {
my ( $self, $variables, $clauses, $model ) = @_;
$model = Hash::Ordered->new if !defined $model;
return $self->SUPER::solve( $variables, $clauses, $model );
}
sub _up {
my ( $self, $variables, $clauses, $model ) = @_;
$model = Hash::Ordered->new if !defined $model;
#Finding single clauses that must be true, and updating the model
( @{$_} != 1 )
? ()
: ( substr( $_->[0], 0, 1 ) eq "-" ) ? (
( run in 0.473 second using v1.01-cache-2.11-cpan-49f99fa48dc )