#include
#include
#include
using namespace std;
#define BORDER -0.00001
#define M 100
int main()
{
int k; //初始变量的个数
int m; //约束条件的个数;
cout<
cin>>k;
cout <
cin>>m;
cout<
cout<
cout<="<
cout<
int NGET=0;
int NLET=0;
int NET =0;
int I =0;//人工变量;
int *code=new int[m]; //the array of the >= <= =;
for(int i=0;i
{
cin>>code[i];
if(code[i]==0)
NGET++;
if(code[i]==1)
NLET++;
I++ ;
if(code[i]==2)
NET++;
I++ ;
}
int n,i; //变量总和;
n=k+2*NLET+NGET+NET;
float *Index=new float[n+1]; //目标函数的系数;
float *c=new float[n+1];
int NTYPE;
for(i=0;i
Index[i]=0.0;//为语法要求定初值;
cout<
for(i=0;i
cin>>Index[i];
for(i=k+NGET+NLET;i
Index[i]=-M; //the initionalization of indexes of manul variable;
cout<
cout<
cout<
cin>>NTYPE;
if(NTYPE) //the initionalization of the c[i];
{
for(i=0;i
c[i]=-Index[i];//一般情况下只要将目标函数系数的相反数输入;
}
if(!NTYPE)
{
for(i=0;i
if(i
c[i]=Index[i];
else c[i]=-Index[i];
}
delete []Index;
float **a=new float*[m+1]; //the array of all the variable to compute;
for(i=0;i
a[i]=new float[n+1];
int INDEXG=k;
int INDEXL=k+NGET;
int INDEXE=k+NGET+NLET;
int *ARTV=new int[I]; //保存人工变量;
for(i=0;i= =);
{
if(code[i]==0)
{
a[i][INDEXL]=1.0;
INDEXL++;
}
if(code[i]==1)
{
a[i][INDEXE]=1.0;
INDEXE++;
a[i][INDEXG]=-1.0;
INDEXG++;
ARTV[I]=i;
I++;
}
if(code[i]==2)
{
a[i][INDEXE]=1.0;
INDEXE++;
ARTV[I]=i;
I++;
}
}
if( (INDEXG!=k+NLET) || (INDEXL!=k+NGET+NLET) || (INDEXE!=n) )//excption
{
return -1;
}
cout<
for(i=0;i
for(int j=0;j
cin>>a[i][j];
float *b=new float[m];
cout<
for(i=0;i
cin>>b[i];
for(i=0;i
a[i][n]=b[i];
float *temp=new float[n+1];
if(I)
{
for(i=0;i
for(int j=0;j
{
temp[j]=-a[ARTV[i]][j];
c[j]+=M*temp[j];
}
}
for(i=0;i
a[m][i]=c[i];
for(i=0;i
{
for(int j=0;j
cout<
cout<
}
int flag=0;
float temp1;
float temp2;
int K,J;
int index;
for(i=0;i
if(a[m][i]<0)flag=1; //检验系数;
while(flag) //Using a[][] to compute the result;
{
temp1=0;
for(i=0;i
{
if(temp1>a[m][i])
{
temp1=a[m][i];
K=i;
}
}
temp2=M;
for(i=0;i
{
if(a[i][K]>0&&(a[i][n]/a[i][K])
{
temp2=a[i][n]/a[i][K];
J=i;
}
}
if(temp2==M)
{
cout<
}
float temp3=a[J][K];
for(i=0;i
{
a[J][i]=a[J][i]/temp3;
}
for(i=0;i
{
if(i!=J)
{
float temp4=a[i][K];
for(int j=0;j
{
a[i][j]=a[i][j]- a[J][j]*temp4;
}
}
cout<
}
flag=0;
for(i=0;i
{
if(a[m][i]
}
cout<
for(i=0;i
{
for(int j=0;j
cout<