ITargetConstraintInfo.OptimalValue

Fore syntax

OptimalValue: Double;

Fore.NET syntax

OptimalValue: double;

Description

The OptimalValue property returns the value corresponding to optimal solution of criterion function.

Comments

The value is available only after criterion problem calculation.

Fore example

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

Sub UserProc;
Var
    TargetAdj: ICpTargetAdjustment;
    T: Integer;
    RetroX1, RetroU: Array Of Double;
    InitApproximation, Ser: Array Of Double;
    i: Integer;
    VarsP: ITargetPhaseVariablesArray;
    VrblP: ITargetPhaseVariable;
    VarConstrs: IVarTargetConstraintsArray;
    VarConstr: IVarTargetConstraint;
    VarsC: ITargetControlVariablesArray;
    VrblC: ITargetControlVariable;
    Constraints: ITargetConstraints;
    Constraint: ITargetConstraint;
    ConInfoArray: ITargetConstraintInfoArray;
    ConInfo: ITargetConstraintInfo;
    Res: ITargetResults;
Begin
    TargetAdj := New TargetAdjustment.Create;
    // Set period
    T := 6;
    // Create variables with restrospective
    RetroX1 := New Double[T];
    RetroU := New Double[T];
    Ser := New Double[T];
    // Create an array of initial approximations
    InitApproximation := New Double[T];
    // Set initial variable values
    For i := 0 To T - 1 Do
        RetroX1[i] := 0.8 + i / 5;
        RetroU[i] := 0.9 + i / 10;
    End For;
    // Get phase variables
    VarsP := TargetAdj.PhaseVariables;
    // Add phase variable x1
    VrblP := VarsP.Add("x1");
    VrblP.Name := "x1";
    // Set retrospective values
    VrblP.Retrospective := RetroX1;
    // Set order of variables
    VrblP.CoefficientsOrder := "x1[t];x1[t-1]";
    // Get phase variable constraints
    VarConstrs := VrblP.Constraints;
    For i := 0 To T - 1 Do
        // Create a new constraint
        VarConstr := VarConstrs.Add;
        // Set borders
        VarConstr.LowerBound := -10 - i / 100;
        VarConstr.UpperBound := 10 + i / 100;
        // Specify the current moment of time
        VarConstr.TimeMoment := i;
    End For;
    // Set frequency equation
    VrblP.FunctionExpression := "0.3 * x1[t-1] + 0.1 * u[t-1] * x1[t-1] *u[t]";
    // Get controlling variables
    VarsC := TargetAdj.ControlVariables;
    // Add controlling variable u
    VrblC := VarsC.Add("u");
    VrblC.Name := "u";
    // Set retrospective values
    VrblC.Retrospective := RetroU;
    // Set order of coefficients
    VrblC.CoefficientsOrder := "u[t];u[t-1]";
    // Set values of initial approximations
    For i := 0 To T - 1 Do
        InitApproximation[i] := 1.2 + (i + 1) / 100;
    End For;
    VrblC.InitApproximation := InitApproximation;
    // Get controlling variable constraints
    VarConstrs := VrblC.Constraints;
    For i := 0 To T - 1 Do
        // Add constraint
        VarConstr := VarConstrs.Add;
        // Set constraint borders
        VarConstr.LowerBound := 1;
        VarConstr.UpperBound := 2;
        // Set the current moment of time
        VarConstr.TimeMoment := i;
    End For;
    // Set criterion trajectory
    For i := 0 To T - 1 Do
        ser[i] := i;
    End For;
    TargetAdj.TargetTrajectory := Ser;
    // Set criterion function
    TargetAdj.CriterionFunction := "x1[t] + u[t-1] - u[t] ";
    // Set number of iterations
    TargetAdj.MaxIterationsCount := 25000;
    // Set accuracy of solution
    TargetAdj.Tolerance := 0.00001;
    // Get non-linear constraints of criterion function
    Constraints := TargetAdj.Constraints;
    // Add non-linear constraint
    Constraint := Constraints.Add;
    // Set non-linear constraint expression
    Constraint.Expression := "u[t] + x1[t]*0.001";
    ConInfoArray := Constraint.Constraints;
    For i := 0 To T - 1 Do
        conInfo := ConInfoArray.Add;
        conInfo.TimeMoment := i;
        conInfo.LowerBound := -1.5555-i;
        coninfo.UpperBound := 1.55555 + i;
        coninfo.LowerBoundFixed := False;
        coninfo.UpperBoundFixed := False;
    End For;
    // Set problem type
    TargetAdj.AutoSearchType := TargetAutoSearchType.MinError;
    // Set number of cycles
    TargetAdj.AutoAdjustMaxIter := 10;
    // Set allowed accuracy
    TargetAdj.AutoAdjustSatisfactoryTolerance := 1.01;
    // Set number of constraints removed in one iteration
    TargetAdj.AutoAdjustRemoveCount := 2;
    // Execute calculation
    Res := TargetAdj.Evaluate(T) As ITargetResults;
    // If calculation is executed without errors, output results to console
    If res.Status = 0 Then
    // Output optimal value
    Debug.WriteLine("Optimal value:");
    Debug.Indent;
        Debug.WriteLine(res.OptimalValue);
    Debug.Unindent;
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008000">//&nbsp;Output &nbsp;optimal&nbsp;trajectory&nbsp;of criterion&nbsp;function<br/> </font>&nbsp;&nbsp;&nbsp;&nbsp;Debug.WriteLine(<font color="#800000">&quot;Optimal&nbsp;trajectory&nbsp;of criterion&nbsp;function:&quot;</font>);<br/> &nbsp;&nbsp;&nbsp;&nbsp;Debug.Indent;<br/> &nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">For</font>&nbsp;i&nbsp;:=&nbsp;<font color="#008000">0</font>&nbsp;<font color="#008080">To</font>&nbsp;Res.CriterionFunctionTrajectory.Length&nbsp;-&nbsp;<font color="#008000">1</font>&nbsp;<font color="#008080">Do</font><br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.WriteLine(Res.CriterionFunctionTrajectory[i]);<br/> &nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">End</font>&nbsp;<font color="#008080">For</font>;<br/> &nbsp;&nbsp;&nbsp;&nbsp;Debug.Unindent;<br/> &nbsp;&nbsp;&nbsp;&nbsp;<font color="#008000">//&nbsp;Output&nbsp;non-linear&nbsp;constraints<br/> </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.WriteLine(<font color="#800000">&quot;Value&nbsp;corresponding to&nbsp;optimal&nbsp;solution&quot;</font>);<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.Indent;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">For</font>&nbsp;i&nbsp;:=&nbsp;<font color="#008000">0</font>&nbsp;<font color="#008080">To</font>&nbsp;ConInfoArray.Count&nbsp;-&nbsp;<font color="#008000">1</font>&nbsp;<font color="#008080">Do</font><br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conInfo&nbsp;:=&nbsp;ConInfoArray.Item(i);<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">If</font>&nbsp;conInfo.Include&nbsp;<font color="#008080">Then</font><br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.WriteLine(conInfo.OptimalValue);<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">End</font>&nbsp;<font color="#008080">If</font>;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">End</font>&nbsp;<font color="#008080">For</font>;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.Unindent;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008000">//&nbsp;Output&nbsp;values of&nbsp;lower&nbsp;constraint&nbsp;limit<br/> </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.WriteLine(<font color="#800000">&quot;Lower&nbsp;limit&nbsp;values;&nbsp;Status&quot;</font>);<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.Indent;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">For</font>&nbsp;i&nbsp;:=&nbsp;<font color="#008000">0</font>&nbsp;<font color="#008080">To</font>&nbsp;ConInfoArray.Count&nbsp;-&nbsp;<font color="#008000">1</font>&nbsp;<font color="#008080">Do</font><br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conInfo&nbsp;:=&nbsp;ConInfoArray.Item(i);<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">If</font>&nbsp;conInfo.Include&nbsp;<font color="#008080">Then</font><br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.Write(conInfo.LowerBound.ToString&nbsp;+&nbsp;<font color="#800000">&quot;;&nbsp;&quot;</font>&nbsp;+&nbsp;#9);<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.WriteLine(StatusToStr(conInfo.LowerConstraintStatus));<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">End</font>&nbsp;<font color="#008080">If</font>;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">End</font>&nbsp;<font color="#008080">For</font>;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.Unindent;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.WriteLine(<font color="#800000">&quot;Lagrange&nbsp;multiplier&nbsp;values&nbsp;for&nbsp;lower&nbsp;border&quot;</font>);<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.Indent;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">For</font>&nbsp;i&nbsp;:=&nbsp;<font color="#008000">0</font>&nbsp;<font color="#008080">To</font>&nbsp;ConInfoArray.Count&nbsp;-&nbsp;<font color="#008000">1</font>&nbsp;<font color="#008080">Do</font><br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conInfo&nbsp;:=&nbsp;ConInfoArray.Item(i);<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">If</font>&nbsp;conInfo.Include&nbsp;<font color="#008080">Then</font><br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.WriteLine(conInfo.LowerBoundLagrangeMultiplier);<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">End</font>&nbsp;<font color="#008080">If</font>;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">End</font>&nbsp;<font color="#008080">For</font>;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.Unindent;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.WriteLine(<font color="#800000">&quot;Upper&nbsp;limit&nbsp;values;&nbsp;Status&quot;</font>);<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.Indent;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">For</font>&nbsp;i&nbsp;:=&nbsp;<font color="#008000">0</font>&nbsp;<font color="#008080">To</font>&nbsp;ConInfoArray.Count&nbsp;-&nbsp;<font color="#008000">1</font>&nbsp;<font color="#008080">Do</font><br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conInfo&nbsp;:=&nbsp;ConInfoArray.Item(i);<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">If</font>&nbsp;conInfo.Include&nbsp;<font color="#008080">Then</font><br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.Write(conInfo.UpperBound.ToString&nbsp;+&nbsp;<font color="#800000">&quot;;&nbsp;&quot;</font>&nbsp;+&nbsp;#9);<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.WriteLine(StatusToStr(conInfo.UpperConstraintStatus));<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">End</font>&nbsp;<font color="#008080">If</font>;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">End</font>&nbsp;<font color="#008080">For</font>;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.Unindent;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.WriteLine(<font color="#800000">&quot;Lagrange&nbsp;multiplier&nbsp;values&nbsp;for&nbsp;upper&nbsp;limit&quot;</font>);<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.Indent;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">For</font>&nbsp;i&nbsp;:=&nbsp;<font color="#008000">0</font>&nbsp;<font color="#008080">To</font>&nbsp;ConInfoArray.Count&nbsp;-&nbsp;<font color="#008000">1</font>&nbsp;<font color="#008080">Do</font><br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conInfo&nbsp;:=&nbsp;ConInfoArray.Item(i);<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">If</font>&nbsp;conInfo.Include&nbsp;<font color="#008080">Then</font><br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.WriteLine(conInfo.UpperBoundLagrangeMultiplier);<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">End</font>&nbsp;<font color="#008080">If</font>;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">End</font>&nbsp;<font color="#008080">For</font>;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.Unindent;<br/> &nbsp;&nbsp;&nbsp;&nbsp;<font color="#008000">//&nbsp;If&nbsp;calculation&nbsp;is competed&nbsp;with&nbsp;error,&nbsp;output&nbsp;its&nbsp;text<br/> </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">Else</font><br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.WriteLine(res.ErrorMsg);<br/> &nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">End</font>&nbsp;<font color="#008080">If</font>;<br/> <font color="#008080">End</font>&nbsp;<font color="#008080">Sub</font>&nbsp;UserProc;<br/> <br/> <font color="#008000">//&nbsp;Function&nbsp;for&nbsp;status&nbsp;output<br/> </font><font color="#008080">Function</font>&nbsp;StatusToStr(Status:&nbsp;TargetConstraintStatusType):&nbsp;String;<br/> <font color="#008080">Var</font><br/> &nbsp;&nbsp;&nbsp;&nbsp;s:&nbsp;String;<br/> <font color="#008080">Begin</font><br/> &nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">Select</font>&nbsp;<font color="#008080">Case</font>&nbsp;Status<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">Case</font>&nbsp;TargetConstraintStatusType.Disabled:&nbsp;s&nbsp;:=&nbsp;<font color="#800000">&quot;Disabled&quot;</font>;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">Case</font>&nbsp;TargetConstraintStatusType.NotReached:&nbsp;s&nbsp;:=&nbsp;<font color="#800000">&quot;Not&nbsp;reached&quot;</font>;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">Case</font>&nbsp;TargetConstraintStatusType.Reached:&nbsp;s&nbsp;:=&nbsp;<font color="#800000">&quot;Reached&quot;</font>;<br/> &nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">End</font>&nbsp;<font color="#008080">Select</font>;<br/> &nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">Return</font>&nbsp;s;<br/> <font color="#008080">End</font>&nbsp;<font color="#008080">Function</font>&nbsp;StatusToStr;

After executing the example optimization problem parameters are set, the problem is calculated, results are displayed to the console.

Fore.NET example

The requirements and result of the Fore.NET example execution match with those in the Fore example.

Imports Prognoz.Platform.Interop.Cp;

Public Shared Sub Main(Params: StartParams);
Var
    TargetAdj: ICpTargetAdjustment;
    T: Integer;
    RetroX1, RetroU: Array Of Double;
    InitApproximation, Ser: Array Of Double;
    i: Integer;
    VarsP: ITargetPhaseVariablesArray;
    VrblP: ITargetPhaseVariable;
    VarConstrs: IVarTargetConstraintsArray;
    VarConstr: IVarTargetConstraint;
    VarsC: ITargetControlVariablesArray;
    VrblC: ITargetControlVariable;
    Constraints: ITargetConstraints;
    Constraint: ITargetConstraint;
    ConInfoArray: ITargetConstraintInfoArray;
    ConInfo: ITargetConstraintInfo;
    Res: ITargetResults;
Begin
    TargetAdj := New TargetAdjustment.Create();
    // Set period
    T := 6;
    // Create variables with restrospective
    RetroX1 := New Double[T];
    RetroU := New Double[T];
    Ser := New Double[T];
    // Create an array of initial approximations
    InitApproximation := New Double[T];
    // Set initial variable values
    For i := 0 To T - 1 Do
        RetroX1[i] := 0.8 + i / 5;
        RetroU[i] := 0.9 + i / 10;
    End For;
    // Get phase variables
    VarsP := TargetAdj.PhaseVariables;
    // Add phase variable x1
    VrblP := VarsP.Add("x1");
    VrblP.Name := "x1";
    // Set retrospective values
    VrblP.Retrospective := RetroX1;
    // Set order of variables
    VrblP.CoefficientsOrder := "x1[t];x1[t-1]";
    // Get phase variable constraints
    VarConstrs := VrblP.Constraints;
    For i := 0 To T - 1 Do
        // Create a new constraint
        VarConstr := VarConstrs.Add();
        // Set borders
        VarConstr.LowerBound := -10 - i / 100;
        VarConstr.UpperBound := 10 + i / 100;
        // Specify the current moment of time
        VarConstr.TimeMoment := i;
    End For;
    // Set frequency equation
    VrblP.FunctionExpression := "0.3 * x1[t-1] + 0.1 * u[t-1] * x1[t-1] *u[t]";
    // Get controlling variables
    VarsC := TargetAdj.ControlVariables;
    // Add controlling variable u
    VrblC := VarsC.Add("u");
    VrblC.Name := "u";
    // Set retrospective values
    VrblC.Retrospective := RetroU;
    // Set order of coefficients
    VrblC.CoefficientsOrder := "u[t];u[t-1]";
    // Set values of initial approximations
    For i := 0 To T - 1 Do
        InitApproximation[i] := 1.2 + (i + 1) / 100;
    End For;
    VrblC.InitApproximation := InitApproximation;
    // Get controlling variable constraints
    VarConstrs := VrblC.Constraints;
    For i := 0 To T - 1 Do
        // Add constraint
        VarConstr := VarConstrs.Add();
        // Set constraint borders
        VarConstr.LowerBound := 1;
        VarConstr.UpperBound := 2;
        // Set the current moment of time
        VarConstr.TimeMoment := i;
    End For;
    // Set criterion trajectory
    For i := 0 To T - 1 Do
        ser[i] := i;
    End For;
    TargetAdj.TargetTrajectory := Ser;
    // Set criterion function
    TargetAdj.CriterionFunction := "x1[t] + u[t-1] - u[t] ";
    // Set number of iterations
    TargetAdj.MaxIterationsCount := 25000;
    // Set accuracy of solution
    TargetAdj.Tolerance := 0.00001;
    // Get non-linear constraints of criterion function
    Constraints := TargetAdj.Constraints;
    // Add non-linear constraint
    Constraint := Constraints.Add();
    // Set non-linear constraint expression
    Constraint.Expression := "u[t] + x1[t]*0.001";
    ConInfoArray := Constraint.Constraints;
    For i := 0 To T - 1 Do
        conInfo := ConInfoArray.Add();
        conInfo.TimeMoment := i;
        conInfo.LowerBound := -1.5555-i;
        coninfo.UpperBound := 1.55555 + i;
        coninfo.LowerBoundFixed := False;
        coninfo.UpperBoundFixed := False;
    End For;
    // Set problem type
    TargetAdj.AutoSearchType := TargetAutoSearchType.tastMinError;
    // Set number of cycles
    TargetAdj.AutoAdjustMaxIter := 10;
    // Set allowed accuracy
    TargetAdj.AutoAdjustSatisfactoryTolerance := 1.01;
    // Set number of constraints removed in one iteration
    TargetAdj.AutoAdjustRemoveCount := 2;
    // Execute calculation
    Res := TargetAdj.Evaluate(T) As ITargetResults;
    // If calculation is executed without errors, output results to console
    If res.Status = 0 Then
    // Output optimal value
</font>&nbsp;&nbsp;&nbsp;&nbsp;System.Diagnostics.Debug.WriteLine(<font color="#800000">&quot;Optimal&nbsp;value:&quot;</font>);<br/> &nbsp;&nbsp;&nbsp;&nbsp;System.Diagnostics.Debug.Indent();<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Diagnostics.Debug.WriteLine(res.OptimalValue);<br/> &nbsp;&nbsp;&nbsp;&nbsp;System.Diagnostics.Debug.Unindent();<br/> &nbsp;&nbsp;&nbsp;&nbsp;<font color="#008000">//&nbsp;Output&nbsp;optimal&nbsp;trajectory&nbsp;of criterion&nbsp;function<br/> </font>&nbsp;&nbsp;&nbsp;&nbsp;System.Diagnostics.Debug.WriteLine(<font color="#800000">&quot;Optimal&nbsp;trajectory&nbsp;of criterion&nbsp;function:&quot;</font>);<br/> &nbsp;&nbsp;&nbsp;&nbsp;System.Diagnostics.Debug.Indent();<br/> &nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">For</font>&nbsp;i&nbsp;:=&nbsp;<font color="#008000">0</font>&nbsp;<font color="#008080">To</font>&nbsp;Res.CriterionFunctionTrajectory.Length&nbsp;-&nbsp;<font color="#008000">1</font>&nbsp;<font color="#008080">Do</font><br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Diagnostics.Debug.WriteLine(Res.CriterionFunctionTrajectory.GetValue(i));<br/> &nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">End</font>&nbsp;<font color="#008080">For</font>;<br/> &nbsp;&nbsp;&nbsp;&nbsp;System.Diagnostics.Debug.Unindent();<br/> &nbsp;&nbsp;&nbsp;&nbsp;<font color="#008000">//&nbsp;Output&nbsp;non-linear&nbsp;constraints<br/> </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Diagnostics.Debug.WriteLine(<font color="#800000">&quot;Value&nbsp;corresponding to&nbsp;optimal&nbsp;solution&quot;</font>);<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Diagnostics.Debug.Indent();<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">For</font>&nbsp;i&nbsp;:=&nbsp;<font color="#008000">0</font>&nbsp;<font color="#008080">To</font>&nbsp;ConInfoArray.Count&nbsp;-&nbsp;<font color="#008000">1</font>&nbsp;<font color="#008080">Do</font><br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conInfo&nbsp;:=&nbsp;ConInfoArray.Item[i];<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">If</font>&nbsp;conInfo.Include&nbsp;<font color="#008080">Then</font><br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Diagnostics.Debug.WriteLine(conInfo.OptimalValue);<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">End</font>&nbsp;<font color="#008080">If</font>;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">End</font>&nbsp;<font color="#008080">For</font>;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Diagnostics.Debug.Unindent();<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008000">//&nbsp;Output&nbsp;values of&nbsp;lower&nbsp;constraint&nbsp;border<br/> </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Diagnostics.Debug.WriteLine(<font color="#800000">&quot;Lower&nbsp;constraint&nbsp;border values;&nbsp;Status&quot;</font>);<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Diagnostics.Debug.Indent();<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">For</font>&nbsp;i&nbsp;:=&nbsp;<font color="#008000">0</font>&nbsp;<font color="#008080">To</font>&nbsp;ConInfoArray.Count&nbsp;-&nbsp;<font color="#008000">1</font>&nbsp;<font color="#008080">Do</font><br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conInfo&nbsp;:=&nbsp;ConInfoArray.Item[i];<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">If</font>&nbsp;conInfo.Include&nbsp;<font color="#008080">Then</font><br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Diagnostics.Debug.Write(conInfo.LowerBound.ToString()&nbsp;+&nbsp;<font color="#800000">&quot;;&nbsp;&quot;</font>&nbsp;+&nbsp;char.ConvertFromUtf32(<font color="#008000">9</font>));<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Diagnostics.Debug.WriteLine(StatusToStr(conInfo.LowerConstraintStatus));<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">End</font>&nbsp;<font color="#008080">If</font>;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">End</font>&nbsp;<font color="#008080">For</font>;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Diagnostics.Debug.Unindent();<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Diagnostics.Debug.WriteLine(<font color="#800000">&quot;Lagrange&nbsp;multiplier&nbsp;values&nbsp;for&nbsp;lower&nbsp;limit&quot;</font>);<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Diagnostics.Debug.Indent();<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">For</font>&nbsp;i&nbsp;:=&nbsp;<font color="#008000">0</font>&nbsp;<font color="#008080">To</font>&nbsp;ConInfoArray.Count&nbsp;-&nbsp;<font color="#008000">1</font>&nbsp;<font color="#008080">Do</font><br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conInfo&nbsp;:=&nbsp;ConInfoArray.Item[i];<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">If</font>&nbsp;conInfo.Include&nbsp;<font color="#008080">Then</font><br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Diagnostics.Debug.WriteLine(conInfo.LowerBoundLagrangeMultiplier);<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">End</font>&nbsp;<font color="#008080">If</font>;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">End</font>&nbsp;<font color="#008080">For</font>;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Diagnostics.Debug.Unindent();<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Diagnostics.Debug.WriteLine(<font color="#800000">&quot;Upper&nbsp;limit&nbsp;values;&nbsp;Status&quot;</font>);<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Diagnostics.Debug.Indent();<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">For</font>&nbsp;i&nbsp;:=&nbsp;<font color="#008000">0</font>&nbsp;<font color="#008080">To</font>&nbsp;ConInfoArray.Count&nbsp;-&nbsp;<font color="#008000">1</font>&nbsp;<font color="#008080">Do</font><br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conInfo&nbsp;:=&nbsp;ConInfoArray.Item[i];<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">If</font>&nbsp;conInfo.Include&nbsp;<font color="#008080">Then</font><br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Diagnostics.Debug.Write(conInfo.UpperBound.ToString()&nbsp;+&nbsp;<font color="#800000">&quot;;&nbsp;&quot;</font>&nbsp;+&nbsp;char.ConvertFromUtf32(<font color="#008000">9</font>));<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Diagnostics.Debug.WriteLine(StatusToStr(conInfo.UpperConstraintStatus));<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">End</font>&nbsp;<font color="#008080">If</font>;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">End</font>&nbsp;<font color="#008080">For</font>;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Diagnostics.Debug.Unindent();<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Diagnostics.Debug.WriteLine(<font color="#800000">&quot;Lagrange&nbsp;multiplier&nbsp;values&nbsp;for&nbsp;upper&nbsp;limit&quot;</font>);<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Diagnostics.Debug.Indent();<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">For</font>&nbsp;i&nbsp;:=&nbsp;<font color="#008000">0</font>&nbsp;<font color="#008080">To</font>&nbsp;ConInfoArray.Count&nbsp;-&nbsp;<font color="#008000">1</font>&nbsp;<font color="#008080">Do</font><br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conInfo&nbsp;:=&nbsp;ConInfoArray.Item[i];<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">If</font>&nbsp;conInfo.Include&nbsp;<font color="#008080">Then</font><br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Diagnostics.Debug.WriteLine(conInfo.UpperBoundLagrangeMultiplier);<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">End</font>&nbsp;<font color="#008080">If</font>;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">End</font>&nbsp;<font color="#008080">For</font>;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Diagnostics.Debug.Unindent();<br/> &nbsp;&nbsp;&nbsp;&nbsp;<font color="#008000">//&nbsp;If&nbsp;calculation&nbsp;is completed&nbsp;with&nbsp;error,&nbsp;output&nbsp;its&nbsp;text<br/> </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">Else</font><br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Diagnostics.Debug.WriteLine(res.ErrorMsg);<br/> &nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">End</font>&nbsp;<font color="#008080">If</font>;<br/> <font color="#008080">End</font>&nbsp;<font color="#008080">Sub</font>;<br/> <br/> <font color="#008000">//&nbsp;Function&nbsp;for&nbsp;status&nbsp;output<br/> </font><font color="#008080">Public</font>&nbsp;<font color="#008080">Shared</font>&nbsp;<font color="#008080">Function</font>&nbsp;StatusToStr(Status:&nbsp;TargetConstraintStatusType):&nbsp;String;<br/> <font color="#008080">Var</font><br/> &nbsp;&nbsp;&nbsp;&nbsp;s:&nbsp;String;<br/> <font color="#008080">Begin</font><br/> &nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">Select</font>&nbsp;<font color="#008080">Case</font>&nbsp;Status<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">Case</font>&nbsp;TargetConstraintStatusType.tcstDisabled:&nbsp;s&nbsp;:=&nbsp;<font color="#800000">&quot;Disabled&quot;</font>;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">Case</font>&nbsp;TargetConstraintStatusType.tcstNotReached:&nbsp;s&nbsp;:=&nbsp;<font color="#800000">&quot;Not&nbsp;reached&quot;</font>;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">Case</font>&nbsp;TargetConstraintStatusType.tcstReached:&nbsp;s&nbsp;:=&nbsp;<font color="#800000">&quot;Reached&quot;</font>;<br/> &nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">End</font>&nbsp;<font color="#008080">Select</font>;<br/> &nbsp;&nbsp;&nbsp;&nbsp;<font color="#008080">Return</font>&nbsp;s;<br/> <font color="#008080">End</font>&nbsp;<font color="#008080">Function</font>&nbsp;StatusToStr;

See also:

ITargetConstraintInfo