コード例 #1
0
        /// <summary>
        /// Generate a hypotheses from a file.
        /// </summary>
        ///
        /// <param name="hypothesesFilePath">The file to read's path.</param>
        ///
        /// <returns>
        /// The created hypotheses object.
        /// Null if the file can not be read of if an error occured during the file reading.
        /// </returns>
        static Hypotheses <string> GenerateHypothesesFromFile(string hypothesesFilePath)
        {
            try
            {
                string[] hypothesesFileLines = System.IO.File.ReadAllLines(hypothesesFilePath);

                Hypotheses <string> hypotheses = new Hypotheses <string>();

                foreach (string line in hypothesesFileLines)
                {
                    string toAdd = line.TrimStart().TrimEnd();

                    if (toAdd[0] == '!')
                    {
                        hypotheses.ListeHypotheses.Add(
                            new Element <string>(toAdd.Substring(1), ElementStateEnum.PresentWithNegation));
                    }
                    else
                    {
                        hypotheses.ListeHypotheses.Add(
                            new Element <string>(toAdd, ElementStateEnum.PresentWithoutNegation));
                    }
                }

                return(!hypotheses.IsEmpty() ? hypotheses : null);
            }
            catch (Exception exception)
            {
                Console.WriteLine("Error during the hypotheses's file reading : " + exception.ToString());
                return(null);
            }
        }
コード例 #2
0
        public bool Equals(Hypotheses <T> toTest)
        {
            if (this.ListeHypotheses.Count != toTest.ListeHypotheses.Count)
            {
                return(false);
            }

            for (int counter = 0; counter < ListeHypotheses.Count; counter++)
            {
                if (!ListeHypotheses[counter].Equals(toTest.ListeHypotheses[counter]))
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #3
0
        /// <summary> (Constructor).
        /// Solve the current system with the given hypotheses.
        /// </summary>
        ///
        /// <param name="hypotheses">Hypotheses used to solve the system.</param>
        ///
        /// <returns>The system after the algorithm.</returns>
        public Systeme <T> SolveWithHypotheses(Hypotheses <T> hypotheses)
        {
            Hypotheses <T> oldHypotheses;

            List <Element <T> > hypothesesList = hypotheses.ListeHypotheses.ToList();

            do
            {
                oldHypotheses = new Hypotheses <T>(hypotheses.ListeHypotheses.ToList());

                foreach (Element <T> hypothese in hypothesesList)
                {
                    if (hypothese.State != ElementStateEnum.Absent)
                    {
                        foreach (Equation <T> equation in Equations)
                        {
                            ElementEquation <T> premisse = equation.DoesPremissesContainsElement(hypothese);

                            if (premisse != null)
                            {
                                premisse.AlwaysTrue = true;
                            }

                            if (equation.ArePremissesTrue() && !hypotheses.Contains(equation.Conclusion))
                            {
                                hypotheses.AddHypothese(equation.Conclusion);
                            }
                        }
                    }
                }

                hypothesesList = hypotheses.ListeHypotheses.ToList();
            } while (!hypotheses.Equals(oldHypotheses));

            return(this);
        }