mirror of
				https://github.com/Brandon-Rozek/matmod.git
				synced 2025-11-03 03:11:12 +00:00 
			
		
		
		
	Introduced ordering at model level...
This commit is contained in:
		
							parent
							
								
									20ccacc166
								
							
						
					
					
						commit
						ae8658fda2
					
				
					 2 changed files with 67 additions and 22 deletions
				
			
		| 
						 | 
				
			
			@ -22,7 +22,7 @@ def possible_functions(operation, carrier_set):
 | 
			
		|||
        new_function = dict()
 | 
			
		||||
        for input, output in zip(inputs, outputs):
 | 
			
		||||
            new_function[input] = output
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        yield ModelFunction(new_function, operation.symbol)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -46,7 +46,6 @@ def only_rules_with(rules: Set[Rule], operation: Operation) -> Set[Rule]:
 | 
			
		|||
    return result_rules
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def possible_interpretations(
 | 
			
		||||
        logic: Logic, carrier_set: Set[ModelValue],
 | 
			
		||||
        designated_values: Set[ModelValue]):
 | 
			
		||||
| 
						 | 
				
			
			@ -88,10 +87,25 @@ def possible_interpretations(
 | 
			
		|||
        yield interpretation
 | 
			
		||||
 | 
			
		||||
def generate_model(logic: Logic, number_elements: int, num_solutions: int = -1, print_model=False):
 | 
			
		||||
    assert number_elements > 0
 | 
			
		||||
    carrier_set = {
 | 
			
		||||
        ModelValue("a" + str(i)) for i in range(number_elements)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ordering = set()
 | 
			
		||||
 | 
			
		||||
    # a(0) is less than all other elements
 | 
			
		||||
    a0 = ModelValue("a0")
 | 
			
		||||
    for v in carrier_set:
 | 
			
		||||
        if v != a0:
 | 
			
		||||
            ordering.add(a0 < v)
 | 
			
		||||
 | 
			
		||||
    # Every other element is less than a(n - 1)
 | 
			
		||||
    an = ModelValue(f"a{number_elements-1}")
 | 
			
		||||
    for v in carrier_set:
 | 
			
		||||
        if an != v:
 | 
			
		||||
            ordering.add(v < an)
 | 
			
		||||
 | 
			
		||||
    possible_designated_values = possible_designations(carrier_set)
 | 
			
		||||
 | 
			
		||||
    satisfied_models = []
 | 
			
		||||
| 
						 | 
				
			
			@ -102,7 +116,7 @@ def generate_model(logic: Logic, number_elements: int, num_solutions: int = -1,
 | 
			
		|||
 | 
			
		||||
        for interpretation in possible_interps:
 | 
			
		||||
            is_valid = True
 | 
			
		||||
            model = Model(carrier_set, set(interpretation.values()), designated_values)
 | 
			
		||||
            model = Model(carrier_set, set(interpretation.values()), designated_values, ordering)
 | 
			
		||||
            # Iteratively test possible interpretations
 | 
			
		||||
            # by adding one axiom at a time
 | 
			
		||||
            for rule in logic.rules:
 | 
			
		||||
| 
						 | 
				
			
			@ -110,12 +124,12 @@ def generate_model(logic: Logic, number_elements: int, num_solutions: int = -1,
 | 
			
		|||
                if not satisfiable(small_logic, model, interpretation):
 | 
			
		||||
                    is_valid = False
 | 
			
		||||
                    break
 | 
			
		||||
            
 | 
			
		||||
 | 
			
		||||
            if is_valid:
 | 
			
		||||
                satisfied_models.append(model)
 | 
			
		||||
                if print_model:
 | 
			
		||||
                    print(model, flush=True)
 | 
			
		||||
            
 | 
			
		||||
 | 
			
		||||
            if num_solutions >= 0 and len(satisfied_models) >= num_solutions:
 | 
			
		||||
                return satisfied_models
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue