资源简介
lp_solve matlab
整数线性规划 工具包
代码片段和文件信息
% Test M-file for lp_solve
clc;
echo on;
% Test and Demonstrate the use of lp_solve
echo off;
disp(‘Press any key to continue.‘);
pause
echo on;
clc;
% Example 1 from the lp_solve distribution
f = [-1 2]‘;
A = [2 1;-4 4];
b = [5 5];
e = -[1 1];
xint = [1 2];
[vx] = lp_solve(fsparse(A)be[][]xint)
echo off;
disp(‘End of Ex1. Expected Solution: v=3 x=[1 2]. Press any key to continue.‘);
pause
echo on;
clc;
% Example 2
f = [50 100];
A = sparse([10 5;4 10; 1 1.5]);
b = [2500 2000 450];
e = [-1 -1 -1];
[vx] = lp_solve(fAbe)
echo off;
disp(‘End of Ex2. Press any key to continue.‘);
pause
echo on;
clc;
% Example 3
f = -[40 36];
vub = [8 10];
A = sparse([5 3]);
b = [45];
e = 1;
[vx] = lp_solve(fAbe[]vub)
echo off;
disp(‘End of Ex3. Press any key to continue.‘);
pause
echo on;
clc;
% Example 4
f = [10 6 4];
A = [1 1 1;10 4 5;2 2 6];
A = sparse(A);
b = [100 600 300];
e = [-1 -1 -1];
xint = [2];
[vx] = lp_solve(fAbe[][]xint)
echo off;
disp(‘End of Ex4. Press any key to continue.‘);
pause
echo on;
clc;
% Example 5
% Integer programming example page 218 of Ecker & Kupferschmid
f = -[3 -7 -12];
a = [-3 6 8;6 -3 7;-6 3 3];
a = sparse(a);
b = [12 8 5];
e = [-1 -1 -1];
xint = [1 2 3];
[vx] = lp_solve(fabe[][]xint)
echo off;
disp(‘End of Ex5. Press any key to continue.‘);
pause
echo on;
clc;
% Example 6
% 0-1 programming example page 228 233 of Ecker & Kupferschmid
f = -[2 3 7 7];
a = [1 1 -2 -5;-1 2 1 4];
a = sparse(a);
b = [2 -3];
e = [1 1];
xint = [1 2 3 4];
vub = [1 1 1 1];
[vx] = lp_solve(fabe[]vubxint)
echo off;
disp(‘End of Ex6. Press any key to continue.‘);
pause
echo on;
clc;
% Example 7
% 0-1 programming example page 238 of Ecker & Kupferschmid
f = -[1 2 3 7 8 8];
a = [5 -3 2 -3 -1 2; -1 0 2 1 3 -3;1 2 -1 0 5 -1];
b = [-5 -1 3];
e = [1 1 1];
xint = [1 2 3 4 5 6];
vub = [1 1 1 1 1 1];
[vx] = lp_solve(fsparse(a)be[]vubxint)
echo off;
disp(‘End of Ex7. Press any key to continue.‘);
pause
echo on;
clc;
% Example 8
% A knapsack problem
% The problem is to maximize the sum of objects
n = 5; % Number of objects
f = ones(n1);
% subject to a constraint not to fill up the bag
a = rand(1n);
b = [1];
e = [-1];
xint = 1:n;
vub = ones(n1);
[vx] = lp_solve(fsparse(a)be[]vubxint)
echo off;
disp(‘End of Ex8. Note that model is random so solution is also random. Press any key to continue.‘);
pause
echo on;
clc;
% Example 9
% L1 Data fitting example with integer constraint on the intercept
n = 40;
t = (0:n-1)‘;
y = 3.5 -.2*t;
y = y + 0.5*randn(size(y));
m = [ones(n1)t(:)];
a = [m-mspeye(n)];
f = -[sum(m)sum(-m)2*ones(1n)];
e = ones(n1);
vub = [10 10 10 10 5*ones(1n)];
[vx] = lp_solve(fsparse(a)ye[]vub[13]);
p = x(1:2)-x(3:4);
err = y-m*p;
plot(ty‘o‘tm*p);
xlabel(‘t‘);
ylabel(‘y‘);
echo off;
disp(‘End of Ex9. Press any key to continue.‘);
pause
echo on;
clc;
% E
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1198 2007-03-29 20:51 lp_solve\changes
文件 56185 2005-07-28 21:06 lp_solve\ex.m
文件 1017 2004-12-22 00:07 lp_solve\example1.m
文件 821 2008-11-30 21:09 lp_solve\example2.m
文件 329 2005-06-07 21:08 lp_solve\example3.m
文件 291 2005-05-26 22:52 lp_solve\example4.m
文件 306 2005-05-26 22:53 lp_solve\example5.m
文件 529 2005-05-26 22:55 lp_solve\example6.m
文件 2788 2008-01-22 18:19 lp_solve\filterlpsolve4.m
文件 3338 2004-12-28 16:50 lp_solve\lpdemo.m
文件 2307 2005-05-26 23:06 lp_solve\lp_maker.m
文件 2708 2005-07-30 00:09 lp_solve\lp_solve.m
文件 2230 2008-01-20 23:16 lp_solve\Makefile64.m
文件 112554 2009-01-02 18:26 lp_solve\MATLAB.htm
文件 71168 2009-01-29 23:03 lp_solve\mxlpsolve.dll
文件 14340 2006-08-26 19:17 lp_solve\mxlpsolve.m
文件 48 2009-02-01 19:35 lp_solve\README.txt
文件 393216 2009-02-01 22:33 lpsolve55.dll
目录 0 2009-09-05 20:14 lp_solve
----------- --------- ---------- ----- ----
665373 19
评论
共有 条评论