#include<iostream>
#include<cmath>
#include<iomanip>
#include<fstream>
#include<cstdlib>
#include<string>
#include<stdlib.h>
#include<time.h>
using namespace std;
const int M=373;
const int N=100;
const int X=4;
const int L=4;
const int S=22;
//----------------------------------------------����ȫ�ֱ���---------------------------------
int jd;
int num1=M,tj[X];
float V[M+1][L],qjqt[M][X],LR[M][X];
float fzs[L][S],fvs[L][S],fzx[X][S],fqx[X][S],zcsw[X],clxs[X];
float Nzh[X],zdq[X],gzNp[X],zxq[X],Np;
float xxz1[L],xxz2[L],sz[L],zcz[L],xxv1[L],xxv2[L],sv[L],zcv[L];
float QT[M][X],QX[M][X],H[M][X],R[M][X],QFD[M][X];
//------------------------------------�����Ķ���--------------------------
void DPSA(void);
float chazhi(float x0,float y1[],float y2[],int num);
//----------------��ֵ����-----------------------------------------------------------
float chazhi(float x0,float y1[],float y2[],int num)
{
int m1;
for(m1=1;m1<=num-1;m1++)
if(x0<=y1[m1]&&x0>y1[m1-1])
return(y2[m1 - 1] + (x0 - y1[m1 - 1]) * (y2[m1] - y2[m1 - 1]) / (y1[m1] -y1[m1 - 1]));
if(x0<=y1[0])
return(y2[0]);
if(x0>y1[num-1])
return(y2[num-2] + (x0- y1[num-2]) * (y2[num-1] - y2[num-2]) / (y1[num-1] - y1[num-2]));
}
//-----------------------������------------------------------------------------
int main()
{
//----------- �����Ķ��� ---------------------------------------------------
int i,j,k,zjs,js[X];
float sum[50],rzz;
float QS[M][X],Z[M+1][L];
float pjfdl[X],pjcl[X],bzl[X],zcl[X],zbzl;
//-----------------------------------------------------------------------------------------
//------- ���ݵ�������� ---------------
char *fname="result.txt"; //physical file name
ofstream fout(fname,ios::out); //opening file for output
if( !fout ) //handles errors in file opening
{
cerr<<"Error in opening file for output!";
exit(1);
}
string ifname;
ifstream fin;
cout<<"Enter the filename of in file"<<endl;
cin>>ifname;
fin.open(ifname.c_str());
if( fin.fail() )
{
cout<<"ERROR open the in file "<<endl;
exit(1);
}
else
{
for(i=0;i<num1;i++)
for(j=0;j<X;j++)
fin>>qjqt[i][j];
for(i=0;i<num1+1;i++)
for(j=0;j<L;j++)
fin>>V[i][j];
for(i=0;i<num1;i++)
for(j=0;j<X;j++)
fin>>LR[i][j];
for(i=0;i<X;i++)
fin>>zdq[i]>>zxq[i]>>zcsw[i]>>Nzh[i]>>gzNp[i]>>clxs[i];
for(i=0;i<L;i++)
fin>>xxz1[i]>>xxz2[i]>>sz[i]>>zcz[i];
for(i=0;i<L;i++)
for(j=0;j<S;j++)
fin>>fzs[i][j];
for(i=0;i<L;i++)
for(j=0;j<S;j++)
fin>>fvs[i][j];
for(i=0;i<X;i++)
for(j=0;j<S;j++)
fin>>fzx[i][j];
for(i=0;i<X;i++)
for(j=0;j<S;j++)
fin>>fqx[i][j];
for(i=0;i<X;i++)
fin>>tj[i];
}//end open infile and intialize tha array x[]
fin.close();
//-------------------��ѭ��------------------------------------------------------------------
Np=0.0;
for(i=0;i<X;i++) Np=Np+gzNp[i];
for(i=0;i<L;i++)
{
sv[i]=chazhi(sz[i],fzs[i],fvs[i],S);
xxv1[i]=chazhi(xxz1[i],fzs[i],fvs[i],S);
xxv2[i]=chazhi(xxz2[i],fzs[i],fvs[i],S);
zcv[i]=chazhi(zcz[i],fzs[i],fvs[i],S);
}
sum[0]=17296.6;
for(k=0;k<50;k++)
{
sum[k+1]=0.0;
for(i=0;i<M-1;i++)
{
jd=i;
cout<<jd<<"\n";
DPSA();
}
for(i=0;i<M;i++)
{
for(j=0;j<X;j++)
{
sum[k+1]+=R[i][j]/M;
}
}
if(sum[k+1]-sum[k]<1&&sum[k+1]-sum[k]>-1) break;
}
//-------------------------�������---------------------------
for(i=0;i<M;i++)
for(j=0;j<X;j++)
QS[i][j]=QX[i][j]-QFD[i][j];
for(i=0;i<M+1;i++)
for(j=0;j<L;j++)
Z[i][j]=chazhi(V[i][j],fvs[j],fzs[j],S);
for(j=0;j<X;j++)
{
zcl[j]=0;
js[j]=0;
for(i=0;i<M;i++) zcl[j]=zcl[j]+R[i][j];
}
zjs=0;
for(i=0;i<M;i++)
{
rzz=0;
for(j=0;j<X;j++)
{
rzz=rzz+R[i][j];
if(R[i][j]>=gzNp[j]) js[j]=js[j]+1;
}
if(rzz>=Np) zjs=zjs+1;
}
zbzl=zjs*1.0/M;
for(j=0;j<X;j++)
{
if(zcl[j]>0)
{
bzl[j]=js[j]*1.0/M;
pjcl[j]=zcl[j]*1.0/num1;
pjfdl[j]=zcl[j]*365*24/num1;
}
else cout<<"���н�,����������";
}
//-----------������-----------------------------------------------------------------------------------
fout<<"�ܱ�֤��="<<zbzl<<"\n";
fout<<"��������="<<k+1<<"\n";
fout<<"��ƽ������="<<sum[k+1]<<"\n";
for(j=0;j<X;j++)
{
fout<<"��"<<j<<"���ݼ��ı�֤��="<<bzl[j]<<"\n"<<"�ܳ���="<<zcl[j]<<"\n"<<"ƽ������="<<pjcl[j]<<"\n"<<"ƽ��������="<<pjfdl[j]<<"\n";
if(tj[j]>0)
{
fout<<"����"<<"\t"<<"��й"<<"\t"<<"��������"<<"\t"<<"��ˮ"<<"\t"<<"����"<<"\t"<<"ˮλ"<<"\t"<<"ˮͷ"<<"\t"<<"����"<<"\n";
for(i=0;i<M;i++)
fout<<QT[i][j]<<"\t"<<QX[i][j]<<"\t"<<QFD[i][j]<<"\t"<<QS[i][j]<<"\t"<<V[i+1][tj[j]-1]<<"\t"<<Z[i+1][tj[j]-1]<<"\t"<<H[i][j]<<"\t"<<R[i][j]<<"\n";
}
else
{
fout<<"����"<<"\t"<<"��������"<<"\t"<<"��ˮ"<<"\t"<<"ˮͷ"<<"\t"<<"����"<<"\n";
for(i=0;i<M;i++)
fout<<QT[i][j]<<"\t"<<QFD[i][j]<<"\t"<<QS[i][j]<<"\t"<<H[i][j]<<"\t"<<R[i][j]<<"\n";
}
}
fout.close();
//------------------------------------------------------------------------------------------------
return 0; // Exit the program
}//end main
//------------------------------DPSA-------------------------------------
//��αƽ���̬�滮��
void DPSA(void)
{
int k,l,i,j,y,xxx[N];
float zhrz[50],vmax,vmin,scfxs,xcfxs,szcl,xzcl,vjun,bvs,bvx,max,c0,vv[L];
float yv[N],ssyq[N][X],xsyq[N][X],sqfd[N][X],xqfd[N][X],zss[N][L],zsx[N][L],zxs[N][X],zxx[N][X],sqx[N][X],xqx[N][X];
float rs[N][X],rx[N][X],hs[N][X],hx[N][X],ye[N];
float yrs[X],yrx[X],yqxs[X],yqxx[X],yssyq[X],yxsyq[X],ysqfd[X],yxqfd[X],yzxs[X],yzxx[X],yhs[X],yhx[X]; //���
zhrz[0]=0.0;
c0=3.0;
for(i=0;i<X;i++)
{
zhrz[0]=zhrz[0]+LR[jd][i];
}
for(k=0;k<50;k++)
{
zhrz[k+1]=0.0;
for(l=0;l<X;l++)
{
if(tj[l]>0)
{
if((jd%12)<3)
{
vmax=xxv1[tj[l]-1];
vmin=sv[tj[l]-1];
}