×

Assembly Line Scheduling

If we take an example of a car factory, there are two assembly lines. In an assembly line, we can assemble and repair the parts of a car. Now, suppose that we have to build a new car from this factory. So, we have to go through one of the assembly lines. In each assembly line, there are many stations. Every station has its own work so, we cannot miss one station. But it is possible to jump from station of one assembly line to the very next station of another assembly line. In every station there are some time taken and to transfer from one station to another, it also takes some time. You have to find minimum time to complete the car. There will be a given time for each station.

Concept behind the solution

Here, we will use recursion and DP. By recursion, we can divide the problem into smaller sub problems. After that it is easy to find out the solution. It is obvious that there will be occurred some repeating sub problems so; we will use dynamic programming to find out optimised solution. Check the following code to understand the things well.

Code:

// C++ program to find minimum possible time to complete the car

#include <bits/stdc++.h>
using namespace std;
#define ASLINE 2
#define STATIONNUM 4
int min(int a, int b)
{
	return a < b ? a : b;
}
int asemblecarfun(int a[][STATIONNUM],
				int t[][STATIONNUM],
				int *e, int *x)
{
	int T1[STATIONNUM], T2[STATIONNUM], i;
	T1[0] = e[0] + a[0][0];	
	T2[0] = e[1] + a[1][0];
	for (i = 1; i < STATIONNUM; ++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[STATIONNUM - 1] + x[0],
			T2[STATIONNUM - 1] + x[1]);
}
int main()
{
	int a[][STATIONNUM] = {{4, 5, 3, 2},
							{2, 10, 1, 4}};
	int t[][STATIONNUM] = {{0, 7, 4, 5},
							{0, 9, 2, 8}};
	int e[] = {10, 12}, x[] = {18, 7};


	cout << asemblecarfun(a, t, e, x);


	return 0;
}

// C program to find minimum possible time to complete the car

#include <stdio.h>
#define ASLINE 2
#define STATIONNUM 4
int min(int a, int b) { return a < b ? a : b; }


int asemblecarfun(int a[][STATIONNUM], int t[][STATIONNUM], int *e, int *x)
{
	int T1[STATIONNUM], T2[STATIONNUM], i;


	T1[0] = e[0] + a[0][0]; 
	T2[0] = e[1] + a[1][0];	
for (i = 1; i < STATIONNUM; ++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[STATIONNUM-1] + x[0], T2[STATIONNUM-1] + x[1]);
}


int main()
{
	int a[][STATIONNUM] = {{4, 5, 3, 2},
				{2, 10, 1, 4}};
	int t[][STATIONNUM] = {{0, 7, 4, 5},
				{0, 9, 2, 8}};
	int e[] = {10, 12}, x[] = {18, 7};


	printf("%d", asemblecarfun(a, t, e, x));


	return 0;
}

// JAVA program to find minimum possible time to complete the car

import java.io.*;
class bn
{
	static int ASLINE = 2;
	static int STATIONNUM = 4;
	
	static int min(int a, int b)
	{
		return a < b ? a : b;
		
	}
	
	static int asemblecarfun(int a[][], int t[][], int e[], int x[])
	{
		int T1[]= new int [STATIONNUM];
		int T2[] =new int[STATIONNUM] ;
		int i;
		T1[0] = e[0] + a[0][0];
		T2[0] = e[1] + a[1][0];
	
		for (i = 1; i < STATIONNUM; ++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[STATIONNUM-1] + x[0],
					T2[STATIONNUM-1] + x[1]);
	}
	
	public static void main (String[] args)
	{
		int a[][] = {{4, 5, 3, 2},
					{2, 10, 1, 4}};
		int t[][] = {{0, 7, 4, 5},
					{0, 9, 2, 8}};
		int e[] = {10, 12}, x[] = {18, 7};
	
		System.out.println(asemblecarfun(a, t, e, x));	
	
	}
}

# Python program to find minimum possible time to complete the car

def asemblecarfun (a, t, e, x):	
	STATIONNUM = len(a[0])
	T1 = [0 for i in range(STATIONNUM)]
	T2 = [0 for i in range(STATIONNUM)]	
	T1[0] = e[0] + a[0][0] # time taken to leave
	T2[0] = e[1] + a[1][0] # time taken to leave
	for i in range(1, STATIONNUM):
		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[STATIONNUM - 1] + x[0],
			T2[STATIONNUM - 1] + x[1])
a = [[4, 5, 3, 2],
	[2, 10, 1, 4]]
t = [[0, 7, 4, 5],
	[0, 9, 2, 8]]
e = [10, 12]
x = [18, 7]
print(asemblecarfun(a, t, e, x))

// C# program to find minimum possible time to complete the car

using System;


class bn {
	
	static int STATIONNUM = 4;
	
	static int min(int a, int b)
	{
		return a < b ? a : b;
		
	}
	
	static int asemblecarfun(int [,]a, int [,]t,
							int []e, int []x)
	{
		int []T1= new int [STATIONNUM];
		int []T2 =new int[STATIONNUM] ;
		int i;
	
		T1[0] = e[0] + a[0,0];
		
		T2[0] = e[1] + a[1,0];
	
		for (i = 1; i < STATIONNUM; ++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[STATIONNUM-1] + x[0],
					T2[STATIONNUM-1] + x[1]);
	}
	
	public static void Main ()
	{
		int [,]a = { {4, 5, 3, 2},
					{2, 10, 1, 4} };
					
		int [,]t = { {0, 7, 4, 5},
					{0, 9, 2, 8} };
					
		int []e = {10, 12};
		int []x = {18, 7};
	
		Console.Write(asemblecarfun(a, t, e, x));
	
	}
}

// PHP program to find minimum possible time to complete the car

<?php
$ASLINE = 2;
$STATIONNUM = 4;
function asemblecarfun($a, $t,
					$e, $x)
{
	global $NUM_LINE,
		$STATIONNUM;
	$T1 = array();
	$T2 = array();
	$i;


	$T1[0] = $e[0] + $a[0][0]; 
	$T2[0] = $e[1] + $a[1][0]; 
	for ($i = 1;
		$i < $STATIONNUM; ++$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[$STATIONNUM - 1] + $x[0],
			$T2[$STATIONNUM - 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 asemblecarfun($a, $t, $e, $x);
?>




// A JavaScript program to find minimum possible time to complete the car

<script>
const ASLINE = 2;
const STATIONNUM = 4;
function min(a, b)
{
	return a < b ? a : b;
}


function asemblecarfun(a, t, e, x)
{
	let T1 = new Array(STATIONNUM);
	let T2 = new Array(STATIONNUM);
	let i;
	T1[0] = e[0] + a[0][0];
	
	T2[0] = e[1] + a[1][0];
	for (i = 1; i < STATIONNUM; ++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[STATIONNUM - 1] + x[0],
			T2[STATIONNUM - 1] + x[1]);
}
	let a = [[4, 5, 3, 2],
							[2, 10, 1, 4]];
	let t = [[0, 7, 4, 5],
							[0, 9, 2, 8]];
	let e = [10, 12], x = [18, 7];


	document.write(asemblecarfun(a, t, e, x));


</script>

Output: 

35

Related Topics

AVL Tree

AVL Tree AVL Tree is referred to as self-balanced or height-balanced binary search tree where the difference between heights of its left subtree and right subtree (Balance Factor) can't more than...

25 minutes read.

Burning binary tree

Burn the Binary tree starting from the target node You have given a binary tree and a target node value. Now you have to burn the tree from target node. You...

4 minutes read.

Given a Binary Tree Check the Zig-Zag Traversal

Implementation // The C++ implementation of the zig-zag traversal method in the O(n) time.  #include <iostream> #include <stack> using namespace std; // creating a binary tree node. struct __nod { int record; struct __nod *Lft, *Rt; }; // creating a...

4 minutes read.

Difference between Structured and Object-Oriented Analysis

Analysis means observing and collecting relevant information about the structure of something or the basic details of a system's requirements. Structured and Object Oriented Analysis are both widely used in...

2 minutes read.

Selection Sort

In each iteration of the selection sort algorithm, the smallest item from an unsorted list is chosen and placed at the top of the unsorted list. Algorithm of Selection Sorting In order...

3 minutes read.

Identical Linked Lists

Identical Linked Lists In this problem, we have given two linked lists, and we need to check whether the given linked lists are identical or not. Identical means they have the...

4 minutes read.

Doubly Linked List

Doubly Linked List Doubly linked list is another kind of Linked list. Doubly linked list contains two pointers for navigation. In this, we can traverse the list in both directions, either...

4 minutes read.

FLEX (Fast Lexical Analyzer Generator)

FLEX stands for Fast Lexical Analyzer Generator. Around 1987, Vern Paxson created Flex in C with a great deal of input and inspiration from Van Jacobson. Van Jacobson's approach is...

3 minutes read.

Bubble Sort vs Heap Sort

In this article, we are going to compare the two most common sorting techniques, Bubble Sort and Heap sort. Before discussing their differences, let us first discuss the idea of...

7 minutes read.

Box Stacking Problem

Stacking of boxes depending on their base You have been given n different boxes. These boxes will have different heights, widths, and depths. You have to stack all these boxes in...

4 minutes read.

Breadth First Search

Breadth First Search Breadth first search is a graph traversing algorithm. In this, we start traversing from the source node or any selected node and traverse the graph layer by layer....

6 minutes read.

Linear Queue Data Structure in C

Data Structure There are many ways to store data in programming, that Queue has features that make it all the more special. We all know that data structure is a way...

9 minutes read.

Interval Tree

Interval Tree Interval Tree: The concept is to increase a Binary Search Tree self-balancing such as Red Black Tree, and AVL Tree, so that every feature can be completed in time O(Logn). Each Interval...

4 minutes read.

Graph Data Structure

A graph is a non-primitive and non-linear data structure. It is a group of (V, E) where V is a set of vertexes, and E is a set of edge....

3 minutes read.

Given a Generate all Structurally Unique Binary Search Trees

Implementation // Creating a C++ program that will help us build all the binary search trees for the keys from 1 to n.  #include <bits/stdc++.h> using namespace std; // creating a structure that will...

8 minutes read.

Types of Data Structures

Almost every programme or software system that has been built makes use of data structures. Furthermore, data structures are basics of computer science and software engineering. When it comes to...

7 minutes read.

Difference between complete and full binary tree

As we all know that the  binary tree is a tree it contains one or two children at each other node. It contains two children's nodes in the Binary tree. The...

6 minutes read.

Counting Sort

Counting Sort: Counting sort is a sorting algorithm that is used to sort the elements of the array within a specific range. It counts the same element number of the...

3 minutes read.

What is B tree?

What do you mean by B Tree in Data Structures? In the technological world, a B tree is simply a well-managed and coordinated tree and an integral part of the data...

6 minutes read.

Sorting Algorithms in Data Structures

A sorting algorithm is used to organize the elements of an array or list. Sorting an array, for example. Unsorted array 572941 Sorted array 124579 We're sorting the array in ascending order right now. This procedure...

4 minutes read.