Introduction to Algorithms Learning Notes (7)--assembly line scheduling of dynamic programming

Source: Internet
Author: User
Tags min

The assembly line problem is as follows:
Colonel Motor Company produces cars in factories with two assembly lines, and a chassis that enters each assembly line will have different parts installed on the chassis of the vehicle at each station, and the final finished car leaves from the end of the assembly line. As shown in the following figure.

Figure 1 assembly line schematic
Each assembly line has n assembly stations, numbered j=1,2,..., N, the assembly line I (I is 1 or 2) of the J Assembly station is represented as S (i,j). The same function is performed for the J station S (1,J) of assembly line 1 and the J Station S (2,J) of assembly line 2. However, these assembly stations are built at different times and use different techniques, so the time required to complete the assembly on each station is not the same, even at the same location on the two assembly lines. The required assembly time for each assembly station is recorded as a (I,J), and the time required for the chassis to enter assembly line I is E (i), and the time required to leave assembly line I is x (i). Normally, the time it takes to move the chassis from the previous station to the next station on an assembly line can be ignored, but occasionally the unfinished chassis will be moved from one station of one assembly line to the next on the other, such as when an emergency order is encountered. Assuming that the time it takes to remove the chassis from Assembly station S (I,J) from assembly line I to another assembly line is T (i,j), the problem is to determine which stations are selected within assembly line 1 and which stations are selected within assembly line 2, so that the total time for the car to pass through the factory is minimized.
At first glance at the problem, the simplest solution is to go through the calendar and draw the minimum time in the process of traversal. However, it should be seen that when the number of sites n is large, it is necessary to traverse 2 of the nth square route, the efficiency is low. So, is there a more efficient solution?
To facilitate the analysis of the problem, we set up a simple mathematical model for the problem. Assuming that the shortest total time through Assembly station J is F (j), the assembly line selected by the shortest route of Assembly station J is R (J) (R (j) with a value of 1 or 2), the total time of the car passing through the factory is F=f (n) +x (R (N)). So the key question now is to figure out F (n) and R (N). The car through the Assembly station N route also inevitably through the assembly station N-1, we can see through the assembly station n the shortest total time f (n) and the choice of assembly line R (N) and through the assembly station n-1 the shortest total time F (n-1) and the selected assembly line R (n-1) there is no correlation between. It should not be difficult to conclude that, if f (n-1) and R (n-1) are calculated, F (n) is f (n-1) plus the shortest time from the N-1 assembly station to the nth assembly station. Knowing R (n-1), it is very easy to calculate the shortest time from the N-1 assembly station to the nth Assembly station, and note!r (j) as another assembly line, you only need to find the smaller values of a (R (n-1), N) and A (!r (n-1), N) +t (R (n-1), n-1).
Based on the above analysis, it can be concluded that:
F (n) =f (n-1) +min (A (R (n-1), N), A (!r (n-1), N) +t (R (n-1), n-1))
R (N) =r (n-1) if A (R (n-1), N) <= A (!r (n-1), N) +t (R (n-1), n-1)
!r (n-1) if A (R (n-1), N) > A (!r (n-1), N) +t (R (n-1), n-1)
More generally, we can conclude that:
F (1) =min (E1+a, E2+a (2, 1))
R (1) =1 if E1+a (<=) E2+a (2, 1)
2 if E1+a > E2+a (2, 1)
F (j) =f (j-1) +min (A (R (j-1), N), A (!r (j-1), N) +t (R (j-1), j-1)) where 2=<j<=n
R (J) =r (J-1) if A (R (j-1), J) <= A (!r (j-1), J) +t (R (j-1), j-1)

!r (J-1) if A (R (j-1), J) > A (!r (j-1), J) +t (R (j-1), j-1)

With the above recursion, we can use a bottom-up approach to calculate the shortest time the car passes through the plant and the specific route used.

C + + code://assembly line scheduling. CPP: The entry point that defines the console application.  //    #include "stdafx.h"   #include <iostream>  using namespace std;   /* Dynamic planning To solve assembly line problems (the problem comes from the introduction to algorithms 15th)     Author: Blackmamba     Time: October 4, 2010 */   /*      A[i][j] Indicates the required assembly time I=1,2;1<=j<=n     E[i],x[i] on the assembly station SI,J, respectively, to indicate the entry and exit times of the chassis entering assembly line I     T[i][j] means that the time     Fi[j] from one assembly line to another after the assembly station SI,J represents the fastest possible time for a chassis to si,j from the starting point to the assembly station 1<=j <=n     Li[j] represents the assembly line number 1 or 2, where the assembly station J-1 is used by the fastest route si,j by the transfer station 2<=j<=n     Fmin represents the shortest length of time     line represents Assembly station N when assembly lines */    int a[3][7] = {{0, 0, 0, 0, 0, 0, 0},   &nbsp ;             {0, 7, 9, 3, 4, 8, 4},                  {0, 8, 5, 6, 4, 5, 7}};  int e[3] = {0, 2, 4 };  int x[3] = {0, 3, 2};  int t[3][6] = {{0, 0, 0, 0, 0, 0},                 {0, 2, 3, 1, 3, 4},                 {0, 2, 1, 2, 2, 1}};    int f[3][7];  int l[3][7];  int fmin;  int line;  void fastestway (int a[3][7], in T t[3][6], int e[], int x[], int n)   {        f[1][1] = e[1] + a[1][1];  &NBSP;&NBSP;&N Bsp F[2][1] = e[2] + a[2][1];      for (int i=2; i<=n; i++)       {   &nbs p;     //Start into line 1          if ((F[1][i-1] + a[1][i ]) <= (F[2][i-1] + t[2][i-1] + a[1][i])           {               F[1][i] = f[1][i-1] + a[1][i];               L[1] [I] = 1;//means select the point on line 1th          }           else          {               F[1][i] = f[2][i-1] + t[2][i-1] + a[1][i];        & nbsp;     L[1][i] = 2;//indicates that point on 2nd line is selected          }         //Start into line 2          if ((f[2][ I-1] + a[2][i]) <= (F[1][i-1] + t[1][i-1] + a[2][i])           {   & nbsp;          F[2][i] = f[2][i-1] + a[2][i];               L[2][i] = 2;         }           else          {              F[2][i] = f[1][i-1] + T[1][I-1] + a[2][i];              l[2][i] = 1;         }     }             if (F[1][n] + x[1] <= F[2][n] + x[2])       {       &nbs p; //From the Nth assembly station of Line 1 out of the time period so select line 1          fmin = f[1][n] + x[1];          line = 1;     }      else  & nbsp;   {          fmin = f[2][n] + x[2];     & nbsp;    line = 2;     } }  void printstation (int l[3][7], int. line, int n)   {      int i = line;      printf ("line%d, station%d/n", I, N);      for (int j=n; j>=2; j--)   &NBSP;&NBSP;&NB Sp {          i = l[i][j];          printf ("line%d, station%d/n", I, j-1);     } }  int _tmain (int argc, _tchar* argv[]) &nbs P {      Fastestway (A, T, E, X, 6);      printstation (L, line, 6);   &nbs p;  printf ("Shortest time:%d/n", fmin);      return 0; } 


Related Article

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.