CriterionFunction: Array;
The CriterionFunction property determines criterion function.
Indexing of array of coefficients of criterion function must start with zero.
To execute the example, add a link to the Stat system assembly.
Sub UserProc;
Var
LP: SmLinearProgramming;
Bound: ISlBoundaryRegion;
LCon1, LCon2: ISlLinearConstraint;
CF, Lb, Ub, LinC1, LinC2, Sol: Array Of Double;
i, N, Res: Integer;
d, OptVal: Double;
Begin
N := 4;
CF := New Double[N];
Lb := New Double[N];
Ub := New Double[N];
LinC1 := New Double[N];
LinC2 := New Double[N];
CF[0] := 5; Lb[0] := 0; Ub[0] := 5; LinC1[0] := 2; LinC2[0] := 3;
CF[1] := -7; Lb[1] := 0; Ub[1] := 10; LinC1[1] := 4; LinC2[1] := 3;
CF[2] := 2; Lb[2] := 0; Ub[2] := 5; LinC1[2] := 1; LinC2[2] := 0;
CF[3] := -2; Lb[3] := 0; Ub[3] := 5; LinC1[3] := 0; LinC2[3] := 2;
LP := New SmLinearProgramming.Create;
LP.InitialApproximation.AutoCreate := True;
//Criterion function
LP.CriterionFunction := CF;
Bound := LP.Boundary;
Bound.BoundaryLower := Lb; //Lower area boundary
Bound.BoundaryUpper := Ub; //Upper area boundary
LCon1 := LP.LinearConstraints.Add; // first linear constraint
LCon1.Value := LinC1; // Linear constraint coefficients
LCon1.BoundaryLower := -100; // lower linear constraint
LCon1.BoundaryUpper := 100; //upper linear constraint
LCon2 := LP.LinearConstraints.Add; // second linear constraint
LCon2.Value := LinC2;
LCon2.BoundaryLower := -100;
LCon2.BoundaryUpper := 90;
Res := LP.Execute;
If Res <> 0 Then
Debug.WriteLine(LP.Errors);
Else
Debug.WriteLine("== Criterion function value ==");
OptVal := LP.OptimalFunctionValue;
Debug.WriteLine(OptVal.ToString);
Debug.WriteLine("== Solution ==");
Sol := LP.Solution;
For i := 0 To N - 1 Do
d := Sol[i];
Debug.AssertMsg(False, i.ToString + " = " + d.ToString);
End For;
End If;
End Sub UserProc;
After executing the example the console window displays the found solution and criterion function value corresponding to this solution:
== Criterion function value ==
-80
== Solution ==
0 = 0
1 = 10
2 = 0
3 = 5
See also: