Example #1
0
        /// <summary>
        /// Add all elements from systeme.premisses which are not in hypotheses.
        /// Add them with the State "Absent"
        /// </summary>
        ///
        /// <param name="systeme">The base system.</param>
        public void AddAbsentHypothesesFromSysteme(Systeme <T> systeme)
        {
            foreach (Equation <T> equation in systeme.Equations)
            {
                foreach (ElementEquation <T> premisse in equation.Premisses)
                {
                    // Search the premisse in hypotheses
                    bool isPremissePresent = false;
                    for (int counter = 0; counter < ListeHypotheses.Count && !isPremissePresent; counter++)
                    {
                        isPremissePresent = ListeHypotheses[counter].Libelle.Equals(premisse.Libelle);
                    }

                    if (!isPremissePresent)
                    {
                        ListeHypotheses.Add(new Element <T>(premisse.Libelle, ElementStateEnum.Absent));
                    }
                }
            }
        }
        /// <summary>
        /// Generate a systeme from a file.
        /// </summary>
        ///
        /// <param name="systemeFilePath">The file to read's path.</param>
        ///
        /// <returns>
        /// The created systeme object.
        /// Null if the file can not be read of if an error occured during the file reading.
        /// </returns>
        static Systeme <string> GenerateSystemeFromFile(string systemeFilePath)
        {
            try
            {
                string[] systemeFileLines = System.IO.File.ReadAllLines(systemeFilePath);

                Systeme <string> systeme = new Systeme <string>();

                foreach (string line in systemeFileLines)
                {
                    List <ElementEquation <string> > premissesEquations = new List <ElementEquation <string> >();

                    string           currentWord = "";
                    int              separatorPremissesAndConclusionIndex = 0;
                    ElementStateEnum stateFlag = ElementStateEnum.PresentWithoutNegation;

                    // Read premisses
                    for (int counter = 0; counter < line.Length && line[counter] != '='; counter++)
                    {
                        if (line[counter] == '+' || line[counter + 1] == '=')
                        {
                            premissesEquations.Add(new ElementEquation <string>(currentWord.TrimStart().TrimEnd(), stateFlag));
                            currentWord = "";
                            stateFlag   = ElementStateEnum.PresentWithoutNegation;
                        }
                        else if (currentWord.TrimStart() == "" && line[counter] == '!')
                        {
                            stateFlag = ElementStateEnum.PresentWithNegation;
                        }
                        else
                        {
                            currentWord += line[counter];
                        }

                        if (counter < line.Length - 1 && line[counter + 1] == '=')
                        {
                            separatorPremissesAndConclusionIndex = counter + 1;
                        }
                    }

                    // Read conclusion
                    stateFlag = ElementStateEnum.PresentWithoutNegation;
                    string conclusion = "";
                    for (int counter = separatorPremissesAndConclusionIndex + 1; counter < line.Length; counter++)
                    {
                        if (currentWord.TrimStart() == "" && line[counter] == '!')
                        {
                            stateFlag = ElementStateEnum.PresentWithNegation;
                        }

                        conclusion += line[counter];
                    }

                    Element <string> conclusionEquation = new Element <string>(conclusion.TrimStart().TrimEnd(), stateFlag);

                    systeme.Equations.Add(
                        new Equation <string>(premissesEquations, conclusionEquation));
                }

                return(systeme.Equations.Count != 0 ? systeme : null);
            }
            catch (Exception exception)
            {
                Console.WriteLine("Error during the system's file reading : " + exception.ToString());
                return(null);
            }
        }