-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathlp.m
executable file
·51 lines (47 loc) · 1.6 KB
/
lp.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function [x, lambda] = lp(c,A,b,vlb,vub,x0,numeq,itermx);
%lp Linear programming (using CPLEX).
% x=lp(c,A,b) solves the linear programming problem:
%
% min c'x subject to: Ax <= b
% x
%
% [x,lambda]=lp(c,A,b) returns lambda = -u, where u are the Lagrange
% multipliers. That is, u solves the dual problem
%
% max -b'u subject to: -A'u = c, u >= 0.
% u
%
% x=lp(c,A,b,vlb,vub) defines a set of lower and upper
% bounds on the design variables, x, so that the solution is always in
% the range vlb <= x <= vub.
%
% x=lp(c,A,b,vlb,vub,x0,numeq) indicates that the first
% numeq constraints defined by A and b are equality constraints.
%
% x=lp(c,A,b,vlb,vub,x0,numeq,itermx) sets the maximum number of
% iterations to itermx
%
% (x0 is completely ignored, but preserved for API compatibility
% with the LP function on the UNIX boxes
if (( nargin < 3) | (nargin > 8) )
error('Wrong # of input parameters');
end;
n=length(c);
m = size(A,1);
if nargin==3
[obj,x,lambda]=cplex(c,A,b,-inf*ones(n,1),inf*ones(n,1),[1:m]);
elseif nargin==4
if ( length(vlb) ~= n )
error('Wrong # of lower bounds.');
end;
[obj,x,lambda]=cplex(c,A,b,vlb,inf*ones(n,1),[1:m]);
elseif (nargin==5 | nargin==6)
if ( length(vub) ~= n )
error('Wrong # of upper bounds.');
end;
[obj,x,lambda]=cplex(c,A,b,vlb,vub,[1:m]);
elseif (nargin==7)
[obj,x,lambda]=cplex(c,A,b,vlb,vub,[numeq+1:m]);
elseif (nargin==8)
[obj,x,lambda]=cplex(c,A,b,vlb,vub,[numeq+1:m],[],itermx);
end;