📄 formmain.cs
字号:
}
private void FormMain_Load(object sender, System.EventArgs e)
{
myControl = new ProbControl();
myControl.Dock = System.Windows.Forms.DockStyle.Fill;
panel1.Controls.Add(myControl);
cridg = new myCriGridCtrl();
cridg.Dock = System.Windows.Forms.DockStyle.Fill;
critabPage.Controls.AddRange(new System.Windows.Forms.Control[] { this.cridg});
cridg.statisRowchange2plot+=new ProbControl.SetEXPSGMDelegate(myControl.SetExptSigma);
examdg = new myExamGridCtrl();
examdg.Dock = System.Windows.Forms.DockStyle.Fill;
examtabPage.Controls.AddRange(new System.Windows.Forms.Control[] { this.examdg});
/*
itemvaluedg = new myItemValueGridCtrl();
itemvaluedg.Dock = System.Windows.Forms.DockStyle.Fill;
itemvaluetabPage.Controls.AddRange(new System.Windows.Forms.Control[] { this.itemvaluedg});
*/
resultdg = new myResultGridCtrl();
resultdg.Dock = System.Windows.Forms.DockStyle.Fill;
resulttabPage.Controls.AddRange(new System.Windows.Forms.Control[] { this.resultdg});
templatedg = new myTemplateGridCtrl();
templatedg.Dock = System.Windows.Forms.DockStyle.Fill;
templatetabPage.Controls.AddRange(new System.Windows.Forms.Control[] { this.templatedg});
dlgTemplateReasonSetting =new TemplateReasonSetting();
this.splitter1.SplitPosition=this.Width/3*2;
//this.currTemplate=new TemplateMapping();
GAProgress=new progress();
Application.Idle+=new EventHandler(Application_Idle);
auotTablenameAndFieldsSetting();//自动参数设置
}
private void toolBar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
// criSet.Update();
}
private void addImage(string imageToLoad)
{
if (imageToLoad != "")
{
//imageListtoolbar.Images.Add(Image.FromFile(imageToLoad));
}
}
private void AboutMenu_Popup(object sender, System.EventArgs e)
{
int i=0;
i++;
}
//概率统计的方法
public void StatisReason()
{
#region make sure that all necessary set and table are there.
//取标准样本数据库
if(CriSet==null)
{
//ShowMessage("清先打开标准样本数据库!");
return;
}
//取待测样本数据库
if(ExamSet==null)
{
//ShowMessage("清先打开待测样本数据库!");
return;
}
//取参数统计表
//myItemValueDataSet aItemset=itemvaluedg.DataSource as myItemValueDataSet;
if(ParamTable==null)
{
ShowMessage("没有能生成参数统计表,无法进行推理!\r\n");
return;
}
//取数据表
if(ExamTable==null)
{
ShowMessage("不存在数据表,无法进行推理!\r\n");
return;
}
#endregion make sure that all necessary table are there.
//生成空的结果表
//将空的结果表加入到结果数据集中
if(StatisResultTable==null)
StatisResultTable=ExamSet.CreateStatisResultTable();
//取结果数据集
//取试油结果数组:油,水,气,干...
ArrayList resulttypes=CriSet.GenerateResultList();
ArrayList arr=examdg.GetDataViewSelected("");
foreach(DataRow row in arr)//examdg.ExamSet.ExamTable.Rows)//取每一个待测纪录
{
ShowMessage("对待测样品 "+row["序号"].ToString()+" 进行统计推理:......");
//生成当前待测纪录对应的油,水,气,干...判断结果纪录
ArrayList results=ResultSet.CreateEmptyStatisResultRows( resulttypes);
//填充当前待测纪录对应的油,水,气,干...判断结果纪录
//并将当前待测纪录对应的油,水,气,干...判断结果纪录加入到结果表中
CriSet.BuildItemResultRecords(results,row);
//resultdg.CurrentRowIndex=StatisResultTable.Rows.Count-1;
resultdg.Refresh();
ShowMessage("统计推理结束!\r\n");
}
//ResultView.RowFilter="可信等级 > 3 and 结论=\'油层\'";
//ResultView.RowFilter="可信等级 > 2 ";
//ShowTable(ResultView);
//ShowTable(ResultView);
UpdateStatisResultinExamSet();
}
public void FuzzyReason()
{
#region make sure that all necessary set and table are there.
//取待测样本数据库
if(ExamSet==null)
{
//ShowMessage("清先打开待测样本数据库!");
return;
}
//取数据表
if(ExamTable==null)
{
ShowMessage("不存在数据表,无法进行推理!");
return;
}
#endregion make sure that all necessary table are there.
//生成空的结果表
//将空的结果表加入到结果数据集中
if(FuzzyResultTable==null)
FuzzyResultTable=ExamSet.CreateFuzzyResultTable();
ArrayList arr=examdg.GetDataViewSelected("");
foreach(DataRow rowData in arr)//examdg.ExamSet.ExamTable.Rows)//取每一个待测纪录
{
DataRow rowResult=FuzzyResultTable.NewRow();
ShowMessage("对待测样品 "+rowData["序号"].ToString()+" 进行模糊推理:......\r\n");
if(FuzzyReasonSingleSample(rowData,rowResult))
{
if(!FuzzySuperReasonSingleSample(rowData,rowResult))
ShowMessage("\t特殊知识推理失败!\r\n");
FuzzyResultTable.Rows.Add(rowResult);
}
ShowMessage("模糊推理结束!\r\n");
resultdg.Refresh();
}
}
void UpdateStatisResultinExamSet()
{
if(ResultTableG==null)
return;
foreach(DataRow dr0 in StatisResultTable.Rows)
{
string select="[序号]=" + Convert.ToString(dr0["序号"]);
DataRow[] dr1=ResultTableG.Select(select);
DataRow temp;
if(dr1.Length<=0)
{
temp=ResultTableG.NewRow();
ResultTableG.Rows.Add(temp);
temp["序号"]=dr0["序号"];
}
else
temp=dr1[0];
switch(Convert.ToInt16(dr0[myResultDataSet.NAME_CREDITLEVEL_FIELDNAME]))
{
case 1:
temp[myExamDataSet.NAME_STATIS_RESULTTYPE1_FIELDNAME]=dr0[myResultDataSet.NAME_RESULT_FIELDNAME];
temp[myExamDataSet.NAME_STATIS_RESULTCREDITSCORE1_FIELDNAME]=dr0[myResultDataSet.NAME_CREDITSCORE_FIELDNAME];
break;
case 2:
temp[myExamDataSet.NAME_STATIS_RESULTTYPE2_FIELDNAME]=dr0[myResultDataSet.NAME_RESULT_FIELDNAME];
temp[myExamDataSet.NAME_STATIS_RESULTCREDITSCORE2_FIELDNAME]=dr0[myResultDataSet.NAME_CREDITSCORE_FIELDNAME];
break;
case 3:
temp[myExamDataSet.NAME_STATIS_RESULTTYPE3_FIELDNAME]=dr0[myResultDataSet.NAME_RESULT_FIELDNAME];
temp[myExamDataSet.NAME_STATIS_RESULTCREDITSCORE3_FIELDNAME]=dr0[myResultDataSet.NAME_CREDITSCORE_FIELDNAME];
break;
default:
break;
}
}
}
void SingleGeneration(float score)
{
GAProgress.progressBar1.PerformStep();
GAProgress.EstimateTime();
GAProgress.progressBar1.Invalidate();
GAProgress.progressBar1.Update();
GAProgress.Invalidate();
GAProgress.Update();
}
//SimpleGA.YQGA.__Delegate_OnProgressStep
unsafe int DoneReport(sbyte** temps,float* scores , int count)
{
int indexbase;
bool autosave=true;
indexbase=Convert.ToInt16(this.NomeS.resultindexbase.Text);
try
{
ShowMessage("Done!\r\n");
for(int i=0;i<count;i++)
{
GetProgressStep(temps[i],scores[i]);
TemplateSet.AddTemplate(temps[i],scores[i],currTemplate,indexbase);
if(autosave)
TemplateSet.Update();
}
//myc.GetTemplates(temps,scores,count);
//myc.GetMapping(&min,&max,&bitnum,&num);
//TemplateSet.AddTemplate(temps,scores,count,min,max,bitnum,num);
}
catch(Exception e)
{
throw e;
}
return 0;
}
unsafe bool GetProgressStep(sbyte* a,float b)
{
String x=new String(' ',0);
for(int i=0;i<myc.Height;i++)
{
for(int j=0;j<myc.Width;j++)
x+=(char)a[i*myc.Width+j];
x+="\r\n";
}
x+="\r\n";
ShowMessage(x+"------:"+b.ToString()+"\r\n");
if(menuAbortCurrentSample.Checked)
{
menuAbortCurrentSample.Checked=false;
return false;
}
else
return true;
}
//indCover 为目标样本的序号字段的值
private unsafe void LaunchGA(int indCover)
{
if(!myc.InitGenome())
return;
//currTemplate.TargetIndex=indCover;
//取指定序号字段的纪录的行号
int indexofrow;
for(indexofrow=0;indexofrow<SampleTable.Rows.Count;indexofrow++)
{
if(Convert.ToInt16(SampleTable.Rows[indexofrow]["序号"])==indCover)
break;
}
currTemplate.Resulttype=SampleTable.Rows[indexofrow]["试油结果"] as string ;
currTemplate.XUHAOinTable=(int )SampleTable.Rows[indexofrow]["序号"] ;
myc.InitScores(indexofrow);
if(!myc.InitGAgrith())
return;
myc.NnGenerations=NomeS.nGenerations;
myc.ProgressStep=NomeS.nProgressStep;
myc.NpopulationSize=NomeS.nPopulationSize;
myc.NnBestGenomes=NomeS.nBestGenomes;
myc.OnProgressStep+=OnProgressStepDelegate;
myc.OnDone+=OnDoneDelegate;
myc.OnSingleGeneration+=OnSingleGeneration;
try
{
myc.Do();
}
catch(ThreadAbortException)
{
ShowMessage("专家模板生成被终止\r\n");
}
catch(System.NullReferenceException e)
{
throw e;
}
finally
{
Console.Write("突然错误!");
}
myc.OnProgressStep-=OnProgressStepDelegate;
myc.OnDone-=OnDoneDelegate;
myc.OnSingleGeneration-=OnSingleGeneration;
return;
}
private unsafe void LaunchGAAll()
{
if(CriSet==null)
return;
GAProgress.Owner=this;
GAProgress.begin= DateTime.Now;
GAProgress.Show();
GAProgress.progressBar1.Value=0;
GAProgress.bCancel=false;
try
{
myc.Width=NomeS.nGAWidth;
CriSet.SetYQGA(myc,ref currTemplate);
currTemplate.SettoGA(ref myc);
myc.Height= myc.ncInclusive;
myc.AdvisorBitScore=NomeS.fAdvisorBitScore;
myc.TargetBitScore=NomeS.fTargetBitScore;
myc.NegativeBitScore=NomeS.fNegativeBitScore;
myc.FullMatchScoreCoeff=NomeS.fFullMatchScoreCoeff;
foreach(object obj in currTemplate.indTarget)
{
LaunchGA((int)(obj));
if(menuAbortAllSamples.Checked)
{
menuAbortAllSamples.Checked=false;
break;
}
if(GAProgress.bCancel)
break;
}//
}
catch(Exception e)
{
throw e;
}
GAProgress.Hide();
GAProgress.end= DateTime.Now;
TimeSpan span=GAProgress.end-GAProgress.begin;
ShowMessage(span.ToString());
return;
}
//*********************
private unsafe void LaunchGAAllold()
{
if(CriSet==null)
return;
try
{
int ind=0;//Convert.ToInt16(NomeS.targetIndex.Text);
for(int i=ind;i<=ind;i++)
{
myc.Width=NomeS.nGAWidth;
CriSet.SetYQGA(myc,ref currTemplate);
currTemplate.SettoGA(ref myc);
myc.Height= myc.ncInclusive;
myc.AdvisorBitScore=NomeS.fAdvisorBitScore;
myc.TargetBitScore=NomeS.fTargetBitScore;
myc.NegativeBitScore=NomeS.fNegativeBitScore;
myc.FullMatchScoreCoeff=NomeS.fFullMatchScoreCoeff;
//for(int i=0;i<42;i++)
//{
LaunchGA(i);
if(menuAbortAllSamples.Checked)
{
menuAbortAllSamples.Checked=false;
break;
}
}//
}
catch(Exception e)
{
throw e;
}
return;
}
//********************
private unsafe void AboutMenu_Click(object sender, System.EventArgs e)
{
aboutForm about=new aboutForm();
about.ShowDialog();
/*
Excel.Application excel=new Excel.Application();
Excel.Workbook book=excel.Workbooks.Add(5);
excel.Visible=true;
excel.Caption="我来也!";
*/
//sheet.Name="abcde";
}
void ShowTable(DataViewSetting view)
{
ShowTable(view.Table);
}
private void FormMain_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
/*
if(GAThread==null)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -