예제 #1
0
파일: dpll.py 프로젝트: Wrrzag/FanSATstic
def solve(num_variables, clauses, selection_heuristic):
    """
    Uses the dpll algorithm to determine if the formula is satisfiable or 
    unsatisfiable
    
    Returns a tuple with the following formats:
        - If the formula is satisfiable
            (True, [None, truth_value1, truth_vaue2, ...] )
        - If the formula is unsatisfiable
            (False, frozenset() ) 
    """
    
    # Dictionary with clauses classified by literals
    litclauses = datautil.classifyClausesByLiteral(clauses)
    
    # Amount of times each clause appears in the formula.
    # At the beginning every clause appears only once but after some
    # branching some clauses can appear more than once
    ctimes = { c : 1 for c in clauses }

    # We use an struct to have less parameters
    cdata = ClausesData(clauses, ctimes, litclauses)
    
    variables, interpretation = getVarsAndFirstIntp(num_variables, cdata)
    
    return _solve(variables, cdata, interpretation, selection_heuristic)
예제 #2
0
def solve(num_variables, clauses, selection_heuristic):
    """
    Uses the dpll algorithm to determine if the formula is satisfiable or 
    unsatisfiable
    
    Returns a tuple with the following formats:
        - If the formula is satisfiable
            (True, [None, truth_value1, truth_vaue2, ...] )
        - If the formula is unsatisfiable
            (False, frozenset() ) 
    """

    # Dictionary with clauses classified by literals
    litclauses = datautil.classifyClausesByLiteral(clauses)

    # Amount of times each clause appears in the formula.
    # At the beginning every clause appears only once but after some
    # branching some clauses can appear more than once
    ctimes = {c: 1 for c in clauses}

    # We use an struct to have less parameters
    cdata = ClausesData(clauses, ctimes, litclauses)

    variables, interpretation = getVarsAndFirstIntp(num_variables, cdata)

    return _solve(variables, cdata, interpretation, selection_heuristic)
예제 #3
0
def solve(num_variables, clauses, selection_heuristic):
    """
    Uses the dp algorithm to determine if the formula is satisfiable or 
    unsatisfiable
    
    Returns a tuple with the following formats:
        - If the formula is satisfiable
            (True, frozenset() )
        - If the formula is unsatisfiable
            (False, frozenset(<core_clause1>, <core_clause2>, ...) ) 
    """

    litclauses = datautil.classifyClausesByLiteral(clauses)
    variables = range(1, num_variables + 1)
    reason = {}  # Clause "parents"

    while variables:

        if unitPropagation(variables, clauses, litclauses, reason):
            return (False, generateCoreFromEmtpyClause(reason))

        # All clauses and variables wasted without finding the emtpy clause
        if not clauses or not variables:
            return (True, frozenset())

        # Select variable
        var = selection_heuristic(variables, litclauses)
        variables.remove(var)

        # Ignore variables that don't belong to any clause
        if not litclauses.has_key(var) and not litclauses.has_key(var):
            continue

        if resolution(var, clauses, litclauses, reason):
            return (False, generateCoreFromEmtpyClause(reason))

    return (True, frozenset())
예제 #4
0
파일: dp.py 프로젝트: Wrrzag/FanSATstic
def solve(num_variables, clauses, selection_heuristic):
    """
    Uses the dp algorithm to determine if the formula is satisfiable or 
    unsatisfiable
    
    Returns a tuple with the following formats:
        - If the formula is satisfiable
            (True, frozenset() )
        - If the formula is unsatisfiable
            (False, frozenset(<core_clause1>, <core_clause2>, ...) ) 
    """
    
    litclauses = datautil.classifyClausesByLiteral(clauses)
    variables = range(1, num_variables+1)
    reason = {} # Clause "parents"
        
    while variables:
        
        if unitPropagation(variables, clauses, litclauses, reason):
            return (False, generateCoreFromEmtpyClause(reason))

        # All clauses and variables wasted without finding the emtpy clause
        if not clauses or not variables:
            return (True, frozenset())
        
        # Select variable
        var = selection_heuristic(variables, litclauses)
        variables.remove(var)
        
        # Ignore variables that don't belong to any clause
        if not litclauses.has_key(var) and not litclauses.has_key(var):
            continue
        
        if resolution(var, clauses, litclauses, reason):
            return (False, generateCoreFromEmtpyClause(reason))
            
    return (True, frozenset())