From 1c2217abc4861fea792e550ccdfd7f1cd6978c85 Mon Sep 17 00:00:00 2001 From: phzrjyvu9 <2026074240@qq.com> Date: Sun, 14 Jul 2024 14:21:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E6=95=B0=E8=A7=84=E5=88=92=EF=BC=88li?= =?UTF-8?q?nprog\optimproblem=E8=A7=A3=E6=B3=95=EF=BC=89=EF=BC=8C01?= =?UTF-8?q?=E8=A7=84=E5=88=92=EF=BC=88=E8=83=8C=E5=8C=85=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- intLP.m | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 intLP.m diff --git a/intLP.m b/intLP.m new file mode 100644 index 0000000..ed837cb --- /dev/null +++ b/intLP.m @@ -0,0 +1,49 @@ +%整数规划 +%P23 ej2.5 +%optimproblem解法 +clc; clear; close all; format long g; +prob=optimproblem; +x=optimvar('x',6,'LowerBound',0,'Type','integer'); +prob.Objective=sum(x); +cnt=[35,40,50,45,55,30]; +con=optimconstr(6); +con(1)=x(1)+x(6)>=35; +for i=1:5 + con(i+1)=x(i)+x(i+1)>=cnt(i+1); +end +prob.Constraints.con=con; +[sol,fval,flag,out]=solve(prob); +X=sol.x; + + +%linprog解法 +clc; clear; close all; format long g; +f=[1,1,1,1,1,1]; +intcon=[1:6]; +A=zeros(6,6); +A(1,1)=-1; +A(1,6)=-1; +for i=1:5 + A(i+1,i)=-1; + A(i+1,i+1)=-1; +end +lb=zeros(6,1);%注意不是lb=0 +b=[-35;-40;-50;-45;-55;-30]; +[x,fval]=intlinprog(f,intcon,A,b,[],[],lb); + + + +%01规划 +%背包问题 + +f=-[540,200,180,350,60,150,280,450,320,120]; +intcon=1:10; +lb=zeros(10); +ub=ones(10); +A=[6,3,4,5,1,2,3,5,4,2]; +b=30; +[x,fval]=intlinprog(f,intcon,A,b,[],[],lb,ub); + + + +