예제 #1
0
        public void AnalyzeImplications()
        {
            Chains = new List <IList <Implication> >();
            Implication mutex;

            // parse all the implications and store in same chains the ones that
            // are linked together by mutex
            foreach (var implication in IB.Where(implication => implication.Mutex != string.Empty))
            {
                // get the mutexed implication and die if it does not exist
                mutex = IB.Get(implication.Mutex);
                if (mutex == null)
                {
                    throw new BREException("Implication " +
                                           implication.Label +
                                           " tries to Mutex the missing implication " +
                                           implication.Mutex);
                }

                // try first to find if the current implication or its mutexed one is somewhere
                // in a chain, else create a new chain.
                var found = false;
                foreach (var chain in Chains.Where(chain => (chain.Contains(implication)) || (chain.Contains(mutex))))
                {
                    found = true;
                    if (!chain.Contains(implication))
                    {
                        chain.Add(implication);
                    }
                    if (!chain.Contains(mutex))
                    {
                        chain.Add(mutex);
                    }
                    break;
                }

                if (found)
                {
                    continue;
                }
                {
                    IList <Implication> chain = new List <Implication>();
                    chain.Add(implication);
                    chain.Add(mutex);
                    Chains.Add(chain);
                }
            }

            // parse a second time to establish all cross references
            // are linked together by mutex
            foreach (var implication in IB)
            {
                foreach (var chain in Chains.Where(chain => chain.Contains(implication)))
                {
                    implication.MutexChain = chain;
                    break;
                }
            }
        }
예제 #2
0
        public void AnalyzeImplications()
        {
            Chains = new List <IList <Implication> >();
            Implication preconditionImplication;
            bool        found;
            int         posImplication;
            int         posPreconditionImplication;

            // parse all the implications and analyze precondition for errors
            foreach (Implication implication in IB)
            {
                if (implication.Precondition != String.Empty)
                {
                    // get the precondition implication and die if it does not exist
                    preconditionImplication = IB.Get(implication.Precondition);
                    if (preconditionImplication == null)
                    {
                        throw new BREException("Implication " +
                                               implication.Label +
                                               " is preconditionned by the missing implication " +
                                               implication.Precondition);
                    }

                    // check if the current implication and its precondition are not involved into
                    // a common mutex chain, and die if it happends
                    if ((implication.MutexChain != null) && (implication.MutexChain.Contains(preconditionImplication)))
                    {
                        throw new BREException("Implication " +
                                               implication.Label +
                                               " is preconditionned by the mutexed implication " +
                                               preconditionImplication.Label);
                    }

                    // assign the precondition implication to save time at execution
                    implication.PreconditionImplication = preconditionImplication;

                    // try first to find if the current implication or its precondition one is somewhere
                    // in a chain, else create a new chain.
                    found = false;
                    foreach (IList <Implication> chain in Chains)
                    {
                        posImplication             = chain.IndexOf(implication);
                        posPreconditionImplication = chain.IndexOf(preconditionImplication);

                        if ((posImplication >= 0) && (posPreconditionImplication >= 0))
                        {
                            found = true;
                            break;
                        }
                        else if (posImplication >= 0)
                        {
                            found = true;
                            chain.Insert(posImplication, preconditionImplication);
                            break;
                        }
                        else if (posPreconditionImplication >= 0)
                        {
                            found = true;
                            chain.Insert(posPreconditionImplication + 1, implication);
                            break;
                        }
                    }

                    if (!found)
                    {
                        IList <Implication> chain = new List <Implication>();
                        chain.Add(preconditionImplication);
                        chain.Add(implication);
                        Chains.Add(chain);
                    }
                }
            }

            int salience;

            foreach (IList <Implication> chain in Chains)
            {
                salience = chain.Count;
                foreach (Implication implication in chain)
                {
                    if (implication.Salience < salience)
                    {
                        implication.Salience = salience;
                    }
                    salience--;
                }
            }
        }