# Calculation with contraints

**URL:** <https://forum.sensmetry.com/t/calculation-with-contraints/148>\
**Category:** How-to Guides\
**Tags:** modeler, sysmlv2\
**Created:** [July 2, 2025, 12:26pm UTC](https://forum.sensmetry.com/t/calculation-with-contraints/148 "2025-07-02T12:26:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![GehlsenAndy](https://avatars.discourse-cdn.com/v4/letter/g/b487fb/32.png) [@GehlsenAndy](https://forum.sensmetry.com/u/GehlsenAndy)\
**Post date:** [July 2, 2025, 12:26pm UTC](https://forum.sensmetry.com/t/calculation-with-contraints/148/1 "2025-07-02T12:26:25Z")

</div>

Hello community,

do anyone know how it is possible to use [SysIDE](https://sensmetry.com/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?

---

<div class="post-metadata">

**Author:** ![Martynas\_Strazdas](https://yyz2.discourse-cdn.com/flex008/user_avatar/forum.sensmetry.com/martynas_strazdas/32/21_2.png) [@Martynas\_Strazdas](https://forum.sensmetry.com/u/Martynas_Strazdas)\
**Post date:** [July 3, 2025, 8:37am UTC](https://forum.sensmetry.com/t/calculation-with-contraints/148/2 "2025-07-03T08:37:10Z")

</div>

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:

```python
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

```sysml
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!
