Hello community,
do anyone know how it is possible to use SysIDE to check compliance with all defined contraints?
Example:
require contraint{
maxLatTime >= realLatTime}
realLatTime = latTime1 + latTime2;
So I have a lot of contraints for timing, mass, etc. Is there a way to run the check of these contraints automatically?
Hi, Andy!
Yes, there is a way of checking these constraints using Automator. I will assume you know how to load your model into a python environment and will refer to it as model
. Below is an example code snippet that would check the constraint you have described:
def check_constraint_expression(constraint: syside.OperatorExpression) -> bool:
referenced_elements = constraint.arguments.collect()
evaluation_1 = syside.Compiler().evaluate(referenced_elements[0])
if evaluation_1[1].fatal:
raise Exception("Error evaluating expression")
else:
value_1 = evaluation_1[0]
evaluation_2 = syside.Compiler().evaluate(referenced_elements[1])
if evaluation_2[1].fatal:
raise Exception("Error evaluating expression")
else:
value_2 = evaluation_2[0]
match constraint.operator:
case syside.Operator.GreaterEqual:
return value_1 >= value_2
case syside.Operator.Greater:
return value_1 > value_2
case syside.Operator.LessEqual:
return value_1 <= value_2
case syside.Operator.Less:
return value_1 < value_2
case syside.Operator.Equals:
return value_1 == value_2
case syside.Operator.NotEquals:
return value_1 != value_2
case _:
raise ValueError(f"Unsupported operator: {constraint.operator}")
for requirement in model.nodes(syside.RequirementDefinition):
for constraint in requirement.required_constraints.collect():
expression = constraint.result_expression
if check_constraint_expression(expression):
print('Constraint is satisfied')
else:
print('Constraint is not satisfied')
One thing worth noting is that SysML v2 does not specify how to execute on calculating requirements and constraints, which is why you have to do so ‘by hand’. As a result, you should modify the above code to your specific needs.
An example of such modifications could be if you have a requirement in the form of
requirement def multipleConstraintRequirement{
require constraint {value1 <= maxValue1}
require constraint {value2 <= maxValue2}
}
The example code evaluates the constraints separately, you would have to add additional logic if you wish to see if all the constraints of a specific requirement are met simultaneously.
Hopefully this solution fits your use case. If you have any further questions, please do let me know!