예제 #1
0
        private void SaveRules(string fileName)
        {
            CellularAutomataRules rules = _genAlg.CurrentRules;
            var settingsCa = _genAlg.CaSettings;
            var saveData   = new RulesSaveData(settingsCa, rules.StateTable);

            saveData.Save(fileName);
        }
예제 #2
0
 private void SaveRules(string fileName)
 {
     CellularAutomataRules rules = _genAlg.CurrentRules;
     var settingsCa = _genAlg.CaSettings;
     var saveData = new RulesSaveData(settingsCa, rules.StateTable);
     saveData.Save(fileName);
 }
예제 #3
0
        public void LoadRules()
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter      = "Lifelike JSON|*.json";
            openFileDialog1.FilterIndex = 1;
            openFileDialog1.Multiselect = false;

            // Call the ShowDialog method to show the dialog box.
            DialogResult result = openFileDialog1.ShowDialog();

            // Process input if the user clicked OK.
            if (result != DialogResult.OK)
            {
                return;
            }

            RulesSaveData data = RulesSaveData.Load(openFileDialog1.FileName);

            if (data == null)
            {
                return;
            }

            CellularAutomataRules rules = new CellularAutomataRules(data.StateTable);

            try
            {
                if (!_genAlg.IsInProgess)
                {
                    ctrlCellularAutomataSettings.Set(data.CellStructure, rules.NumStates, data.NeighborhoodFunction);
                    ctrlGeneticAlgorithmSettings.SetNumStates(rules.NumStates);
                }
                else
                {
                    if (_genAlg.CaSettings.NeighborhoodFunction.Name != data.NeighborhoodFunction ||
                        _genAlg.CaSettings.NumStates != rules.NumStates ||
                        _genAlg.CaSettings.CellStructure.Name != data.CellStructure)
                    {
                        MessageBox.Show(
                            "Neighbor function, cell structure, and/or number states do not match the currently running genetic algorithm settings",
                            "Error",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error
                            );
                        return;
                    }
                    _genAlg.CurrentRules = rules;
                }

                if (data.CustomColors != null)
                {
                    Colors = data.CustomColors.Select(
                        ary => Color.FromArgb(ary[0], ary[1], ary[2])
                        ).ToList();
                }

                Cells cells = _genAlg.CaSettings.GetInitialCells(_genAlg.GaSettings.InitialStateDistribution);
                ctrlCellularAutomata.Run(cells, rules);
            }
            catch (Exception)
            {
                MessageBox.Show(
                    "Invalid CA rules file.",
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );
            }
        }