Beispiel #1
0
        static void Main(string[] args)
        {
            UCTProblem test;
            UCTProblem.HillClimbMode temp = UCTProblem.HillClimbMode.None;
            if (args == null || args.Length == 0)
            {
                Console.WriteLine("Starting with default parameters."); // Check for null array
                test = new UCTProblem(0.75, 200, 10000, 3, 0, true, 0.75, 0.0232558, false);
            }
            else
            {
                if (args.Length == 4)
                {
                    try
                    {
                        double seed = double.Parse(args[0],CultureInfo.InvariantCulture);

                        int pop = int.Parse(args[1]);
                        int gen = int.Parse(args[2]);

                        test = new UCTProblem(seed, pop, gen, 3, 0, true, 0.75, 0.0232558, false);

                        if (args[3] == "0")
                            temp = UCTProblem.HillClimbMode.None;
                        else if (args[3] == "1")
                            temp = UCTProblem.HillClimbMode.ChildOnly;
                        else if (args[3] == "3")
                            temp = UCTProblem.HillClimbMode.ParentOnly;
                        else if (args[3] == "4")
                            temp = UCTProblem.HillClimbMode.All;
                        else if (args[3] == "5")
                            temp = UCTProblem.HillClimbMode.BestOfParent;
                        else if (args[3] == "6")
                            temp = UCTProblem.HillClimbMode.AllBestOfParent;
                        else if (args[3] == "7")
                            temp = UCTProblem.HillClimbMode.AdaptiveParent;
                        else if (args[3] == "8")
                            temp = UCTProblem.HillClimbMode.Rank1Best;
                        else if (args[3] == "9")
                            temp = UCTProblem.HillClimbMode.Rank1All;
                        else if (args[3] == "10")
                            temp = UCTProblem.HillClimbMode.AdaptiveRank1All;

                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"Parameter Error: {ex}.");
                        Console.WriteLine("Usage: -seed -pop -generation");
                        return;
                    }
                }
                else
                {
                    Console.WriteLine("Wrong number of parameters.");
                    Console.WriteLine("Usage: -seed -pop -generation");
                    return;
                }
            }

            test.WriteMethod(temp);
            test.FirstGeneration();

            for (int i = 0; i < test.ProblemObj.MaxGeneration; i++)
            {
                test.NextGeneration(temp);
            }

            test.WriteBestGeneration();
            test.WriteFinalGeneration();
            UCTProblem.SaveToFile(test, test.ProblemObj.Title);
        }
Beispiel #2
0
        private void LoadProblem_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

            // Set filter for file extension and default file extension
            dlg.DefaultExt = ".out";
            dlg.Filter = "Problem save (*.problem)|*.problem";

            // Display OpenFileDialog by calling ShowDialog method
            bool? result = dlg.ShowDialog();

            // Get the selected file name and display in a TextBox
            if (result == true)
            {
                // Open document
                _generationTimer.Stop();
                StartPauseGeneration.Content = "Start";
                string filename = dlg.FileName;
                _uctproblem = UCTProblem.LoadFromFile(filename);
                if (_uctproblem != null)
                {
                    ProblemTitle.Content = _uctproblem.ProblemObj.Title;
                    EnableGenerationControls();
                    //CreateProblem.IsEnabled = false;
                    LogBox.Items.Clear();
                    ListIndividuals();
                    LogBox.Items.Add("Load completed.");
                    SetTitleToProblem();
                    ClearTeacherTabs();
                }

            }
        }
Beispiel #3
0
 private void CloseProblem_Click(object sender, RoutedEventArgs e)
 {
     _generationTimer.Stop();
     StartPauseGeneration.Content = "Start";
     _uctproblem = null;
     ProblemTitle.Content = "";
     EnableGenerationControls(false);
     LogBox.Items.Clear();
     IndBox.Items.Clear();
     TeacherTab.Items.Clear();
     ClearTables();
     this.Title = "UCT";
 }
Beispiel #4
0
        private void CreateProblem_Click(object sender, RoutedEventArgs e)
        {
            _generationTimer.Stop();
            StartPauseGeneration.Content = "Start";
            //Random rnd = new Random((int)DateTime.Now.Ticks);

            double seed = 0.75;
            double customSeed;
            if (CustomSeed.Text != "0.75" && double.TryParse(CustomSeed.Text, NumberStyles.Float, CultureInfo.InvariantCulture, out customSeed))
            {
                if (customSeed >= 0 & customSeed <= 1)
                {
                    seed = customSeed;

                }

            }

            int population = 200;
            int customPop;
            if (CustomPopulation.Text != "200" && int.TryParse(CustomPopulation.Text, out customPop))
            {
                if (customPop >= 10 & customPop <= 100000)
                {
                    population = customPop - (customPop % 4);

                }

            }
            int generation = 20000;

            _uctproblem = new UCTProblem(seed, population, generation, 3, 0, true, 0.75, 0.0232558);
            ProblemTitle.Content = _uctproblem.ProblemObj.Title;
            EnableGenerationControls();
            //CreateProblem.IsEnabled = false;
            LogBox.Items.Clear();
            LogBox.Items.Add("Create completed.");

            SetTitleToProblem();

            ClearTeacherTabs();
        }
Beispiel #5
0
        public static bool SaveToFile(UCTProblem uctToSave, string filename)
        {
            try
            {
                Directory.CreateDirectory("report");
                var textToSave = SerializationHelper.SerializeObject(uctToSave);

                File.WriteAllText("report\\" + filename + ".problem", textToSave, Encoding.UTF8);
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }