-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated pysat solver wrapper, added solving algorithm
- Loading branch information
1 parent
6575d58
commit 68de1d6
Showing
6 changed files
with
203 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from typing import Dict, Any | ||
from time import time as now | ||
|
||
from ..abc import Core | ||
|
||
from space.model import Backdoor | ||
from lib_satprob.solver import Report | ||
from lib_satprob.derived import get_derived_by | ||
from lib_satprob.variables import Supplements | ||
|
||
|
||
class Solving(Core): | ||
slug = 'core:solving' | ||
|
||
def launch(self, *backdoors: Backdoor) -> Report: | ||
stamp, formula, = now(), self.problem.encoding.get_formula() | ||
assumptions_set, constraints_set, all_stats = set(), set(), {} | ||
|
||
def add_supplements(_supplements: Supplements): | ||
_assumptions, _constraints = _supplements | ||
assumptions_set.update(set(_assumptions)) | ||
for _clause in map(tuple, _constraints): | ||
constraints_set.add(_clause) | ||
|
||
def get_report(_status, _stats, _model) -> Report: | ||
_time = _stats.get('time', 0.) + now() - stamp | ||
return Report(_status, {'time': _time}, _model) | ||
|
||
with self.problem.solver.get_instance(formula) as solver: | ||
for backdoor, easy, hard in [(bd, [], []) for bd in backdoors]: | ||
for supplements in backdoor.enumerate(): | ||
status, stats, model, _ = solver.propagate(supplements) | ||
(easy if status is False else hard).append(supplements) | ||
if status is True: return get_report(status, {}, model) | ||
|
||
if len(hard) == 0: return get_report(False, {}, None) | ||
add_supplements( | ||
hard[0] if len(hard) == 1 else get_derived_by(easy) | ||
) | ||
|
||
assumptions = list(assumptions_set) | ||
constraints = [list(c) for c in constraints_set] | ||
report = solver.solve((assumptions, constraints)) | ||
return get_report(report.status, report.stats, report.model) | ||
|
||
def __config__(self) -> Dict[str, Any]: | ||
return {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,5 +14,7 @@ | |
'WCNFPlus', | ||
# types | ||
'Clause', | ||
'Clauses' | ||
'Clauses', | ||
# utility | ||
'wcnf_to_cnf' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.