コード例 #1
0
        public void GA_Start()
        {
            string          filePath    = @"D:\PhDWorkwc\PhDWorks\trunk\trunk\ResearchProgramming\DeterministicApproach-GA\StatisticalApproach-GA-NewFlow\bin\Debug\OUT\STDGA\bestmove";
            string          output      = null;
            LocalFileAccess lfa         = new LocalFileAccess();
            double          bestFitness = -1;
            int             generation  = 0;

            FitnessEvaVect();
            PopulationGen();
            bestFitness = enVar.population.OrderByDescending(x => x.Value).First().Value;
            Console.WriteLine("{0},{1}", generation, bestFitness);
            output = "gen: " + generation + " Fitness: " + bestFitness;
            lfa.StoreListToLinesAppend(filePath, new List <string>()
            {
                output
            });
            while (generation <= 500)
            {
                Reproduction();
                FitnessEvaVect();
                PopulationGen();
                bestFitness = enVar.population.OrderByDescending(x => x.Value).First().Value;

                enVar.genFitRecord[0] = generation;
                enVar.genFitRecord[1] = bestFitness;
                generation++;
                Console.WriteLine("{0},{1}", generation, bestFitness);
                output = "gen: " + generation + " Fitness: " + bestFitness;
                lfa.StoreListToLinesAppend(filePath, new List <string>()
                {
                    output
                });
                enVar.continueIndicate = false;
                while (enVar.continueIndicate == false)
                {
                    ;
                }
            }
            enVar.finishIndicate = true;
        }
コード例 #2
0
        public async Task <int> Invoke(EnvironmentVar enVar)
        {
            Dictionary <string, object> sutParam = SUT.SelectSUT(_selectSUT);

            sutParam["SUTPath"] = _sutPath;
            _record.sutInfo     = sutParam;
            Task taskInitialSUT = Task.Run(() => {
                LocalFileAccess lfa = new LocalFileAccess();
                List <string> list  = new List <string>();
                lfa.StoreLinesToList(_sutPath.ToString(), list);
                DataTable dt = new DataTable();
                dt.Columns.Add("Input", Type.GetType("System.String"));
                for (int i = 0; i < (int)sutParam["NumOfCE"]; i++)
                {
                    dt.Columns.Add((i + 1).ToString(), Type.GetType("System.String"));
                }

                foreach (string s in list)
                {
                    int length = dt.Rows.Count;

                    if (length == 0)
                    {
                        int c             = Convert.ToInt32(s.Substring(s.IndexOf(' ', s.IndexOf(' ') + 1))) + 1;
                        object[] coverSeq = new object[(int)sutParam["NumOfCE"] + 1];
                        for (int i = 0; i < coverSeq.Length; i++)
                        {
                            coverSeq[i] = 0.0;
                        }
                        coverSeq[c] = 1.0;
                        coverSeq[0] = s.Substring(0, s.IndexOf(' ', s.IndexOf(' ') + 1));
                        dt.Rows.Add(
                            coverSeq
                            );
                    }
                    else if (s.Substring(0, s.IndexOf(' ', s.IndexOf(' ') + 1))
                             == dt.Rows[length - 1].ItemArray[0].ToString())
                    {
                        int c = Convert.ToInt32(s.Substring(s.IndexOf(' ', s.IndexOf(' ') + 1) + 1)) + 1;
                        dt.Rows[length - 1][c] = 1.0;
                    }
                    else
                    {
                        int c             = Convert.ToInt32(s.Substring(s.IndexOf(' ', s.IndexOf(' ') + 1))) + 1;
                        object[] coverSeq = new object[(int)sutParam["NumOfCE"] + 1];
                        for (int i = 0; i < coverSeq.Length; i++)
                        {
                            coverSeq[i] = 0.0;
                        }
                        coverSeq[c] = 1.0;
                        coverSeq[0] = s.Substring(0, s.IndexOf(' ', s.IndexOf(' ') + 1));
                        dt.Rows.Add(
                            coverSeq
                            );
                    }
                }
                sutParam["Map"] = dt.AsEnumerable()
                                  .ToDictionary <DataRow, string, double[]>(
                    row => row.Field <string>(0),
                    row =>
                {
                    double[] coverSeq = new double[(int)sutParam["NumOfCE"]];
                    for (int i = 0; i < (int)sutParam["NumOfCE"]; i++)
                    {
                        coverSeq[i] = Convert.ToDouble(row.ItemArray[i + 1]);
                    }
                    return(coverSeq);
                });
            });

            await taskInitialSUT;

            await _next(enVar);

            Console.WriteLine("All tasks are done");
            return(0);
        }