public Node(Node node) { parents = new List <Node>(); key = node.Key; val = node.Value; for (int i = 0; i < node.Parents.Count; i++) { if (node.Parents[i] != null) { parents.Add(node.Parents[i]); } } if (node.Zero != null) { zero = new Node(node.Zero); zero.ConnectToParent(zero); } if (node.One != null) { one = new Node(node.One); one.ConnectToParent(one); } if (node.ResultOne != null) { resultOne = new NodeValueFunction(node.ResultOne); } if (node.ResultZero != null) { resultZero = new NodeValueFunction(node.ResultZero); } }
public NodeValueFunction(NodeValueFunction node) { value = node.Value; variable = new List <Node>(); for (int i = 0; i < node.Variable.Count; i++) { variable.Add(node.Variable[i]); } }
public void ReductionToZeroAndUnit() { NodeValueFunction trueNode = new NodeValueFunction(true); NodeValueFunction falseNode = new NodeValueFunction(false); List <Node> nodes = ListNodesDFS(root); if (nodes.Count == 1 && nodes[0].ResultZero != null && nodes[0].ResultOne != null && nodes[0].ResultZero.Value == nodes[0].ResultOne.Value) { isConst = nodes[0].ResultZero.Value; action = "Функция представлена константой"; if (IsConst != null) { IsConst(); } return; } for (int i = 0; i < nodes.Count; i++) { if (nodes[i].ResultZero != null) { if (nodes[i].ResultZero.Value) { nodes[i].ResultZero = null; nodes[i].ResultZero = trueNode; trueNode.AddNewVariable(nodes[i]); } else { nodes[i].ResultZero = null; nodes[i].ResultZero = falseNode; falseNode.AddNewVariable(nodes[i]); } } if (nodes[i].ResultOne != null) { if (nodes[i].ResultOne.Value) { nodes[i].ResultOne = null; nodes[i].ResultOne = trueNode; trueNode.AddNewVariable(nodes[i]); } else { nodes[i].ResultOne = null; nodes[i].ResultOne = falseNode; falseNode.AddNewVariable(nodes[i]); } } } action = "Сведение всех ветвей дерева к единым \"0\" и \"1\". Конечная конфигурация"; if (refresh != null) { refresh(); } }
public Node(int v, Node o = null, Node z = null, Node p = null, NodeValueFunction rOne = null, NodeValueFunction rZero = null) { parents = new List <Node>(); key = ""; val = v; if (p != null) { parents.Add(p); } zero = z; one = o; resultOne = rOne; resultZero = rZero; }