示例#1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                double left  = Double.Parse(textBox1.Text);
                double right = Double.Parse(textBox2.Text);
                double step  = Double.Parse(textBox3.Text);
                double a     = Double.Parse(textBox4.Text);
                double b     = Double.Parse(textBox5.Text);
                ContinuousFuzzySet <double, double> set = null;
                switch (comboBox1.SelectedIndex)
                {
                case 0: FuzzySetCreator <double, double> .MemberShipFunction3 SFunction =
                    new FuzzySetCreator <double, double> .MemberShipFunction3(FuzzyHelper.SFunction);

                    set = FuzzySetCreator <double, double> .CreateInstance(SFunction, left, right, step, a, b);

                    ElementsCache.Add(set);
                    break;

                case 1: FuzzySetCreator <double, double> .MemberShipFunction3 ZFunction =
                    new FuzzySetCreator <double, double> .MemberShipFunction3(FuzzyHelper.ZFunction);

                    set = FuzzySetCreator <double, double> .CreateInstance(ZFunction, left, right, step, a, b);

                    ElementsCache.Add(set);
                    break;

                case 2: FuzzySetCreator <double, double> .MemberShipFunction4 PFunction =
                    new FuzzySetCreator <double, double> .MemberShipFunction4(FuzzyHelper.PFunction);

                    double c = Double.Parse(textBox7.Text);
                    set = FuzzySetCreator <double, double> .CreateInstance(PFunction, left, right, step, a, b, c);

                    ElementsCache.Add(set);
                    break;

                default: throw new Exception("The membership function hasn't been selected.");
                }
                listBox1.Items.Add("Set #" + ElementsCache.Count.ToString());
                ViewSet(set, chart1);
            }
            catch (Exception ex)
            {
                string message = "An exception has occured. Details: " +
                                 ex.Message;
                MessageBox.Show(message, "Message");
            }
        }
示例#2
0
        private void открытьToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFileDialog1.FileName = string.Empty;
            openFileDialog1.ShowDialog();
            string file = openFileDialog1.FileName;

            try
            {
                StreamReader reader = new StreamReader(file);
                string       line   = string.Empty;
                ICollection <KeyValuePair <double, double> > list =
                    new List <KeyValuePair <double, double> >();
                while (!reader.EndOfStream)
                {
                    line = reader.ReadLine();
                    string[] items = line.Split(new char[] { ' ' },
                                                StringSplitOptions.RemoveEmptyEntries);
                    if (items.Length != 2)
                    {
                        throw new IOException("Incorrect number of arguments!");
                    }
                    KeyValuePair <double, double> pair =
                        new KeyValuePair <double, double>(Convert.ToDouble(items[0]), Convert.ToDouble(items[1]));
                    list.Add(pair);
                }
                ContinuousFuzzySet <double, double> set = new ContinuousFuzzySet <double, double>(list);
                ElementsCache.Add(set);
                listBox1.Items.Add("Set #" + ElementsCache.Count.ToString());
                ViewSet(set, chart1);
            }
            catch (Exception ex)
            {
                string message = "An exception has occured. Details: " +
                                 ex.Message;
                MessageBox.Show(message, "Message");
            }
        }