naginterfaces.library.opt.lp_​solve¶

naginterfaces.library.opt.lp_solve(bl, bu, x, comm, a=None, cvec=None, istate=None, io_manager=None)[source]

lp_solve solves general linear programming problems. It is not intended for large sparse problems.

Note: this function uses optional algorithmic parameters, see also: lp_option_file(), lp_option_string(), nlp1_init().

For full information please refer to the NAG Library document for e04mf

https://www.nag.com/numeric/nl/nagdoc_29/flhtml/e04/e04mff.html

Parameters
blfloat, array-like, shape

must contain the lower bounds for all the constraints

bufloat, array-like, shape

must contain the upper bounds for all the constraints

xfloat, array-like, shape

An initial estimate of the solution.

commdict, communication object, modified in place

Communication structure.

This argument must have been initialized by a prior call to nlp1_init().

aNone or float, array-like, shape , optional

Note: the required extent for this argument in dimension 2 is determined as follows: if : ; if : ; otherwise: .

The th row of must contain the coefficients of the th general linear constraint, for .

cvecNone or float, array-like, shape , optional

The coefficients of the objective function when the problem is of type LP.

If the problem is of type FP, is not referenced.

istateNone or int, array-like, shape , optional

Need not be set if the (default) option ‘Cold Start’ is used.

If the option ‘Warm Start’ has been chosen, specifies the desired status of the constraints at the start of the feasibility phase.

More precisely, the first elements of refer to the upper and lower bounds on the variables, and the next elements refer to the general linear constraints (if any).

Possible values for are as follows:

Meaning

0

The corresponding constraint should not be in the initial working set.

1

The constraint should be in the initial working set at its lower bound.

2

The constraint should be in the initial working set at its upper bound.

3

The constraint should be in the initial working set as an equality. This value must not be specified unless .

The values , and are also acceptable but will be reset to zero by the function.

If lp_solve has been called previously with the same values of and , already contains satisfactory information. (See also the description of the option ‘Warm Start’.) The function also adjusts (if necessary) the values supplied in to be consistent with .

io_managerFileObjManager, optional

Manager for I/O in this routine.

Returns
istateint, ndarray, shape

The status of the constraints in the working set at the point returned in . The significance of each possible value of is as follows:

Meaning

The constraint violates its lower bound by more than the feasibility tolerance.

The constraint violates its upper bound by more than the feasibility tolerance.

The constraint is satisfied to within the feasibility tolerance, but is not in the working set.

This inequality constraint is included in the working set at its lower bound.

This inequality constraint is included in the working set at its upper bound.

This constraint is included in the working set as an equality. This value of can occur only when .

This corresponds to optimality being declared with being temporarily fixed at its current value. This value of can occur only when = 1 on exit.

xfloat, ndarray, shape

The point at which lp_solve terminated. If the function exits successfully or = 1 or 4, contains an estimate of the solution.

iteraint

The total number of iterations performed.

objfloat

The value of the objective function at if is feasible, or the sum of infeasibiliites at otherwise. If the problem is of type FP and is feasible, is set to zero.

axNone or float, ndarray, shape

The final values of the linear constraints .

clamdafloat, ndarray, shape

The values of the Lagrange multipliers for each constraint with respect to the current working set. The first elements contain the multipliers for the bound constraints on the variables, and the next elements contain the multipliers for the general linear constraints (if any). If (i.e., constraint is not in the working set), is zero. If is optimal, should be non-negative if , non-positive if and zero if .

Other Parameters
‘Check Frequency’int

Default

Every th iteration, a numerical test is made to see if the current solution satisfies the constraints in the working set. If the largest residual of the constraints in the working set is judged to be too large, the current working set is refactorized and the variables are recomputed to satisfy the constraints more accurately. If , the default value is used.

‘Cold Start’valueless

Default

This option specifies how the initial working set is chosen. With a ‘Cold Start’, lp_solve chooses the initial working set based on the values of the variables and constraints at the initial point. Broadly speaking, the initial working set will include equality constraints and bounds or inequality constraints that violate or ‘nearly’ satisfy their bounds (to within ‘Crash Tolerance’).

With a ‘Warm Start’, you must provide a valid definition of every element of the array . lp_solve will override your specification of if necessary, so that a poor choice of the working set will not cause a fatal error. For instance, any elements of which are set to , or will be reset to zero, as will any elements which are set to when the corresponding elements of and are not equal. A warm start will be advantageous if a good estimate of the initial working set is available – for example, when lp_solve is called repeatedly to solve related problems.

‘Warm Start’valueless

This option specifies how the initial working set is chosen. With a ‘Cold Start’, lp_solve chooses the initial working set based on the values of the variables and constraints at the initial point. Broadly speaking, the initial working set will include equality constraints and bounds or inequality constraints that violate or ‘nearly’ satisfy their bounds (to within ‘Crash Tolerance’).

With a ‘Warm Start’, you must provide a valid definition of every element of the array . lp_solve will override your specification of if necessary, so that a poor choice of the working set will not cause a fatal error. For instance, any elements of which are set to , or will be reset to zero, as will any elements which are set to when the corresponding elements of and are not equal. A warm start will be advantageous if a good estimate of the initial working set is available – for example, when lp_solve is called repeatedly to solve related problems.

‘Crash Tolerance’float

Default

This value is used in conjunction with the option ‘Cold Start’ (the default value) when lp_solve selects an initial working set. If , the initial working set will include (if possible) bounds or general inequality constraints that lie within of their bounds. In particular, a constraint of the form will be included in the initial working set if . If or , the default value is used.

‘Defaults’valueless

This special keyword may be used to reset all options to their default values.

‘Expand Frequency’int

Default

This option is part of an anti-cycling procedure designed to guarantee progress even on highly degenerate problems.

The strategy is to force a positive step at every iteration, at the expense of violating the constraints by a small amount. Suppose that the value of the option ‘Feasibility Tolerance’ is . Over a period of iterations, the feasibility tolerance actually used by lp_solve (i.e., the working feasibility tolerance) increases from to (in steps of ).

At certain stages the following ‘resetting procedure’ is used to remove constraint infeasibilities. First, all variables whose upper or lower bounds are in the working set are moved exactly onto their bounds. A count is kept of the number of nontrivial adjustments made. If the count is positive, iterative refinement is used to give variables that satisfy the working set to (essentially) machine precision. Finally, the working feasibility tolerance is reinitialized to .

If a problem requires more than iterations, the resetting procedure is invoked and a new cycle of iterations is started with incremented by . (The decision to resume the feasibility phase or optimality phase is based on comparing any constraint infeasibilities with .)

The resetting procedure is also invoked when lp_solve reaches an apparently optimal, infeasible or unbounded solution, unless this situation has already occurred twice. If any nontrivial adjustments are made, iterations are continued.

If , the default value is used. If , no anti-cycling procedure is invoked.

‘Feasibility Tolerance’float

Default

If , defines the maximum acceptable absolute violation in each constraint at a ‘feasible’ point. For example, if the variables and the coefficients in the general constraints are of order unity, and the latter are correct to about decimal digits, it would be appropriate to specify as . If , the default value is used.

lp_solve attempts to find a feasible solution before optimizing the objective function. If the sum of infeasibilities cannot be reduced to zero, the option ‘Minimum Sum of Infeasibilities’ can be used to find the minimum value of the sum. Let Sinf be the corresponding sum of infeasibilities. If Sinf is quite small, it may be appropriate to raise by a factor of or . Otherwise, some error in the data should be suspected.

Note that a ‘feasible solution’ is a solution that satisfies the current constraints to within the tolerance .

‘Infinite Bound Size’float

Default

If , defines the ‘infinite’ bound in the definition of the problem constraints. Any upper bound greater than or equal to will be regarded as (and similarly any lower bound less than or equal to will be regarded as ). If , the default value is used.

‘Infinite Step Size’float

Default

If , specifies the magnitude of the change in variables that will be considered a step to an unbounded solution. (Note that an unbounded solution can occur only when the problem is of type LP.) If the change in during an iteration would exceed the value of , the objective function is considered to be unbounded below in the feasible region. If , the default value is used.

‘Iteration Limit’int

Default

The value of specifies the maximum number of iterations allowed before termination. With and , the workspace needed will be computed and printed, but no iterations will be performed. If , the default value is used.

‘Iters’int

Default

The value of specifies the maximum number of iterations allowed before termination. With and , the workspace needed will be computed and printed, but no iterations will be performed. If , the default value is used.

‘Itns’int

Default

The value of specifies the maximum number of iterations allowed before termination. With and , the workspace needed will be computed and printed, but no iterations will be performed. If , the default value is used.

‘List’valueless

Option ‘List’ enables printing of each option specification as it is supplied. ‘Nolist’ suppresses this printing.

‘Nolist’valueless

Default

Option ‘List’ enables printing of each option specification as it is supplied. ‘Nolist’ suppresses this printing.

‘Minimum Sum of Infeasibilities’str

Default

If no feasible point exists for the constraints, this option is used to control whether or not lp_solve will calculate a point that minimizes the constraint violations. If , lp_solve will terminate as soon as it is evident that no feasible point exists for the constraints. The final point will generally not be the point at which the sum of infeasibilities is minimized. If , lp_solve will continue until the sum of infeasibilities is minimized.

‘Monitoring File’int

Default

If and , monitoring information produced by lp_solve at every iteration is sent to a file with logical unit number . If and/or , no monitoring information is produced.

‘Optimality Tolerance’float

Default

If , defines the tolerance used to determine if the bounds and general constraints have the right ‘sign’ for the solution to be judged to be optimal.

If , the default value is used.

‘Print Level’int

Default

The value of controls the amount of printout produced by lp_solve, as indicated below. A detailed description of the printed output is given in Further Comments (summary output at each iteration and the final solution) and Monitoring Information (monitoring information at each iteration).

The following printout is sent to the file object associated with the advisory I/O unit (see FileObjManager):

Output

No output.

The final solution only.

One line of summary output ( characters; see Further Comments) for each iteration (no printout of the final solution).

The final solution and one line of summary output for each iteration.

The following printout is sent to the unit number given by the option ‘Monitoring File’:

Output

No output.

One long line of output ( characters; see Monitoring Information) for each iteration (no printout of the final solution).

At each iteration, the Lagrange multipliers, the variables , the constraint values and the constraint status (see ).

At each iteration, the diagonal elements of the upper triangular matrix associated with the factorization (3) (see Definition of Search Direction) of the working set.

If and the unit number defined by the option ‘Monitoring File’ is the advisory unit number, the summary output for each major iteration is suppressed.

‘Problem Type’str

Default LP

This option specifies the type of objective function to be minimized during the optimality phase. The following is the optional keyword and the dimensions of the array that must be specified in order to define the objective function:

 LP length-n cvec required. FP the objective function is omitted and cvec is not referenced.

For problems of type FP, the objective function is omitted and is not referenced. The following keywords are also acceptable.

Option

Linear

LP

Feasible

FP

Raises
NagValueError
(errno )

Too many iterations.

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, the equal bounds on are infinite, because and , but : and .

(errno )

On entry, the bounds on are inconsistent: and .

(errno )

On entry with a Warm Start, .

(errno )

On entry with a Cold Start, .

(errno )

On entry, the equal bounds on variable are infinite, because and , but : and .

(errno )

On entry, the equal bounds on linear constraint are infinite, because and , but : and .

(errno )

On entry, the equal bounds on nonlinear constraint are infinite, because and , but : and .

(errno )

On entry, the bounds on variable are inconsistent: and .

(errno )

On entry, the bounds on linear constraint are inconsistent: and .

(errno )

On entry, the bounds on nonlinear constraint are inconsistent: and .

(errno )

‘Problem Type’ not recognized. Problem abandoned.

Warns
NagAlgorithmicWarning
(errno )

Weak solution.

(errno )

solution is unbounded.

(errno )

No feasible point for the linear constraints.

(errno )

Cannot satisfy the working-set constraints to the accuracy requested.

Notes

In the NAG Library the traditional C interface for this routine uses a different algorithmic base. Please contact NAG if you have any questions about compatibility.

lp_solve is designed to solve Linear Programming (LP) problems of the form

where is an -element vector and is an matrix.

This is the default type of problem, referred to as type LP. The option ‘Problem Type’ may be used to specify an alternative problem type FP, in which the objective function is omitted and the function attempts to find a feasible point for the set of constraints.

The constraints involving are called the general constraints. Note that upper and lower bounds are specified for all the variables and for all the general constraints. An equality constraint can be specified by setting . If certain bounds are not present, the associated elements of or can be set to special values that will be treated as or . (See the description of the option ‘Infinite Bound Size’.)

You must supply an initial estimate of the solution.

The method used by lp_solve is described in detail in Algorithmic Details.

References

Gill, P E, Hammarling, S, Murray, W, Saunders, M A and Wright, M H, 1986, Users’ guide for LSSOL (Version 1.0), Report SOL 86-1, Department of Operations Research, Stanford University

Gill, P E and Murray, W, 1978, Numerically stable methods for quadratic programming, Math. Programming (14), 349–372

Gill, P E, Murray, W, Saunders, M A and Wright, M H, 1984, Procedures for optimization problems with a mixture of bounds and general linear constraints, ACM Trans. Math. Software (10), 282–298

Gill, P E, Murray, W, Saunders, M A and Wright, M H, 1989, A practical anti-cycling procedure for linearly constrained optimization, Math. Programming (45), 437–474

Gill, P E, Murray, W, Saunders, M A and Wright, M H, 1991, Inertia-controlling methods for general quadratic programming, SIAM Rev. (33), 1–36

Gill, P E, Murray, W and Wright, M H, 1981, Practical Optimization, Academic Press