0% found this document useful (0 votes)
77 views

Dynamic Programming

The document describes an algorithm to find the fastest route between stations on two assembly lines, taking into account entry times, assembly times at each station, and transfer times between lines. It collects input for the number of stations and various timing values, calculates the fastest times to reach each station on each line, and traces back the optimal line to take at each station. The algorithm then prints the fastest route from the starting station to the ending station.

Uploaded by

Muaz Butt
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views

Dynamic Programming

The document describes an algorithm to find the fastest route between stations on two assembly lines, taking into account entry times, assembly times at each station, and transfer times between lines. It collects input for the number of stations and various timing values, calculates the fastest times to reach each station on each line, and traces back the optimal line to take at each station. The algorithm then prints the fastest route from the starting station to the ending station.

Uploaded by

Muaz Butt
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

SUPERIOR UNIVERSITY LAHORE

Faculty of Computer Science & IT

DESIGN AND ANALYSIS OF ALGORITHMS

Student Detail

Student Name Roll # Program Email Address


Muaz Ahmed Butt BCSM-F17-054 BSCS – 5A [email protected]
#include<iostream>
#include<stdio.h>
#include<conio.h>
using namespace std;
int l[2][100];
int nodes;
int e[2];
int x[2];
int a[2][100];
int t[2][100];
int f1[100], f2[100];
int fs,ls;

void PrintStation()
{
int i = ls;
cout<<"\n\n\t LINE "<<i<<", STATION "<<nodes<<"\n";
for(int j=nodes; j>=2; j--)
{
i = l[i][j];
cout<<"\t LINE "<<i<<", STATION "<<j-1<<"\n";
}

void FastestWay()
{
f1[1] = e[1] + a[1][1];
f2[1] = e[2] + a[2][1];

for(int j=2; j<=nodes; j++)


{
if( f1[j-1] + a[1][j] <= f2[j-1] + t[2][j-1] + a[1][j] )
{
f1[j] = f1[j-1] + a[1][j];
l[1][j] = 1;
}
else
{
f1[j] = f2[j-1] + t[2][j-1] + a[1][j];
l[1][j] = 2;
}
if( f2[j-1] + a[2][j] <= f1[j-1] + t[1][j-1] + a[2][j] )
{
f2[j] = f2[j-1] + a[2][j];
l[2][j] = 2;
}
else
{
f2[j] = f1[j-1] + t[1][j-1] + a[2][j];
l[2][j] = 1;
}
if( f1[nodes] + x[1] <= f2[nodes] + x[2] )
{
fs = f1[nodes] + x[1];
ls = 1;
}
else
{
fs = f2[nodes] + x[2];
ls = 2;
}
}
PrintStation();
}
int main()
{

cout<<"Enter No. of Stations Each Assembly Line: "; cin>>nodes;


for(int i=1; i<=2; i++){
cout<<"Enter ENTRY Time Line 1 : "; cin>>e[i];
}
for(int i=1; i<=2; i++){
cout<<"Enter ENTRY Time Line 2 : "; cin>>x[i];
}
cout<<"Enter Assembly Time for in Line 1 \n";
for(int i=1; i<=nodes; i++){
cin>>a[1][i];
}
cout<<"Enter Assembly Time for in Line 1 \n";
for(int i=1; i<=nodes; i++){
cin>>a[2][i];
}
cout<<"Enter Transfer Time for Line 1 \n";
for(int i=1; i<=nodes-1; i++){
cin>>t[1][i];
}
cout<<"Enter Transfer Time for Line 2 \n";
for(int i=1; i<=nodes-1; i++){
cin>>t[2][i];
}

FastestWay();
return 0;
}

You might also like