Uploaded by sakthi9feb20002014

Assignment 1

advertisement
Operations and Supply Chain Management
Assignment – 1
C Implementation of CDS Algorithm
Group Details
Dhilipan
MSM17B002
Vijay
MSM17B017
Krishna
MSM17B026
Midurn
MSM17B028
Sakthi Pandian
MSM17B037
Code :
#include<stdio.h>
#include<stdlib.h>
FILE* ptr;
int job,machine;
int ar[50][50];
int bestsequence[100];
int index1[100];
int sum[50][50];
int make[50][50];
int value2=10000;
int make1[50][50];
int tmp1[50];
int tmp2[50];
int tmp[100];
void makespan()
//makespan calculator
{
int i,j;
for(i=0;i<job;i++)
for(j=0;j<machine;j++)
make[i][j]=0;
make[0][0]=ar[index1[0]][0];
for(i=1;i<job;i++)
make[i][0]=make[i-1][0]+ar[index1[i]][0];
for(j=1;j<machine;j++)
make[0][j]=make[0][j-1]+ar[index1[i]][j];
for(i=1;i<job;i++)
{for(j=1;j<machine;j++)
{ if(make[i-1][j]>=make[i][j-1])
make[i][j]=make[i-1][j]+ar[index1[i]][j];
else
make[i][j]=make[i][j-1]+ar[index1[i]][j];
}
}
if(value2>make[job-1][machine-1])
{ value2=make[job-1][machine-1];
for(i=0;i<job;i++)
bestsequence[i]=index1[i];
}
}
void algo2()
{int k,i,j,var,m,front,rear,count,n;
front=0;
rear=job;
m=2*job;
for(i=0;i<job;i++)
tmp[i]=tmp1[i];
j=0;
for(i=job;i<m;i++)
{tmp[i]=tmp2[j];
j++;
}
for(i=0;i<m-1;i++)
//sorting the array
{for(j=i+1;j<m;j++)
if(tmp[i]>tmp[j])
{ var=tmp[j];
tmp[j]=tmp[i];
tmp[i]=var;
}
}
for(i=0;i<job;i++)
index1[i]=-1;
for(k=0;k<m;k++)
{ for(i=0;i<job;i++)
{ for(j=0;j<2;j++)
{if(tmp[k]==sum[i][j])
{if(j==0)
{ count=0;
for(n=0;n<job;n++)
{if(index1[n]==i)
count=1;
}
if(count!=1)
{index1[front]=i;
front++;
//finding the index and arranging them in sequence
}
}
else
{ count=0;
for(n=0;n<job;n++)
{if(index1[n]==i)
count=1;
}
if(count!=1)
{index1[rear]=i;
rear--;
}
}
}
}
}
}
makespan();
}
void summation()
{
int i,j,k,m;
for(i=0;i<job;i++)
for(j=0;j<machine;j++)
{ sum[i][j]=0;
tmp1[i]=0;
tmp2[i]=0;
//using cds concept
}
for(k=0;k<machine-1;k++)
{ for(m=0;m<job;m++)
{ sum[m][0]=sum[m][0]+ar[m][k];
sum[m][1]=sum[m][1]+ar[m][machine-1-k];
}
for(i=0;i<job;i++)
for(j=0;j<1;j++)
{ tmp1[i]=sum[i][j];
}
for(i=0;i<job;i++)
for(j=1;j<2;j++)
{ tmp2[i]=sum[i][j];
}
algo2();
}
}
void allsum()
{int i,j;
for(i=0;i<job;i++)
for(j=0;j<machine;j++)
make1[i][j]=0;
make1[0][0]=ar[0][0];
for(i=1;i<job;i++)
make1[i][0]=make1[i-1][0]+ar[i][0];
for(j=1;j<machine;j++)
//for makespan every job every machine case
make1[0][j]=make1[0][j-1]+ar[0][j];
for(i=1;i<job;i++)
{for(j=1;j<machine;j++)
{ if(make1[i-1][j]>=make1[i][j-1])
make1[i][j]=make1[i-1][j]+ar[i][j];
else
make1[i][j]=make1[i][j-1]+ar[i][j];
}
}
if(value2>make1[job-1][machine-1])
{ value2=make1[job-1][machine-1];
for(i=0;i<job;i++)
bestsequence[i]=i;
}
printf("The Makespan for noraml sequence is %d",make1[job-1][machine-1]);
}
void main()
{int i,j,k;
int var;
printf("\n\t\t\t Operations and Supply Chain Management");
printf("\n\t\t\t
Assignment-1\n");
printf("\t\t\tGroup Details \n");
printf("\t\t
1
Dhilipan
MSM17B002\n");
printf("\t\t\t2 Vijay
MSM17B017\n");
printf("\t\t\t3 Krishna
MSM17B026\n");
printf("\t\t\t4 Midurn
MSM17B028\n");
printf("\t\t\t5 Sakthi Pandian
MSM17B037\n");
printf("MakeSpan using CDS Algorithm\n");
printf("Enter the Number of Jobs\n");
scanf("%d",&job);
printf("Enter the Number of Machines\n");
scanf("%d",&machine);
ptr=fopen("1.txt","rb+");
printf("The Input Array is \n");
for(i=0;i<job;i++)
{
for(j=0;j<machine;j++)
{ fscanf(ptr,"%d",&var);
ar[i][j]=var;
printf("%d ",ar[i][j]);
}
printf("\n");
}
fclose(ptr);
allsum();
summation();
printf("\nThe Best Sequence is ");
for(i=0;i<job;i++)
printf("%d ",bestsequence[i]+1);
//storing array from file to local variable
printf("\nThe Best Makespan is %d",value2);
}
Output :
Theoretical Proof :
Download