Coverage for src/SymbSyntDec/state_variables.py: 57%

1

2 from functools import singledispatch

3

4 from pylogics_modalities.syntax.base import (

5 And as PLTLAnd,

6 Or as PLTLOr,

7 Formula,

8 Not as PLTLNot,

9 _UnaryOp

10)

11 from pylogics_modalities.syntax.pltl import (

12 Atomic as PLTLAtomic,

13 Before,

14 WeakBefore,

15 PropositionalFalse,

16 PropositionalTrue,

17 Since,

18 Triggers

19)

20

21

22 State_variables_simple_dict = {}

23 complex_dic_atoms = {}

24 index = 1

25

26

27 def state_variables_unaryop(formula: _UnaryOp):

28 return state_variables_operands(formula.argument)

29

30

31 def 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

35

36

37@ singledispatch

38 def state_variables_operands(formula: object) -> Formula:

39 raise NotImplementedError(

40 f"State_variables not implemented for object of type {type(formula)}"

41 )

42

43

44@state_variables_operands.register

45 def state_variables_prop_true(formula: PropositionalTrue):

46 True

47

48

49@state_variables_operands.register

50 def state_variables_prop_false(formula: PropositionalFalse):

51 True

52

53

54@state_variables_operands.register

55 def state_variables_atomic(formula: PLTLAtomic):

56 True

57

58

59@state_variables_operands.register

60 def state_variables_and(formula: PLTLAnd):

61 True

62

63

64@state_variables_operands.register

65 def state_variables_or(formula: PLTLOr):

66 True

67

68

69@state_variables_operands.register

70 def state_variables_not(formula: PLTLNot):

71 True

72

73

74@state_variables_operands.register

75 def 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)

79

80

81@state_variables_operands.register

82 def 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)

86

87

88 def 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

102

103

104@state_variables_operands.register

105 def state_variables_since(formula: Since):

106 True

107

108

109@state_variables_operands.register

110 def state_variables_since(formula: Triggers):

111 True