/// <summary> /// Method which starts the GA executing. /// </summary> public void Go() { if (getFitness == null) { throw new ArgumentNullException("Need to supply fitness function"); } if (m_genomeSize == 0) { throw new IndexOutOfRangeException("Genome size not set"); } if (m_fitnessSize == 0) { throw new IndexOutOfRangeException("Fitness size not set"); } Cancelled = false; Running = true; // Create the fitness table. //m_fitnessTable = new ArrayList(); m_thisGeneration = new List <Individual>(m_generationSize); allGenerations = new List <Individual>(); Individual.MutationRate = m_mutationRate; CreateGenomes(); RankPopulation(); // first step events if (StepFinish != null) { StepFinish.Invoke(this, 0); } StreamWriter outputFitness = null; if (m_fitnessFile != "") { outputFitness = new StreamWriter(m_fitnessFile); outputFitness.WriteLine("{0}\t{1}", GenomeSize, FitnessSize);//sizes // first gen writeData(outputFitness, m_thisGeneration, true); } for (int i = 0; i < m_generationSize; i++) { CreateNextGeneration(); // rank, create non-dominated group RankPopulation(); // check cancel flag after most time-consuming method if (Cancelled) { break; } // debug if (outputFitness != null) { // write this generation data writeData(outputFitness, m_thisGeneration); } // events if (StepFinish != null) { StepFinish.Invoke(this, i + 1); } } if (outputFitness != null) { outputFitness.Close(); } // write final nondominated set if (m_fitnessFile != "") { string fn = Path.GetDirectoryName(m_fitnessFile) + "\\" + Path.GetFileNameWithoutExtension(m_fitnessFile) + "_final" + Path.GetExtension(m_fitnessFile); using (StreamWriter sw = new StreamWriter(fn)) { m_finalNonDominatedSet = buildNonDominatedSetFromGeneration(allGenerations); sw.WriteLine("{0}\t{1}", GenomeSize, FitnessSize);//sizes writeData(sw, m_finalNonDominatedSet); } } Running = false; }
private void OnSeqRun() { var testStepList = ManualConnectionList[currentConnIndex].TestStepList; for (int i = stopIndex; i < testStepList.Count; i++) { if (IsRun) { if (testStepList[i].IsTest) { try { if (StepStart != null) { StepStart.Invoke(i); } testStepList[i].DetailProgressReport = (traceIndex, markerIndex) => { if (PointFinish != null) { PointFinish.Invoke(i, traceIndex, markerIndex); } }; testStepList[i].RunState = () => GetRunState(); if (!GeneTestSetup.Instance.IsSimulated) { //set path config if (pathConfig == null) { DataUtils.LOGINFO.WriteLog(testStepList[i].DisplayName + " path is empty"); } else { string configName = testStepList[i].PathConfigName; if (string.IsNullOrWhiteSpace(configName)) { DataUtils.LOGINFO.WriteLog(testStepList[i].DisplayName + " path is empty"); } else { var config = testStepList[i].GetPathConfigInfo(configName); if (config != null) { string configValue = config.Path; string[] pathConfigList = pathConfig.GetPathConfigNameList(); if (pathConfigList != null && pathConfigList.Contains(configValue)) { pathConfig.SetPathConfig(configValue); } else { DataUtils.LOGINFO.WriteLog(testStepList[i].DisplayName + " " + configValue + " path is not found"); throw (new Exception(testStepList[i].DisplayName + " " + configValue + " path is not found")); } } } } } DataUtils.LOGINFO.WriteLog(DateTime.Now.ToString() + testStepList[i].DisplayName + " single start"); testStepList[i].Single(); DataUtils.LOGINFO.WriteLog(DateTime.Now.ToString() + testStepList[i].DisplayName + " single finish"); if (!GeneTestSetup.Instance.IsSimulated) { if (pathConfig == null) { DataUtils.LOGINFO.WriteLog(testStepList[i].DisplayName + " path is empty"); } else { string configName = testStepList[i].PathConfigName; if (string.IsNullOrWhiteSpace(configName)) { DataUtils.LOGINFO.WriteLog(testStepList[i].DisplayName + " path is empty"); } else { var config = testStepList[i].GetPathConfigInfo(configName); if (config != null) { string configValue = config.Path; string[] pathConfigList = pathConfig.GetPathConfigNameList(); if (pathConfigList != null && pathConfigList.Contains(configValue)) { pathConfig.PostPathConfig(configValue); } else { DataUtils.LOGINFO.WriteLog(testStepList[i].DisplayName + " " + configValue + " path is not found"); throw (new Exception(testStepList[i].DisplayName + " " + configValue + " path is not found")); } } } } } testStepList[i].CalcStepInfo(); //更新连接步骤中的passfail ManualConnectionList[currentConnIndex].PassFail = Symtant.GeneFunLib.GeneFun.NullBoolAndList(testStepList.Select(x => x.PassFail).ToList()); if (StepFinish != null) { StepFinish.Invoke(i); } } catch (Exception exp) { testStepList[i].CleanUp(); ExceptionCollection.Add(exp); IsRun = IsRunWhenException; } } } else { stopIndex = i; System.Diagnostics.Debug.WriteLine(stopIndex); break; } } if (DXSplashScreen.IsActive) { DXSplashScreen.Close(); } IsRuning = false; if (SeqFinish != null) { SeqFinish.Invoke(); } }