Esempio n. 1
0
def test_dsharp_output():
    with (satlib / "uf20-01.nnf").open() as f:
        sentence = dsharp.load(f)
    with (satlib / "uf20-01.cnf").open() as f:
        clauses = dimacs.load(f)
    assert sentence.decomposable()
    # this is not a complete check, but clauses.models() is very expensive
    assert all(clauses.satisfied_by(model) for model in sentence.models())
Esempio n. 2
0
def sat(args: argparse.Namespace) -> int:
    with open_read(args.file) as f:
        sentence = dimacs.load(f)
    if args.verbose:
        print_stats(sentence)
    with timer(args):
        sat = sentence.satisfiable()
    if sat:
        if not args.quiet:
            print("SATISFIABLE")
        return 0
    else:
        if not args.quiet:
            print("UNSATISFIABLE")
        return 1
Esempio n. 3
0
def sharpsat(args: argparse.Namespace) -> int:
    with open_read(args.file) as f:
        sentence = dimacs.load(f)
    if args.deterministic:
        sentence.mark_deterministic()
    if args.verbose:
        print_stats(sentence)
    with timer(args):
        num = sentence.model_count()
    if args.quiet:
        print(num)
    else:
        print("{} solutions found.".format(num))
    if num == 0:
        return 1
    return 0
Esempio n. 4
0
def draw(args: argparse.Namespace) -> int:
    with open_read(args.file) as f:
        sentence = dimacs.load(f)
    label = 'symbol' if args.symbol else 'text'
    dot = sentence.to_DOT(color=args.color, label=label)

    ext = extension(args.out)
    if ext in DOT_FORMATS or args.format is not None:
        argv = [
            'dot',
            '-T' + (
                ext if args.format is None  # type: ignore
                else args.format)
        ]
        if args.out != '-':
            argv.append('-o' + args.out)
        try:
            proc = subprocess.Popen(argv,
                                    stdin=subprocess.PIPE,
                                    universal_newlines=True)
        except FileNotFoundError:
            print("Can't find `dot` executable. Is it installed and in your "
                  "PATH?")
            return 1
        assert proc.stdin
        proc.stdin.write(dot)
        proc.stdin.close()
        ret = proc.wait()
        if ret != 0:
            print("dot failed with status code {}".format(ret))
        return ret

    else:
        with open_write(args.out) as f:
            f.write(dot)
        return 0
Esempio n. 5
0
def info(args: argparse.Namespace) -> int:
    with open_read(args.file) as f:
        sentence = dimacs.load(f)
    print_stats(sentence)
    return 0
Esempio n. 6
0
def test_cnf_benchmark_data(fname: str, clauses: int):
    with (satlib / fname).open() as f:
        sentence = dimacs.load(f)
    assert isinstance(sentence, And) and len(sentence.children) == clauses
Esempio n. 7
0
    method.set = lambda *args: None  # type: ignore

settings.register_profile('patient',
                          deadline=2000,
                          suppress_health_check=(HealthCheck.too_slow, ))
settings.load_profile('patient')

a, b, c = Var('a'), Var('b'), Var('c')

fig1a = (~a & b) | (a & ~b)
fig1b = (~a | ~b) & (a | b)

satlib = pathlib.Path(__file__).parent / "testdata" / "satlib"
uf20 = [dsharp.load(file.open()) for file in (satlib / "uf20").glob("*.nnf")]
uf20_cnf = [
    dimacs.load(file.open()) for file in (satlib / "uf20").glob("*.cnf")
]  # type: t.List[And[Or[Var]]]

# Test config default value before the tests start mucking with the state
assert config.sat_backend == "auto"


def test_all_models_basic():
    assert list(nnf.all_models([])) == [{}]
    assert list(nnf.all_models([1])) == [{1: False}, {1: True}]
    assert len(list(nnf.all_models(range(10)))) == 1024


@given(st.sets(st.integers(), max_size=8))
def test_all_models(names):
    result = list(nnf.all_models(names))