예제 #1
0
 private void fourthToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (dgwSets.SelectedRows.Count != 2)
     {
         return;
     }
     if ((dgwSets.SelectedRows[0].Tag as FuzzySet).Discrete != (dgwSets.SelectedRows[1].Tag as FuzzySet).Discrete)
     {
         return;
     }
     if (dgwSets.SelectedRows[0].Tag.GetType() != dgwSets.SelectedRows[1].Tag.GetType())
     {
         return;
     }
     if (dgwSets.SelectedRows[0].Tag is FuzzySet1D)
     {
         FuzzySet1D set = (dgwSets.SelectedRows[0].Tag as FuzzySet1D) / (dgwSets.SelectedRows[1].Tag as FuzzySet1D);
         sets.Add(set);
     }
     if (dgwSets.SelectedRows[0].Tag is FuzzySet2D)
     {
         FuzzySet2D set = (dgwSets.SelectedRows[0].Tag as FuzzySet2D) / (dgwSets.SelectedRows[1].Tag as FuzzySet2D);
         sets.Add(set);
     }
     UpdateListToDgw();
 }
예제 #2
0
        private void btnCreateNew_Click(object sender, EventArgs e)
        {
            {
                FuzzySet1D fs = new FuzzySet1D();
                fs.Discrete = false;

                FParser parser = new FParser();
                for (int i = 0; i < FuzzySet.maxDotCount; i++)
                {
                    double x = 1.0 * i * (FuzzySet.toX - FuzzySet.fromX) / FuzzySet.maxDotCount + FuzzySet.fromX;
                    parser.Eval(tbFormula.Text, x);
                    if (!parser.SyntaxCorrect)
                    {
                        MessageBox.Show(parser.ErrText, "Синтаксична помилка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    fs.AddDot(x, parser.Result());
                }
                for (int i = 0; i < tbFormula.Text.Length; i++)
                {
                    if (Char.IsLetterOrDigit(tbFormula.Text[i]))
                    {
                        fs.Name += tbFormula.Text[i];
                    }
                }
                sets.Add(fs);
            }
            UpdateListToDgw();
        }
예제 #3
0
 private void tbDotDel_Click(object sender, EventArgs e)
 {
     if (!(dgwItems.Tag as FuzzySet).Discrete)
     {
         return;
     }
     if (dgwItems.Tag is FuzzySet1D)
     {
         FuzzySet1D set = dgwItems.Tag as FuzzySet1D;
         foreach (DataGridViewRow row in dgwItems.SelectedRows)
         {
             set.RemoveDot(double.Parse(row.Cells[0].Value.ToString()));
         }
         set.ToMatrix(dgwItems);
         pGraph.Tag = set.Render(pGraph.Size);
         pGraph.Invalidate();
     }
     if (dgwItems.Tag is FuzzySet2D)
     {
         FuzzySet2D set = dgwItems.Tag as FuzzySet2D;
         foreach (DataGridViewCell cell in dgwItems.SelectedCells)
         {
             if (dgwItems.Columns[cell.ColumnIndex].Tag != null && dgwItems.Rows[cell.RowIndex].Tag != null)
             {
                 set.RemoveDot((double)dgwItems.Columns[cell.ColumnIndex].Tag, (double)dgwItems.Rows[cell.RowIndex].Tag);
             }
         }
         set.ToMatrix(dgwItems);
         pGraph.Tag = set.Render(pGraph.Size);
         pGraph.Invalidate();
     }
 }
예제 #4
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            switch (sType)
            {
            case StandartSet.NormalDistribution:
                res = FuzzySet1D.CreateNormalDistribution((double)dgwMain.Rows[0].Cells[1].Value,
                                                          (double)dgwMain.Rows[1].Cells[1].Value);
                break;

            case StandartSet.Triangle:
                res = FuzzySet1D.CreateTriangle(
                    (double)dgwMain.Rows[0].Cells[1].Value,
                    (double)dgwMain.Rows[1].Cells[1].Value,
                    (double)dgwMain.Rows[2].Cells[1].Value);
                break;

            case StandartSet.Trapeze:
                res = FuzzySet1D.CreateTrapeze(
                    (double)dgwMain.Rows[0].Cells[1].Value,
                    (double)dgwMain.Rows[1].Cells[1].Value,
                    (double)dgwMain.Rows[2].Cells[1].Value,
                    (double)dgwMain.Rows[3].Cells[1].Value);
                break;
            }
            Close();
        }
예제 #5
0
        private void неперервнаToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FuzzySet1D fs = new FuzzySet1D();

            fs.Discrete = false;
            sets.Add(fs);
            UpdateListToDgw();
        }
예제 #6
0
        private void nineteenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FuzzySet1D res = StandartSetForm.GetSet(StandartSet.Trapeze);

            if (res != null)
            {
                sets.Add(res);
                UpdateListToDgw();
            }
        }
예제 #7
0
        private void трикутнаМножинаToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FuzzySet1D res = StandartSetForm.GetSet(StandartSet.Triangle);

            if (res != null)
            {
                sets.Add(res);
                UpdateListToDgw();
            }
        }
예제 #8
0
        private void seventeenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FuzzySet1D res = StandartSetForm.GetSet(StandartSet.NormalDistribution);

            if (res != null)
            {
                sets.Add(res);
                UpdateListToDgw();
            }
        }
예제 #9
0
 private void зберегтиToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (dgwSets.SelectedRows.Count != 1)
     {
         return;
     }
     if (dgwSets.SelectedRows[0].Tag is FuzzySet1D)
     {
         FuzzySet1D set = dgwSets.SelectedRows[0].Tag as FuzzySet1D;
         Common.DataBuffer.Instance.SaveDialog(new Matrix <double>(set.toMassiv()));
     }
 }
예제 #10
0
        private void перетинToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (dgwSets.SelectedRows.Count == 0)
            {
                return;
            }
            if (dgwSets.SelectedRows.Count == 1)
            {
                sets.Add(new FuzzySet1D(dgwSets.SelectedRows[0].Tag as FuzzySet1D));
            }

            else
            {
                for (int i = 1; i < dgwSets.SelectedRows.Count; i++)
                {
                    if ((dgwSets.SelectedRows[i].Tag as FuzzySet).Discrete != (dgwSets.SelectedRows[0].Tag as FuzzySet).Discrete)
                    {
                        return;
                    }
                }
                for (int i = 1; i < dgwSets.SelectedRows.Count; i++)
                {
                    if (((dgwSets.SelectedRows[i].Tag is FuzzySet1D) && (dgwSets.SelectedRows[0].Tag is FuzzySet2D)) ||
                        ((dgwSets.SelectedRows[i].Tag is FuzzySet2D) && (dgwSets.SelectedRows[0].Tag is FuzzySet1D)))
                    {
                        return;
                    }
                }
                if (dgwSets.SelectedRows[0].Tag is FuzzySet1D)
                {
                    FuzzySet1D set = (dgwSets.SelectedRows[0].Tag as FuzzySet1D) & (dgwSets.SelectedRows[1].Tag as FuzzySet1D);
                    for (int i = 2; i < dgwSets.SelectedRows.Count; i++)
                    {
                        set = set & (dgwSets.SelectedRows[i].Tag as FuzzySet1D);
                    }
                    sets.Add(set);
                }
                if (dgwSets.SelectedRows[0].Tag is FuzzySet2D)
                {
                    FuzzySet2D set = (dgwSets.SelectedRows[0].Tag as FuzzySet2D) & (dgwSets.SelectedRows[1].Tag as FuzzySet2D);
                    for (int i = 2; i < dgwSets.SelectedRows.Count; i++)
                    {
                        set = set & (dgwSets.SelectedRows[i].Tag as FuzzySet2D);
                    }
                    sets.Add(set);
                }
            }
            UpdateListToDgw();
        }
예제 #11
0
        private void завантажитиToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Matrix <double> data = (Common.DataBuffer.Instance.LoadDialog(FuzzySet1D.ValidationCallback) as Matrix <double>);

            if (data == null)
            {
                return;
            }
            FuzzySet1D res;

            if (MessageBox.Show("Завантажити як дискретну множину?", "Завантаження даних", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                res = new FuzzySet1D(data.Value, true);
            }
            else
            {
                res = new FuzzySet1D(data.Value, false);
            }
            sets.Add(res);
            UpdateListToDgw();
        }
예제 #12
0
 private void btnDFormula_Click(object sender, EventArgs e)
 {
     if (dgwItems.Tag == null)
     {
         return;
     }
     if (dgwItems.Tag is FuzzySet1D)
     {
         FuzzySet1D set = dgwItems.Tag as FuzzySet1D;
         double     x   = 0.0;
         try
         {
             x = double.Parse(tbMuX.Text);
         }
         catch
         {
             tbMuX.Text = "";
             return;
         }
         tbMuRes.Text = set.Mu(x).ToString();
     }
     else
     {
         FuzzySet2D set = dgwItems.Tag as FuzzySet2D;
         double     x   = 0.0;
         double     y   = 0.0;
         try
         {
             x = double.Parse(tbMuX1.Text);
             y = double.Parse(tbMuX2.Text);
         }
         catch
         {
             tbMuX1.Text = "";
             tbMuX2.Text = "";
             return;
         }
         tbMuRes.Text = set.Mu(x, y).ToString();
     }
 }
예제 #13
0
        private void Y()
        {
            if (cTk.Type != Token.MULT && cTk.Type != Token.COMPOS)
            {
                return;
            }
            int tType = cTk.Type;

            GetToken();
            F();
            if (tType == Token.MULT)
            {
                FuzzySet1D s1 = stack.Pop() as FuzzySet1D;
                FuzzySet1D s2 = stack.Pop() as FuzzySet1D;
                if (s1 == null || s2 == null)
                {
                    throw new SemError("Декартів добуток для двовимірних нечітких множин не визначено");
                }
                FuzzySet2D res = s1 * s2;
                if (res != null)
                {
                    stack.Push(s1 * s2);
                }
                else
                {
                    throw new SemError("Помилка при декартовому добутку");
                }
            }
            if (tType == Token.COMPOS)
            {
                FuzzySet2D s1 = stack.Pop() as FuzzySet2D;
                FuzzySet2D s2 = stack.Pop() as FuzzySet2D;
                if (s1 == null || s2 == null)
                {
                    throw new SemError("Композиція визначена тільки для двовимірних множин");
                }
                stack.Push(FuzzySet2D.MaxMinCompose(s1, s2));
            }
            Y();
        }
예제 #14
0
 private void btnAddDot_Click(object sender, EventArgs e)
 {
     if (!(dgwItems.Tag as FuzzySet).Discrete)
     {
         return;
     }
     if (dgwItems.Tag is FuzzySet1D)
     {
         FuzzySet1D set = dgwItems.Tag as FuzzySet1D;
         try
         {
             double x = double.Parse(tbDotX1.Text);
             double y = double.Parse(tbDotX2.Text);
             set.AddDot(x, y);
         }
         catch { return; }
         set.ToMatrix(dgwItems);
         pGraph.Tag = set.Render(pGraph.Size);
         pGraph.Invalidate();
     }
     if (dgwItems.Tag is FuzzySet2D)
     {
         FuzzySet2D set = dgwItems.Tag as FuzzySet2D;
         try
         {
             double x = double.Parse(tbDotX1.Text);
             double y = double.Parse(tbDotX2.Text);
             double z = double.Parse(tbDotX3.Text);
             set.RemoveDot(x, y);
             set.AddDot(x, y, z);
         }
         catch { return; }
         set.ToMatrix(dgwItems);
         pGraph.Tag = set.Render(pGraph.Size);
         pGraph.Invalidate();
     }
 }
예제 #15
0
        public frmModule()
        {
            InitializeComponent();
            #region Dgw & List
            sets = new List <FuzzySet>();
            dgwSets.DataSource = null;
            dgwSets.Columns.Clear();
            {
                DataGridViewColumn col = new DataGridViewTextBoxColumn();
                col.ValueType    = typeof(string);
                col.Name         = "Name";
                col.HeaderText   = Properties.Resources.Name;
                col.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                col.ReadOnly     = false;
                col.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                dgwSets.Columns.Add(col);
            }
            {
                DataGridViewColumn col = new DataGridViewTextBoxColumn();
                col.ValueType    = typeof(string);
                col.Name         = "Dimension";
                col.HeaderText   = Properties.Resources.Dimension;
                col.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                col.ReadOnly     = true;
                col.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                dgwSets.Columns.Add(col);
            }
            #endregion
#if DEBUG
            {
                FuzzySet1D fs = new FuzzySet1D();
                fs.Name = "A";
                fs.AddDot(1.0, 1.0);
                fs.AddDot(2.0, 0.3);
                fs.AddDot(2.5, 0.4);
                fs.AddDot(3.0, 0.7);
                sets.Add(fs);
            }
            {
                FuzzySet1D fs = new FuzzySet1D();
                fs.Name = "B";
                fs.AddDot(1.0, 0.2);
                fs.AddDot(3.0, 0.1);
                fs.AddDot(4.0, 0.3);
                fs.AddDot(5.0, 0.4);
                sets.Add(fs);
            }
            {
                FuzzySet1D fs = new FuzzySet1D();
                fs.Name = "C";
                fs.AddDot(1.0, 0.1);
                fs.AddDot(3.0, 0.1);
                fs.AddDot(4.0, 0.1);
                fs.AddDot(5.0, 0.1);
                sets.Add(fs);
            }
            {
                FuzzySet1D fs = new FuzzySet1D();
                fs.Name = "D";
                fs.AddDot(1.0, 0.5);
                fs.AddDot(3.0, 0.5);
                fs.AddDot(4.0, 0.5);
                fs.AddDot(5.0, 0.5);
                sets.Add(fs);
            }
            {
                FuzzySet2D fs = new FuzzySet2D();
                fs.Name = "E";
                fs.AddDot(1.0, 1.0, 0.5);
                fs.AddDot(3.0, 3.0, 0.5);
                fs.AddDot(4.0, 4.0, 0.5);
                fs.AddDot(5.0, 5.0, 0.5);
                sets.Add(fs);
            }
            {
                FuzzySet2D fs = new FuzzySet2D();
                fs.Name = "F";
                fs.AddDot(1.0, 0.3, 0.3);
                fs.AddDot(3.0, 1.7, 0.1);
                fs.AddDot(4.0, 3.6, 0.3);
                fs.AddDot(5.0, 8.0, 0.7);
                sets.Add(fs);
            }
#endif
            UpdateListToDgw();
        }
예제 #16
0
 private void btnCancel_Click(object sender, EventArgs e)
 {
     res = null;
     Close();
 }