예제 #1
0
 /// <summary>
 /// Reiter’s HS-Tree Algorithm 3
 /// </summary>
 /// <param name="paths">Already explored paths</param>
 /// <param name="newPathLabel">the newPathLabel to be explored</param>
 /// <returns>Flag indicating successful addition</returns>
 private bool CheckAndAddPath(List <HSTreePath> paths, HSTreePath newPathLabel)
 {
     if (!paths.Contains(newPathLabel))
     {
         paths.Add(newPathLabel);
         return(true);
     }
     return(false);
 }
예제 #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);
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Reiter’s HS-Tree Algorithm 3
        /// </summary>
        /// <param name="paths">Already explored paths</param>
        /// <param name="newPathLabel">the newPathLabel to be explored</param>
        /// <returns>Flag indicating successful addition</returns>
        private bool CheckAndAddPath(List <HSTreePath> paths, HSTreePath newPathLabel)
        {
            try
            {
                if (!paths.Contains(newPathLabel))
                {
                    paths.Add(newPathLabel);
                    return(true);
                }
            }
            catch (Exception)
            {
                //Getiing index out of rangle when running multiple threads
                return(false);
            }

            return(false);
        }
예제 #4
0
        /// <summary>
        /// Is Subset Of Path Does Exit In Diagnosis
        /// For example:
        /// path = {'a', 'b'}   diagnosis.TheDiagnosis = {'a','b','c'}  ===> Return true
        /// path = {'a', 'b'}   diagnosis.TheDiagnosis = {'a','c','d'}  ===> Return false
        /// </summary>
        /// <param name="newPathLabel"></param>
        /// <param name="diagnosisSet"></param>
        /// <returns></returns>
        public static bool IsSubsetOfPathDoesExitInDiagnosis(HSTreePath newPathLabel, DiagnosisSet diagnosisSet)
        {
            //Check if in any diagnosis:
            for (int j = 0; j < diagnosisSet.Diagnoses.Count; j++)
            {
                Diagnosis diagnosis = diagnosisSet.Diagnoses[j];


                List <Gate> path = newPathLabel.Path;

                //Check if path is in diagnosis:
                if (!diagnosis.TheDiagnosis.Except(path).Any())
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #5
0
        /// <summary>
        /// Is A Conflict Exist Conj With "newPathLabel" Is Empty
        /// </summary>
        /// <param name="conflicts"></param>
        /// <param name="newPathLabel"></param>
        /// <returns> Return the conflict if found. If not found return null </returns>
        public static Conflict IsAConflictExistConjWithPathLabelIsEmpty(ConflictSet conflicts, HSTreePath newPathLabel)
        {
            List <Gate> pathLabelsGates = newPathLabel.Path;

            //Check if in any conflict:
            for (int j = 0; j < conflicts.Conflicts.Count; j++)
            {
                Conflict conflict = conflicts.Conflicts[j];

                List <Gate> conflictGats = conflict.TheConflict;

                //Check if pathLabelsGates Conj (CHITOCH)  conflictGats is empty
                bool intersect = conflictGats.Intersect(pathLabelsGates).Any();
                if (!intersect)
                {
                    return(conflict);
                }
            }

            return(null);
        }
예제 #6
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();
        }
예제 #7
0
 public HSTreeNode(HSTreePath pathLabel)
 {
     PathLabel = pathLabel;
 }
예제 #8
0
 public HSTreeNode(Conflict conflict)
 {
     Conflict  = conflict;
     PathLabel = new HSTreePath();
 }