//--------------------------------------------------------------------------- #include #include #pragma hdrstop #include "Unit1.h" #include "globals.h" #include "grAuditory.h" #include "cell3Maker.h" #include "exhaustCellMaker.h" #include "restandCellMaker.h" #include "dynamicCell3Maker.h" #include "dynamicExhaustCellMaker.h" #include "dynamicRestandCellMaker.h" #include "topology.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "perfgrap" #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { EditStartValue->Text=BFGRStartValue; EditQuotient->Text=BFGRQuotient; EditConstant->Text=BFConstant; EditRoundsCountInitial->Text=RCInitial; EditRoundsCount->Text=RCInitial; EditBiasMax->Text=BFGRStartValue; EditInitialApplausMean->Text=BegValEditInitialApplausMean; EditInitialApplausSD->Text=BegValEditInitialApplausSD; EditCTNMean->Text=BegValEditCTNMean; EditCTNSD->Text=BegValEditCTNSD; EditCTGMean->Text=BegValEditCTGMean; EditCTGSD->Text=BegValEditCTGSD; EditAPTOSTDM->Text=BegValEditAPTOSTDM; EditAPTOSTDSD->Text=BegValEditAPTOSTDSD; EditCNTSTDNTSTNDM->Text=BegValEditCNTSTDNTSTNDM; EditCNTSTDNTSTNDSD->Text=BegValEditCNTSTDNTSTNDSD; EditEXHAUSTM->Text=BegValEditEXHAUSTM; EditEXHAUSTSD->Text=BegValEditEXHAUSTSD; EditRESTANDM->Text=BegValEditRESTANDM; EditRESTANDSD->Text=BegValEditRESTANDSD; EditRandomProbablity->Text=BegValEditRandomProbablity; TrackBarBrightness->OnChange=0; TrackBarBrightness->Min=BightnessMin; TrackBarBrightness->Max=BightnessMax; TrackBarBrightness->Position=BightnessBeg; TrackBarBrightness->OnChange=TForm1::TrackBarBrightnessChange; PaintBox1->Canvas->Pen->Width=CELLBORDERWIDTH; EditScale->Text=PERFGRAPHGRADIENT; PerformanceGraph1->Gradient=PERFGRAPHGRADIENT; newNCell2=NCELL2BEG; EditShowCountOfCells->Text=sqr(NCELL2BEG); auditoryRestart(); Application->OnIdle=MyIdleHandler; // computing=false; } //--------------------------------------------------------------------------- void __fastcall TForm1::BtRoundClick(TObject *Sender) { round(); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormDestroy(TObject *Sender) { delete Auditory; } //--------------------------------------------------------------------------- void __fastcall TForm1::FormPaint(TObject *Sender) { auditoryShowNoPerfGraph(); } //--------------------------------------------------------------------------- void __fastcall TForm1::RestartButtonClick(TObject *Sender) { delete Auditory; Auditory=0; PaintBox1->Canvas->Brush->Color=clBtnFace; PaintBox1->Canvas->FillRect(Rect(0,0,PaintBox1->Width,PaintBox1->Height)); auditoryRestart(); auditoryShow(); } //--------------------------------------------------------------------------- void __fastcall TForm1::MyIdleHandler(TObject *Sender, bool &Done) { speedStep++; if ((runSimul)&&(speedStep>=speed)) { round(); speedStep=0; }; Done=false; }; //--------------------------------------------------------------------------- void __fastcall TForm1::TrackBarNCELL2Change(TObject *Sender) { newNCell2=TrackBarNCELL2->Position; }; //--------------------------------------------------------------------------- void __fastcall TForm1::ButtonStopClick(TObject *Sender) { runSimul=false; } //--------------------------------------------------------------------------- void __fastcall TForm1::ButtonStartClick(TObject *Sender) { runSimul=true; } //--------------------------------------------------------------------------- void TForm1::myInitialize() { nCell2=newNCell2; nCell=nCell2*nCell2; cellWidth=((PaintBox1->Height-(nCell2-1)*CELLSPACE)/nCell2); runSimul=false; speed=TrackBarSpeed->Max-TrackBarSpeed->Position; speedStep=0; EditRoundsCount->Text=EditRoundsCountInitial->Text; cellHotApplaus=TrackBarBrightness->Position; }; //--------------------------------------------------------------------------- void TForm1::auditoryShowNoPerfGraph() { Auditory->show(); float ApplausMean=Auditory->getApplausMean(); int nOfStanding=Auditory->nOfStanding(); float Bias=Auditory->getBias(); EditShowApplausMeanValue->Text=(ApplausMean); EditShowStandingValue->Text=(nOfStanding); EditShowBiasValue->Text=(Bias); EditShowStandTimeValue->Text=(Auditory->getStandTime()); EditShowRoundsPassed->Text=(Auditory->getRoundCount()); EditShowCountOfCells->Text=(Auditory->nOfCells); }; void TForm1::auditoryShowOnlyPerfraph() { float ApplausMean=Auditory->getApplausMean(); int nOfStanding=Auditory->nOfStanding(); float Bias=Auditory->getBias(); int PERFGRAPHTOP=EditScale->Text.ToIntDef(PERFGRAPHGRADIENT)*PERFGRAPHRATIOTOP; int pgApplausMean=(int)ApplausMean, pgnOfStanding=(int)(PERFGRAPHTOP*(nOfStanding)/nCell), pgBias=(int)(PERFGRAPHTOP*(Bias/EditBiasMax->Text.ToDouble())); PerformanceGraph1->DataPoint(PERFGRAPHApplausMeanCOLOR, pgApplausMean); PerformanceGraph1->DataPoint(PERFGRAPHNOFSTANDINGCOLOR, pgnOfStanding); PerformanceGraph1->DataPoint(PERFGRAPHBIASCOLOR, pgBias); PerformanceGraph1->Update(); PerformanceGraph1->Gradient=EditScale->Text.ToIntDef(PERFGRAPHGRADIENT); }; void TForm1::auditoryShow() { auditoryShowNoPerfGraph(); auditoryShowOnlyPerfraph(); }; //--------------------------------------------------------------------------- void __fastcall TForm1::TrackBarSpeedChange(TObject *Sender) { speed=TrackBarSpeed->Max-TrackBarSpeed->Position; // speedStep=0; } //--------------------------------------------------------------------------- void TForm1::round() { if(Auditory->getRoundCount()Text.ToIntDef(RCInitial)) { Auditory->round(); auditoryShow(); }; }; //--------------------------------------------------------------------------- void TForm1::auditoryRestart() { myInitialize(); pBias Bias=0; if(RBGeomRow->Checked) Bias=new biasGeomRow(EditStartValue->Text.ToDouble(),EditQuotient->Text.ToDouble()); else if (RBAritmRow->Checked) Bias=new biasAritmRow(EditStartValue->Text.ToDouble(),EditQuotient->Text.ToDouble()); else Bias=new biasConstant(EditConstant->Text.ToDouble()); pGrCellMaker Maker=0; if (CBMemory->Checked) { // Memory ON if (CBExhaust->Checked) { if(CBReStand->Checked) { Maker = new RestandCellMaker( EditInitialApplausMean->Text.ToDouble(), EditInitialApplausSD->Text.ToDouble(), EditCTNMean->Text.ToDouble(), EditCTNSD->Text.ToDouble(), EditCTGMean->Text.ToDouble(), EditCTGSD->Text.ToDouble(), EditAPTOSTDM->Text.ToDouble(), EditAPTOSTDSD->Text.ToDouble(), EditCNTSTDNTSTNDM->Text.ToDouble(), EditCNTSTDNTSTNDSD->Text.ToDouble(), EditEXHAUSTM->Text.ToDouble(), EditEXHAUSTSD->Text.ToDouble(), EditRESTANDM->Text.ToDouble(), EditRESTANDSD->Text.ToDouble(), CBContStEx->Checked ); } else { Maker = new ExhaustCellMaker( EditInitialApplausMean->Text.ToDouble(), EditInitialApplausSD->Text.ToDouble(), EditCTNMean->Text.ToDouble(), EditCTNSD->Text.ToDouble(), EditCTGMean->Text.ToDouble(), EditCTGSD->Text.ToDouble(), EditAPTOSTDM->Text.ToDouble(), EditAPTOSTDSD->Text.ToDouble(), EditCNTSTDNTSTNDM->Text.ToDouble(), EditCNTSTDNTSTNDSD->Text.ToDouble(), EditEXHAUSTM->Text.ToDouble(), EditEXHAUSTSD->Text.ToDouble(), CBContStEx->Checked ); }; } else { Maker= new Cell3Maker( EditInitialApplausMean->Text.ToDouble(), EditInitialApplausSD->Text.ToDouble(), EditCTNMean->Text.ToDouble(), EditCTNSD->Text.ToDouble(), EditCTGMean->Text.ToDouble(), EditCTGSD->Text.ToDouble(), EditAPTOSTDM->Text.ToDouble(), EditAPTOSTDSD->Text.ToDouble(), EditCNTSTDNTSTNDM->Text.ToDouble(), EditCNTSTDNTSTNDSD->Text.ToDouble() ); }; } else { // Memory OFF if (CBExhaust->Checked) { if(CBReStand->Checked) { Maker = new DynamicRestandCellMaker( EditInitialApplausMean->Text.ToDouble(), EditInitialApplausSD->Text.ToDouble(), EditCTNMean->Text.ToDouble(), EditCTNSD->Text.ToDouble(), EditCTGMean->Text.ToDouble(), EditCTGSD->Text.ToDouble(), EditAPTOSTDM->Text.ToDouble(), EditAPTOSTDSD->Text.ToDouble(), EditCNTSTDNTSTNDM->Text.ToDouble(), EditCNTSTDNTSTNDSD->Text.ToDouble(), EditEXHAUSTM->Text.ToDouble(), EditEXHAUSTSD->Text.ToDouble(), EditRESTANDM->Text.ToDouble(), EditRESTANDSD->Text.ToDouble(), CBContStEx->Checked ); } else { Maker = new DynamicExhaustCellMaker( EditInitialApplausMean->Text.ToDouble(), EditInitialApplausSD->Text.ToDouble(), EditCTNMean->Text.ToDouble(), EditCTNSD->Text.ToDouble(), EditCTGMean->Text.ToDouble(), EditCTGSD->Text.ToDouble(), EditAPTOSTDM->Text.ToDouble(), EditAPTOSTDSD->Text.ToDouble(), EditCNTSTDNTSTNDM->Text.ToDouble(), EditCNTSTDNTSTNDSD->Text.ToDouble(), EditEXHAUSTM->Text.ToDouble(), EditEXHAUSTSD->Text.ToDouble(), CBContStEx->Checked ); }; } else { Maker= new DynamicCell3Maker( EditInitialApplausMean->Text.ToDouble(), EditInitialApplausSD->Text.ToDouble(), EditCTNMean->Text.ToDouble(), EditCTNSD->Text.ToDouble(), EditCTGMean->Text.ToDouble(), EditCTGSD->Text.ToDouble(), EditAPTOSTDM->Text.ToDouble(), EditAPTOSTDSD->Text.ToDouble(), EditCNTSTDNTSTNDM->Text.ToDouble(), EditCNTSTDNTSTNDSD->Text.ToDouble() ); }; }; pTopology topology=0; if (RBToroid4->Checked) { topology = new Toroid4(nCell2); } else if (RBToroid8->Checked) { topology = new Toroid8(nCell2); } else // (RBRandom->Checked) { topology = new RandomTopology(nCell2, (float)EditRandomProbablity->Text.ToDouble() ); }; clearPerfGraph(); Auditory = new GrAuditory(Bias,this,Maker,topology); Auditory->countApplausMean(); }; //--------------------------------------------------------------------------- void __fastcall TForm1::TrackBarBrightnessChange(TObject *Sender) { cellHotApplaus=TrackBarBrightness->Position; auditoryShowNoPerfGraph(); } //--------------------------------------------------------------------------- void TForm1::clearPerfGraph() { for(int i=0; iUpdate(); PerformanceGraph1->Gradient=EditScale->Text.ToIntDef(PERFGRAPHGRADIENT); }; void __fastcall TForm1::EditScaleChange(TObject *Sender) { PerformanceGraph1->Gradient=EditScale->Text.ToIntDef(PERFGRAPHGRADIENT); } //--------------------------------------------------------------------------- void TForm1::compute() { FILE *f; if(!(f=fopen("vysledky.txt","at"))) { Application->MessageBox("file acces error", "Message Box", MB_DEFBUTTON1); return; }; int rndscnt = EditRoundsCount->Text.ToInt(); CBContStEx->Checked=true; fprintf(f,"continuous "); for (int j=0; j<5; j++) { EditRandomProbablity->Text=0.5+j*0.1; fprintf(f,"pr> %f ",EditRandomProbablity->Text.ToDouble()); for (int i=0; i<4; i++) { auditoryRestart(); for (int k=0; kText.ToInt()); }; fprintf(f,"\n"); }; CBContStEx->Checked=false; fprintf(f,"discontinuous"); for (int j=0; j<5; j++) { EditRandomProbablity->Text=0.5+j*0.1; fprintf(f,"pr> %f ",EditRandomProbablity->Text.ToDouble()); for (int i=0; i<4; i++) { auditoryRestart(); for (int k=0; kText.ToInt()); }; fprintf(f,"\n"); }; fclose(f); }; //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { compute(); } //---------------------------------------------------------------------------