From 811bec3b62f217b9858eeed6ad3daac1f6e770b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9B=98=E8=8D=A3=E5=8D=9A?= <2858829498@qq.com> Date: Sun, 14 Jul 2024 14:58:42 +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..2de2640 --- /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); + + + +