internal override BoolExpr <T_Identifier> VisitAnd(AndExpr <T_Identifier> expression) { return(new OrExpr <T_Identifier>(expression.Children.Select(child => child.Accept(this)))); }
internal override BoolExpr <T_Identifier> VisitAnd(AndExpr <T_Identifier> expression) { return(this.SimplifyTree((TreeExpr <T_Identifier>)expression)); }
internal override BoolExpr <T_Identifier> VisitAnd(AndExpr <T_Identifier> expression) { return((BoolExpr <T_Identifier>) new AndExpr <T_Identifier>(this.AcceptChildren((IEnumerable <BoolExpr <T_Identifier> >)expression.Children))); }
internal override bool VisitAnd(AndExpr <T_Identifier> expression) { return(this.VisitTree((TreeExpr <T_Identifier>)expression)); }
private BoolExpr <T_Identifier> SimplifyTree(TreeExpr <T_Identifier> tree) { var isAnd = ExprType.And == tree.ExprType; Debug.Assert(isAnd || ExprType.Or == tree.ExprType); // Get list of simplified children, flattening nested And/Or expressions var simplifiedChildren = new List <BoolExpr <T_Identifier> >(tree.Children.Count); foreach (var child in tree.Children) { var simplifiedChild = child.Accept(this); // And(And(A, B), C) iff. And(A, B, C) // Or(Or(A, B), C) iff. Or(A, B, C) if (simplifiedChild.ExprType == tree.ExprType) { simplifiedChildren.AddRange(((TreeExpr <T_Identifier>)simplifiedChild).Children); } else { simplifiedChildren.Add(simplifiedChild); } } // Track negated children separately to identify tautologies and contradictions var negatedChildren = new Dictionary <BoolExpr <T_Identifier>, bool>(tree.Children.Count); var otherChildren = new List <BoolExpr <T_Identifier> >(tree.Children.Count); foreach (var simplifiedChild in simplifiedChildren) { switch (simplifiedChild.ExprType) { case ExprType.Not: negatedChildren[((NotExpr <T_Identifier>)simplifiedChild).Child] = true; break; case ExprType.False: // False And A --> False if (isAnd) { return(FalseExpr <T_Identifier> .Value); } // False || A --> A (omit False from child collections) break; case ExprType.True: // True Or A --> True if (!isAnd) { return(TrueExpr <T_Identifier> .Value); } // True And A --> A (omit True from child collections) break; default: otherChildren.Add(simplifiedChild); break; } } var children = new List <BoolExpr <T_Identifier> >(); foreach (var child in otherChildren) { if (negatedChildren.ContainsKey(child)) { // A && !A --> False, A || !A --> True if (isAnd) { return(FalseExpr <T_Identifier> .Value); } else { return(TrueExpr <T_Identifier> .Value); } } children.Add(child); } foreach (var child in negatedChildren.Keys) { children.Add(child.MakeNegated()); } if (0 == children.Count) { // And() iff. True if (isAnd) { return(TrueExpr <T_Identifier> .Value); } // Or() iff. False else { return(FalseExpr <T_Identifier> .Value); } } else if (1 == children.Count) { // Or(A) iff. A, And(A) iff. A return(children[0]); } else { // Construct simplified And/Or expression TreeExpr <T_Identifier> result; if (isAnd) { result = new AndExpr <T_Identifier>(children); } else { result = new OrExpr <T_Identifier>(children); } return(result); } }
internal override BoolExpr <T_To> VisitAnd(AndExpr <T_From> expression) { return(new AndExpr <T_To>(VisitChildren(expression))); }
internal override int VisitAnd(AndExpr <T_Identifier> expression) { return(VisitTree(expression)); }
internal override BoolExpr <T_Identifier> VisitAnd(AndExpr <T_Identifier> expression) { return((BoolExpr <T_Identifier>) new OrExpr <T_Identifier>(expression.Children.Select <BoolExpr <T_Identifier>, BoolExpr <T_Identifier> >((Func <BoolExpr <T_Identifier>, BoolExpr <T_Identifier> >)(child => child.Accept <BoolExpr <T_Identifier> >((Visitor <T_Identifier, BoolExpr <T_Identifier> >) this))))); }
internal override Vertex VisitAnd(AndExpr <T_Identifier> expression) { return(_context.Solver.And(expression.Children.Select(child => child.Accept(this)))); }
internal override BoolExpr <T_To> VisitAnd(AndExpr <T_From> expression) { return((BoolExpr <T_To>) new AndExpr <T_To>(this.VisitChildren((TreeExpr <T_From>)expression))); }