Esempio n. 1
0
        public static Component CloneNode(Component node, BinaryTree bt, char current = '!', char rename = '!')
        {
            Component newNode;

            if (node is BiImplication)
            {
                newNode = new BiImplication();
            }
            else if (node is Implication)
            {
                newNode = new Implication();
            }
            else if (node is Conjunction)
            {
                newNode = new Conjunction();
            }
            else if (node is Disjunction)
            {
                newNode = new Disjunction();
            }
            else if (node is Negation negation)
            {
                newNode = new Negation();
                ((Negation)newNode).GammaProcessed = negation.GammaProcessed;
            }
            else if (node is Nand)
            {
                newNode = new Nand();
            }
            else if (node is TrueFalse)
            {
                newNode = new TrueFalse(((TrueFalse)node).Data);
            }
            else if (node is Predicate predicate)
            {
                newNode = new Predicate(node.Symbol);
                predicate.ObjectVariables.Variables.ForEach(x => ((IVariableContainer)newNode)
                                                            .ObjectVariables.AddPropositionalVariable(CloneVariableForPredicate(x, current, rename))
                                                            );
            }
            else if (node is Universal universal)
            {
                newNode = new Universal();
                universal.ObjectVariables.Variables.ForEach(x => ((IVariableContainer)newNode)
                                                            .ObjectVariables.AddPropositionalVariable(CloneVariableForPredicate(x, current, rename))
                                                            );
                ((Universal)newNode).GammaProcessed = universal.GammaProcessed;
            }
            else if (node is Existential existential)
            {
                newNode = new Existential();
                existential.ObjectVariables.Variables.ForEach(x => ((IVariableContainer)newNode)
                                                              .ObjectVariables.AddPropositionalVariable(CloneVariableForPredicate(x, current, rename))
                                                              );
            }
            else
            {//
                newNode = new Variable(((Variable)node).Symbol, ((Variable)node).BindVariable);
                bt.PropositionalVariables.AddPropositionalVariable((Variable)newNode);
            }

            newNode.Parent = node.Parent;
            if (node is CompositeComponent)
            {
                if (node is Negation)
                {
                    newNode.LeftNode = CloneNode(node.LeftNode, bt, current, rename);
                }
                else
                {
                    newNode.LeftNode = node.LeftNode != null?CloneNode(node.LeftNode, bt, current, rename) : node.LeftNode;

                    newNode.RightNode = node.RightNode != null?CloneNode(node.RightNode, bt, current, rename) : node.RightNode;
                }
            }
            newNode.NodeNumber++;
            return(newNode);
        }