ISmNonLinearOptimization.LindoSettings

Syntax

LindoSettings: 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.

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.

See also:

ISmNonLinearOptimization