Ejemplo n.º 1
0
        private void PushButton_Click(object sender, RoutedEventArgs e)
        {
            var str = InputFormulaTextBox.GetTextWithoutSubs();

            if (Formula.IsFormula(str) == false)
            {
                MessageBox.Show("это не формула");
                return;
            }

            var formula = new Formula(str);

            var B = new Formula("(A→(¬(¬A)))");
            var C = new Formula("(A→A)");
            var L = new List <Formula>();

            //L.Add(B);
            L.Add(C);

            //var hyp = new Hypotheses(L);
            Hypotheses hyp = null;

            //var inference = (new InferenceFinderBruteForce(formula, hyp)).BuildInference();
            //var inference = InferenceFinder.FindInference(formula, hyp);
            var inference = InferenceFinder.FindInference(hyp, formula);

            InferenceTextBox.Text = inference.ToString();
        }
Ejemplo n.º 2
0
        public static Inference FindInference(Hypotheses hypotheses, Formula target)
        {
            var inference = new Inference(hypotheses);

            if (inference.Push(target))
            {
                inference.Minimize();
                return(inference);
            }

            var formulas = new HashSet <Formula>();

            if (hypotheses is null == false)
            {
                foreach (var h in hypotheses)
                {
                    inference.Push(h);
                    formulas.Add(h);
                }
            }

            ParseFormula(target, formulas);

            var addingFormulas = new Thread(() => AddingFormulas(inference, formulas, target));
            var genFormulas    = new Thread(() => GenFormulas(inference, formulas, target));

            addingFormulas.Start();
            genFormulas.Start();

            while (true)
            {
                lock (inference)
                {
                    if (inference.Push(target) || inference.Contains(target))
                    {
                        break;
                    }
                }

                Thread.Sleep(1000);
            }

            addingFormulas.Abort();
            genFormulas.Abort();

            inference.Minimize();
            return(inference);
        }
Ejemplo n.º 3
0
 public void Remove(char c)
 {
     //Debug.WriteLine("({0},{1}) : ~{2}", X, Y, c);
     if (Resolved)
     {
         //Debug.WriteLine("known...");
         return;
     }
     Hypotheses.Remove(c);
     //si retirer ça nous permet de résoudre, on le dit a la grille
     if (Resolved)
     {
         //Debug.WriteLine("({0},{1}) -> {2}",X,Y,Value);
         Grille.PropagerCertitudes(Value, X, Y);
     }
 }
Ejemplo n.º 4
0
 public InferenceFinderBruteForce(Formula target, Hypotheses hypotheses = null)
 {
     Target     = target;
     Hypotheses = hypotheses;
     _inference = null;
 }
Ejemplo n.º 5
0
        public override string ToString()
        {
            return(string.Format("({0},{1}) : {2}", X, Y,
                                 Hypotheses.Select(h => h.ToString()).Aggregate((s, v) => s + ", " + v)));
//            return Resolved ? Value.ToString() : Hypotheses.Aggregate("", (s,v) => s + v);
        }
Ejemplo n.º 6
0
 public void addHypothese(char h)
 {
     Hypotheses.Add(h);
 }
Ejemplo n.º 7
0
        private void КритерійПірсонаToolStripMenuItem_Click(object sender, EventArgs e)
        {
            parseParamsFromForm();

            logTextBox.Text += Hypotheses.KZPirsona(stat, m_aplha);
        }
Ejemplo n.º 8
0
        private void КритерійКолмогороваToolStripMenuItem_Click(object sender, EventArgs e)
        {
            parseParamsFromForm();

            logTextBox.Text += Hypotheses.KZKolvogorov(stat, m_aplha);
        }
Ejemplo n.º 9
0
        public static Inference FindInference(Formula target, Hypotheses hypotheses)
        {
            var inference = new Inference(hypotheses);

            if (inference.Push(target))
            {
                inference.Minimize();
                return(inference);
            }
            var formulas = new HashSet <Formula>();

            if (hypotheses is null == false)
            {
                foreach (var h in hypotheses)
                {
                    inference.Push(h);
                    formulas.Add(h);
                }
            }

            ParseFormula(target, formulas);

            while (true)
            {
                var newF = new HashSet <Formula>();

                //foreach (var a in Axioms.GetAxioms())
                //{
                //    GenAxioms(target, formulas, a, inference, newF);
                //}

                Parallel.ForEach(Axioms.GetAxioms(), a => GenAxioms(target, formulas, a, inference, newF));

                foreach (var f in newF)
                {
                    formulas.Add(f);
                }
                newF.Clear();

                var ok = true;
                while (ok)
                {
                    ok = false;
                    foreach (var f in formulas)
                    {
                        if (inference.Push(f))
                        {
                            ok = true;
                            if (target.Equals(f))
                            {
                                ok = false;
                                break;
                            }
                        }
                    }
                }

                if (inference.Contains(target))
                {
                    break;
                }
            }

            inference.Minimize();
            return(inference);
        }