Algorithm-SAT-Backtracking

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN


Have a look also at the tests file for an example of usage.

[Algorithm::SAT::Expression](https://metacpan.org/pod/Algorithm::SAT::Expression) use this module to solve Boolean expressions.

# METHODS

## solve()

The input consists of a boolean expression in Conjunctive Normal Form.
This means it looks something like this:

    `(blue OR green) AND (green OR NOT yellow)`

    We encode this as an array of strings with a `-` in front for negation:

       `[['blue', 'green'], ['green', '-yellow']]`

Hence, each row means an **AND**, while a list groups two or more **OR** clauses.

Returns 0 if the expression can't be solved with the given clauses, the model otherwise in form of a hash .

lib/Algorithm/SAT/Backtracking.pm  view on Meta::CPAN

package Algorithm::SAT::Backtracking;
use strict;
use warnings;
use Storable qw(dclone);

# This is an extremely simple implementation of the 'backtracking' algorithm for
# solving boolean satisfiability problems. It contains no optimizations.

# The input consists of a boolean expression in Conjunctive Normal Form.
# This means it looks something like this:
#
# `(blue OR green) AND (green OR NOT yellow)`
#
# We encode this as an array of strings with a `-` in front for negation:
#
# `[['blue', 'green'], ['green', '-yellow']]`

our $VERSION = "0.13";

sub new {

lib/Algorithm/SAT/Backtracking.pm  view on Meta::CPAN


Have a look also at the tests file for an example of usage.

L<Algorithm::SAT::Expression> use this module to solve Boolean expressions.

=head1 METHODS

=head2 solve()

The input consists of a boolean expression in Conjunctive Normal Form.
This means it looks something like this:

 `(blue OR green) AND (green OR NOT yellow)`

 We encode this as an array of strings with a `-` in front for negation:

    `[['blue', 'green'], ['green', '-yellow']]`

Hence, each row means an B<AND>, while a list groups two or more B<OR> clauses.

Returns 0 if the expression can't be solved with the given clauses, the model otherwise in form of a hash .



( run in 0.344 second using v1.01-cache-2.11-cpan-64827b87656 )