📄 复件 formmain.cs
字号:
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;
}
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 Reason()
{
#region make sure that all necessary set and table are there.
//取标准样本数据库
if(CriSet==null)
{
//MessageBox.Show("清先打开标准样本数据库!");
return;
}
//取待测样本数据库
if(ExamSet==null)
{
//MessageBox.Show("清先打开待测样本数据库!");
return;
}
//取参数统计表
//myItemValueDataSet aItemset=itemvaluedg.DataSource as myItemValueDataSet;
if(ParamTable==null){
MessageBox.Show("没有能生成参数统计表,无法进行推理!");
return;
}
//取数据表
if(ExamTable==null)
{
MessageBox.Show("不存在数据表,无法进行推理!");
return;
}
#endregion make sure that all necessary table are there.
//生成空的结果表
//将空的结果表加入到结果数据集中
ResultTable=ExamSet.CreateResultTable();
//取结果数据集
//取试油结果数组:油,水,气,干...
ArrayList resulttypes=CriSet.GenerateResultList();
foreach(DataRow row in examdg.ExamSet.ExamTable.Rows)//取每一个待测纪录
{
//生成当前待测纪录对应的油,水,气,干...判断结果纪录
ArrayList results=ResultSet.CreateEmptyResultRows( resulttypes);
//填充当前待测纪录对应的油,水,气,干...判断结果纪录
//并将当前待测纪录对应的油,水,气,干...判断结果纪录加入到结果表中
CriSet.BuildItemResultRecords(results,row);
//resultdg.CurrentRowIndex=ResultTable.Rows.Count-1;
resultdg.Refresh();
}
//ResultView.RowFilter="可信等级 > 3 and 结论=\'油层\'";
//ResultView.RowFilter="可信等级 > 2 ";
//ShowTable(ResultView);
//ShowTable(ResultView);
}
void SingleGeneration(float score)
{
int i=0;
i++;
}
//SimpleGA.YQGA.__Delegate_OnProgressStep
unsafe int DoneReport(sbyte** temps,float* scores , int count)
{
try
{
output.Text+="Done!\r\n";
for(int i=0;i<count;i++)
{
GetProgressStep(temps[i],scores[i]);
TemplateSet.AddTemplate(temps[i],scores[i],currTemplate);
}
//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";
}
output.Text+=x+"\r\n";
output.Text+="------:"+b.ToString()+"\r\n";
if(menuAbortCurrentSample.Checked)
{
menuAbortCurrentSample.Checked=false;
return false;
}
else
return true;
}
private unsafe void LaunchGA(int indCover)
{
if(!myc.InitGenome())
return;
currTemplate.TargetIndex=indCover;
currTemplate.Resulttype=SampleTable.Rows[indCover]["试油结果"] as string ;
currTemplate.XUHAOinTable=(int )SampleTable.Rows[indCover]["序号"] ;
myc.InitScores(indCover);
if(!myc.InitGAgrith())
return;
myc.NnGenerations=Convert.ToInt16(NomeS.NnGenerations.Text);
myc.ProgressStep=Convert.ToInt16(NomeS.ProgressStep.Text);
myc.NpopulationSize=Convert.ToInt16(NomeS.NpopulationSize.Text);
myc.NnBestGenomes=Convert.ToInt16(NomeS.NnBestGenomes.Text);
myc.OnProgressStep+=OnProgressStepDelegate;
myc.OnDone+=OnDoneDelegate;
myc.OnSingleGeneration+=OnSingleGeneration;
try
{
myc.Do();
}
catch(ThreadAbortException)
{
output.Text+="专家模板生成被终止\r\n";
}
myc.OnProgressStep-=OnProgressStepDelegate;
myc.OnDone-=OnDoneDelegate;
myc.OnSingleGeneration-=OnSingleGeneration;
return;
}
private unsafe void LaunchGAAllnew()
{
if(CriSet==null)
return;
try
{
int ind=Convert.ToInt16(NomeS.targetIndex.Text);
for(int i=ind;i<=ind;i++)
{
myc.Width= Convert.ToInt16(NomeS.GAWidth.Text);
CriSet.SetYQGA(myc,ref currTemplate);
currTemplate.SettoGA(ref myc);
myc.Height= myc.ncInclusive;
myc.AdvisorBitScore=Convert.ToSingle(NomeS.AdvisorBitScore.Text);
myc.TargetBitScore=Convert.ToSingle(NomeS.TargetBitScore.Text);
myc.NegativeBitScore=Convert.ToSingle(NomeS.NegativeBitScore.Text);
myc.FullMatchScoreCoeff=Convert.ToSingle(NomeS.FullMatchScoreCoeff.Text);
//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 LaunchGAAll()
{
if(CriSet==null)
return;
try
{
int ind=Convert.ToInt16(NomeS.targetIndex.Text);
for(int i=ind;i<=ind;i++)
{
myc.Width= Convert.ToInt16(NomeS.GAWidth.Text);
CriSet.SetYQGA(myc,ref currTemplate);
currTemplate.SettoGA(ref myc);
myc.Height= myc.ncInclusive;
myc.AdvisorBitScore=Convert.ToSingle(NomeS.AdvisorBitScore.Text);
myc.TargetBitScore=Convert.ToSingle(NomeS.TargetBitScore.Text);
myc.NegativeBitScore=Convert.ToSingle(NomeS.NegativeBitScore.Text);
myc.FullMatchScoreCoeff=Convert.ToSingle(NomeS.FullMatchScoreCoeff.Text);
//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)
{
/*
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)
return;
switch(GAThread.ThreadState)
{
case ThreadState.Unstarted:
break;
case ThreadState.Running:
case ThreadState.WaitSleepJoin:
case ThreadState.SuspendRequested:
case ThreadState.Suspended:
case ThreadState.AbortRequested:
GAThread.Abort();
break;
case ThreadState.Stopped:
break;
}
}
private void menuGA_Popup(object sender, System.EventArgs e)
{
if(GAThread==null)
{
GAThread=new Thread(new ThreadStart(LaunchGAAll));
GAThread.Name="专家模板遗传算法";
}
if(GAThread.ThreadState==ThreadState.Aborted ||
GAThread.ThreadState==ThreadState.Stopped)
{
GAThread=new Thread(new ThreadStart(LaunchGAAll));
GAThread.Name="专家模板遗传算法";
}
menuGAStart.Enabled=(GAThread.ThreadState==ThreadState.Unstarted);
menuGASuspend.Enabled=(GAThread.ThreadState==ThreadState.Running);
menuGAResume.Enabled=(GAThread.ThreadState==ThreadState.Suspended);
menuGAAbort.Enabled=(GAThread.ThreadState==ThreadState.Running
||GAThread.ThreadState==ThreadState.WaitSleepJoin);
menuAbortCurrentSample.Enabled=GAThread.IsAlive;
menuAbortAllSamples .Enabled=GAThread.IsAlive;
/*
switch(GAThread.ThreadState)
{
case ThreadState.Unstarted:
GAThread.Start();
break;
case ThreadState.Running:
case ThreadState.WaitSleepJoin:
case ThreadState.SuspendRequested:
case ThreadState.Suspended:
case ThreadState.AbortRequested:
break;
case ThreadState.Stopped:
GAThread=new Thread(new ThreadStart(LaunchGAAll));
GAThread.Start();
break;
}
*/
}
private void menuGAStart_Click(object sender, System.EventArgs e)
{
if(NomeS.ShowDialog(this)!= DialogResult.OK)
return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -