IMsUORuntime.Constraints

Syntax

Constraints: IMsUORuntimeConstraints;

Description

The Constraints property returns the collection of criterion function constraints.

Example

Executing the example requires that the repository contains a modeling container containing a custom optimization model. The problem should have a unit that implements a custom algorithm. Consider the example of this unit contents.

Add links to the Ms and Xml system assemblies.

Public Class UserOptimization: Object, IMsUserOptimizationCallback
    _b: Boolean;
    
    Public Sub OnLoad(Xml: IXMLDOMElement);
    Begin
        _b := False;
    End Sub OnLoad;

    Public Sub OnSave(Xml: IXMLDOMElement);
    Begin
    End Sub OnSave;

    Public Sub OnBeforeExecute(Calculation: IMsMethodCalculation; Coord: IMsFormulaTransformCoord; Problem: IMsUserOptimizationProblem);
    Begin
    End Sub OnBeforeExecute;

    Public Sub OnExecute(Runtime: IMsUORuntime);
    Var
        Constraints: IMsUORuntimeConstraints;
        Constraint: IMsUORuntimeConstraint;
        i, c: Integer;
    Begin
        If Not _b Then
            Constraints := Runtime.Constraints;
            c := Constraints.Count;
            For i := 0 To c - 1 Do
                Debug.WriteLine("Constraint " + i.ToString);
                Constraint := Constraints.Item(i);
                Debug.Indent;
                Debug.WriteLine("Expression: " + Constraint.Constraint.Expression.AsString);
                Debug.WriteLine("H: " + Constraint.ExecuteH);
                Debug.WriteLine("M: " + Constraint.ExecuteM);
                Debug.WriteLine("L: " + Constraint.ExecuteL);
                Debug.WriteLine("String H: " + Constraint.GenerateStringH);
                Debug.WriteLine("String M: " + Constraint.GenerateStringM);
                Debug.WriteLine("String L: " + Constraint.GenerateStringL);
                Debug.Unindent;
            End For;
            _b := True;
        End If;
        // Calculate equations in the current point
        Runtime.Equations.ExecuteAll;
    End Sub OnExecute;

    Public Sub OnAfterExecute(Calculation: IMsMethodCalculation; Coord: IMsFormulaTransformCoord; Problem: IMsUserOptimizationProblem);
    Begin
    End Sub OnAfterExecute;

    Public Sub OnSetupParams(Params: IMsModelParams);
    Begin
    End Sub OnSetupParams;
End Class UserOptimization;

When a custom optimization problem is is started, the OnExecute event will occur in each calculation point. The development environment console will once display information about existing criterion function constraints. After this, all equations will be calculated in each calculation point.

See also:

IMsUORuntime