Exemplo n.º 1
0
 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);
     }
 }
Exemplo n.º 2
0
 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]);
     }
 }
Exemplo n.º 3
0
        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();
            }
        }
Exemplo n.º 4
0
 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;
 }