Modeling Algorithm (ii)--integer programming

Source: Internet
Author: User

I. Overview

1, definition: The variable part or all of the plan is defined as an integer is, called Integer planning.

2, Cent: pure integer programming and mixed integer programming.

3. Features:

(1) The original linear programming has the optimal solution, when the argument is limited to an integer:

A, the original optimal solution is all integers, the optimal solution is still established

B, integer programming no feasible solution

C, there is a feasible solution, but not the original optimal solution

4. Classification of solution methods

(1) Branch-bound method

(2) Cutting plane method

(3) Implicit enumeration method

(4) Hungarian law

(5) Monte Carlo method

Ii. Branch and bound method

1, the algorithm is as follows (solve integer programming maximization problem)

MATLAB implementation

function r=checkint (x)% to determine if x (i) is not an integer. Yes R (i) return 1, no, return 0 input parameter: x   x vector % output parameter: R   r vector for i=  1: Length (x)     if (min (ABS (x (i)-floor (x (i))), ABS (x (i)-ceil (x (i))) <1e-3)        R (i)=1;     Else         R (i)=0;    EndEnd
function val=Isrowinmat (Arow,mat)%to determine if the mat contains the same vector as the arow.%input variable: arow vector%Mat Matrix%Output Variable: Val 1 indicates there, 0 means no Val=0; rows=size (Mat,1); forI=1: Rows Temp= (Mat (i,:) = =Arow); ifLength (Find (temp==0))==0Val=1; return; ElseVal=0; End End
function [x,fval,exitflag,output,lambda]=Linprogdis (ifint,f,a,b,aeq,beq,lb,ub,x0,options)%usage% [x,fval,exitflag,output,lambda]=lpint (IFINT.F,A,B,AEQ,BEQ)% [x,fval,exitflag,output,lambda]=lpint (ifint,f,a,b,aeq,beq,lb)% [x,fval,exitflag,output,lambda]=lpint (Ifint,f,a,b,aeq,beq,lb,ub)% [x,fval,exitflag,output,lambda]=lpint (ifint,f,a,b,aeq,beq,lb,ub,x0)% [x,fval,exitflag,output,lambda]=lpint (ifint,f,a,b,aeq,beq,lb,ub,x0,options)ifnargin<Ten, options=[]; Endifnargin<9, x0=[]; Endifnargin<8, ub=inf*ones (Size (f)); Endifnargin<7, lb=Zeros (Size (f)); END[X,FVAL,EXITFLAG,OUTPUT,LAMBDA]=Linprog (f,a,b,aeq,beq,lb,ub,x0,options);ifexitflag<=0%indicates that there is no optimal solution for linear programmingreturnEndv1=find (ifint==1); %Locate the subscript temp for variables that require integer planning=x (v1);If you do not require an integer plan, you can return it. ifIsEmpty (temp)returnEndv2=find (Checkint (temp) = =0);ifIsEmpty (v2)%are all integers, get the most solutionsreturnENDK=V1 (V2 (1)); Temp1=zeros (1, Length (f)); Temp1 (k)=1; Low=Floor (x (k));ifIsrowinmat ([temp1,low],[a,b]) = =1Thisa=A; THISB=b;ElseThisa=[A;TEMP1]; THISB=b; THISB (End+1)=LOW;END[X1,FVAL1,EXITFLAG1,OUTPUT1,LAMBDA1]=Linprogdis (ifint,f,thisa,thisb,aeq,beq,lb,ub,x0,options); Temp2=zeros (1, Length (f)); Temp2 (k)=-1; High=-ceil (x (k));ifIsrowinmat ([temp2,high],[a,b]) = =1Thisa=A; THISB=b;ElseThisa=[A;TEMP2]; THISB=b; THISB (End+1)=High;end[x2,fval2,exitflag2,output2,lambda2]=Linprogdis (ifint,f,thisa,thisb,aeq,beq,lb,ub,x0,options);if(IsEmpty (v2) && (exitflag1>0&& exitflag2<=0&& fval<=fval) | | (exitflag2>0&& exitflag1<=0&& Fval<=fval2) | | (exitflag1>0&& exitflag2>0&& Fval<=fval1 && fval<=FVAL2)))  Disp ('Error Call'); return; %indicates that both are integer endifExitflag1>0&&exitflag2<=0x=X1; FVal=Fval1; Exitflag=Exitflag1; Output=output1; Lambda=Lambda1;elseif Exitflag1<=0&&exitflag2>0x=x2; FVal=Fval2; Exitflag=Exitflag2; Output=Output2; Lambda=Lambda2;elseif Exitflag1>0&& exitflag2>0    iffval1<Fval2 x=X1; FVal=Fval1; Exitflag=Exitflag1; Output=output1; Lambda=lambda1; Elsex=x2; FVal=Fval2; Exitflag=Exitflag2; Output=Output2; Lambda=lambda2; EndEnd

Modeling Algorithm (ii)--integer programming

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.