Lien000034
2014-10-06
1. Problem Description
A car factory has two assembly lines, each of which has n assembly stations. The assembly station J of assembly line I is represented as Si, J, and the Assembly time of the station is Ai, J. An automobile chassis enters the factory, and then enters the assembly line I (I is 1 or 2), which takes the time of EI. After passing through the J assembly station of a line, the chassis came to the J + 1 assembly station of any assembly line. If it stays in the same assembly line, there is no moving overhead. However, if it is moved to another line, it takes Ti, J. After leaving the nth assembly station in an assembly line, the finished car chassis took time for Xi to leave the factory. The problem to be solved is to determine which stations should be selected in assembly line 1 and which stations should be selected in assembly line 2 to minimize the total time for automobile passing through the factory.
2 algorithm Parsing
The following describes the Scheduling Problem of the assembly line through dynamic planning.
2.1 Step 1: Describe the features of the Optimal Solution Structure
Observe the fastest route through the assembly station S1, J, and find that it must be through the assembly station (J-1) on the assembly line 1 or 2 ). Therefore, through the assembly station S1, J's fastest route can only be one of the following:
• The fastest route through the assembly station S1, J −1, and then directly through the assembly station S1, J.
• Transfer from assembly line 2 to assembly line 1 through the fastest route of assembly station S2 and J-1, and then through assembly station S1, J.
So looking for the fastest route through any assembly station J on the assembly line, we can plan first looking for the fastest route through the assembly station J-1 on the two assembly lines.
2.2 Step 2: Use the final solution of the problem to recursively define the value of an optimal solution
Note fi [J] indicates the shortest time for a car chassis from the starting point to the assembly station Si, and J indicates the shortest time for the chassis to pass through all assembly stations in the factory.
2.3 Step 3: Calculate the fastest time
The execution time of recursive algorithms is about the exponential form of N, so we use the implementation method from low to top to calculate the fastest time. Note: Li [J] indicates entering the assembly station Si. The first assembly station of J comes from which assembly line; L branch indicates from which assembly line leaves the factory.
FATEST-WAY(a, t, e, x, n) f1 [1] ← e1 + a1,1 f2 [1] ← e2 + a2,1 for j ← 2 to n if f1 [j − 1] + a1,j ≤ f2 [j − 1] + t2,j−1 + a1,j then f1 [j] ← f1 [j − 1] + a1,j l1 [j] ← 1 else f1 [j] ← f2 [j − 1] + t2,j−1 + a1,j l1 [j] ← 2 endif if f2 [j − 1] + a2,j ≤ f1 [j − 1] + t1,j−1 + a2,j then f2 [j] ← f2 [j − 1] + a2,j l2 [j] ← 2 else f2 [j] ← f1 [j − 1] + t1,j−1 + a2,j l2 [j] ← 1 endif endfor if f1 [n] + x1 ≤ f2 [n] + x2 then f∗ ← f1 [n] + x1 l∗ ← 1 else f∗ ← f2 [n] + x2 l∗ ← 2 endifend
2.4 Step 4: Build the fastest route through the factory
According to the Li [J] And l pair obtained in step 3, the route with the minimum scheduling time is printed.
PRINT-STATIONS(l, l∗ , n) i ← l∗ print ’line:’ i ’, station:’ n for j ← n downto 2 i ← li [j] print ’line:’ i ’, station:’ j-1 endforend
3 C language implementation verification
Assume that there are two assembly lines with five assembly stations, as shown in figure,
Figure 1: assembly line example
The left side of the assembly line is the entrance, and the right side is the exit. The numbers on the entrance and exit indicate the time consumed to enter the assembly line and to exit the assembly line respectively. The green circle indicates the assembly station, and the number in the circle indicates the assembly time on the assembly station. The number on the line between each assembly line indicates the time consumed by transferring from one assembly line to another.
The verification code in C language is as follows,
#include <stdlib.h>#include <stdio.h>void PrintPath(int *, int , int);void FastestWay(int *, int *, int [], int [], int);intmain(void){ int enterTimes[2] = {1, 2}; int exitTimes[2] = {2, 1}; int assemblyTimes[2][5] = { {4, 2, 3, 5, 3}, {7, 2, 4, 2, 4}}; int transferTimes[2][5] = { {2, 1, 2, 2, 1}, {1, 1, 2, 4, 2}}; FastestWay(&assemblyTimes[0][0], &transferTimes[0][0], enterTimes, exitTimes, 5); exit(0);}void FastestWay(int *assemblyTimes, int *transferTimes, int enterTimes[2], int exitTimes[2], int n){ int fastestTime = 0; int exitLine; int j; int *fastest, *lineTag; int temp1, temp2; fastest = malloc(sizeof(int) * 2 * n); lineTag = malloc(sizeof(int) * 2 * n); *(fastest) = enterTimes[0] + *assemblyTimes; *(fastest + n) = enterTimes[1] + *(assemblyTimes + n); for (j = 1; j < n; j++) { temp1 = *(fastest + (j-1)); temp2 = *(fastest + (n + j - 1)) + *(transferTimes + (n + j - 1)); if (temp1 <= temp2) { *(fastest + j) = temp1 + *(assemblyTimes + j); *(lineTag + j) = 1; } else { *(fastest + j) = temp2 + *(assemblyTimes + j); *(lineTag + j) = 2; } temp1 = *(fastest + (n + j - 1)); temp2 = *(fastest + (j - 1)) + *(transferTimes + (j - 1)); if (temp1 <= temp2) { *(fastest + (n + j)) = temp1 + *(assemblyTimes + (n + j)); *(lineTag + (n + j)) = 2; } else { *(fastest + (n + j)) = temp2 + *(assemblyTimes + (n + j)); *(lineTag + (n + j)) = 1; } } temp1 = *(fastest + (n - 1)) + exitTimes[0]; temp2 = *(fastest + (n + n - 1)) + exitTimes[1]; if (temp1 <= temp2) { fastestTime = temp1; exitLine = 1; } else { fastestTime = temp2; exitLine = 2; } printf("The cost of the fastest path: %d\n", fastestTime); PrintPath(lineTag, exitLine, n);}void PrintStation(int line, int station){ printf("line: %d, station: %d\n", line, station);}void PrintPath(int *lineTag, int exitLine, int n){ int i = exitLine; int j; PrintStation(exitLine, 5); for (j = 5; j >= 2; j--) { i = *(lineTag + (n * (i - 1) + j - 1)); PrintStation(i, j-1); }}View code
Compile the program and generate and execute the assemblylineschedule file,
lienhua34:algorithm$ gcc -o AssemblyLineSchedule AssemblyLineSchedule.clienhua34:algorithm$ ./AssemblyLineScheduleThe cost of the fastest path: 19line: 2, station: 5line: 2, station: 4line: 2, station: 3line: 1, station: 2line: 1, station: 1
Therefore, the shortest path takes 19 times in total, and the path is like a red line,
Figure 2 assembly line example with the fastest path
(Done)
Algorithm analysis and verification of assembly line Scheduling Problems