Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
r""" Solve SAT problems Integer Linear Programming
The class defined here is a :class:`~sage.sat.solvers.satsolver.SatSolver` that solves its instance using :class:`MixedIntegerLinearProgram`. Its performance can be expected to be slower than when using :class:`~sage.sat.solvers.cryptominisat.cryptominisat.CryptoMiniSat`. """
r""" Initializes the instance
INPUT:
- ``solver`` -- (default: ``None``) Specify a Linear Program (LP) solver to be used. If set to ``None``, the default one is used. For more information on LP solvers and which default solver is used, see the method :meth:`~sage.numerical.mip.MixedIntegerLinearProgram.solve` of the class :class:`~sage.numerical.mip.MixedIntegerLinearProgram`.
- ``verbose`` -- integer (default: ``0``). Sets the level of verbosity of the LP solver. Set to 0 by default, which means quiet.
EXAMPLES::
sage: S=SAT(solver="LP"); S an ILP-based SAT Solver """
""" Return a *new* variable.
EXAMPLES::
sage: S=SAT(solver="LP"); S an ILP-based SAT Solver sage: S.var() 1 """
""" Return the number of variables.
EXAMPLES::
sage: S=SAT(solver="LP"); S an ILP-based SAT Solver sage: S.var() 1 sage: S.var() 2 sage: S.nvars() 2 """
""" Add a new clause to set of clauses.
INPUT:
- ``lits`` - a tuple of integers != 0
.. note::
If any element ``e`` in ``lits`` has ``abs(e)`` greater than the number of variables generated so far, then new variables are created automatically.
EXAMPLES::
sage: S=SAT(solver="LP"); S an ILP-based SAT Solver sage: for u,v in graphs.CycleGraph(6).edges(labels=False): ....: u,v = u+1,v+1 ....: S.add_clause((u,v)) ....: S.add_clause((-u,-v)) """ raise ValueError("0 should not appear in the clause: {}".format(lits)) >=1)
""" Solve this instance.
OUTPUT:
- If this instance is SAT: A tuple of length ``nvars()+1`` where the ``i``-th entry holds an assignment for the ``i``-th variables (the ``0``-th entry is always ``None``).
- If this instance is UNSAT: ``False``
EXAMPLES::
sage: def is_bipartite_SAT(G): ....: S=SAT(solver="LP"); S ....: for u,v in G.edges(labels=False): ....: u,v = u+1,v+1 ....: S.add_clause((u,v)) ....: S.add_clause((-u,-v)) ....: return S sage: S = is_bipartite_SAT(graphs.CycleGraph(6)) sage: S() # random [None, True, False, True, False, True, False] sage: True in S() True sage: S = is_bipartite_SAT(graphs.CycleGraph(7)) sage: S() False """
""" TESTS::
sage: S=SAT(solver="LP"); S an ILP-based SAT Solver """ |