mirror of
https://github.com/Brandon-Rozek/matmod.git
synced 2024-11-20 21:56:29 -05:00
Playing around with orderings
This commit is contained in:
parent
ae8658fda2
commit
39a6bf84fb
2 changed files with 39 additions and 9 deletions
|
@ -3,7 +3,7 @@ File which generates all the models
|
||||||
"""
|
"""
|
||||||
from common import set_to_str
|
from common import set_to_str
|
||||||
from logic import Logic, Operation, Rule, get_operations_from_term, PropositionalVariable
|
from logic import Logic, Operation, Rule, get_operations_from_term, PropositionalVariable
|
||||||
from model import ModelValue, Model, satisfiable, ModelFunction
|
from model import ModelValue, Model, satisfiable, ModelFunction, ModelOrderConstraint
|
||||||
from itertools import combinations, chain, product
|
from itertools import combinations, chain, product
|
||||||
from typing import Set
|
from typing import Set
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ def only_rules_with(rules: Set[Rule], operation: Operation) -> Set[Rule]:
|
||||||
|
|
||||||
def possible_interpretations(
|
def possible_interpretations(
|
||||||
logic: Logic, carrier_set: Set[ModelValue],
|
logic: Logic, carrier_set: Set[ModelValue],
|
||||||
designated_values: Set[ModelValue]):
|
designated_values: Set[ModelValue], ordering: Set[ModelOrderConstraint]):
|
||||||
operations = []
|
operations = []
|
||||||
model_functions = []
|
model_functions = []
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ def possible_interpretations(
|
||||||
if len(restricted_rules) > 0:
|
if len(restricted_rules) > 0:
|
||||||
small_logic = Logic({operation,}, restricted_rules)
|
small_logic = Logic({operation,}, restricted_rules)
|
||||||
for f in candidate_functions:
|
for f in candidate_functions:
|
||||||
small_model = Model(carrier_set, {f,}, designated_values)
|
small_model = Model(carrier_set, {f,}, designated_values, ordering)
|
||||||
interp = {operation: f}
|
interp = {operation: f}
|
||||||
if satisfiable(small_logic, small_model, interp):
|
if satisfiable(small_logic, small_model, interp):
|
||||||
passed_functions.append(f)
|
passed_functions.append(f)
|
||||||
|
@ -112,7 +112,7 @@ def generate_model(logic: Logic, number_elements: int, num_solutions: int = -1,
|
||||||
for designated_values in possible_designated_values:
|
for designated_values in possible_designated_values:
|
||||||
designated_values = set(designated_values)
|
designated_values = set(designated_values)
|
||||||
print("Considering models for designated values", set_to_str(designated_values))
|
print("Considering models for designated values", set_to_str(designated_values))
|
||||||
possible_interps = possible_interpretations(logic, carrier_set, designated_values)
|
possible_interps = possible_interpretations(logic, carrier_set, designated_values, ordering)
|
||||||
|
|
||||||
for interpretation in possible_interps:
|
for interpretation in possible_interps:
|
||||||
is_valid = True
|
is_valid = True
|
||||||
|
|
40
model.py
40
model.py
|
@ -4,7 +4,7 @@ Defining what it means to be a model
|
||||||
from common import set_to_str
|
from common import set_to_str
|
||||||
from logic import (
|
from logic import (
|
||||||
PropositionalVariable, get_propostional_variables, Logic, Term,
|
PropositionalVariable, get_propostional_variables, Logic, Term,
|
||||||
Operation
|
Operation, Conjunction, Disjunction
|
||||||
)
|
)
|
||||||
from typing import Set, List, Dict, Tuple, Optional
|
from typing import Set, List, Dict, Tuple, Optional
|
||||||
from itertools import product
|
from itertools import product
|
||||||
|
@ -130,14 +130,44 @@ def all_model_valuations_cached(
|
||||||
mvalues: Tuple[ModelValue]):
|
mvalues: Tuple[ModelValue]):
|
||||||
return list(all_model_valuations(pvars, mvalues))
|
return list(all_model_valuations(pvars, mvalues))
|
||||||
|
|
||||||
|
def rule_ordering_satisfied(model: Model, interpretation: Dict[Operation, ModelFunction]) -> bool:
|
||||||
|
"""
|
||||||
|
Currently testing whether this function helps with runtime...
|
||||||
|
"""
|
||||||
|
if Conjunction in interpretation:
|
||||||
|
possible_inputs = ((a, b) for (a, b) in product(model.carrier_set, model.carrier_set))
|
||||||
|
for a, b in possible_inputs:
|
||||||
|
output = interpretation[Conjunction](a, b)
|
||||||
|
if a < b in model.ordering and output != a:
|
||||||
|
print("RETURNING FALSE")
|
||||||
|
return False
|
||||||
|
if b < a in model.ordering and output != b:
|
||||||
|
print("RETURNING FALSE")
|
||||||
|
return False
|
||||||
|
|
||||||
|
if Disjunction in interpretation:
|
||||||
|
possible_inputs = ((a, b) for (a, b) in product(model.carrier_set, model.carrier_set))
|
||||||
|
for a, b in possible_inputs:
|
||||||
|
output = interpretation[Disjunction](a, b)
|
||||||
|
if a < b in model.ordering and output != b:
|
||||||
|
print("RETURNING FALSE")
|
||||||
|
return False
|
||||||
|
if b < a in model.ordering and output != a:
|
||||||
|
print("RETURNING FALSE")
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def satisfiable(logic: Logic, model: Model, interpretation: Dict[Operation, ModelFunction]) -> bool:
|
def satisfiable(logic: Logic, model: Model, interpretation: Dict[Operation, ModelFunction]) -> bool:
|
||||||
pvars = tuple(get_propostional_variables(tuple(logic.rules)))
|
pvars = tuple(get_propostional_variables(tuple(logic.rules)))
|
||||||
mappings = all_model_valuations_cached(pvars, tuple(model.carrier_set))
|
mappings = all_model_valuations_cached(pvars, tuple(model.carrier_set))
|
||||||
|
|
||||||
"""
|
# NOTE: Does not look like rule ordering is helping for finding
|
||||||
TODO: Make sure that ordering for conjunction and disjunction
|
# models of R...
|
||||||
at the model function level.
|
if not rule_ordering_satisfied(model, interpretation):
|
||||||
"""
|
return False
|
||||||
|
|
||||||
for mapping in mappings:
|
for mapping in mappings:
|
||||||
for rule in logic.rules:
|
for rule in logic.rules:
|
||||||
|
|
Loading…
Reference in a new issue