Colin THOMAS

Add comments and logic attribute

...@@ -15,6 +15,16 @@ def fixpoint(fonction, start): ...@@ -15,6 +15,16 @@ def fixpoint(fonction, start):
15 ####################### CTL ####################### 15 ####################### CTL #######################
16 16
17 class CTL_model_checker(object): 17 class CTL_model_checker(object):
18 + """
19 + Object which can symbolically compute the subset of the universe where a given CTL formula is satisfied.
20 +
21 + Attributes :
22 + - variables : the list of the variables
23 +
24 + Methods :
25 + - check(formula) : returns the sdd representing the subset of the universe where the input formula is satisfied
26 + - atom(var) : returns the sdd representing the subset of the universe where var is True
27 + """
18 def __init__ (self, universe, pred): 28 def __init__ (self, universe, pred):
19 """ 29 """
20 Input : 30 Input :
...@@ -24,6 +34,8 @@ class CTL_model_checker(object): ...@@ -24,6 +34,8 @@ class CTL_model_checker(object):
24 # TODO : mettre en cache les output de phi2sdd ? 34 # TODO : mettre en cache les output de phi2sdd ?
25 assert isinstance(universe, sdd), "universe must be of type sdd" 35 assert isinstance(universe, sdd), "universe must be of type sdd"
26 assert isinstance(pred, shom), "pred must be of type shom" 36 assert isinstance(pred, shom), "pred must be of type shom"
37 +
38 + self.logic = "CTL"
27 39
28 self.variables = next(iter(universe))[0].vars() # c'est tres sale mais je trouve pas d'autre solution pour l'instant 40 self.variables = next(iter(universe))[0].vars() # c'est tres sale mais je trouve pas d'autre solution pour l'instant
29 41
...@@ -60,7 +72,11 @@ class CTL_model_checker(object): ...@@ -60,7 +72,11 @@ class CTL_model_checker(object):
60 @lru_cache(maxsize=None) # si la version de python etait 3.9 on pourrait utiliser functools.cache directement 72 @lru_cache(maxsize=None) # si la version de python etait 3.9 on pourrait utiliser functools.cache directement
61 def atom(self, var): 73 def atom(self, var):
62 """ 74 """
75 + Input :
76 + - var : string
63 77
78 + Output :
79 + The sdd representing the subset of the universe where var is True.
64 """ 80 """
65 assert var in self.variables, var + " is not a variable" 81 assert var in self.variables, var + " is not a variable"
66 d = ddd.one() 82 d = ddd.one()
...@@ -93,10 +109,17 @@ class CTL_model_checker(object): ...@@ -93,10 +109,17 @@ class CTL_model_checker(object):
93 elif phi.kind in self.binarymod: 109 elif phi.kind in self.binarymod:
94 return self.binarymod[phi.kind](self._phi2sdd(phi.children[0]), self._phi2sdd(phi.children[1])) 110 return self.binarymod[phi.kind](self._phi2sdd(phi.children[0]), self._phi2sdd(phi.children[1]))
95 else: 111 else:
96 - raise ValueError(repr(phi) + "is not a CTL sub formula") 112 + raise ValueError(repr(phi) + "is not a " + self.logic + " CTL sub formula")
97 113
98 114
99 def check(self, formula): 115 def check(self, formula):
116 + """
117 + Input :
118 + - formula : string or tl.Phi object
119 +
120 + Output :
121 + The sdd representing the subset of the universe where the formula is satisfied.
122 + """
100 assert isinstance(formula , str) or isinstance(formula , Phi), "The formula given in input must be a string or a parsed formula" 123 assert isinstance(formula , str) or isinstance(formula , Phi), "The formula given in input must be a string or a parsed formula"
101 if isinstance(formula , str): 124 if isinstance(formula , str):
102 formula = parse(formula).ctl() 125 formula = parse(formula).ctl()
...@@ -115,6 +138,7 @@ class FairCTL_model_checker(CTL_model_checker): ...@@ -115,6 +138,7 @@ class FairCTL_model_checker(CTL_model_checker):
115 - fairness is a list of CTL formulae (or sdd) to be used as fairness constraints (the fair trajectory must satisfy and[GF f for f in fairness]) 138 - fairness is a list of CTL formulae (or sdd) to be used as fairness constraints (the fair trajectory must satisfy and[GF f for f in fairness])
116 """ 139 """
117 super().__init__(universe, pred) 140 super().__init__(universe, pred)
141 + self.logic = "Fair CTL"
118 if isinstance(fairness, list): 142 if isinstance(fairness, list):
119 pass 143 pass
120 elif isinstance(fairness, str) or isinstance(fairness, sdd) : 144 elif isinstance(fairness, str) or isinstance(fairness, sdd) :
......