ObjValByIter: Array;
ObjValByIter: System.Array;
The ObjValByIter property returns values of the criterion function by iterations.
To determine criterion function, use the ISmNonLinearOptimization.FunctionString property.
To execute the example, add a link to the Stat system assembly.
Sub UserProc;
Var
nlo: ISmNonLinearOptimization;
lb, ub: Array[0..3] Of Double;
init: Array[0..3] Of Double;
LinConCfs: Array[0..3] Of Double;
LinCons: ISlLinearConstraints;
LinCon: ISlLinearConstraint;
NonLinCons: INonLinearConstraints;
NonLinCon: INonLinearConstraint;
i, res: Integer;
Begin
nlo := New SmNonLinearOptimization.Create;
For i := 0 To 3 Do
lb[i] := 1;
ub[i] := 5;
LinConCfs[i] := 1;
End For;
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;
LinCons := nlo.LinearConstraints;
LinCon := LinCons.Add;
LinCon.BoundaryLower := -10e20;
LinCon.BoundaryUpper := 20;
LinConCfs[0] := 1;
LinConCfs[1] := 1;
LinConCfs[2] := 1;
LinConCfs[3] := 1;
LinCon.Value := LinConCfs;
nlo.MaxIteration := 75;
NonLinCons := nlo.NonLinearConstraints;
NonLinCon := NonLinCons.Add;
NonLinCon.BoundaryLower := -10e20;
NonLinCon.BoundaryUpper := 40;
NonLinCon.NonLinearFunction := "x1*x1+x2*x2+x3*x3+x4*x4";
NonLinCon := NonLinCons.Add;
NonLinCon.BoundaryLower := 25;
NonLinCon.BoundaryUpper := 10e21;
NonLinCon.NonLinearFunction := "x1*x2*x3*x4";
// Do not use analytical derivatives when searching the solution:
nlo.UseDerivatives := False;
res := nlo.Execute;
If res <> 0 Then
Debug.WriteLine(nlo.Errors);
Else
Debug.WriteLine("=== Criterion function value by iterations ===");
For i := 0 To nlo.ObjValByIter.Length - 1 Do
Debug.WriteLine(i.ToString + ", " + nlo.ObjValByIter[i].ToString)
End For;
End If;
End Sub UserProc;
After executing the example the console window displays criterion function values by iterations.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.Stat;
…
Public Shared Sub Main(Params: StartParams);
Var
nlo: ISmNonLinearOptimization;
lb, ub: Array[0..3] Of Double;
init: Array[0..3] Of Double;
LinConCfs: Array[0..3] Of Double;
LinCons: ISlLinearConstraints;
LinCon: ISlLinearConstraint;
NonLinCons: INonLinearConstraints;
NonLinCon: INonLinearConstraint;
i, res: Integer;
ObjValByIter: System.Array;
Begin
nlo := New SmNonLinearOptimization.Create();
For i := 0 To 3 Do
lb[i] := 1;
ub[i] := 5;
LinConCfs[i] := 1;
End For;
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;
LinCons := nlo.LinearConstraints;
LinCon := LinCons.Add();
LinCon.BoundaryLower := -10e20;
LinCon.BoundaryUpper := 20;
LinConCfs[0] := 1;
LinConCfs[1] := 1;
LinConCfs[2] := 1;
LinConCfs[3] := 1;
LinCon.Value := LinConCfs;
nlo.MaxIteration := 75;
NonLinCons := nlo.NonLinearConstraints;
NonLinCon := NonLinCons.Add();
NonLinCon.BoundaryLower := -10e20;
NonLinCon.BoundaryUpper := 40;
NonLinCon.NonLinearFunction := "x1*x1+x2*x2+x3*x3+x4*x4";
NonLinCon := NonLinCons.Add();
NonLinCon.BoundaryLower := 25;
NonLinCon.BoundaryUpper := 10e21;
NonLinCon.NonLinearFunction := "x1*x2*x3*x4";
// Do not use analytical derivatives when searching the solution:
nlo.UseDerivatives := False;
res := nlo.Execute();
If res <> 0 Then
System.Diagnostics.Debug.WriteLine(nlo.Errors);
Else
System.Diagnostics.Debug.WriteLine("=== Criterion function value by iterations ===");
ObjValByIter := nlo.ObjValByIter;
For i := 0 To nlo.ObjValByIter.Length - 1 Do
System.Diagnostics.Debug.WriteLine(i.ToString() + ", " + ObjValByIter[i].ToString())
End For;
End If;
End Sub;
See also: