private async void EditorDownRemove(Grid sender) { FaultTreeNode node = (FaultTreeNode)sender.DataContext; if (Config.Instance.ShowWarningWhenRemoval) { var t = await MessageDialogs.ShowWarningAsync("Are you sure you want to remove this node?"); if (t != MessageDialogResult.Affirmative) { return; } } var parents = this.ViewModel.FaultTree.Traverse()?.Where(n => n.Childs.Contains(node)).ToList(); parents?.ForEach(parent => parent.Childs.Remove(node)); parents?.ForEach(parent => parent.Childs.AddRange(node.Childs)); parents?.ForEach(parent => parent.Childs = parent.Childs.Distinct().ToList()); if (node is FaultTreeTerminalNode) { this.ViewModel.FaultTree.MarkovChain.RemoveVertex((FaultTreeTerminalNode)node); } this.ViewModel.RaisePropertyChanged("FaultTree"); }
private FaultTreeNode COPY(FaultTreeNode node) { FaultTreeNode node_copy, node_child, node_copy_p, node_copy_q = null; node_copy = new FaultTreeNode(); node_copy.Gate_Type = node.Gate_Type; node_copy.Node_Num = node.Node_Num; node_copy.Node_Type = node.Node_Type; node_copy.Edge_Uncertainty = node.Edge_Uncertainty; node_copy.Data = node.Data; node_child = node.Child; while (node_child != null) { node_copy_p = COPY(node_child); if (node_copy.Child == null) { node_copy.Child = node_copy_q = node_copy_p; } else { node_copy_q.Sibling = node_copy_p; node_copy_q = node_copy_p; } node_child = node_child.Sibling; } return(node_copy); }
void SetNodePositions(FaultTreeNode node) { FaultTreeNode temp = node.Child; int childNumber = 0; while (temp != null) { childNumber++; temp = temp.Sibling; } temp = node.Child; int shift = childNumber / 2; while (temp != null) { DrawLocation newDrawLocation = _listOfDrawLocations.Find(item => item.Node == temp); DrawLocation drawLocationOfCurrentNode = _listOfDrawLocations.Find(item => item.Node == node); int nodeDepth = temp.Depth; // Node distance 2^depth distance from max depth, node draw size is 3/2 to add a small distance // between nodes at the same depth, the value is divided by 2 (for each side of the tree) // bit-shifting is a more optimal solution for powers of 2 int spacing = ((int)(_nodeDrawSize.Width * 1f) * (1 << (2 * (_maxNodeDepth - nodeDepth)))) / childNumber; newDrawLocation.DrawPosition.X = drawLocationOfCurrentNode.DrawPosition.X - shift * spacing; shift--; // Increase the Y distance by a base distance plus 10 for each level // newDrawLocation.DrawPosition.Y = drawLocationOfCurrentNode.DrawPosition.Y + ((_nodeDrawSize.Height * nodeDepth) * 1.1f); newDrawLocation.DrawPosition.Y = drawLocationOfCurrentNode.DrawPosition.Y + 2f * _nodeDrawSize.Height; SetNodePositions(temp); temp = temp.Sibling; } }
private FaultTreeNode Build_FAT() { FaultTreeNode node, p, q = null; string endMark; node = new FaultTreeNode(); node.Edge_Uncertainty = Int32.Parse(file.ReadLine()); node.Node_Type = Int32.Parse(file.ReadLine()); node.Node_Num = Int32.Parse(file.ReadLine()); if (node.Node_Type == 1) { node.Gate_Type = Int32.Parse(file.ReadLine()); node.Data = "G" + node.Node_Num.ToString(); do { p = Build_FAT(); if (node.Child == null) { node.Child = p; } else { q.Sibling = p; } q = p; endMark = file.ReadLine(); } while (endMark.Equals("Y")); } else { node.Data = node.Node_Num.ToString(); // Add_Leaf_Node(node.Node_Num); } return(node); }
public bool Add(string value, string parentValue) { if (!_faultTree.Push(value, parentValue)) { TreeError.DisplayError(_faultTree.PrevErrorMsg); return(false); } if (_faultTree.NumOfNodes == 1) { _listOfDrawLocations.Add(new DrawLocation(new PointF(425.0f, 15.0f), _faultTree.MostRecentAddedNode)); } else { int currentNodeDepth = _faultTree.MostRecentAddedNode.Depth; if (currentNodeDepth > _maxNodeDepth) { _maxNodeDepth = currentNodeDepth; } // Find the added node in the list of draw locations, find its parent, add its child to this list for (int i = 0; i < _faultTree.NumOfNodes - 1; ++i) { FaultTreeNode temp = _listOfDrawLocations[i].Node.Child; while (temp != null) { if (temp == _faultTree.MostRecentAddedNode) { PointF nodePos = _listOfDrawLocations[i].DrawPosition; _listOfDrawLocations.Add(new DrawLocation(nodePos, _faultTree.MostRecentAddedNode)); break; } temp = temp.Sibling; } } } int charLengthOfNodeData = _faultTree.MostRecentAddedNode.Data.ToString().Length; if (charLengthOfNodeData > _maxCharLengthOfData) { _maxCharLengthOfData = charLengthOfNodeData; _nodeDrawSize.Width = (int)(_font.Size * _maxCharLengthOfData * 1.2f); if (_nodeDrawSize.Width < _nodeDrawSize.Height) { _nodeDrawSize.Width = _nodeDrawSize.Height; } } SetNodePositions(_faultTree.RootNode); EstablishNodeLines(); return(true); }
// public LeafNode leaflists { set; get; } public FaultTreeNode Build_fault_tree(string filename) { this.filename = filename; file = File.OpenText(filename); FaultTreeNode root = Build_FAT(); return(root); file.Close(); }
private void Build_lists(FaultTreeNode node) { if (node.Node_Type == 0) { Add_Leaf_Node(node.Node_Num); } else { FaultTreeNode temp = node.Child; while (temp != null) { Build_lists(temp); temp = temp.Sibling; } } }
public bool Add(FaultTreeNode root) { if (_faultTree.NumOfNodes == 0) { _faultTree.Push(root.Data, "null"); _listOfDrawLocations.Add(new DrawLocation(new PointF(425.0f, 15.0f), _faultTree.MostRecentAddedNode)); } FaultTreeNode child = root.Child; while (child != null) { _faultTree.Push(child.Data, root.Data); int currentNodeDepth = _faultTree.MostRecentAddedNode.Depth; if (currentNodeDepth > _maxNodeDepth) { _maxNodeDepth = currentNodeDepth; } for (int i = 0; i < _faultTree.NumOfNodes - 1; ++i) { if (_listOfDrawLocations[i].Node.Data == root.Data) { PointF nodePos = _listOfDrawLocations[i].DrawPosition; _listOfDrawLocations.Add(new DrawLocation(nodePos, _faultTree.MostRecentAddedNode)); break; } } Add(child); child = child.Sibling; } int charLengthOfNodeData = _faultTree.MostRecentAddedNode.Data.ToString().Length; if (charLengthOfNodeData > _maxCharLengthOfData) { _maxCharLengthOfData = charLengthOfNodeData; _nodeDrawSize.Width = (int)(_font.Size * _maxCharLengthOfData * 1.25f); if (_nodeDrawSize.Width < _nodeDrawSize.Height) { _nodeDrawSize.Width = _nodeDrawSize.Height; } } SetNodePositions(_faultTree.RootNode); EstablishNodeLines(); return(true); }
void EstablishNodeLines() { _listOfNodeLines.Clear(); for (int i = 0; i < _faultTree.NumOfNodes - 1; ++i) { FaultTreeNode child = _listOfDrawLocations[i].Node.Child; while (child != null) { NodeLine newLine = new NodeLine(); DrawLocation currentDrawLocation = _listOfDrawLocations.Find(item => (item.Node == child)); // DrawLocation currentDrawLocation = _listOfDrawLocations.Find(item => (item.Node == _listOfDrawLocations[i].Node.Child)); // Line start and end positions are translated to the center of each node newLine.Start.X = _listOfDrawLocations[i].DrawPosition.X + (_nodeDrawSize.Width / 2.0f); newLine.Start.Y = _listOfDrawLocations[i].DrawPosition.Y + (_nodeDrawSize.Height / 2.0f); newLine.End.X = currentDrawLocation.DrawPosition.X + (_nodeDrawSize.Width / 2.0f); newLine.End.Y = currentDrawLocation.DrawPosition.Y + (_nodeDrawSize.Height / 2.0f); _listOfNodeLines.Add(newLine); child = child.Sibling; } } }
public BinaryTreeNode FAT_BDD(FaultTreeNode FAT) { if (FAT.Node_Type == 0) { BinaryTreeNode BDD, left, right; BDD = new BinaryTreeNode(); left = new BinaryTreeNode(); right = new BinaryTreeNode(); BDD.Node_Num = FAT.Node_Num; BDD.Data = FAT.Node_Num.ToString(); left.Node_Num = 1; left.Data = "1"; right.Node_Num = 0; right.Data = "0"; BDD.Left = left; BDD.Right = right; return(BDD); } FaultTreeNode p, q; q = FAT.Child; p = q.Sibling; BinaryTreeNode itep, iteq; iteq = FAT_BDD(q); while (p != null) { itep = FAT_BDD(p); iteq = ToolFunction.APPLY(FAT.Gate_Type, iteq, itep); p = p.Sibling; } if (FAT.Gate_Type == 3) { iteq = ToolFunction.OPPOSE(iteq); } return(iteq); }
/// <summary> /// Helper method for recursive BDD construction from FaultTree. /// </summary> /// <param name="node"> /// The node. /// </param> /// <param name="nodeFactory"> /// The node factory. /// </param> /// <returns> /// The <see cref="BDDNode"/>. /// </returns> private BDDNode CreateBDD(FaultTreeNode node, BDDNodeFactory nodeFactory) { if (node.GetType() == typeof(FaultTreeTerminalNode)) { return(nodeFactory.CreateNode(((FaultTreeTerminalNode)node).Label)); } BDDOperator op = BDDOperator.BDD_OPERATOR_AND; if (node.GetType() == typeof(FaultTreeOrGateNode)) { op = BDDOperator.BDD_OPERATOR_OR; } BDDNode current = null; foreach (FaultTreeNode tn in node.Childs) { BDDNode n = this.CreateBDD(tn, nodeFactory); current = this.Apply(nodeFactory, op, current, n); } return(current); }
public Build_Leaf_lists(FaultTreeNode rootNode) { Build_lists(rootNode); }
public Build_Uncertainty_Tree(FaultTreeNode root) { this.root = root; }
private bool Build_UFT(FaultTreeNode FAT, ref FaultTreeNode FAT_UNCERTAINTY) { bool flag = false; if (FAT.Node_Type == 0) { if (FAT.Edge_Uncertainty == 1) { FAT_UNCERTAINTY = COPY(FAT); flag = true; } return(flag); } FaultTreeNode p_FAT, p_UNCERTAINTY = null, q_UNCERTAINTY = null; p_FAT = FAT.Child; if (FAT.Gate_Type == 3) { if (Build_UFT(p_FAT, ref p_UNCERTAINTY) == true) { FAT_UNCERTAINTY = new FaultTreeNode(); FAT_UNCERTAINTY.Edge_Uncertainty = FAT.Edge_Uncertainty; FAT_UNCERTAINTY.Node_Type = FAT.Node_Type; FAT_UNCERTAINTY.Node_Num = FAT.Node_Num; FAT_UNCERTAINTY.Gate_Type = FAT.Gate_Type; FAT_UNCERTAINTY.Data = FAT.Data; FAT_UNCERTAINTY.Child = p_UNCERTAINTY; flag = true; } else if (FAT.Edge_Uncertainty == 1) { flag = true; FAT_UNCERTAINTY = COPY(FAT); } return(flag); } if (FAT.Gate_Type == 2) { while (p_FAT != null) { if (Build_UFT(p_FAT, ref p_UNCERTAINTY) == true) { if (flag == false) { FAT_UNCERTAINTY = new FaultTreeNode(); FAT_UNCERTAINTY.Edge_Uncertainty = FAT.Edge_Uncertainty; FAT_UNCERTAINTY.Node_Type = FAT.Node_Type; FAT_UNCERTAINTY.Node_Num = FAT.Node_Num; FAT_UNCERTAINTY.Gate_Type = FAT.Gate_Type; FAT_UNCERTAINTY.Data = FAT.Data; } flag = true; if (FAT_UNCERTAINTY.Child == null) { FAT_UNCERTAINTY.Child = q_UNCERTAINTY = p_UNCERTAINTY; } else { q_UNCERTAINTY.Sibling = p_UNCERTAINTY; q_UNCERTAINTY = p_UNCERTAINTY; } } p_FAT = p_FAT.Sibling; } if (FAT.Edge_Uncertainty == 1) { flag = true; FAT_UNCERTAINTY = COPY(FAT); } return(flag); } if (FAT.Gate_Type == 1) { FAT_UNCERTAINTY = new FaultTreeNode(); FAT_UNCERTAINTY.Edge_Uncertainty = FAT.Edge_Uncertainty; FAT_UNCERTAINTY.Node_Type = FAT.Node_Type; FAT_UNCERTAINTY.Node_Num = FAT.Node_Num; FAT_UNCERTAINTY.Gate_Type = FAT.Gate_Type; FAT_UNCERTAINTY.Data = FAT.Data; while (p_FAT != null) { if (Build_UFT(p_FAT, ref p_UNCERTAINTY) == true) { flag = true; } else { p_UNCERTAINTY = COPY(p_FAT); } if (FAT_UNCERTAINTY.Child == null) { FAT_UNCERTAINTY.Child = q_UNCERTAINTY = p_UNCERTAINTY; } else { q_UNCERTAINTY.Sibling = p_UNCERTAINTY; q_UNCERTAINTY = p_UNCERTAINTY; } p_FAT = p_FAT.Sibling; } if (FAT.Edge_Uncertainty == 1) { flag = true; } if (flag == false) { // FREE_FAT_NODE(FAT_UNCERTAINTY); FAT_UNCERTAINTY = null; } return(flag); } return(flag); }
public DrawLocation(PointF drawPosition, FaultTreeNode node) { DrawPosition = drawPosition; Node = node; }
/// <summary> /// Initializes a new instance of the <see cref="FaultTree"/> class. /// </summary> /// <param name="root"> /// Root node of FaultTree /// </param> /// <param name="markovChain"> /// Markov chain used in <see cref="FaultTree"/> /// </param> public FaultTree(FaultTreeNode root, MarkovChain <FaultTreeTerminalNode> markovChain) { this.MarkovChain = markovChain; this.Root = root; }
/// <summary> /// Initializes a new instance of the <see cref="FaultTree"/> class. /// </summary> /// <param name="root"> /// Root node of FaultTree /// </param> public FaultTree(FaultTreeNode root) { this.Root = root; this.MarkovChain = new MarkovChain <FaultTreeTerminalNode>(1); }