第二章 所用的源程序 【PT主文件中的函数】

来源:互联网 发布:中华合众国知乎 编辑:程序博客网 时间:2024/06/16 17:09

 

。。。。。。。。。。。。。。。。。。。。。。。。。。。。

PT 主文件中的函数

。。。。。。。。。。。。。。。。。。。。。。。。。。。。 

#include <time.h>#include<fstream>using namespace std;#include"function.cpp"void main(void){ifstream fin("self.txt");ifstream fin1("test.txt");ifstream fin2("control.txt");ofstream   fout("PT-result.xls",ios::app);QueueElementType rr;long double cost;for(int i=0;i<NS;i++){fin>>self[i].x;fin>>self[i].y; }long double x,y;long double p_d;long double area_non;for(int i=0;i<NT;i++){fin1>>test[i].x;fin1>>test[i].y;fin1>>test[i].z;}fin2>>n_time;fin2>>n_r;long double *Array[3];for(int j=0;j<3;j++){Array[j]=new long double[n_r];}long double *Array_s[5];for(int j=0;j<5;j++){Array_s[j]=new long double[n_time];}for(int i=0;i<n_r;i++){fin2>>Array[0][i];                      //rsfin2>>Array[1][i];                      //r0fin2>>Array[2][i];                      //p_d}fout<<endl<<endl;  fout<<"Radius"<<'\t'<<'\t'<<"dr_max"<<'\t'<<"dr_min"<<'\t'<<"dr_mean"<<'\t'<<"dr_sd"<<'\t'<<'\t'<<"can_max"<<'\t'<<"can_min"<<'\t'<<"can_mean"<<'\t'<<"can_sd"<<'\t'<<'\t'<<"mature_max"<<'\t'<<"mature_min"<<'\t'<<"mature_mean"<<'\t'<<"mature_sd"<<'\t'<<'\t'<<"cost_max"<<'\t'<<"cost_min"<<'\t'<<"cost_mean"<<'\t'<<"cost_sd"<<endl;  for(int i=0;i<n_r;i++){rs=Array[0][i];r0=Array[1][i];p_d=Array[2][i];cout<<i+1<<endl;for(int i=0;i<NS;i++){self[i].r=rs;}for(int j=0;j<n_time;j++){srand((unsigned)time(NULL));area_non=area_nonself(self);detector.clear();p1=&Q;InitQueue(p1);s_all=0;sum=0;QueueElementType e;e.x=0.5;e.y=0.5;e.r=0.5;EnQueue(p1,e);while(p1->front!=p1->rear)          //  if Q is not null ...................................................... { DeQueue(p1,&e);PT_detec(e.x,e.y,e.r);if(s_all/area_non>p_d)break;if(sum>1000000)break;};cost=sum/detector.size();Array_s[0][j]=sum;                     //    the number of the candidate detectors                                                           Array_s[1][j]=detector.size();         //    the number of the mature detectorsArray_s[2][j]=cost;                    //    the cost to generate one mature detectorlong double count_1_true=0;long double count_1_false=0;long double count_2_flase=0;long double count_2_true=0;long double count_1=0;long double dr=0;long double fa=0;for(int i=0;i<NT;i++){intflag=0;for(int j=0;j<detector.size();j++){if(intersect(detector[j],test[i])){count_1++;flag=1;if(test[i].z==0)count_1_true++;// true abnormal   TN          elsecount_1_false++;// false abnormal   FN           break;}}if(flag==0){if(test[i].z==0)count_2_flase++;// false normal    FP              elsecount_2_true++;//  true   normal    TP           }}dr=count_1_true/(count_1_true+count_2_flase);                 //  fa=count_1_false/(count_1_false+count_2_true);                 // Array_s[3][j]=dr;                                              //  the detection rate   Array_s[4][j]=fa;                                              // false alarm rate}   long  double can_max=_max(Array_s[0]);               // Maxlong double can_min=_min(Array_s[0]);                //Minlong double can_mean=mean(Array_s[0]);               // Meanlong double can_sd=sd(Array_s[0],can_mean);           // Stardard deviationlong  double mature_max=_max(Array_s[1]);long double mature_min=_min(Array_s[1]);long double mature_mean=mean(Array_s[1]);long double mature_sd=sd(Array_s[1],mature_mean);long  double cost_max=_max(Array_s[2]);long double cost_min=_min(Array_s[2]);long double cost_mean=mean(Array_s[2]);long double cost_sd=sd(Array_s[2],cost_mean);long  double dr_max=_max(Array_s[3]);long double dr_min=_min(Array_s[3]);long double dr_mean=mean(Array_s[3]);long double dr_sd=sd(Array_s[3],dr_mean);long  double fa_max=_max(Array_s[4]);long double fa_min=_min(Array_s[4]);long double fa_mean=mean(Array_s[4]);long double fa_sd=sd(Array_s[4],fa_mean);fout<<rs<<'\t'<<'\t'<<dr_max<<'\t'<<dr_min<<'\t'<<dr_mean<<'\t'<<dr_sd<<'\t'<<'\t'<<can_max<<'\t'<<can_min<<'\t'<<can_mean<<'\t'<<can_sd<<'\t'<<'\t'<<mature_max<<'\t'<<mature_min<<'\t'<<mature_mean<<'\t'<<mature_sd<<'\t'<<'\t'<<cost_max<<'\t'<<cost_min<<'\t'<<cost_mean<<'\t'<<cost_sd<<endl;}      fout<<p_d<<endl;cout<<"ok!"<<endl;char c;cin>>c;}