First, the problem description
There are two assembly lines in a car factory, each with N assembly stations. The J Assembly station of assembly line I is expressed as SI,j , at which the assembly time of the station is ai,j . A car chassis enters the factory and then enters assembly line I (I is 1 or 2) and takes time to ei . After passing through the first assembly station of a line, the chassis comes to the assembly station of any assembly line (j+1). If it stays on the same assembly line, there is no move overhead. However, if it moves to another line, it takes a time of Ti,j . After leaving the nth Assembly station on an assembly line, the completed car chassis takes time for xI to leave the factory. The problem to be solved is to determine which stations should be selected within the assembly line 1, and which stations to select within the assembly line 2, so that the total time of the car passes through the factory is shortest.
The variables provided by the problem
EI: Time to enter assembly line I
AIJ: The time spent at the assembly station IJ
Tij: Extra time to leave the assembly station after the IJ assembly is finished
Xi: Time for assembly to leave I
Second, the Thinking analysis
Observe the quickest route through the assembly station S1,j , and find that it must be an assembly station (J-1) on the assembly line 1 or 2. Therefore, the quickest route through the assembly station S1,j can only be one of the following:
? Through the assembly station s1,j?1 the quickest route, and then directly through the assembly station s1,j .
? The fastest route through the assembly station s2,j?1 , from assembly line 2 to assembly line 1, and then through the assembly station s1,j .
So looking for the quickest route through the Assembly station J on either assembly line, we can plan to find the quickest route to j-1 through the Assembly station on the two assembly lines first.
The optimal condition of the j-1 can be determined by the J-2 case, which can be pushed forward to s0,0 and S1, 0, while the S0,0 can be determined by adding E0 and a0,0, ands-a can be determined by adding E1 and a1,0.
Third, the code implementation
The code stores the path with path, which represents the assembly line represented by the shortest path. The assembly line is 2, with 6 assembly stations per assembly line. Other data structure meanings are shown in comments.
int main () {//two assembly line//Enter assembly line I time int e[2] = {1,2};//time spent in the assembly station IJ int A[2][6] = {{4,2,3,5,3},{7,2,4,2,4}};// Extra time to leave the assembly station after the IJ assembly is finished int t[2][6] = {{2,3,2,2,1},{1,1,2,4,2}};//assembly complete leave I time int x[2] = {2,1};//use path to store shortest path int path[6 ] = {0};//the number of assembly stations contained in each assembly line int n = 6;//result[i][j] means the minimum time taken to leave the assembly station IJ int result[2][6] = {0};result[0][0] = e[0] + a[0][0];res Ult[1][0] = e[1] + a[1][0];if (Result[0][0] < result[1][0]) path[0] = 0;elsepath[0] = 1;for (int j = 1; j < N; j + +) { if (Result[0][j-1] < result[1][j-1] + t[1][j-1]) result[0][j] = Result[0][j-1] + a[0][j];elseresult[0][j] = ResU LT[1][J-1] + a[0][j] + t[1][j-1];if (result[0][j-1] + t[0][j-1] < result[1][j-1]) result[1][j] = result[0][j- 1] + a[1][j] + t[0][j-1];elseresult[1][j] = result[1][j-1] + a[1][j];//save path if (Result[0][j] < result[1][j]) Path[j] = 0 ; elsepath[j] = 1;} RESULT[0][5] = result[0][5] + x[0];result[1][5] = result[1][5] + x[1];for (int i = 0; i < 5; i++) cout << Path[i] << endl;if (Result[0][5] < result[1][5]) cout << result[0][5] <<endl;elsecout << result[1][5] << endl;system (" Pause "); return 0;}
Dynamic programming--assembly line scheduling algorithm