You are on page 1of 4

Problem Statement

A flour company that uses jackfruit seed as its raw material produces various kinds of flour as shown
below in Table 1. It produces three kinds of flour such as All-purpose flour, cake or pastry flour and
bread flour.

The profit on processing Batch #1 is Php 200/sack and on Batch #2 is Php 165/sack. Find the
approximate optimum monthly production rate of the two batches of flour.

Table 1

Flour Batch 1 (% distribution) Batch 2 (% distribution) Max. Production Rate


(sacks/monthly)
All-purpose 71 41 8500
Cake or pastry 17 43 3200
Bread 12 16 2800

Where x1 = no. of sacks of flour from Batch 1

x2 = no. of sacks of flour from Batch 2

Maximize:

z = 200 x1 + 165 x2

Constraints:

0.71 x1 + 0.41 x2 < 8500

0.17 x1+ 0.43 x2 < 3200

0.12 x1 + 0.16 x2 < 2800


Program

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main ()
{
int nc, ne , nopt, pivot1, pivot2, xerr=0,i,j;
double cf1,cf2,simtab[20][20],flag,aux,xmax;
char res;
printf("\n LINEAR PROGRAMMING - SIMPLEX METHOD \n");
printf("<A> Maximize or <B> Minimize:");
scanf("%c",&res);
printf("\n Enter Number of Variables in Objective Function:");
scanf("%d",&ne);
printf(" Enter Number of Constraints:");
scanf("%d",&nc);
if(res == 'A'|| res == 'a')
cf1=1.0;
else
cf1 = -1.0;
printf("\n Enter Coefficient of Function:\n");
for(j=1;j<=ne;j++)
{
printf("\tCoefficient #%d = ",j);
scanf("%lf",&cf2);
simtab[1][j+1] = cf2*cf1;
}
cf2=0;
simtab[1][1] =cf2 * cf1;
for(i=1; i<=nc; i++)
{
printf("\n Constraint #%d:\n",i);
for(j=1;j<=ne;j++)
{
printf("\tCoefficient #%d = ",j);
scanf("%lf",&cf2);
simtab [i+1][j+1] = -cf2;
}
printf("\tValue at right side =");
scanf("%lf",&simtab[i+1][1]);
}
printf("\n _____________________ \n\n");
for(j=1;j<=ne;j++) simtab [0][j+1]=j;
for(i=ne+1;i<=ne+nc; i++) simtab [i-ne+1][0]=i;
do{
xmax =0.0;
for(j=2;j<=ne+1;j++)
{
if(simtab [1][j]>0.0 && simtab [1][j] > xmax)
{
xmax = simtab [1][j];
pivot2= j;
}
}
flag =1000000.0;
for(i=2; i<=nc+1;i++)
{
if (simtab [i][pivot2]<0.0)
{
aux= fabs (simtab [i][1]/ simtab [i][pivot2]);
if (aux < flag)
{
flag = aux;
pivot1 = i;
}
}
}
aux = simtab [0][pivot2];
simtab[0][pivot2]= simtab[pivot1][0];
simtab [pivot1][0] = aux;
for (i=1; i<=nc+1 ; i++)
{
if (i != pivot1)
{
for(j=1; j<=ne+1;j++)
{
if(j != pivot2) simtab [i][j] -= simtab [pivot1][j]* simtab [i][pivot2]
/ simtab[pivot1][pivot2];
}
}
}
simtab[pivot1][pivot2] = 1.0/simtab[pivot1][pivot2];
for (j=1; j<=ne+1;j++)
{
if (j != pivot2) simtab[pivot1][j] *= fabs (simtab [pivot1][pivot2]);
}
for (i=1;i<=nc+1;i++)
{
if(i != pivot1) simtab [i][pivot2] *= simtab [pivot1][pivot2];
}
for (i=2; i<=nc+1; i++)
if (simtab [i][1] < 0.0) xerr =1;
nopt = 0;
if(xerr != 1)
{
for (j=2; j<=ne+1; j++)
if (simtab [1][j] > 0.0) nopt = 1;
}
}while (nopt==1);
if (xerr == 0)
{
for (i=1; i<=ne ; i++)
for (j=2; j<=nc+1; j++)
{
if (simtab [j][0] == 1.0*i)
printf(" Variable #%d: %f\n", i, simtab[j][1]);
}
printf("\nValue of Objective: %f\n", simtab[1][1]);
}
else printf("No Feasible Solution.\n");
system("pause");
return 0;
}

Screenshot of the Program Output

You might also like