InitApproximation: 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.
See also: