Click or drag to resize

Linear Programming

Linear Programming Problem Specification

General form of linear programming problem has the form:

LP Problem

where

  • LP f - linear objective function vector,

  • LP A - matrix for linear equality constraints,

  • LP b - vector for linear equality constraints,

  • LP C - matrix for linear inequality constraints,

  • LP d - vector for linear inequality constraints,

  • LP l - vector of lower bounds,

  • LP u - vector of upper bounds.

Implementation and Usage

The linear programming solver implements a variant of Mehrotra's predictor-corrector algorithm, a primal-dual interior-point method. A number of preprocessing steps occur before the algorithm begins to iterate. The linear programming solver is implemented by the LinearProgramming class. The following constructors create an instance of this class:

The class implements the IConstrainedProgramming interface.

Constructor

Description

Performance

A and C - dense matrices

Creates new instance of LinearProgramming class.

methodLinearProgramming(Vector, Matrix, Vector, Matrix, Vector, Vector, Vector)

A and C - sparse matrices

Creates new instance of LinearProgramming class.

methodLinearProgramming(Vector, SparseMatrix, Vector, SparseMatrix, Vector, Vector, Vector)

The class implements an event LogMessage that occurs every time the INumericalOptimization wants to send a log message, and the following methods:

Method

Description

Performance

minimum

Finds minimum of constrained multivariable function and returns true in case the optimization algorithm succeeded.

methodMinimize

minimum with initial point provided

Finds minimum of constrained multivariable function and returns true in case the optimization algorithm succeeded. The initial point for the algorithm is passed as a parameter.

methodMinimize(Vector)

Class provides the following properties:

Property

Description

Performance

iterations done

Number of iterations done.

PropertyIterationsDone

iterations limit

Maximum number of iterations allowed, a positive integer.

PropertyIterationsLimit

minimum point

Minimum point of objective function.

PropertyMinimumPoint

minimum value

Minimum value of objective function.

PropertyMinimumValue

status

Status of algorithm termination.

PropertyStatus

tolerance

Algorithm termination tolerance, a positive scalar.

PropertyTolerance

Note Note

Usually the default tolerance settings provide good convergence so there is no need to adjust them.

Code Sample

The example demonstrate how to determine input parameters in standard form and use the LP solver for the following problem:

LP Sample

To present this problem in the standard form, there should be:

LP Sample f
LP Sample A
LP Sample b
LP Sample l

The following code solves the problem:

C#
 1using System;
 2using FinMath.LinearAlgebra;
 3using FinMath.NumericalOptimization.Constrained;
 4
 5namespace FinMath.Samples
 6{
 7    class LinearProgrammingSample
 8    {
 9        static void Main()
10        {
11            // Objective function.
12            Vector F = new Vector(new Double[] { -2.0, -50.0 });
13
14            // Linear inequality constraints.
15            Matrix Ai = new Matrix(new Double[,] { { -1.0, 2.0 }, { 1.0, 2.0 } });
16            Vector Bi = new Vector(new Double[] { 2.0, 6.0 });
17
18            // Lower bounds on variables.
19            Vector L = new Vector(new Double[] { 0.0, 0.0 });
20
21            // Create an instance of the solver.
22            LinearProgramming solver = new LinearProgramming(F, null, null, Ai, Bi, L, null);
23
24            // Setting of the solver.
25            solver.Tolerance = 1.0E-8;
26            solver.IterationsLimit = 50;
27
28            // Delegate used to print messages.
29            solver.LogMessage += Console.WriteLine;
30
31            // Find minimum.
32            solver.Minimize();
33
34            // Get minimum point.
35            if (solver.Status == FMStatus.MethodSucceeded)
36            {
37                Console.WriteLine("MinimumPoint = " + solver.MinimumPoint.ToString(""));
38            }
39            else
40            {
41                Console.WriteLine("Linear programming solver failed.");
42            }
43        }
44    }
45}

See Also