mirror of
https://github.com/Brandon-Rozek/matmod.git
synced 2025-12-19 05:10:25 +00:00
Implementing optimization #14
Discard subalgebras which are order-dependent
This commit is contained in:
parent
9f80fb8bba
commit
4b907281a5
3 changed files with 43 additions and 6 deletions
18
vsp.py
18
vsp.py
|
|
@ -6,7 +6,7 @@ from itertools import chain, combinations, product
|
|||
from typing import Dict, List, Optional, Set, Tuple
|
||||
from common import set_to_str
|
||||
from model import (
|
||||
Model, model_closure, ModelFunction, ModelValue
|
||||
Model, model_closure, ModelFunction, ModelValue, OrderTable
|
||||
)
|
||||
from logic import Conjunction, Disjunction, Implication, Operation
|
||||
|
||||
|
|
@ -79,6 +79,15 @@ def find_bottom(algebra: Set[ModelValue], mconjunction: Optional[ModelFunction],
|
|||
print("[Warning] Failed to find the bottom of the lattice")
|
||||
return None
|
||||
|
||||
def order_dependent(subalgebra1: Set[ModelValue], subalegbra2: Set[ModelValue], ordering: OrderTable):
|
||||
"""
|
||||
Returns true if there exists a value in subalgebra1 that's less than a value in subalgebra2
|
||||
"""
|
||||
for x in subalgebra1:
|
||||
for y in subalegbra2:
|
||||
if ordering.is_lt(x, y):
|
||||
return True
|
||||
return False
|
||||
|
||||
class VSP_Result:
|
||||
def __init__(
|
||||
|
|
@ -111,6 +120,8 @@ def has_vsp(model: Model, impfunction: ModelFunction, mconjunction: Optional[Mod
|
|||
if len(model.designated_values) == 1:
|
||||
return VSP_Result(False, model.name)
|
||||
|
||||
assert model.ordering is not None, "Expected ordering table in model"
|
||||
|
||||
# Compute I the set of tuples (x, y) where
|
||||
# x -> y does not take a designiated value
|
||||
I: Set[Tuple[ModelValue, ModelValue]] = set()
|
||||
|
|
@ -158,6 +169,11 @@ def has_vsp(model: Model, impfunction: ModelFunction, mconjunction: Optional[Mod
|
|||
if bottom is not None and bottom in xs:
|
||||
continue
|
||||
|
||||
# NOTE: Optimization
|
||||
# If the subalgebras are order-dependent, skip this pair
|
||||
if order_dependent(xs, ys, model.ordering):
|
||||
continue
|
||||
|
||||
# Compute the closure of all operations
|
||||
# with just the xs
|
||||
carrier_set_left: Set[ModelValue] = model_closure(xs, model.logical_operations, bottom)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue