ISmLinearProgramming.MethodType

Fore Syntax

MethodType: LPMethodType;

Fore.NET Syntax

MethodType: Prognoz.Platform.Interop.Stat.LPMethodType;

Description

The MethodType property determines the method for solving a problem of linear programming.

Comments

To get the found solution, use the ISmLinearProgramming.Solution property.

Fore Example

Add a link to the Stat system assembly.

Sub UserProc;
Var
    LP: SmLinearProgramming;
    CF, Lb, Ub, LinC1, LinC2: Array[4Of Double;
    Z: Array[4Of Integer;
    Bound: ISlBoundaryRegion;
    LCon1, LCon2: ISlLinearConstraint;
    i, Res: Integer;
    OptVal: Double;
    Sol: Array Of Double;
Begin
    LP := New SmLinearProgramming.Create;
    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.InitialApproximation.AutoCreate := True;
    // Criterion function
    LP.CriterionFunction := CF;
    Bound := LP.Boundary;
    // Lower and upper area borders
    Bound.BoundaryLower := Lb;
    Bound.BoundaryUpper := Ub;
    // === First linear constraint ===
    LCon1 := LP.LinearConstraints.Add;
    // Linear constraint coefficients
    LCon1.Value := LinC1;
    // Lower and upper linear constraints
    LCon1.BoundaryLower := -100;
    LCon1.BoundaryUpper := 100;
    // === Second linear constraint ===
    LCon2 := LP.LinearConstraints.Add;
    // Linear constraint coefficients
    LCon2.Value := LinC2;
    // Lower and upper linear constraints
    LCon2.BoundaryLower := -100;
    LCon2.BoundaryUpper := 90;
    // Vector of logical values
    Z[0]:=1; Z[1]:=1; Z[2]:=1; Z[3]:=1;
    lp.IntVec:=Z;
    // Problem solution method 
    LP.MethodType := LPMethodType.SimplexDualPrimal;
    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 LP.Solution.Length-1 Do
                Debug.WriteLine(i.ToString+" = "+Sol[i].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.

Fore.NET Example

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
    LP: SmLinearProgramming;
    CF, Lb, Ub, LinC1, LinC2: Array[4Of Double;
    Z: Array[4Of Integer;
    Bound: ISlBoundaryRegion;
    LCon1, LCon2: ISlLinearConstraint;
    i, Res: Integer;
    OptVal: Double;
    Sol: System.Array;
Begin
    LP := New SmLinearProgramming.Create();
    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.InitialApproximation.AutoCreate := True;
    // Criterion function
    LP.CriterionFunction := CF;
    Bound := LP.Boundary;
    // Lower and upper area borders
    Bound.BoundaryLower := Lb;
    Bound.BoundaryUpper := Ub;
    // === First linear constraint ===
    LCon1 := LP.LinearConstraints.Add();
    // Linear constraint coefficients
    LCon1.Value := LinC1;
    // Lower and upper linear constraints
    LCon1.BoundaryLower := -100;
    LCon1.BoundaryUpper := 100;
    // === Second linear constraint ===
    LCon2 := LP.LinearConstraints.Add();
    // Linear constraint coefficients
    LCon2.Value := LinC2;
    // Lower and upper linear constraints
    LCon2.BoundaryLower := -100;
    LCon2.BoundaryUpper := 90;
    // Vector of logical values
    Z[0]:=1; Z[1]:=1; Z[2]:=1; Z[3]:=1;
    lp.IntVec:=Z;
    // Problem solution method 
    LP.MethodType := LPMethodType.lpmtSimplexDualPrimal;
    Res := LP.Execute();
    If Res <> 0 Then
        System.Diagnostics.Debug.WriteLine(LP.Errors);
        Else
            System.Diagnostics.Debug.WriteLine("== Criterion function value ==");
            OptVal := LP.OptimalFunctionValue;
            System.Diagnostics.Debug.WriteLine(OptVal.ToString());
            System.Diagnostics.Debug.WriteLine("== Solution ==");
            Sol := LP.Solution;
            For i := 0 To LP.Solution.Length-1 Do
                System.Diagnostics.Debug.WriteLine(i.ToString()+" = "+Sol[i].ToString());
            End For;
    End If;
End Sub;

See also:

ISmLinearProgramming