InitApproximation: Array;
InitApproximation: System.Array;
The InitApproximation property determines initial approximations.
Indexing of initial approximation array must start with zero.
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;
OptVal: Double;
Begin
nlo := New SmNonLinearOptimization.Create;
// Set definition area parameters
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;
// Set coefficient order
nlo.CoefficientsOrder := "x1;x2;x3;x4";
// Set criterion function
nlo.FunctionString := "x1*x4*(x1+x2+x3)+x3*0.5";
// Set initial approximations
init[0] := 1;
init[1] := 7;
init[2] := 5;
init[3] := 1;
nlo.InitApproximation := init;
// Set linear constraints and their parameters
LinCons := nlo.LinearConstraints;
LinCon := LinCons.Add;
LinCon.BoundaryLower := -10e20;
LinCon.BoundaryUpper := 20;
LinConCfs[0] := 1.5;
LinConCfs[1] := 1.7;
LinConCfs[2] := 1.9;
LinConCfs[3] := 1.2;
LinCon.Value := LinConCfs;
// Set maximum number of iterations for search of solution
nlo.MaxIteration := 75;
// Set accuracy of solution
nlo.Tolerance := 0.00001;
// Set non-linear constraints and their parameters
NonLinCons := nlo.NonLinearConstraints;
NonLinCon := NonLinCons.Add;
NonLinCon.BoundaryLower := -10e20;
NonLinCon.BoundaryUpper := 40;
NonLinCon.NonLinearFunction := "x1*x1+x2*x2+x3*x3+x4*0.47";
NonLinCon := NonLinCons.Add;
NonLinCon.BoundaryLower := 25;
NonLinCon.BoundaryUpper := 10e21;
NonLinCon.NonLinearFunction := "x1*x2*x3*x4+9";
// Perform calculation
res := nlo.Execute;
If res <> 0 Then
Debug.WriteLine(nlo.Errors);
// Display calculation results
Else
Debug.WriteLine("== Criterion function value ==");
OptVal := nlo.OptimalFunctionValue;
Debug.WriteLine(OptVal.ToString);
Debug.WriteLine("=== Solution ===");
For i := 0 To nlo.Solution.Length - 1 Do
Debug.WriteLine(i.ToString + ", " + nlo.Solution[i].ToString)
End For;
Debug.WriteLine("=== Criterion function gradient ===");
For i := 0 To nlo.FunctionGradient.Length - 1 Do
Debug.WriteLine(i.ToString + ", " + nlo.FunctionGradient[i].ToString)
End For;
Debug.WriteLine("=== Actually used initial approximations ===");
For i := 0 To nlo.InitApproximationActual.Length - 1 Do
Debug.WriteLine(i.ToString + ", " + nlo.InitApproximationActual[i].ToString)
End For;
End If;
End Sub UserProc;
Executing this example shows the calculation results in the console window.
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;
OptVal: Double;
Sol, FuncGrad, InitApproxActual: System.Array;
Begin
nlo := New SmNonLinearOptimization.Create();
// Set definition area parameters
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;
// Set coefficient order
nlo.CoefficientsOrder := "x1;x2;x3;x4";
// Set criterion function
nlo.FunctionString := "x1*x4*(x1+x2+x3)+x3*0.5";
// Set initial approximations
init[0] := 1;
init[1] := 7;
init[2] := 5;
init[3] := 1;
nlo.InitApproximation := init;
// Set linear constraints and their parameters
LinCons := nlo.LinearConstraints;
LinCon := LinCons.Add();
LinCon.BoundaryLower := -10e20;
LinCon.BoundaryUpper := 20;
LinConCfs[0] := 1.5;
LinConCfs[1] := 1.7;
LinConCfs[2] := 1.9;
LinConCfs[3] := 1.2;
LinCon.Value := LinConCfs;
// Set maximum number of iterations for search of solution
nlo.MaxIteration := 75;
// Set accuracy of solution
nlo.Tolerance := 0.00001;
// Set non-linear constraints and their parameters
NonLinCons := nlo.NonLinearConstraints;
NonLinCon := NonLinCons.Add();
NonLinCon.BoundaryLower := -10e20;
NonLinCon.BoundaryUpper := 40;
NonLinCon.NonLinearFunction := "x1*x1+x2*x2+x3*x3+x4*0.47";
NonLinCon := NonLinCons.Add();
NonLinCon.BoundaryLower := 25;
NonLinCon.BoundaryUpper := 10e21;
NonLinCon.NonLinearFunction := "x1*x2*x3*x4+9";
// Execute calculation
res := nlo.Execute();
If res <> 0 Then
System.Diagnostics.Debug.WriteLine(nlo.Errors);
// Display calculation results
Else
System.Diagnostics.Debug.WriteLine("== Criterion function value ==");
OptVal := nlo.OptimalFunctionValue;
System.Diagnostics.Debug.WriteLine(OptVal.ToString());
System.Diagnostics.Debug.WriteLine("=== Solution ===");
Sol := nlo.Solution;
For i := 0 To Sol.Length - 1 Do
System.Diagnostics.Debug.WriteLine(i.ToString() + ", " + Sol[i].ToString())
End For;
System.Diagnostics.Debug.WriteLine("=== Criterion function gradient ===");
FuncGrad := nlo.FunctionGradient;
For i := 0 To FuncGrad.Length - 1 Do
System.Diagnostics.Debug.WriteLine(i.ToString() + ", " + FuncGrad[i].ToString())
End For;
System.Diagnostics.Debug.WriteLine("=== Actually used initial approximations ===");
InitApproxActual := nlo.InitApproximationActual;
For i := 0 To InitApproxActual.Length - 1 Do
System.Diagnostics.Debug.WriteLine(i.ToString() + ", " + InitApproxActual[i].ToString())
End For;
End If;
End Sub;
See also: