Mathematical modeling four 0-1 planning

This is the problem:

 

 solution:

 

Unit conversion: 1'06'8 = 66.8 seconds 

Key points: Let Cij be the result of the player i swimming stroke j; i = 1,2,3,4,5; j = 1,2,3,4; Xij = 1 means the player i participates in the swimming stroke j competition;

①.lingo code

 

Min = 66.8 * x11 + 75.6 * x12 + 87 * x13 + 58.6 * x14 + 57.2 * x21 + 66 * x22 + 66.4 * x23 + 53 * x24 + 78 * x31 + 67.8 * x32 + 84.6 * x33 + 59.4 * x34 + 70 * x41 + 74.2 * x42 + 
69.6 * x43 + 57.2 * x44 + 67.4 * x51 + 71 * x52 + 83.8 * x53 + 62.4 * x54; 
% refers to the inequality constraint A * x <= b refers to each person taking at most one posture Swimming [st_1] x11 + x12 + x13 + x14 <1; [st_2] x21 + x22 + x23 + x24 <1; [st_3] x31 + x32 + x33 + x34 <1; [st_4] x41 + x42 + x43 + x44 <1; [st_5] x51 + x52 + x53 + x54 <1;

% refers to the equality constraint Aeq * x = beq refers to each style of swimming with only one person participating [st_6] x11 + x21 + x31 + x41 + x51 = 1; [st_7] x12 + x22 + x32 + x42 + x52 = 1; [st_8] x13 + x23 + x33 + x43 + x53 = 1; [st_9] x14 + x24 + x34 + x44 + x54 = 1;

  

% Note one by one

The result is as follows:

 

 

 

 Pay attention to the results, the fastest result is 253.2 seconds, x14 = x21 = x32 = x43 = 1; others = 0; at this time A-freestyle; B-butterfly; C-backstroke; D-breaststroke

 

② matlab code [super detailed! ! Just watch it once! !

>>  f=[66.8 75.6 87 58.6 57.2 66 66.4 53 78 67.8 84.6 59.4 70 74.2 69.6 57.2 67.4 71 83.8 64.2];
>> A=[1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0;...
0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0;0 0 0 0 0 0 0 0 0 0 0 0  0  0  0  0  1  1  1  1 ];
 >> b = [ 1 ; 1 ; 1 ; 1 ; 1 ];
 % refers to the inequality constraint A * x <= b refers to everyone participating in at most one posture swimming

 >> Aeq = [ 1  0  0  0  1  0  0  0  1  0  0  0  1  0  0  0  1  0  0  0 ; 0  1  0  0  0  1  0  0  0  1  0  0  0  1 0 0 0 1 0 0;0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 ;...
0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 ];
>>  beq=[1;1;1;1];
% Refers to the equality constraint Aeq * x = beq refers to each

 style of swimming with only one person participating >> intcon = 1 : 1 : 20 ; % refers to the position of 20 integer variables
 >> lb = zeros ( 20 , 1 ) ; % Means that the lower bound of each integer variable is 0; here you can also write zeros (20) or zeros (1,20) just to generate vectors, as long as the final result is a vector.
 >> ub = ones ( 20 , 1 ); % means that the upper bound of each integer variable is 1; here you can also write zeros (20) or zeros (1,20)
 >> [x, fval] = intlinprog (f, intcon, A, b, Aeq, beq, lb, ub) % Use the function intlinprog to solve integer linear programming problems, or use bintprog

The running result is:

LP:                Optimal objective value is 253.200000.                                           


Optimal solution found.

Intlinprog stopped at the root node because the objective value is within a gap tolerance of the optimal value,
options.AbsoluteGapTolerance = 0 (the default value). The intcon variables are integer within tolerance, options.IntegerTolerance = 1e-05
(the default value).


x =

     0
     0
     0
     1
     1
     0
     0
     0
     0
     1
     0
     0
     0
     0
     1
     0
     0
     0
     0
     0


fval =

  253.2000

Summary: The lingo code is relatively simple. Matlab code is very easy to make mistakes, you must be careful; then the ability to analyze the problem should be strengthened, learn to extract the mathematical model from the actual problem, and then solve it. This question is a 0-1 planning problem and can be understood using two-dimensional vectors; that is, Xij = 1 is the jth swimming stroke of the ith person to participate in the competition; Xij = 0 is the jth swimming stroke of the ith person is not participating in the competition! When writing matlab vectors, you must be careful, and there is still time conversion to convert 60 points into 100 points!

Guess you like

Origin www.cnblogs.com/lysun/p/12720380.html