{"id":15441773,"url":"https://github.com/mudler/algorithm-sat-backtracking","last_synced_at":"2025-03-28T07:12:15.095Z","repository":{"id":56836315,"uuid":"27380704","full_name":"mudler/Algorithm-Sat-Backtracking","owner":"mudler","description":"A switchable Pure Perl SAT solver with backtracking","archived":false,"fork":false,"pushed_at":"2017-10-05T08:07:51.000Z","size":74,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-02T07:43:35.936Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mudler.png","metadata":{"files":{"readme":"README.md","changelog":"Changes","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-12-01T13:29:13.000Z","updated_at":"2024-01-02T22:20:19.000Z","dependencies_parsed_at":"2022-09-09T20:02:07.671Z","dependency_job_id":null,"html_url":"https://github.com/mudler/Algorithm-Sat-Backtracking","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mudler%2FAlgorithm-Sat-Backtracking","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mudler%2FAlgorithm-Sat-Backtracking/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mudler%2FAlgorithm-Sat-Backtracking/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mudler%2FAlgorithm-Sat-Backtracking/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mudler","download_url":"https://codeload.github.com/mudler/Algorithm-Sat-Backtracking/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245984589,"owners_count":20704798,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T19:22:53.196Z","updated_at":"2025-03-28T07:12:15.071Z","avatar_url":"https://github.com/mudler.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/mudler/Algorithm-Sat-Backtracking.svg?branch=master)](https://travis-ci.org/mudler/Algorithm-Sat-Backtracking)\n# NAME\n\nAlgorithm::SAT::Backtracking - A simple Backtracking SAT solver written in pure Perl\n\n# SYNOPSIS\n\n    # You can use it with Algorithm::SAT::Expression\n    use Algorithm::SAT::Expression;\n\n    my $expr = Algorithm::SAT::Expression-\u003enew-\u003ewith(\"Algorithm::SAT::Backtracking\"); #Uses Algorithm::SAT::Backtracking by default, so with() it's not necessary in this case\n    $expr-\u003eor( '-foo@2.1', 'bar@2.2' );\n    $expr-\u003eor( '-foo@2.3', 'bar@2.2' );\n    $expr-\u003eor( '-baz@2.3', 'bar@2.3' );\n    $expr-\u003eor( '-baz@1.2', 'bar@2.2' );\n    my $model = $exp-\u003esolve();\n\n    # Or you can use it directly:\n    use Algorithm::SAT::Backtracking;\n    my $solver = Algorithm::SAT::Backtracking-\u003enew;\n    my $variables = [ 'blue', 'green', 'yellow', 'pink', 'purple' ];\n    my $clauses = [\n        [ 'blue',  'green',  '-yellow' ],\n        [ '-blue', '-green', 'yellow' ],\n        [ 'pink', 'purple', 'green', 'blue', '-yellow' ]\n    ];\n\n    my $model = $solver-\u003esolve( $variables, $clauses );\n\n# DESCRIPTION\n\nAlgorithm::SAT::Backtracking is a pure Perl implementation of a simple SAT Backtracking solver.\n\nIn computer science, the Boolean Satisfiability Problem (sometimes called Propositional Satisfiability Problem and abbreviated as _SATISFIABILITY_ or _SAT_) is the problem of determining if there exists an interpretation that satisfies a given Boolean formula. In other words, it asks whether the variables of a given Boolean formula can be consistently replaced by the values **TRUE** or **FALSE** in such a way that the formula evaluates to **TRUE**. If this is the case, the formula is called satisfiable. On the other hand, if no such assignment exists, the function expressed by the formula is identically **FALSE** for all possible variable assignments and the formula is unsatisfiable.\n\nFor example, the formula \"a AND NOT b\" is satisfiable because one can find the values a = **TRUE** and b = **FALSE**, which make (a AND NOT b) = TRUE. In contrast, \"a AND NOT a\" is unsatisfiable. More: [https://en.wikipedia.org/wiki/Boolean\\_satisfiability\\_problem](https://en.wikipedia.org/wiki/Boolean_satisfiability_problem) .\n\nHave a look also at the tests file for an example of usage.\n\n[Algorithm::SAT::Expression](https://metacpan.org/pod/Algorithm::SAT::Expression) use this module to solve Boolean expressions.\n\n# METHODS\n\n## solve()\n\nThe input consists of a boolean expression in Conjunctive Normal Form.\nThis means it looks something like this:\n\n    `(blue OR green) AND (green OR NOT yellow)`\n\n    We encode this as an array of strings with a `-` in front for negation:\n\n       `[['blue', 'green'], ['green', '-yellow']]`\n\nHence, each row means an **AND**, while a list groups two or more **OR** clauses.\n\nReturns 0 if the expression can't be solved with the given clauses, the model otherwise in form of a hash .\n\nHave a look at [Algorithm::SAT::Expression](https://metacpan.org/pod/Algorithm::SAT::Expression) to see how to use it in a less painful way.\n\n## resolve()\n\nUses the model to resolve some variable to its actual value, or undefined if not present.\n\n    my $model = { blue =\u003e 1, red =\u003e 0 };\n    my $a=$solver-\u003eresolve( \"blue\", $model );\n    #$a = 1\n\n## satisfiable()\n\nDetermines whether a clause is satisfiable given a certain model.\n\n    my $model\n        = { pink =\u003e 1, purple =\u003e 0, green =\u003e 0, yellow =\u003e 1, red =\u003e 0 };\n    my $a=$solver-\u003esatisfiable( [ 'purple', '-pink' ], $model );\n    #$a = 0\n\n## update()\n\nCopies the model, then sets \\`choice\\` = \\`value\\` in the model, and returns it.\n\n    my $model\n        = { pink =\u003e 1, red =\u003e 0, purple =\u003e 0, green =\u003e 0, yellow =\u003e 1 };\n    my $new_model = $solver-\u003eupdate( $model, 'foobar', 1 );\n    # now $new_model-\u003e{foobar} is 1\n\n# LICENSE\n\nCopyright (C) mudler.\n\nThis library is free software; you can redistribute it and/or modify\nit under the same terms as Perl itself.\n\n# AUTHOR\n\nmudler \u003cmudler@dark-lab.net\u003e\n\n# SEE ALSO\n\n[Algorithm::SAT::Expression](https://metacpan.org/pod/Algorithm::SAT::Expression), [Algorithm::SAT::Backtracking::DPLL](https://metacpan.org/pod/Algorithm::SAT::Backtracking::DPLL), [Algorithm::SAT::Backtracking::Ordered](https://metacpan.org/pod/Algorithm::SAT::Backtracking::Ordered), [Algorithm::SAT::Backtracking::Ordered::DPLL](https://metacpan.org/pod/Algorithm::SAT::Backtracking::Ordered::DPLL)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmudler%2Falgorithm-sat-backtracking","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmudler%2Falgorithm-sat-backtracking","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmudler%2Falgorithm-sat-backtracking/lists"}