Coverage for src/SymbSyntDec/state_variables.py: 57%
54 statements
« prev ^ index » next coverage.py v7.5.4, created at 2024-08-11 18:00 +0200
« prev ^ index » next coverage.py v7.5.4, created at 2024-08-11 18:00 +0200
2from functools import singledispatch
4from pylogics_modalities.syntax.base import (
5 And as PLTLAnd,
6 Or as PLTLOr,
7 Formula,
8 Not as PLTLNot,
9 _UnaryOp
10)
11from pylogics_modalities.syntax.pltl import (
12 Atomic as PLTLAtomic,
13 Before,
14 WeakBefore,
15 PropositionalFalse,
16 PropositionalTrue,
17 Since,
18 Triggers
19)
22State_variables_simple_dict = {}
23complex_dic_atoms = {}
24index = 1
27def state_variables_unaryop(formula: _UnaryOp):
28 return state_variables_operands(formula.argument)
31def state_variables(formula: set) -> (set, dict): # type: ignore
32 for form in formula:
33 state_variables_operands(form)
34 return State_variables_simple_dict, complex_dic_atoms
37@ singledispatch
38def state_variables_operands(formula: object) -> Formula:
39 raise NotImplementedError(
40 f"State_variables not implemented for object of type {type(formula)}"
41 )
44@state_variables_operands.register
45def state_variables_prop_true(formula: PropositionalTrue):
46 True
49@state_variables_operands.register
50def state_variables_prop_false(formula: PropositionalFalse):
51 True
54@state_variables_operands.register
55def state_variables_atomic(formula: PLTLAtomic):
56 True
59@state_variables_operands.register
60def state_variables_and(formula: PLTLAnd):
61 True
64@state_variables_operands.register
65def state_variables_or(formula: PLTLOr):
66 True
69@state_variables_operands.register
70def state_variables_not(formula: PLTLNot):
71 True
74@state_variables_operands.register
75def state_variables_yesterday(formula: Before) -> Formula:
76 """Compute the base formula for a Before (Yesterday) formula."""
77 add_variable(formula, "Yesterday")
78 # state_variables_unaryop(formula)
81@state_variables_operands.register
82def state_variables_weak_yesterday(formula: WeakBefore) -> Formula:
83 """Compute the base formula for a WeakBefore (Weak Yesterday) formula."""
84 add_variable(formula, "WeakYesterday")
85 # state_variables_unaryop(formula)
88def add_variable(formula, modality):
89 global complex_dic_atoms
90 if not (formula in complex_dic_atoms):
91 global index
92 complex_dic_atoms['x_var' + str(index)] = formula
93 complex_dic_atoms[formula] = 'x_var' + str(index)
94 State_variables_simple_dict['x_var' + str(index)] = formula
95 if not (modality in complex_dic_atoms):
96 complex_dic_atoms[
97 modality] = ['x_var' + str(index)]
98 else:
99 complex_dic_atoms[modality] = complex_dic_atoms[modality] + [
100 'x_var' + str(index)]
101 index += 1
104@state_variables_operands.register
105def state_variables_since(formula: Since):
106 True
109@state_variables_operands.register
110def state_variables_since(formula: Triggers):
111 True