You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This has been extracted from the Constraint class in the FM_METAMODEL, and it should be included in a kind of ConstraintsHelper.
This can be implemented using the AST directly like for the following "is_requires_constraint" :
def is_simple_constraint(self) -> bool:
return self.is_requires_constraint() or self.is_excludes_constraint()
def is_complex_constraint(self) -> bool:
return self.is_pseudocomplex_constraint() or self.is_strictcomplex_constraint()
def is_requires_constraint(self) -> bool:
root_op = self._ast.root
if root_op.is_binary_op():
if root_op.data in [ASTOperation.REQUIRES, ASTOperation.IMPLIES]:
return root_op.left.is_term() and root_op.right.is_term()
elif root_op.data == ASTOperation.OR:
neg_left = root_op.left.data == ASTOperation.NOT and root_op.left.left.is_term()
neg_right = root_op.right.data == ASTOperation.NOT and root_op.right.left.is_term()
return neg_left and root_op.right.is_term() or neg_right and root_op.left.is_term()
return False
or using the CNF form of the AST as follows:
def is_requires_constraint(self) -> bool:
if len(self._clauses) == 1 and len(self._clauses[0]) == 2:
nof_negative_clauses = sum(var.startswith('-') for var in self._clauses[0])
return nof_negative_clauses == 1
return False
def is_excludes_constraint(self) -> bool:
if len(self._clauses) == 1 and len(self._clauses[0]) == 2:
nof_negative_clauses = sum(var.startswith('-') for var in self._clauses[0])
return nof_negative_clauses == 2
return False
def is_strictcomplex_constraint(self) -> bool:
if len(self._clauses) == 1 and len(self._clauses[0]) == 2:
nof_negative_clauses = sum(var.startswith('-') for var in self._clauses[0])
return nof_negative_clauses == 0
strictcomplex = False
i = iter(self._clauses)
while not strictcomplex and (cls := next(i, None)) is not None:
if len(cls) != 2:
strictcomplex = True
else:
nof_negative_clauses = sum(var.startswith('-') for var in cls)
if nof_negative_clauses not in [1, 2]:
strictcomplex = True
return strictcomplex
def is_pseudocomplex_constraint(self) -> bool:
if len(self._clauses) == 1:
return False
strictcomplex = False
i = iter(self._clauses)
while not strictcomplex and (cls := next(i, None)) is not None:
if len(cls) != 2:
strictcomplex = True
else:
nof_negative_clauses = sum(var.startswith('-') for var in cls)
if nof_negative_clauses not in [1, 2]:
strictcomplex = True
return not strictcomplex
The text was updated successfully, but these errors were encountered:
This has been extracted from the Constraint class in the FM_METAMODEL, and it should be included in a kind of ConstraintsHelper.
This can be implemented using the AST directly like for the following "is_requires_constraint" :
or using the CNF form of the AST as follows:
The text was updated successfully, but these errors were encountered: