INonLinearConstraint.Result

Syntax

Result: Double;

Description

The Result property returns non-linear constraint value.

Comments

To determine non-linear function of constraint, use the INonLinearConstraint.NonLinearFunction property.

Example

To execute the example, add a link to the Stat system assembly.

Sub UserProc;
Var
    nlo: ISmNonLinearOptimization;
    LinCons: ISlLinearConstraints;
    LinCon: ISlLinearConstraint;
    NonLinCons: INonLinearConstraints;
    NonLinCon1, NonLinCon2: INonLinearConstraint;
    lb,ub: Array[0..3Of Double;
    init: Array[0..3Of Double;
    LinConCfs: Array[0..3Of Double;
    i,res: Integer;
    OptVal: Double;
    Sol, FuncGrad: Array Of Double;
Begin
    nlo := New SmNonLinearOptimization.Create;
    For i := 0 To 3 Do
        lb[i] := 1;
        ub[i] := 5;
        LinConCfs[i] := 1;
    End For;
    // Function optimization parameters
    nlo.Boundary.BoundaryLower := lb;
    nlo.Boundary.BoundaryUpper := ub;
    nlo.CoefficientsOrder := "x1;x2;x3;x4";
    nlo.FunctionString := "x1*x4*(x1+x2+x3)+x3";
    init[0] := 1;
    init[1] := 5;
    init[2] := 5;
    init[3] := 1;
    nlo.InitApproximation := init;
    nlo.MaxIteration := 75;
    // === Collection of linear constraints ===
    LinCons := nlo.LinearConstraints;
    // Linear constraint parameters
    LinCon := LinCons.Add;
    LinCon.BoundaryLower := -10e20;
    LinCon.BoundaryUpper := 20;
    LinConCfs[0] := 1;
    LinConCfs[1] := 1;
    LinConCfs[2] := 1;
    LinConCfs[3] := 1;
    LinCon.Value := LinConCfs;
    // === Collection of non-linear constraints ===
    NonLinCons := nlo.NonLinearConstraints;
    // First non-linear constraint
    NonLinCon1 := NonLinCons.Add;
    NonLinCon1.BoundaryLower := -10e20;
    NonLinCon1.BoundaryUpper := 40;
    NonLinCon1.NonLinearFunction := "x1*x1+x2*x2+x3*x3+x4*x4";
    // Second non-linear constraint
    NonLinCon2 := NonLinCons.Add;
    NonLinCon2.BoundaryLower := 25;
    NonLinCon2.BoundaryUpper := 10e21;
    NonLinCon2.NonLinearFunction := "x1*x2*x3*x4";
    // Calculate model
    res := nlo.Execute;
    If res<>0 Then
        Debug.WriteLine(nlo.Errors);
        Else
            Debug.WriteLine("== Criterion function value ==");
            OptVal := nlo.OptimalFunctionValue;
            Debug.WriteLine(OptVal.ToString);
            Debug.WriteLine("=== Solution ===");
            Sol := nlo.Solution;
            For i := 0 To Sol.Length - 1 Do
                Debug.WriteLine(i.ToString + ". " + Sol[i].ToString);
            End For;
            Debug.WriteLine("=== Criterion function gradient ===");
            FuncGrad := nlo.FunctionGradient;
            For i := 0 To FuncGrad.Length - 1 Do
                Debug.WriteLine(i.ToString + ". " + FuncGrad[i].ToString);
            End For;
            Debug.WriteLine("=== Values of non-linear constraints ===");
            Debug.WriteLine("1. " + NonLinCon1.Result.ToString);
            Debug.WriteLine("2. " + NonLinCon2.Result.ToString);
    End If;
End Sub UserProc;

After executing the example the console window displays the found solution, criterion function gradient, and values of non-linear constraints.

See also:

INonLinearConstraint