/// <summary> (Constructor).
 /// Initialize a new ElementEquation with given properties.
 /// </summary>
 ///
 /// <param name="libelle">The label which will intialize the ElementEqualtion</param>
 /// <param name="stateFlag">
 /// The state flag which will initialize the ElementEquation.
 /// PresentWithoutNegation as default.
 /// </param>
 /// <param name="alwaysTrue">
 /// The alwaysTrue flag which will intialize the ElementEquation.
 /// False as default.
 /// </param>
 public ElementEquation(T libelle, ElementStateEnum stateFlag = ElementStateEnum.PresentWithoutNegation, bool alwaysTrue = false) : base(libelle, stateFlag)
 {
     this.AlwaysTrue = alwaysTrue;
 }
Exemple #2
0
 /// <summary> (Constructor).
 ///  Initialize a new element with an defined element.
 /// </summary>
 ///
 /// <param name="libelle">The label which will initialize the element.</param>
 public Element(T libelle, ElementStateEnum stateFlag = ElementStateEnum.Absent)
 {
     Libelle = libelle;
     State   = stateFlag;
 }
        /// <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);
            }
        }