-
Notifications
You must be signed in to change notification settings - Fork 3.9k
FOIL #625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
FOIL #625
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -196,7 +196,7 @@ def tt_entails(kb, alpha): | |
True | ||
""" | ||
assert not variables(alpha) | ||
symbols = prop_symbols(kb & alpha) | ||
symbols = list(prop_symbols(kb & alpha)) | ||
return tt_check_all(kb, alpha, symbols, {}) | ||
|
||
|
||
|
@@ -216,23 +216,33 @@ def tt_check_all(kb, alpha, symbols, model): | |
|
||
|
||
def prop_symbols(x): | ||
"""Return a list of all propositional symbols in x.""" | ||
"""Return the set of all propositional symbols in x.""" | ||
if not isinstance(x, Expr): | ||
return [] | ||
return set() | ||
elif is_prop_symbol(x.op): | ||
return [x] | ||
return {x} | ||
else: | ||
return list(set(symbol for arg in x.args for symbol in prop_symbols(arg))) | ||
return {symbol for arg in x.args for symbol in prop_symbols(arg)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, or could be |
||
|
||
|
||
def constant_symbols(x): | ||
"""Return a list of all constant symbols in x.""" | ||
"""Return the set of all constant symbols in x.""" | ||
if not isinstance(x, Expr): | ||
return [] | ||
return set() | ||
elif is_prop_symbol(x.op) and not x.args: | ||
return [x] | ||
return {x} | ||
else: | ||
return list({symbol for arg in x.args for symbol in constant_symbols(arg)}) | ||
return {symbol for arg in x.args for symbol in constant_symbols(arg)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar here as for prop_symbols |
||
|
||
|
||
def predicate_symbols(x): | ||
"""Return a set of (symbol_name, arity) in x. | ||
All symbols (even functional) with arity > 0 are considered.""" | ||
if not isinstance(x, Expr) or not x.args: | ||
return set() | ||
pred_set = {(x.op, len(x.args))} if is_prop_symbol(x.op) else set() | ||
pred_set.update({symbol for arg in x.args for symbol in predicate_symbols(arg)}) | ||
return pred_set | ||
|
||
|
||
def tt_true(s): | ||
|
@@ -549,7 +559,7 @@ def dpll_satisfiable(s): | |
function find_pure_symbol is passed a list of unknown clauses, rather | ||
than a list of all clauses and the model; this is more efficient.""" | ||
clauses = conjuncts(to_cnf(s)) | ||
symbols = prop_symbols(s) | ||
symbols = list(prop_symbols(s)) | ||
return dpll(clauses, symbols, {}) | ||
|
||
|
||
|
@@ -652,7 +662,7 @@ def WalkSAT(clauses, p=0.5, max_flips=10000): | |
"""Checks for satisfiability of all clauses by randomly flipping values of variables | ||
""" | ||
# Set of all symbols in all clauses | ||
symbols = set(sym for clause in clauses for sym in prop_symbols(clause)) | ||
symbols = {sym for clause in clauses for sym in prop_symbols(clause)} | ||
# model is a random assignment of true/false to the symbols in clauses | ||
model = {s: random.choice([True, False]) for s in symbols} | ||
for i in range(max_flips): | ||
|
@@ -663,7 +673,7 @@ def WalkSAT(clauses, p=0.5, max_flips=10000): | |
return model | ||
clause = random.choice(unsatisfied) | ||
if probability(p): | ||
sym = random.choice(prop_symbols(clause)) | ||
sym = random.choice(list(prop_symbols(clause))) | ||
else: | ||
# Flip the symbol in clause that maximizes number of sat. clauses | ||
def sat_count(sym): | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be called FOILKB.