Exemplo n.º 1
0
        private int Applicable(Regle r)
        {
            int iNiveauMax = -1;

            foreach (IFait f in r.Hypot)
            {
                IFait fTrouve = _bdFaits.Chercher(f.Libelle());
                if (fTrouve == null)
                {
                    if (f.Question() != null)
                    {
                        fTrouve = CalculFait.Determiner(f, this);
                        _bdFaits.Ajouter(fTrouve);
                        iNiveauMax = Math.Max(iNiveauMax, 0);
                    }
                    else
                    {
                        return(-1);
                    }
                }
                if (!fTrouve.Valeur().Equals(f.Valeur()))
                {
                    return(-1);
                }
                else
                {
                    iNiveauMax = Math.Max(iNiveauMax, fTrouve.Niveau());
                }
            }
            return(iNiveauMax);
        }
Exemplo n.º 2
0
        public void Resoudre()
        {
            _ihm.AfficherRegles(_bdRegles.Regles);
            bool       resteRegles = true;
            BaseRegles reglesDispo = new BaseRegles
            {
                Regles = new List <Regle>(_bdRegles.Regles)
            };

            _bdFaits.RaZ();
            while (resteRegles)
            {
                Tuple <Regle, int> regleIns = TrouverDispo(reglesDispo);
                if (regleIns != null)
                {
                    IFait faitIns = regleIns.Item1.These;
                    faitIns.DefinirNiveau(regleIns.Item2 + 1);
                    _bdFaits.Ajouter(faitIns);
                    reglesDispo.Supprimer(regleIns.Item1);
                }
                else
                {
                    resteRegles = false;
                }
            }
            _ihm.AfficherFaits(_bdFaits.Faits);
        }
Exemplo n.º 3
0
 internal static IFait Determiner(IFait fFait, Moteur mMoteur)
 {
     if (fFait.GetType() == typeof(FaitEntier))
     {
         int iTmp = mMoteur.QuestionEntier(fFait.Question());
         return(new FaitEntier(fFait.Libelle(), iTmp, null, 0));
     }
     else
     {
         bool bTmp = mMoteur.QuestionLogique(fFait.Question());
         return(new FaitLogique(fFait.Libelle(), bTmp, null, 0));
     }
 }
Exemplo n.º 4
0
        public object Valeur(string Libelle_)
        {
            IFait f = Faits.FirstOrDefault(x => x.Libelle().Equals(Libelle_));

            if (f != null)
            {
                return(f.Valeur());
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 5
0
 public void AjouterRegle(string sRegle)
 {
     string[] aTmp = sRegle.Split(new[] { " : " }, StringSplitOptions.RemoveEmptyEntries);
     if (aTmp.Length == 2)
     {
         string[] aHypotThese = aTmp[1].Split(new[] { "SI", " ALORS " }, StringSplitOptions.RemoveEmptyEntries);
         if (aHypotThese.Length == 2)
         {
             List <IFait> lHypot = new List <IFait>();
             string[]     aHypot = aHypotThese[0].Split(new[] { " ET " }, StringSplitOptions.RemoveEmptyEntries);
             foreach (string sHypot in aHypot)
             {
                 lHypot.Add(CalculFait.Determiner(sHypot));
             }
             IFait these = CalculFait.Determiner(aHypotThese[1].Trim());
             _bdRegles.Ajouter(new Regle(aTmp[0], lHypot, these));
         }
     }
 }
Exemplo n.º 6
0
 public void Ajouter(IFait f)
 {
     _Faits.Add(f);
 }
Exemplo n.º 7
0
 public Regle(string nom, List <IFait> hypot, IFait these)
 {
     Nom   = nom;
     Hypot = hypot;
     These = these;
 }