Exemplo n.º 1
0
        /// <summary>
        /// Reiter’s HS-Tree Algorithm 2
        /// </summary>
        /// <param name="existingNode"></param>
        /// <param name="c"></param>
        /// <param name="diagnosisSet"></param>
        /// <param name="paths"></param>
        /// <param name="conflicts"></param>
        /// <param name="newNodes"></param>
        private void Expand(HSTreeNode existingNode, Gate c, DiagnosisSet diagnosisSet, List <HSTreePath> paths, ConflictSet conflicts, List <HSTreeNode> newNodes)
        {
            HSTreePath newPathLabel = new HSTreePath(existingNode.PathLabel, c);

            if (!HSHelper.IsSubsetOfPathDoesExitInDiagnosis(newPathLabel, diagnosisSet) &&
                CheckAndAddPath(paths, newPathLabel))
            {
                HSTreeNode node = new HSTreeNode(newPathLabel);

                Conflict S = HSHelper.IsAConflictExistConjWithPathLabelIsEmpty(conflicts, newPathLabel);

                if (S != null)
                {
                    node.Conflict = S;
                }
                else
                {
                    //consistency checker, which tests if the new node is a diagnosis or returns a minimal conflict otherwise.
                    bool IsDiagnosis = ConstraintSystemSolver.Instance.CheckConsistensy(_observation, node.PathLabel.Path);

                    //If its not a diagnosis we add it as a conflict
                    if (!IsDiagnosis)
                    {
                        node.Conflict = new Conflict(node.PathLabel.Path);
                    }
                }

                lock (_expendLock)
                {
                    if (node.Conflict != null && node.Conflict.TheConflict.Count > 0)
                    {
                        // Add if not exist
                        if (!newNodes.Any(e => e.CompareTo(node) == 0))
                        {
                            newNodes.Add(node);
                        }

                        // Add if not exist
                        if (!conflicts.Conflicts.Contains(node.Conflict))
                        {
                            conflicts.Conflicts.Add(node.Conflict);
                        }
                    }
                    else if (!HSHelper.IsSubsetOfPathDoesExitInDiagnosis(newPathLabel, diagnosisSet))
                    {
                        Diagnosis diagnosis = new Diagnosis(node.PathLabel.Path);
                        diagnosisSet.AddDiagnosis(diagnosis);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reiter’s HS-Tree Algorithm 2
        /// </summary>
        /// <param name="existingNode"></param>
        /// <param name="c"></param>
        /// <param name="diagnosisSet"></param>
        /// <param name="paths"></param>
        /// <param name="conflicts"></param>
        /// <param name="newNodes"></param>
        private void Expand(HSTreeNode existingNode, Gate c, DiagnosisSet diagnosisSet, List <HSTreePath> paths, ConflictSet conflicts, List <HSTreeNode> newNodes)
        {
            HSTreePath newPathLabel = new HSTreePath(existingNode.PathLabel, c);

            if (!HSHelper.IsSubsetOfPathDoesExitInDiagnosis(newPathLabel, diagnosisSet) &&
                CheckAndAddPath(paths, newPathLabel))
            {
                HSTreeNode node = new HSTreeNode(newPathLabel);

                Conflict S = HSHelper.IsAConflictExistConjWithPathLabelIsEmpty(conflicts, newPathLabel);

                if (S != null)
                {
                    node.Conflict = S;
                }
                else
                {
                    //consistency checker, which tests if the new node is a diagnosis or returns a minimal conflict otherwise.
                    bool IsDiagnosis = ConstraintSystemSolver.Instance.CheckConsistensy(_observation, node.PathLabel.Path);

                    //If its not a diagnosis we add it as a conflict
                    if (!IsDiagnosis)
                    {
                        node.Conflict = new Conflict(node.PathLabel.Path);
                    }
                }

                lock (_expendLock)
                {
                    if (node.Conflict != null && node.Conflict.TheConflict.Count > 0)
                    {
                        // Add if not exist
                        if (!newNodes.Any(e => e.CompareTo(node) == 0))
                        {
                            newNodes.Add(node);
                        }

                        // Add if not exist
                        if (!conflicts.Conflicts.Contains(node.Conflict))
                        {
                            conflicts.Conflicts.Add(node.Conflict);
                        }
                    }
                    else if (!HSHelper.IsSubsetOfPathDoesExitInDiagnosis(newPathLabel, diagnosisSet))
                    {
                        Diagnosis diagnosis = new Diagnosis(node.PathLabel.Path);
                        diagnosisSet.AddDiagnosis(diagnosis);
                        for (int i = 0; i < diagnosisSet.Diagnoses.Count; i++)
                        {
                            Diagnosis d = diagnosisSet.Diagnoses[i];

                            /// path = {'a', 'b'}   diagnosis.TheDiagnosis = {'a','b','c'}  ===> Return true
                            /// path = {'a', 'b'}   diagnosis.TheDiagnosis = {'a','c','d'}  ===> Return false
                            if (d.TheDiagnosis.Count <= newPathLabel.Path.Count)
                            {
                                continue;
                            }
                            if (d.TheDiagnosis.Except(newPathLabel.Path).Any())
                            {
                                diagnosisSet.Diagnoses.RemoveAt(i);
                                i--;
                            }
                        }
                    }
                }
            }

            _waitEvent.Set();
        }