📄 lp_solve.m
字号:
%LP_SOLVE Solves mixed integer linear programming problems.%% SYNOPSIS: [obj,x,duals] = lp_solve(f,a,b,e,vlb,vub,xint,autoscale,keep)%% solves the MILP problem%% max v = f'*x % a*x <> b% x >= vlb >= 0% x <= vub% x(int) are integer %% ARGUMENTS: The first four arguments are required: %% f: n vector of coefficients for a linear objective function.% a: m by n sparse matrix representing linear constraints.% b: m vector of right sides for the inequality constraints.% e: m vector that determines the sense of the inequalities:% e(i) = -1 ==> Less Than % e(i) = 0 ==> Equals% e(i) = 1 ==> Greater Than % vlb: n vector of non-negative lower bounds. If empty or omitted,% then the lower bounds are set to zero.% vub: n vector of upper bounds. May be omitted or empty.% autoscale: Autoscale flag. Off when 0 or omitted.% keep: Flag for keeping the lp problem after it's been solved.% If omitted, the lp will be deleted when solved.%% OUTPUT: A nonempty output is returned if a solution is found:%% obj: Optimal value of the objective function.% x: Optimal value of the decision variables.% duals: solution of the dual problem.%% Copyright (c) 1995 by Jeffrey C. Kantor. All rights reserved.%% Email: jeff@control.cheg.nd.edu% cchen@darwin.cc.nd.edufunction [obj,x,duals] = lp_solve(f,a,b,e,vlb,vub,xint,autoscale,keep)[m,n] = size(a);lp = lpmex('make_lp',m,n);lpmex('set_mat', lp, a);lpmex('set_rh_vec', lp, b);lpmex('set_obj_fn', lp, f);lpmex('set_maxim', lp); % default is solving minimum lp.for i = 1:length(e) lpmex('set_constr_type', lp, i,e(i)+1);endif nargin > 4for i = 1:length(vlb) lpmex('set_lowbo', lp,i,vlb(i));endendif nargin > 5for i = 1:length(vub) lpmex('set_upbo', lp,i,vub(i));endendif nargin > 6for i = 1:length(xint) lpmex('set_int', lp,xint(i),1);endendif nargin > 7if autoscale ~= 0 lpmex('auto_scale', lp);else lpmex('unscale', lp);endendlpmex('solve',lp);[obj,x,duals] = lpmex('get_solution',lp);if nargin < 9lpmex('delete_lp',lp);end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -