CriterionFunction: Array;
CriterionFunction: System.Array;
The CriterionFunction property determines the linear part of the criterion function.
Indexing of array of coefficients of criterion function must start with zero.
Quadratic part of the criterion function is determined by the ISmQuadraticProgramming.QuadraticForm property.
Add a link to the Stat system assembly.
Sub UserProc;
Var
QP: SmQuadraticProgramming;
i, Res: Integer;
CF, Lb, Ub, LinC1, LinC2, LinC3, init: Array[3] Of Double;
H: Array[3, 3] Of Double;
Bound: ISlBoundaryRegion;
LCon1, LCon2, LCon3: ISlLinearConstraint;
Begin
QP := New SmQuadraticProgramming.Create;
// Set initial approximations
init[0] := 1; init[1] := 1;
QP.InitialApproximation.AutoCreate := False;
QP.InitialApproximation.InitValues := init;
// Set linear part of criterion function
CF[0] := 1; CF[1] := 1; CF[2] := -1;
QP.CriterionFunction := CF;
//Set quadratic part of criterion function
H[0, 0] := -2; H[0, 1] := 2; H[0, 2] := 0;
H[1, 0] := 2; H[1, 1] := -2; H[1, 2] := 0;
H[2, 0] := 0; H[2, 1] := 0; H[2, 2] := -2;
QP.QuadraticForm := H;
// Set definition area
Lb[0] := 0; Lb[1] := 0; Lb[2] := 0;
Ub[0] := 1; Ub[1] := 1; Ub[2] := 1;
Bound := QP.Boundary;
// Set area borders
Bound.BoundaryLower := Lb;
Bound.BoundaryUpper := Ub;
// Set first coefficient of linear constraint
LinC1[0] := 1; LinC1[1] := 1; LinC1[2] := 1;
LCon1 := QP.LinearConstraints.Add;
LCon1.Value := LinC1;
// Set borders of first coefficient of linear constraint
LCon1.BoundaryLower := 1;
LCon1.BoundaryUpper := Double.PositiveInfinity;
// Set second coefficient of linear constraint
LinC2[0] := 2; LinC2[1] := 1; LinC2[2] := -1;
LCon2 := QP.LinearConstraints.Add;
LCon2.Value := LinC2;
// Set borders of second coefficient of linear constraint
LCon2.BoundaryLower := -1;
LCon2.BoundaryUpper := Double.PositiveInfinity;
// Set third coefficient of linear constraint
LinC3[0] := 1; LinC3[1] := -1; LinC3[2] := 1;
LCon3 := QP.LinearConstraints.Add;
LCon3.Value := LinC3;
// Set borders of third coefficient of linear constraint
LCon3.BoundaryLower := 0;
LCon3.BoundaryUpper := 0;
// Run calculation and show results
Res := QP.Execute;
If res = 0 Then
Debug.WriteLine("== Criterion function value ==");
Debug.WriteLine(QP.OptimalFunctionValue.ToString);
Debug.WriteLine("== Solution ==");
For i := 0 To QP.Solution.Length - 1 Do
Debug.WriteLine(i.ToString + ": " + QP.Solution[i].ToString);
End For;
End If;
End Sub UserProc;
After executing the example the console window displays the results of quadratic programming problem calculation.
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
QP: SmQuadraticProgramming;
i, Res: integer;
CF, Lb, Ub, LinC1, LinC2, LinC3, init: Array[3] Of double;
H: Array[3, 3] Of double;
Bound: ISlBoundaryRegion;
LCon1, LCon2, LCon3: ISlLinearConstraint;
Begin
QP := New SmQuadraticProgramming.Create();
// Set initial approximations
init[0] := 1; init[1] := 1;
QP.InitialApproximation.AutoCreate := False;
QP.InitialApproximation.InitValues := init;
// Set linear part of criterion function
CF[0] := 1; CF[1] := 1; CF[2] := -1;
QP.CriterionFunction := CF;
//Set quadratic part of criterion function
H[0, 0] := -2; H[0, 1] := 2; H[0, 2] := 0;
H[1, 0] := 2; H[1, 1] := -2; H[1, 2] := 0;
H[2, 0] := 0; H[2, 1] := 0; H[2, 2] := -2;
QP.QuadraticForm := H;
// Set definition area
Lb[0] := 0; Lb[1] := 0; Lb[2] := 0;
Ub[0] := 1; Ub[1] := 1; Ub[2] := 1;
Bound := QP.Boundary;
// Set area borders
Bound.BoundaryLower := Lb;
Bound.BoundaryUpper := Ub;
// Set first coefficient of linear constraint
LinC1[0] := 1; LinC1[1] := 1; LinC1[2] := 1;
LCon1 := QP.LinearConstraints.Add();
LCon1.Value := LinC1;
// Set borders of first coefficient of linear constraint
LCon1.BoundaryLower := 1;
LCon1.BoundaryUpper := Double.PositiveInfinity;
// Set second coefficient of linear constraint
LinC2[0] := 2; LinC2[1] := 1; LinC2[2] := -1;
LCon2 := QP.LinearConstraints.Add();
LCon2.Value := LinC2;
// Set borders of second coefficient of linear constraint
LCon2.BoundaryLower := -1;
LCon2.BoundaryUpper := Double.PositiveInfinity;
// Set third coefficient of linear constraint
LinC3[0] := 1; LinC3[1] := -1; LinC3[2] := 1;
LCon3 := QP.LinearConstraints.Add();
LCon3.Value := LinC3;
// Set borders of third coefficient of linear constraint
LCon3.BoundaryLower := 0;
LCon3.BoundaryUpper := 0;
// Run calculation and show results
Res := QP.Execute();
If res = 0 Then
System.Diagnostics.Debug.WriteLine("== Criterion function value ==");
System.Diagnostics.Debug.WriteLine(QP.OptimalFunctionValue.ToString());
System.Diagnostics.Debug.WriteLine("== Solution ==");
For i := 0 To QP.Solution.Length - 1 Do
System.Diagnostics.Debug.WriteLine(i.ToString() + ": " + QP.Solution.GetValue(i).ToString());
End For;
End If;
End Sub;
See also