다음: Quadratic Programming, 상위 문서: Optimization [차례][찾아보기]
Octave can solve Linear Programming problems using the glpk
function. That is, Octave can solve
min C'*x
subject to the linear constraints A*x = b where x ≥ 0.
The glpk
function also supports variations of this problem.
Solve a linear program using the GNU GLPK library.
Given three arguments, glpk
solves the following standard LP:
min C'*x
subject to
A*x = b x >= 0
but may also solve problems of the form
[ min | max ] C'*x
subject to
A*x [ "=" | "<=" | ">=" ] b x >= LB x <= UB
Input arguments:
A column array containing the objective function coefficients.
A matrix containing the constraints coefficients.
A column array containing the right-hand side value for each constraint in the constraint matrix.
An array containing the lower bound on each of the variables. If lb is not supplied, the default lower bound for the variables is zero.
An array containing the upper bound on each of the variables. If ub is not supplied, the default upper bound is assumed to be infinite.
An array of characters containing the sense of each constraint in the constraint matrix. Each element of the array may be one of the following values
"F"
A free (unbounded) constraint (the constraint is ignored).
"U"
An inequality constraint with an upper bound (A(i,:)*x <= b(i)
).
"S"
An equality constraint (A(i,:)*x = b(i)
).
"L"
An inequality with a lower bound (A(i,:)*x >= b(i)
).
"D"
An inequality constraint with both upper and lower bounds
(A(i,:)*x >= -b(i)
) and (A(i,:)*x <= b(i)
).
A column array containing the types of the variables.
"C"
A continuous variable.
"I"
An integer variable.
If sense is 1, the problem is a minimization. If sense is -1, the problem is a maximization. The default value is 1.
A structure containing the following parameters used to define the behavior of solver. Missing elements in the structure take on default values, so you only need to set the elements that you wish to change from the default.
Integer parameters:
msglev (default: 1)
Level of messages output by solver routines:
GLP_MSG_OFF
)No output.
GLP_MSG_ERR
)Error and warning messages only.
GLP_MSG_ON
)Normal output.
GLP_MSG_ALL
)Full output (includes informational messages).
scale (default: 16)
Scaling option. The values can be combined with the bitwise OR operator and may be the following:
GLP_SF_GM
)Geometric mean scaling.
GLP_SF_EQ
)Equilibration scaling.
GLP_SF_2N
)Round scale factors to power of two.
GLP_SF_SKIP
)Skip if problem is well scaled.
Alternatively, a value of 128 (GLP_SF_AUTO
) may be also
specified, in which case the routine chooses the scaling options
automatically.
dual (default: 1)
Simplex method option:
GLP_PRIMAL
)Use two-phase primal simplex.
GLP_DUALP
)Use two-phase dual simplex, and if it fails, switch to the primal simplex.
GLP_DUAL
)Use two-phase dual simplex.
price (default: 34)
Pricing option (for both primal and dual simplex):
GLP_PT_STD
)Textbook pricing.
GLP_PT_PSE
)Steepest edge pricing.
itlim (default: intmax)
Simplex iterations limit. It is decreased by one each time when one simplex iteration has been performed, and reaching zero value signals the solver to stop the search.
outfrq (default: 200)
Output frequency, in iterations. This parameter specifies how frequently the solver sends information about the solution to the standard output.
branch (default: 4)
Branching technique option (for MIP only):
GLP_BR_FFV
)First fractional variable.
GLP_BR_LFV
)Last fractional variable.
GLP_BR_MFV
)Most fractional variable.
GLP_BR_DTH
)Heuristic by Driebeck and Tomlin.
GLP_BR_PCH
)Hybrid pseudocost heuristic.
btrack (default: 4)
Backtracking technique option (for MIP only):
GLP_BT_DFS
)Depth first search.
GLP_BT_BFS
)Breadth first search.
GLP_BT_BLB
)Best local bound.
GLP_BT_BPH
)Best projection heuristic.
presol (default: 1)
If this flag is set, the simplex solver uses the built-in LP presolver. Otherwise the LP presolver is not used.
lpsolver (default: 1)
Select which solver to use. If the problem is a MIP problem this flag will be ignored.
Revised simplex method.
Interior point method.
rtest (default: 34)
Ratio test technique:
GLP_RT_STD
)Standard ("textbook").
GLP_RT_HAR
)Harris’ two-pass ratio test.
tmlim (default: intmax)
Searching time limit, in milliseconds.
outdly (default: 0)
Output delay, in seconds. This parameter specifies how long the solver should delay sending information about the solution to the standard output.
save (default: 0)
If this parameter is nonzero, save a copy of the problem in CPLEX LP format to the file "outpb.lp". There is currently no way to change the name of the output file.
Real parameters:
tolbnd (default: 1e-7)
Relative tolerance used to check if the current basic solution is primal feasible. It is not recommended that you change this parameter unless you have a detailed understanding of its purpose.
toldj (default: 1e-7)
Absolute tolerance used to check if the current basic solution is dual feasible. It is not recommended that you change this parameter unless you have a detailed understanding of its purpose.
tolpiv (default: 1e-10)
Relative tolerance used to choose eligible pivotal elements of the simplex table. It is not recommended that you change this parameter unless you have a detailed understanding of its purpose.
objll (default: -DBL_MAX)
Lower limit of the objective function. If the objective function reaches this limit and continues decreasing, the solver stops the search. This parameter is used in the dual simplex method only.
objul (default: +DBL_MAX)
Upper limit of the objective function. If the objective function reaches this limit and continues increasing, the solver stops the search. This parameter is used in the dual simplex only.
tolint (default: 1e-5)
Relative tolerance used to check if the current basic solution is integer feasible. It is not recommended that you change this parameter unless you have a detailed understanding of its purpose.
tolobj (default: 1e-7)
Relative tolerance used to check if the value of the objective function is not better than in the best known integer feasible solution. It is not recommended that you change this parameter unless you have a detailed understanding of its purpose.
Output values:
The optimizer (the value of the decision variables at the optimum).
The optimum value of the objective function.
Error code.
No error.
GLP_EBADB
)Invalid basis.
GLP_ESING
)Singular matrix.
GLP_ECOND
)Ill-conditioned matrix.
GLP_EBOUND
)Invalid bounds.
GLP_EFAIL
)Solver failed.
GLP_EOBJLL
)Objective function lower limit reached.
GLP_EOBJUL
)Objective function upper limit reached.
GLP_EITLIM
)Iterations limit exhausted.
GLP_ETMLIM
)Time limit exhausted.
GLP_ENOPFS
)No primal feasible solution.
GLP_ENODFS
)No dual feasible solution.
GLP_EROOT
)Root LP optimum not provided.
GLP_ESTOP
)Search terminated by application.
GLP_EMIPGAP
)Relative MIP gap tolerance reached.
GLP_ENOFEAS
)No primal/dual feasible solution.
GLP_ENOCVG
)No convergence.
GLP_EINSTAB
)Numerical instability.
GLP_EDATA
)Invalid data.
GLP_ERANGE
)Result out of range.
A data structure containing the following fields:
lambda
Dual variables.
redcosts
Reduced Costs.
time
Time (in seconds) used for solving LP/MIP problem.
status
Status of the optimization.
GLP_UNDEF
)Solution status is undefined.
GLP_FEAS
)Solution is feasible.
GLP_INFEAS
)Solution is infeasible.
GLP_NOFEAS
)Problem has no feasible solution.
GLP_OPT
)Solution is optimal.
GLP_UNBND
)Problem has no unbounded solution.
Example:
c = [10, 6, 4]'; A = [ 1, 1, 1; 10, 4, 5; 2, 2, 6]; b = [100, 600, 300]'; lb = [0, 0, 0]'; ub = []; ctype = "UUU"; vartype = "CCC"; s = -1; param.msglev = 1; param.itlim = 100; [xmin, fmin, status, extra] = ... glpk (c, A, b, lb, ub, ctype, vartype, s, param);
다음: Quadratic Programming, 상위 문서: Optimization [차례][찾아보기]