Exemplo n.º 1
0
        private SolverNode CloseVariable(IVariable variable,
                                         IAbstractExpr expression,
                                         AbstractConstraint sourceConstraintToBeRemoved)
        {
            //var foldingVisitor = new ConstantFoldingVisitor();
            var foldingVisitor = new PolynomialFoldingVisitor();
            expression = expression.Accept(foldingVisitor);

            // Rewrite all constraints
            //var rewriter = new RewritingVisitor(
            //    new Dictionary<IAbstractExpr, IAbstractExpr> { { variable, expression } });
            var rewriter = new RewritingVisitor(variable, expression);
            IEnumerable<AbstractConstraint> rewrittenConstraints =
                Constraints.Except(sourceConstraintToBeRemoved)
                    .Select(c => c.Accept(rewriter, Ig.nore));

            // Create new variable->value knowledge or new backsubstition.
            var newBacksubstitutions = new Dictionary<IVariable, AbstractClosedVariable>(ClosedVariables) {{
                variable, expression is IConstant
                    ? (AbstractClosedVariable)
                        new VariableWithValue(variable, ((IConstant) expression).Value)
                    : new VariableWithBacksubstitution(variable, expression)
                }};

            // Create new node.
            return new SolverNode(rewrittenConstraints, newBacksubstitutions, this);
        }
Exemplo n.º 2
0
 private IAbstractExpr Fold(IAbstractExpr expr)
 {
     return expr.Accept(new PolynomialFoldingVisitor(), Ig.nore);
     //return expr.Accept(new PolynomialFoldingVisitor(), 0);
 }