Assembly Line Scheduling | DP | A PHP program to find minimum possible time by the car chassis to complete ; Utility function to find minimum of two numbers ; time taken to leave first station in line 1 ; time taken to leave first station in line 2 ; Fill tables T1 [ ] and T2 [ ] using the above given recursive relations ; Consider exit times and return minimum ; Driver Code
< ? php $ NUM_LINE = 2 ; $ NUM_STATION = 4 ; function carAssembly ( $ a , $ t , $ e , $ x ) { global $ NUM_LINE , $ NUM_STATION ; $ T1 = array ( ) ; $ T2 = array ( ) ; $ i ; $ T1 [ 0 ] = $ e [ 0 ] + $ a [ 0 ] [ 0 ] ; $ T2 [ 0 ] = $ e [ 1 ] + $ a [ 1 ] [ 0 ] ; for ( $ i = 1 ; $ i < $ NUM_STATION ; ++ $ i ) { $ T1 [ $ i ] = min ( $ T1 [ $ i - 1 ] + $ a [ 0 ] [ $ i ] , $ T2 [ $ i - 1 ] + $ t [ 1 ] [ $ i ] + $ a [ 0 ] [ $ i ] ) ; $ T2 [ $ i ] = min ( $ T2 [ $ i - 1 ] + $ a [ 1 ] [ $ i ] , $ T1 [ $ i - 1 ] + $ t [ 0 ] [ $ i ] + $ a [ 1 ] [ $ i ] ) ; } return min ( $ T1 [ $ NUM_STATION - 1 ] + $ x [ 0 ] , $ T2 [ $ NUM_STATION - 1 ] + $ x [ 1 ] ) ; } $ a = array ( array ( 4 , 5 , 3 , 2 ) , array ( 2 , 10 , 1 , 4 ) ) ; $ t = array ( array ( 0 , 7 , 4 , 5 ) , array ( 0 , 9 , 2 , 8 ) ) ; $ e = array ( 10 , 12 ) ; $ x = array ( 18 , 7 ) ; echo carAssembly ( $ a , $ t , $ e , $ x ) ; ? >