/// <summary> /// Reiter’s HS-Tree Algorithm 1 /// </summary> /// <param name="conflicts"></param> /// <returns></returns> private DiagnosisSet DiagnoseMainLoop(ConflictSet conflicts) { DiagnosisSet diagnosisSet = new DiagnosisSet(); List <HSTreePath> paths = new List <HSTreePath>(); List <HSTreeNode> newNodes = new List <HSTreeNode>(); List <HSTreeNode> nodesToExpand = HSHelper.ConvertConflictSetToNodes(conflicts); //nodesToExpand.RemoveAt(1); //Not sure if this should be empty or not.... //conflicts = new ConflictSet(); //conflicts.Conflicts = new List<Conflict>(); while (nodesToExpand.Count > 0) { newNodes = new List <HSTreeNode>(); HSTreeNode node = nodesToExpand[0]; nodesToExpand.RemoveAt(0); for (int i = 0; i < node.Conflict.TheConflict.Count; i++) { Gate c = node.Conflict.TheConflict[i]; Expand(node, c, diagnosisSet, paths, conflicts, newNodes); } if (nodesToExpand.Count > 3000) { Debug.WriteLine("Nodes to expand over 3000! ignore this obs"); return(diagnosisSet); } //Adding new nodes foreach (HSTreeNode nodeToAdd in newNodes) { bool foundSameNode = false; foreach (HSTreeNode existingNode in nodesToExpand) { foundSameNode = existingNode.CompareTo(nodeToAdd) == 0; if (foundSameNode) { break; } } if (!foundSameNode) { nodesToExpand.Add(nodeToAdd); } } //nodesToExpand.AddRange(newNodes); } return(diagnosisSet); }
/// <summary> /// Reiter’s HS-Tree Algorithm 1 /// </summary> /// <param name="conflicts"></param> /// <returns></returns> private DiagnosisSet DiagnoseMainLoop(ConflictSet conflicts) { DiagnosisSet diagnosisSet = new DiagnosisSet(); List <HSTreePath> paths = new List <HSTreePath>(); List <HSTreeNode> newNodes = new List <HSTreeNode>(); List <HSTreeNode> nodesToExpand = HSHelper.ConvertConflictSetToNodes(conflicts); //nodesToExpand.RemoveAt(1); //Not sure if this should be empty or not.... //conflicts = new ConflictSet(); //conflicts.Conflicts = new List<Conflict>(); int size = 1; int lastSize = 0; while (size != lastSize || Process.GetCurrentProcess().Threads.OfType <ProcessThread>().Where(t => t.ThreadState == System.Diagnostics.ThreadState.Running).Count() != 1) { //for (int j = 0; j < (size - lastSize); j++) Parallel.For(0, size - lastSize, j => { HSTreeNode node = nodesToExpand[lastSize + j]; // Parallelize the outer loop to partition the source array by rows. Parallel.For(0, node.Conflict.TheConflict.Count, i => { Gate c = node.Conflict.TheConflict[i]; Expand(node, c, diagnosisSet, paths, conflicts, nodesToExpand); }); // Parallel.For }); lastSize = size; /* * for (int i = 0; i < nodesToExpand.Count; i++) * { * HSTreeNode node = nodesToExpand[i]; * System.Diagnostics.Debug.WriteLine(node.ToString()); * }*/ size = nodesToExpand.Count; if (size - lastSize > 3000) { Debug.WriteLine("Nodes to expand over 3000! ignore this obs"); return(diagnosisSet); } } return(diagnosisSet); }
/// <summary> /// Reiter’s HS-Tree Algorithm 1 /// </summary> /// <param name="conflicts"></param> /// <returns></returns> private DiagnosisSet DiagnoseMainLoop(ConflictSet conflicts) { DiagnosisSet diagnosisSet = new DiagnosisSet(); List <HSTreePath> paths = new List <HSTreePath>(); List <HSTreeNode> newNodes = new List <HSTreeNode>(); List <HSTreeNode> nodesToExpand = HSHelper.ConvertConflictSetToNodes(conflicts); //nodesToExpand.RemoveAt(1); //Not sure if this should be empty or not.... //conflicts = new ConflictSet(); //conflicts.Conflicts = new List<Conflict>(); int size = 1; int lastSize = 0; while (size != lastSize || Process.GetCurrentProcess().Threads.OfType <ProcessThread>().Where(t => t.ThreadState == System.Diagnostics.ThreadState.Running).Count() != 1) { for (int j = 0; j < (size - lastSize); j++) { HSTreeNode node = nodesToExpand[lastSize + j]; for (int i = 0; i < node.Conflict.TheConflict.Count; i++) { Gate c = node.Conflict.TheConflict[i]; Thread thread = new Thread(() => Expand(node, c, diagnosisSet, paths, conflicts, nodesToExpand)); thread.Start(); } } lastSize = size; /* * for (int i = 0; i < nodesToExpand.Count; i++) * { * HSTreeNode node = nodesToExpand[i]; * System.Diagnostics.Debug.WriteLine(node.ToString()); * }*/ _waitEvent.WaitOne(); size = nodesToExpand.Count; if (size - lastSize > 3000) { Debug.WriteLine("Nodes to expand over 3000! ignore this obs"); return(diagnosisSet); } } return(diagnosisSet); }