Simplex Method
Simplex Method
'*
SIMPLEX METHOD
*
'*
-------------*
'*
*
'* LIST OF MAIN VARIABLES:
*
'*
*
'* R:
MAXIMIZE = Y, MINIMIZE = N
*
'* NV:
NUMBER OF VARIABLES OF ECONOMIC FUNCTION *
'*
(TO MAXIMIZE OR MINIMIZE).
*
'* NC:
NUMBER OF CONSTRAINTS
*
'* TS:
SIMPLEX TABLE OF SIZE NC+1 x NV+1
*
'* R1:
=1 TO MAXIMIZE, =-1 TO MINIMIZE
*
'* R2:
AUXILIARY VARIABLE FOR INPUTS
*
'* NOPTIMAL
BOOLEAN IF FALSE, CONTINUE ITERATIONS
*
'* XMAX:
STORES GREATER COEFFICIENT OF ECONOMIC
*
'*
FUNCTION.
*
'* RAP
STORES SMALLEST RATIO > 0
*
'* V:
AUXILIARY VARIABLE
*
'* P1,P2:
LINE, COLUMN INDEX OF PIVOT
*
'* XERR:
BOOLEAN IF TRUE, NO SOLUTION.
*
'* ----------------------------------------------------- *
'* PROBLEM DESCRIPTION:
*
'* A builder of houses can make 3 kinds of them with
*
'* various profits: 15000$, 17000$ and 20000$.
*
'* Each kind must respect following conditions:
*
'* 1) for supply reasons, the number of houses of kind 2 *
'*
built each month must not exceed the number of
*
'*
kind 3 by more than two.
*
'* 2) for staff reasons, the buider can make each month *
'*
up to 5, 5 and 3, respectively of kinds 1, 2 and 3.*
'* 3) for organisation reasons, the builder can make up *
'*
to 8 houses monthly of kinds 1,2 and 3, respecti- *
'*
vely in the proportions of 3, 2 and 1.
*
'* The builder, having these data, wants to maximize his *
'* monthly profit by knowing the number oh houses of
*
'* each kind to build monthly.
*
'* ----------------------------------------------------- *
'* SAMPLE RUN:
*
'* (Maximize 15 X1 + 17 X2 + 20 X3 with conditions:
*
'*
X2 X3 <= 2
*
'*
3 X1 + 3 X2 + 5 X3 <= 15
*
'*
3 X1 + 2 X2 +
X3 <= 8
)
*
'*
*
'* LINEAR PROGRAMMING
*
'*
*
'* MAXIMIZE ? Y
*
'*
*
'* NUMBER OF VARIABLES OF ECONOMIC FUNCTION ? 3
*
'*
*
'* NUMBER OF CONSTRAINTS ? 3
*
'*
*
'* INPUT COEFFICIENTS OF ECONOMIC FUNCTION:
*
'*
#1 ? 15
*
'*
#2 ? 17
*
'*
#3 ? 20
*
'*
Right hand side ? 0
*
'*
*
10
10
R1 = -1.0;
printf("\n INPUT COEFFICIENTS OF ECONOMIC FUNCTION:\n");
for (J = 1; J<=NV; J++) {
printf("
#%d ? ", J); scanf("%lf", &R2);
TS[1][J+1] = R2 * R1;
}
printf("
Right hand side ? "); scanf("%lf", &R2);
TS[1][1] = R2 * R1;
for (I = 1; I<=NC; I++) {
printf("\n CONSTRAINT #%d:\n", I);
for (J = 1; J<=NV; J++) {
printf("
#%d ? ", J); scanf("%lf", &R2);
TS[I + 1][J + 1] = -R2;
}
printf("
Right hand side ? "); scanf("%lf", &TS[I+1][1]);
}
printf("\n\n RESULTS:\n\n");
for(J=1; J<=NV; J++) TS[0][J+1] = J;
for(I=NV+1; I<=NV+NC; I++) TS[I-NV+1][0] = I;
}
void Pivot();
void Formula();
void Optimize();
void Simplex() {
e10: Pivot();
Formula();
Optimize();
if (NOPTIMAL == 1) goto e10;
}
void Pivot() {
double RAP,V,XMAX;
int I,J;
XMAX = 0.0;
for(J=2; J<=NV+1; J++) {
if (TS[1][J] > 0.0 && TS[1][J] > XMAX) {
XMAX = TS[1][J];
P2 = J;
}
}
RAP = 999999.0;
for (I=2; I<=NC+1; I++) {
if (TS[I][P2] >= 0.0) goto e10;
V = fabs(TS[I][1] / TS[I][P2]);
if (V < RAP) {
RAP = V;
P1 = I;
}
e10:;}
V = TS[0][P2]; TS[0][P2] = TS[P1][0]; TS[P1][0] = V;
}
void Formula() {;
//Labels: e60,e70,e100,e110;
int I,J;
for (I=1; I<=NC+1; I++) {
if (I == P1) goto e70;
for (J=1; J<=NV+1; J++) {
if (J == P2) goto e60;
TS[I][J] -= TS[P1][J] * TS[I][P2] / TS[P1][P2];
e60:;}
e70:;}
TS[P1][P2] = 1.0 / TS[P1][P2];
for (J=1; J<=NV+1; J++) {
if (J == P2) goto e100;
TS[P1][J] *= fabs(TS[P1][P2]);
e100:;}
for (I=1; I<=NC+1; I++) {
if (I == P1) goto e110;
TS[I][P2] *= TS[P1][P2];
e110:;}
}
void Optimize() {
int I,J;
for (I=2; I<=NC+1; I++)
if (TS[I][1] < 0.0) XERR = 1;
NOPTIMAL = 0;
if (XERR == 1) return;
for (J=2; J<=NV+1; J++)
if (TS[1][J] > 0.0) NOPTIMAL = 1;
}
void Results() {
//Labels: e30,e70,e100;
int I,J;
if (XERR == 0) goto e30;
printf(" NO SOLUTION.\n"); goto e100;
e30:for (I=1; I<=NV; I++)
for (J=2; J<=NC+1; J++) {
if (TS[J][0] != 1.0*I) goto e70;
printf("
VARIABLE #%d: %f\n", I, TS[J][1]);
e70: ;}
printf("\n
ECONOMIC FUNCTION: %f\n", TS[1][1]);
e100:printf("\n");
}
void main()
Data();
Simplex();
Results();
}
//end of file simplex.cpp
/***************************************************************
*
LINEAR PROGRAMMING: THE SIMPLEX METHOD
*
* ------------------------------------------------------------ *
* SAMPLE RUN:
*
* Maximize z = x1 + x2 + 3x3 -0.5x4 with conditions:
*
*
x1 + 2x3 <= 740
*
*
2x2 - 7x4 <= 0
*
*
x2 - x3 + 2x4 >= 0.5
*
*
x1 + x2 + x3 +x4 = 9
*
*
and all x's >=0.
*
*
*
* Number of variables in E.F.: 4
*
* Number of <= inequalities..: 2
*
* Number of >= inequalities..: 1
*
* Number of = equalities.....: 1
*
* Input Economic Function:
*
* Coefficient # 1: 1
*
* Coefficient # 2: 1
*
* Coefficient # 3: 3
*
* Coefficient # 4: -0.5
*
* Constant term..: 0
*
* Input constraint # 1:
*
* Coefficient # 1: 1
*
* Coefficient # 2: 0
*
* Coefficient # 3: 2
*
* Coefficient # 4: 0
*
* Constant term..: 740
*
* Input constraint # 2:
*
* Coefficient # 1: 0
*
* Coefficient # 2: 2
*
* Coefficient # 3: 0
*
* Coefficient # 4: -7
*
* Constant term..: 0
*
* Input constraint # 3:
*
* Coefficient # 1: 0
*
* Coefficient # 2: 1
*
* Coefficient # 3: -1
*
* Coefficient # 4: 2
*
* Constant term..: 0.5
*
* Input constraint # 4:
*
* Coefficient # 1: 1
*
* Coefficient # 2: 1
*
* Coefficient # 3: 1
*
* Coefficient # 4: 1
*
* Constant term..: 9
*
*
*
* Input Table:
*
*
0.00
1.00
1.00
3.00
-0.50
*
* 740.00
-1.00
0.00
-2.00
0.00
*
*
0.00
0.00
-2.00
0.00
7.00
*
*
0.50
0.00
-1.00
1.00
-2.00
*
*
9.00
-1.00
-1.00
-1.00
-1.00
*
*
*
* Maximum of E.F. =
17.02500
*
* X1 =
0.000000
*
* X2 =
3.325000
*
* X3 =
4.725000
*
* X4 =
0.950000
*
*
*
* ------------------------------------------------------------ *
* Reference: "Numerical Recipes By W.H. Press, B. P. Flannery, *
*
S.A. Teukolsky and W.T. Vetterling, Cambridge
*
*
University Press, 1986" [BIBLI 08].
*
*
*
*
C++ Release 1.0 By J-P Moreau, Paris
*
***************************************************************/
#include <stdio.h>
#include <math.h>
#define
#define
#define
MMAX
NMAX
REAL
25
25
double
A;
IPOSV[MMAX], IZROV[NMAX];
i,j,ICASE,N,M,M1,M2,M3;
R;
simp3(a,m,n,ip,kp);
(phase two),
goto e20;
and
}
e6:
}
}
return;
}
void simp3(MAT a,int i1,int k1,int ip,int kp) {
//Matrix operations to exchange a left-hand and right-hand variable (see
text).
int ii,kk;
REAL piv;
piv=1.0/a[ip+1][kp+1];
if (i1 >= 0)
for (ii=1; ii<=i1+1; ii++)
if (ii-1 != ip) {
a[ii][kp+1] *= piv;
for (kk=1; kk<=k1+1; kk++)
if (kk-1 != kp)
a[ii][kk] -= a[ip+1][kk]*a[ii][kp+1];
}
for (kk=1; kk<=k1+1; kk++)
if(kk-1 != kp) a[ip+1][kk] =-a[ip+1][kk]*piv;
a[ip+1][kp+1]=piv;
return;
}
void main() {
printf("\n");
printf(" Number
printf(" Number
printf(" Number
printf(" Number
M=M1+M2+M3;
of
of
of
of
variables in E.F.:
<= inequalities..:
>= inequalities..:
= equalities.....:
");
");
");
");
scanf("%d",
scanf("%d",
scanf("%d",
scanf("%d",
&N);
&M1);
&M2);
&M3);
scanf("%lf", &A[i+1][1]);
}
printf("\n Input Table:\n");
for (i=1; i<=M+1; i++) {
for (j=1; j<=N+1; j++)
printf("%8.2f", A[i][j]);
printf("\n");
}
simplx(A,M,N,M1,M2,M3,&ICASE,IZROV,IPOSV);
if (ICASE==0) { //result ok.
printf("\n Maximum of E.F. = %f\n", A[1][1]);
for (i=1; i<=N; i++) {
for (j=1; j<=M; j++)
if (IPOSV[j] == i) {
printf(" X%d = %f\n", i, A[j+1][1]);
goto e3;
}
printf(" X%d = %f\n", i, 0.0);
e3:;}
}
else
printf(" No solution (error code = %d).\n", ICASE);
printf("\n");
}
// end of file tsimplex.cpp
# include <iostream.h>
void main () {
long X1 , X2,, f;
long X1result,X2result,,MaxF;
MaxF= initialize with the minimum possible value of f;
for (X1= minimum value of X1; X1< =maximum value of X1; X1 ++)
for (X2= minimum value of X2; X2< =maximum value of X2; X2 ++)
MaxF= f;
}
}
cout <<endl <<Maximum f =<<MaxF;
cout <<endl <<X1 solution =<<X1s;
cout <<endl <<X2 solution =<<X2s;
#include <iostream>
#include <lemon/lp.h>
using namespace lemon;
int main()
{
// Create an instance of the default LP solver class
// (it will represent an "empty" problem at first)
Lp lp;
// Add two columns (variables) to the problem
Lp::Col x1 = lp.addCol();
Lp::Col x2 = lp.addCol();
// Add rows (constraints) to the problem
lp.addRow(x1 - 5 <= x2);
lp.addRow(0 <= 2 * x1 + x2 <= 25);
// Set lower and upper bounds for the columns (variables)
lp.colLowerBound(x1, 0);
lp.colUpperBound(x2, 10);
// Specify the objective function
lp.max();
lp.obj(5 * x1 + 3 * x2);
// Solve the problem using the underlying LP solver
lp.solve();
// Print the results
if (lp.primalType() == Lp::OPTIMAL) {
std::cout << "Objective function value: " << lp.primal() << std::endl;
std::cout << "x1 = " << lp.primal(x1) << std::endl;
std::cout << "x2 = " << lp.primal(x2) << std::endl;
} else {
std::cout << "Optimal solution not found." << std::endl;
}
return 0;
}
#include <stdio.h>
#include <conio.h>
#define INFINITY 999
#define N 3
#define M 6
/************************************************************/
/***** Solves the LPP by "SIMPLEX" method i.e. by table *****/
/************************************************************/
void minimum(float *arr,int *arrminpos,int n);
/* Calculates the minimum valued position among the array arr having n
elements. */
void display (float c[],float b[],float a[][M],int basic[]);
/* Display the table */
void displayframe(float c[M]);
/* Displays the frame of the table */
void calctemp(float *,float [][M],float [],int []);
/* Calculates Zj-Cj */
/*-------------------------------------------------------------------------*\
Cj
5
4
3
0
0
0
miniRatio
cB
xB
b
a1
a2
a3
a4
a5
a6
bi/aij
0
x4
5
2
3
1
1
0
0
2.5
0
x5
11
4
1
2
0
1
0
2.75
0
x6
8
3
4
2
0
0
1
2.66
---------------------------------------------------------------------------Zj-Cj
-5
-4
-3
0
0
0
---------------------------------------------------------------------------5
x1
2.5
1
1.5
0.5
0.5
0
0
5
0
x5
1
0
-5
0
-2
1
0
infinity
0
x6
105
0
-0.5
0.5
-1.5
0
1
1
---------------------------------------------------------------------------Zj-Cj
0
3.5
-0.5
2.5
0
0
---------------------------------------------------------------------------5
x1
2
1
2
0
2
0
-1
0
x5
1
0
-5
0
-2
1
0
3
x3
1
0
-1
1
-3
0
2
---------------------------------------------------------------------------Zj-Cj
0
3
0
1
0
1
---------------------------------------------------------------------------So the solution is :x1=2
x2=0
x3=1
x4=0
x5=1
x6=0
max(z) = 5*2 + 4*0 + 3*1 = 13.
\*-------------------------------------------------------------------------*/
void main()
{
float c[M]={{5},{4},{3},{0},{0},{0}};
/* Stores co-efficient of the objective function Max(z) */
float a[N][M]={
{2,3,1,1,0,0},
{4,1,2,0,1,0},
{3,4,2,0,0,1}
};
/* Stores the co-efficent of the constraints */
float b[N]={{5},{11},{8}};
/* Stores the values on RHS of constraints */
float temp[M]={{0},{0},{0},{0},{0},{0}};
/* Stores the values of Zj-Cj*/
int tempminpos;
/* Stores the minimum valued position
of {Zj-Cj} i.e. coming in variable */
float miniratio[N];
/* Stores the value of the ratio b[i]/a[i][j] */
int miniratiominpos; /* Stores the minimum valued position of
b[i]/a[i][j] i.e. going out variable */
float key;
/* Stores the key element */
int gooutcol;
/* Stores the column number which goes out */
float z;
/* Stores the value of the objective function */
float x[M];
/* Stores the value of the variables */
int i,j;
/* Loop variables */
int basic[N];
/* Stores the basic variable */
int nonbasic[N];
/* Stores the non-basic variable */
int flag=0;
/* Terminating variable */
//clrscr();
/*** Initializing basic variables to 3,4,5 i.e. x4,x5,x6 ***/
for(i=0;i<N;i++)
{
basic[i]=(i+N);
nonbasic[i]=i;
}
printf("\nMax z = c1x1 + c2x2 + c3x3\n");
printf("\na11x1 + a12x2 + a13x3 <= b1\n");
printf("\na21x1 + a22x2 + a23x3 <= b2\n");
printf("\na31x1 + a31x2 + a32x3 <= b3\n");
printf("\nEnter values of ci's\n");
/*** Inputing requisite amount of data ***/
for(i=0;i<N;i++)
{
printf("\nEnter c[%d]\t",i+1);
scanf("%f",&c[i]);
}
printf("\nEnter values of ai's\n");
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
printf("\nEnter a[%d][%d]\t",i+1,j+1);
scanf("%f",&a[i][j]);
}
}
printf("\nEnter values of bi's\n");
for(i=0;i<N;i++)
{
printf("\nEnter b[%d]\t",i+1);
scanf("%f",&b[i]);
}
key=a[miniratiominpos][tempminpos];
b[miniratiominpos]=b[miniratiominpos]/key;
for(i=0;i<M;i++)
a[miniratiominpos][i]=a[miniratiominpos][i]/key;
for(i=0;i<N;i++)
{
if(miniratiominpos==i)
continue;
key=a[i][tempminpos];
for(j=0;j<M;j++)
{
a[i][j]=a[i][j]-a[miniratiominpos][j]*key;
}
b[i]=b[i]-b[miniratiominpos]*key;
}
getch();
/*** Terminating condition ***/
for(i=0;i<M;i++)
{
flag=1;
if(temp[i]<0)
{
flag=0;
break;
}
}
}
printf("\nPress any key to exit...\n");
getch();
}
void calctemp(float *temp,float a[N][M],float c[M],int basic[N])
{
int i,j;
for(i=0;i<M;i++)
{
temp[i]=0;
for(j=0;j<N;j++)
temp[i]=temp[i]+c[basic[j]]*a[j][i];
temp[i]=temp[i]-c[i];
}
}
void minimum(float *arr,int *arrminpos, int n)
{
int i;
float arrmin;
arrmin=arr[0];
*arrminpos=0;
for(i=0;i<n;i++)
if(arr[i]<arrmin)
{
arrmin=arr[i];
*arrminpos=i;
}
printf("\n%d\n",*arrminpos);
}
void display (float c[N],float b[N],float a[N][M],int basic[N])
{
int i,j;
displayframe(c);
for(i=0;i<N;i++)
{
printf("\n%.4g\tX%d\t%.4g\t",c[basic[i]],basic[i]+1,b[i]);
for(j=0;j<M;j++)
printf("%.4g\t",a[i][j]);
printf("\n");
}
}
void displayframe(float c[M])
{
printf("\t\tc[j]\t");
printf("%g\t%g\t%g\t%g\t%g\t%g\n",c[0],c[1],c[2],c[3],c[4],c[5]);
printf("\nc[b]\tB\tb\ta1\ta2\ta3\ta4\ta5\ta6\n");
}
#include <stdio.h>
#include <conio.h>
#define INFINITY -999
#define N 10
#define M 20
/***************************************************/
/***** Solves the LPP by "DUAL SIMPLEX" method *****/
/***************************************************/
void minimum(float *arr,int *arrminpos,int n);
/* Calculates the minimum valued position among the array arr having n
elements. */
void maximum(float *arr,int *arrminpos,int n);
/* Calculates the minimum valued position among the array arr having n
elements. */
void display (float c[],float b[],float a[][M],int basic[]);
/* Display the table */
void displayframe(float c[M]);
/* Displays the frame of the table */
void calctemp(float *,float [][M],float [],int []);
/* Calculates Zj-Cj */
int countmaxzterms;
int constraint;
void main()
{
float c[M];
/* Stores co-efficient of the objective function Max(z) */
float a[N][M];
/* Stores the co-efficent of the constraints */
float b[N];
/* Stores the values on RHS of constraints */
float temp[M];
/* Stores the values of Zj-Cj*/
int bminpos;
/* Stores the minimum valued position
of {Zj-Cj} i.e. coming in variable */
float maxratio[M];
/* Stores the value of the ratio Zj-Cj/a[i][j] */
int maxratiomaxpos; /* Stores the minimum valued position of
b[i]/a[i][j] i.e. going out variable */
float key;
/* Stores the key element */
int gooutcol;
/* Stores the column number which goes out */
int incomingcol;
float z;
/* Stores the value of the objective function */
float x[M];
/* Stores the value of the variables */
int i,j;
/* Loop variables */
int basic[N];
/* Stores the basic variable */
int flag=0;
/* Terminating variable */
/*** Initializing basic variables ***/
for(i=0;i<M;i++)
c[i]=x[i]=temp[i]=0;
for(i=0;i<N;i++)
for(j=0;j<M;j++)
a[i][j]=0;
/*** Inputing requisite amount of data ***/
printf("\nEnter number of terms in objective function\n");
scanf("%d",&countmaxzterms);
printf("\nEnter the co-efficient\n");
for(i=0;i<countmaxzterms;i++)
scanf("%f",&c[i]);
printf("\nYou have entered the function as follows:-\n");
printf("\nMax z = ");
for(i=0;i<countmaxzterms;i++)
{
if(i==0)
printf("%g*x%d",c[i],i+1);
else
printf(" + %g*x%d",c[i],i+1);
}
printf("\nEnter number of constraint\n");
scanf("%d",&constraint);
printf("\nEnter the co-efficient of constraints\n");
for(i=0;i<constraint;i++)
for(j=0;j<countmaxzterms;j++)
scanf("%f",&a[i][j]);
for(i=0;i<constraint;i++)
a[i][j++]=1;
printf("\nEnter values of bi's\n");
for(i=0;i<constraint;i++)
scanf("%f",&b[i]);
for(i=0;i<countmaxzterms+constraint;i++)
basic[i]=(i+countmaxzterms);
printf("\nYou have entered the function as follows:-\n");
for(i=0;i<constraint;i++)
{
for(j=0;j<countmaxzterms;j++)
{
if(j==0)
printf(" %g*x%d ",a[i][j],j+1);
else
printf(" + %g*x%d ",a[i][j],j+1);
}
printf(" <= %g\n",b[i]);
}
getch();
/*** Calculation for actual table ***/
do
{
/*** Terminating condition ***/
for(i=0;i<constraint;i++)
{
flag=1;
if(b[i]<=0)
{
flag=0;
break;
}
}
z=0;
calctemp(temp,a,c,basic);
printf("\n");
display(c,b,a,basic);
printf("\n\tZj-Cj\t\t");
for(i=0;i<constraint+countmaxzterms;i++)
printf("%0.3g\t",temp[i]);
printf("\n\n");
/*** Determining the outgoing column ***/
minimum(b,&bminpos,constraint);
gooutcol=basic[bminpos];
/*** Determining the incoming column ***/
for(i=0;i<M;i++)
maxratio[i]=INFINITY;
for(i=0;i<constraint+countmaxzterms;i++)
{
if(a[bminpos][i]==0)
{
maxratio[i]=INFINITY;
continue;
}
if(a[bminpos][i]>0)
{
maxratio[i]=INFINITY;
continue;
}
maxratio[i]=temp[i]/a[bminpos][i];
}
maximum(maxratio,&maxratiomaxpos,2*constraint);
incomingcol=maxratiomaxpos;
for(i=0;i<constraint+countmaxzterms;i++)
x[i]=0;
for(i=0;i<constraint;i++)
{
x[basic[i]]=b[i];
printf("x[%d]=%0.3g\n",basic[i]+1,b[i]);
}
for(i=0;i<constraint;i++)
z=z+c[i]*x[i];
printf("Max(z) = %g",z);
printf("\nComing in variable = X%d\t",incomingcol+1);
printf("Going out variable = X%d\n",gooutcol+1);
/*** Changing the basic and non-basic variable ***/
basic[bminpos]=incomingcol;
/*** Performing the operations to bring similar expressions in
in-coming variable as out-going variable by row operations ***/
key=a[bminpos][incomingcol];
b[bminpos]=b[bminpos]/key;
for(i=0;i<constraint+countmaxzterms;i++)
a[bminpos][i]=a[bminpos][i]/key;
for(i=0;i<constraint;i++)
{
if(bminpos==i)
continue;
key=a[i][incomingcol];
for(j=0;j<(constraint+countmaxzterms);j++)
a[i][j]=a[i][j]-a[bminpos][j]*key;
b[i]=b[i]-b[bminpos]*key;
}
getch();
}while(flag==0);
printf("\nPress any key to exit...\n");
getch();
}
void calctemp(float *temp,float a[N][M],float c[M],int basic[N])
{
int i,j;
for(i=0;i<constraint+countmaxzterms;i++)
{
temp[i]=0;
for(j=0;j<constraint;j++)
temp[i]=temp[i]+c[basic[j]]*a[j][i];
temp[i]=temp[i]-c[i];
}
}
void maximum(float *arr,int *arrmaxpos, int n)
{
int i;
int arrmax;
arrmax=arr[0];
*arrmaxpos=0;
for(i=0;i<n;i++)
if(arr[i]>arrmax)
{
arrmax=arr[i];
*arrmaxpos=i;
}
}
void minimum(float *arr,int *arrminpos, int n)
{
int i;
int arrmin;
arrmin=arr[0];
*arrminpos=0;
for(i=0;i<n;i++)
if(arr[i]<arrmin)
{
arrmin=arr[i];
*arrminpos=i;
}
}
void display (float c[N],float b[N],float a[N][M],int basic[N])
{
int i,j;
displayframe(c);
for(i=0;i<constraint;i++)
{
printf("\n%0.3g\tX%d\t%0.3g\t",c[basic[i]],basic[i]+1,b[i]);
for(j=0;j<constraint+countmaxzterms;j++)
printf("%0.3g\t",a[i][j]);
printf("\n");
}
}
void displayframe(float c[M])
{
int i;
printf("\t\tc[j]\t");
for(i=0;i<constraint+countmaxzterms;i++)
printf("%0.2g\t",c[i]);
printf("\n");
printf("\nc[b]\tB\tb\t");
for(i=0;i<constraint+countmaxzterms;i++)
printf("a[%d]\t",i+1);
printf("\n");
}