Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to solve the 0- 1 programming problem with matlab?
How to solve the 0- 1 programming problem with matlab?
Example to solve the following 0- 1 integer linear programming.

objective function

Maximum f=-3x 1+2x2-5x3

Constraint condition

x 1+2x2-x3≤2,

x 1+4x2+x3≤4,

x 1+x2≤3,

4x 1+x3≤6,

X 1, x2 and x3 are 0 or 1.

Enter the following command in the Matlab command window:

f=[-3,2,-5];

a=[ 1,2,- 1,; 1,4, 1; 1, 1,0; 0,4, 1]; b =[2; 4; 3; 6];

[x,fval]=bintprog(-f,a,b)

% because bintprog is solving the minimum value of the objective function, a negative sign should be added before F.

The running results are as follows:

Optimization terminated.

x = 0

1

fval = -2

It means that when x 1=0, x2= 1, x3=0, the maximum value of f is 2.

Of course, we can also enter the following command in the Matlab command window to inquire about the usage of the 0- 1 integer programming command.

Help bintprog