ISmNonLinearOptimization.LindoSettings

Fore Syntax

LindoSettings: ILindoSettings;

Fore.NET Syntax

LindoSettings: Prognoz.Platform.Interop.Stat.ILindoSettings;

Description

The LindoSettings property returns parameters of the LINDO mobule.

Comments

Parameters of the LINDO module are taken into account if it is selected for solving non-linear optimization problem, that is, the ISmNonLinearOptimization.SolverType property is set to NLOSolverType.Lindo.

Fore Example

Executing the example requires a LINDO module installed at the path: c:\Lindoapi\.

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;
    intvec: Array[0..3] Of Integer;
    LinConCfs: Array[0..3] Of Double;
    LinCons: ISlLinearConstraints;
    LinCon: ISlLinearConstraint;
    NonLinCons: INonLinearConstraints;
    NonLinCon: INonLinearConstraint;
    LindoSettings: ILindoSettings;
    LindoParamUnit: ILindoParamUnit;
    LindoParamUnits: ILindoParamUnits;
    i,res: Integer;
    OptVal, Dval: Double;
    s: string;
    Warnings: Array Of String;
Begin
    // Create object for solving optimization problem
    nlo := New SmNonLinearOptimization.Create;
    // Set plot 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 coefficients order
    nlo.CoefficientsOrder := "x1;x2;x3;x4";
    // Set criterion function
    nlo.FunctionString := "x1*x4*(x1+x2+x3)+x3";
    // // Set initial approximations
    init[0] := 1;
    init[1] := 5;
    init[2] := 5;
    init[3] := 1;
    nlo.InitApproximation := init;
    // Set array of integer variable attributes
    intvec[0] := 1;
    intvec[1] := 1;
    intvec[2] := 1;
    intvec[3] := 1;
    nlo.IntVec := intvec;
    // Set linear constraint parameters
    LinCons := nlo.LinearConstraints;
    LinCon := LinCons.Add;
    LinCon.BoundaryLower := -10e20;
    LinCon.BoundaryUpper := 20;
    LinConCfs[0] := 1;
    LinConCfs[1] := 1;
    LinConCfs[2] := 1;
    LinConCfs[3] := 1;
    LinCon.Value := LinConCfs;
    // Set number of iterations for problem solving
    nlo.MaxIteration := 75;
    // Set non-linear constraint parameters
    NonLinCons := nlo.NonLinearConstraints;
    NonLinCon := NonLinCons.Add;
    NonLinCon.BoundaryLower := -10e20;
    NonLinCon.BoundaryUpper := 40;
    NonLinCon.NonLinearFunction := "x1*x1+x2*x2+x3*x3+x4*x4";
    NonLinCon := NonLinCons.Add;
    NonLinCon.BoundaryLower := 25;
    NonLinCon.BoundaryUpper := 10e21;
    NonLinCon.NonLinearFunction := "x1*x2*x3*x4";
    // Specify that problem is solved by means of the LINDO module
    nlo.SolverType := NLOSolverType.Lindo;
    // Get module parameters
    LindoSettings := nlo.LindoSettings;
    // Specify paths to LINDO library and license
    LindoSettings.DLLPath := "c:\Lindoapi\bin\win32\lindo8_0.dll";
    LindoSettings.LicensePath := "c:\Lindoapi\license\lndapi80.lic";
    // Specify a file, to which problem is unloaded
    LindoSettings.MPIPath := "c:\Problem.mpi";
    // Specify that model is not deleted right after execution
    LindoSettings.DisposeLindoModelAfterExecute := False;
    // Set model parameters
    LindoParamUnits := LindoSettings.ModelParams;
    LindoParamUnit := LindoParamUnits.Add;
    // Specify value of the LS_DPARAM_SOLVER_OPTTOL parameter
    LindoParamUnit.ParamKey := 1257;
    LindoParamUnit.ParamValue := 0.001;
    // Set environment parameters
    LindoParamUnits := LindoSettings.EnvParams;
    // Specify value of the LS_DPARAM_SOLVER_FEASTOL parameter
    LindoParamUnit := LindoParamUnits.Add;
    LindoParamUnit.ParamKey := 1254;
    LindoParamUnit.ParamValue := 0.003;
    // Set type of solved problem and solution method             
    LindoSettings.ProblemType := LindoProblemType.MIP;
    LindoSettings.SolverType := LindoSolverType.Barrier;
    // Set result type
    LindoSettings.ProblemResultType := LindoProblemResultType.MIPPrimalSolution;
    LindoSettings.ProblemResultWhichType := LindoProblemResultWhichType.BasicPrimal;
    // Perform calculation
    res := nlo.Execute;
    If (res <> 0) Or (LindoSettings.nErrorCode <> 0) Then
        Debug.WriteLine(nlo.Errors);
        Debug.WriteLine("Code of Lindo error: " + LindoSettings.nErrorCode.ToString);
        Debug.WriteLine("Test of Lindo error: " + LindoSettings.MessageString);
    Else
        // Get warnings occurred on calculation and display them
        Warnings := LindoSettings.Warnings;
        For i := 0 To Warnings.Length - 1 Do
            Debug.WriteLine("Warning: " + Warnings[i]);
        End For;
        // Display calculation results
        Debug.WriteLine("== Criterion function value ==");
        OptVal := nlo.OptimalFunctionValue;
        Debug.WriteLine(OptVal.ToString);
        Debug.WriteLine("=== Solution ===");
        Print(nlo.Solution);
        Debug.WriteLine("=== Criterion function gradient ===");
        Print(nlo.FunctionGradient);
        // Display information about calculation method
        Dval := LindoSettings.GetDouLindoInfo(LindoDouInfoType.DINFO_MIP_TOT_TIME, res);
        Debug.WriteLine("Total time of integer optimization problem calculation, " +
            "including time for loading and unloading a model, optimization and heuristics: " + Dval.ToString);
        i := LindoSettings.GetIntLindoInfo(LindoIntInfoType.IINFO_MIP_THREADS, res);
        Debug.WriteLine("Number of parallel streams used for " +
            "integer optimization problem solution: " + i.ToString);
        s := LindoSettings.GetStrLindoInfo(LindoStrInfoType.SINFO_MIP_THREAD_LOAD, res);
        Debug.WriteLine("A string containing workload thread in the last call of LSsolveMIP: " + s);
    End If;
End Sub UserProc;

// Data call procedure
Sub Print(Data: Array Of Double);
Var
    i: Integer;
    CI: ICultureInfo;
Begin
    CI := CultureInfo.Current;
    Debug.WriteLine("---Begin---");
    For i := 0 To Data.Length - 1 Do
        If Double.IsNan(Data[i]) Then
            Debug.WriteLine("---empty---");
        Else
            Debug.WriteLine(i.ToString + ", " + CI.FormatDoublePrec(Data[i], 4));
        End If;
    End For;
    Debug.WriteLine("---End---");
End Sub Print;

After executing the example, the optimization problem is calculated by means of the LINDO module. Calculation results are displayed in the console window. The problem in the format appropriate for using in LINDO is loaded into the C:\Problem.mpi file.

Fore.NET Example

The requirements and result of the Fore.NET example execution match with those in the Fore example.

Imports Prognoz.Platform.Interop.ForeSystem;
Imports Prognoz.Platform.Interop.Stat;

Public Shared Sub UserProc();
Var
    nlo: ISmNonLinearOptimization;
    lb, ub: Array[0..3] Of Double;
    init: Array[0..3] Of Double;
    intvec: Array[0..3] Of Integer;
    LinConCfs: Array[0..3] Of Double;
    LinCons: ISlLinearConstraints;
    LinCon: ISlLinearConstraint;
    NonLinCons: INonLinearConstraints;
    NonLinCon: INonLinearConstraint;
    LindoSettings: ILindoSettings;
    LindoParamUnit: ILindoParamUnit;
    LindoParamUnits: ILindoParamUnits;
    i,res: Integer;
    OptVal, Dval: Double;
    s: string;
    Warnings: System.Array;
Begin
    // Create object for solving optimization problem
    nlo := New SmNonLinearOptimization.Create();
    // Set plot 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 coefficients order
    nlo.CoefficientsOrder := "x1;x2;x3;x4";
    // Set criterion function
    nlo.FunctionString := "x1*x4*(x1+x2+x3)+x3";
    // // Set initial approximations
    init[0] := 1;
    init[1] := 5;
    init[2] := 5;
    init[3] := 1;
    nlo.InitApproximation := init;
    // Set array of integer variable attributes
    intvec[0] := 1;
    intvec[1] := 1;
    intvec[2] := 1;
    intvec[3] := 1;
    nlo.IntVec := intvec;
    // Set linear constraint parameters
    LinCons := nlo.LinearConstraints;
    LinCon := LinCons.Add();
    LinCon.BoundaryLower := -10e20;
    LinCon.BoundaryUpper := 20;
    LinConCfs[0] := 1;
    LinConCfs[1] := 1;
    LinConCfs[2] := 1;
    LinConCfs[3] := 1;
    LinCon.Value := LinConCfs;
    // Set number of iterations for problem solving
    nlo.MaxIteration := 75;
    // Set non-linear constraint parameters
    NonLinCons := nlo.NonLinearConstraints;
    NonLinCon := NonLinCons.Add();
    NonLinCon.BoundaryLower := -10e20;
    NonLinCon.BoundaryUpper := 40;
    NonLinCon.NonLinearFunction := "x1*x1+x2*x2+x3*x3+x4*x4";
    NonLinCon := NonLinCons.Add();
    NonLinCon.BoundaryLower := 25;
    NonLinCon.BoundaryUpper := 10e21;
    NonLinCon.NonLinearFunction := "x1*x2*x3*x4";
    // Specify that problem is solved by means of the LINDO module
    nlo.SolverType := NLOSolverType.nlostLindo;
    // Get module parameters
    LindoSettings := nlo.LindoSettings;
    // Specify paths to LINDO library and license
    LindoSettings.DLLPath := "c:\Lindoapi\bin\win32\lindo8_0.dll";
    LindoSettings.LicensePath := "c:\Lindoapi\license\lndapi80.lic";
    // Specify a file, to which problem is unloaded
    LindoSettings.MPIPath := "c:\Problem.mpi";
    // Specify that model is not deleted right after execution
    LindoSettings.DisposeLindoModelAfterExecute := False;
    // Set model parameters
    LindoParamUnits := LindoSettings.ModelParams;
    LindoParamUnit := LindoParamUnits.Add();
    // Specify value of the LS_DPARAM_SOLVER_OPTTOL parameter
    LindoParamUnit.ParamKey := 1257;
    LindoParamUnit.ParamValue := 0.001;
    // Set environment parameters
    LindoParamUnits := LindoSettings.EnvParams;
    // Specify value of the LS_DPARAM_SOLVER_FEASTOL parameter
    LindoParamUnit := LindoParamUnits.Add();
    LindoParamUnit.ParamKey := 1254;
    LindoParamUnit.ParamValue := 0.003;
    // Set type of solved problem and solution method             
    LindoSettings.ProblemType := LindoProblemType.lptMIP;
    LindoSettings.SolverType := LindoSolverType.lstBarrier;
    // Set result type
    LindoSettings.ProblemResultType := LindoProblemResultType.lprtMIPPrimalSolution;
    LindoSettings.ProblemResultWhichType := LindoProblemResultWhichType.lprwtBasicPrimal;
    // Perform calculation
    res := nlo.Execute();
    If (res <> 0) Or (LindoSettings.nErrorCode <> 0) Then
        System.Diagnostics.Debug.WriteLine(nlo.Errors);
        System.Diagnostics.Debug.WriteLine("Code of Lindo error: " + LindoSettings.nErrorCode.ToString());
        System.Diagnostics.Debug.WriteLine("Test of Lindo error: " + LindoSettings.MessageString);
    Else
        // Get warnings occurred on calculation and display them
        Warnings := LindoSettings.Warnings;
        For i := 0 To Warnings.Length - 1 Do
            System.Diagnostics.Debug.WriteLine("Warning: " + Warnings[i]);
        End For;
        // Display calculation results
        System.Diagnostics.Debug.WriteLine("== Criterion function value ==");
        OptVal := nlo.OptimalFunctionValue;
        System.Diagnostics.Debug.WriteLine(OptVal.ToString());
        System.Diagnostics.Debug.WriteLine("=== Solution ===");
        Print(nlo.Solution);
        System.Diagnostics.Debug.WriteLine("=== Criterion function gradient ===");
        Print(nlo.FunctionGradient);
        // Display information about calculation method
        Dval := LindoSettings.GetDouLindoInfo(LindoDouInfoType.ldi_DINFO_MIP_TOT_TIME, Var res);
        System.Diagnostics.Debug.WriteLine("Total time of integer optimization problem calculation, " +
            "including time for loading and unloading a formula, optimization and heuristics: " + Dval.ToString());
        i := LindoSettings.GetIntLindoInfo(LindoIntInfoType.lii_IINFO_MIP_THREADS, Var res);
        System.Diagnostics.Debug.WriteLine("Number of parallel threads used for " +
            "solution of integer optimization problem solution: " + i.ToString());
        s := LindoSettings.GetStrLindoInfo(LindoStrInfoType.lsi_SINFO_MIP_THREAD_LOAD, Var res);
        System.Diagnostics.Debug.WriteLine("A string containing workload thread in the las call of LSsolveMIP: " + s);
    End If;
End Sub UserProc;

// Data display procedure
Public Shared Sub Print(Data: System.Array);
Var
    i: Integer;
    CultureInfo: CultureInfoClassClass;
    CI: ICultureInfo;
Begin
    CultureInfo := New CultureInfoClassClass.Create();
    CI := CultureInfo.Current;
    System.Diagnostics.Debug.WriteLine("---Begin---");
    For i := 0 To Data.Length - 1 Do
        If Double.IsNan(Data[i] As double) Then
            System.Diagnostics.Debug.WriteLine("---empty---");
        Else
            System.Diagnostics.Debug.WriteLine(i.ToString() + ", " + CI.FormatDoublePrec(Data[i] As double, 4));
        End If;
    End For;
    System.Diagnostics.Debug.WriteLine("---End---");
End Sub Print;

See also:

ISmNonLinearOptimization