Ejemplo n.º 1
0
        /// <summary>
        /// Translates a domain constraint term to an N-ary DD vertex.
        /// </summary>
        internal override Vertex TranslateTermToVertex(TermExpr <DomainConstraint <T_Variable, T_Element> > term)
        {
            var range          = term.Identifier.Range;
            var domainVariable = term.Identifier.Variable;
            var domain         = domainVariable.Domain;

            if (range.All(element => !domain.Contains(element)))
            {
                // trivially false
                return(Vertex.Zero);
            }

            if (domain.All(element => range.Contains(element)))
            {
                // trivially true
                return(Vertex.One);
            }

            // determine assignments for this constraints (if the range contains a value in the domain, '1', else '0')
            Vertex[] children = domain.Select(element => range.Contains(element) ? Vertex.One : Vertex.Zero).ToArray();

            // see if we know this variable
            int robddVariable;

            if (!_domainVariableToRobddVariableMap.TryGetValue(domainVariable, out robddVariable))
            {
                robddVariable = Solver.CreateVariable();
                _domainVariableToRobddVariableMap[domainVariable] = robddVariable;
            }

            // create a new vertex with the given assignments
            return(Solver.CreateLeafVertex(robddVariable, children));
        }
            internal override Literal <DomainConstraint <T_Variable, T_Element> > NegateLiteral(Literal <DomainConstraint <T_Variable, T_Element> > literal)
            {
                // negate the literal by inverting the range, rather than changing the sign
                // of the literal
                TermExpr <DomainConstraint <T_Variable, T_Element> > term = new TermExpr <DomainConstraint <T_Variable, T_Element> >(
                    literal.Term.Identifier.InvertDomainConstraint());

                return(new Literal <DomainConstraint <T_Variable, T_Element> >(term, literal.IsTermPositive));
            }
        internal override Vertex TranslateTermToVertex(TermExpr <T_Identifier> term)
        {
            int variable;

            if (!_variableMap.TryGetValue(term, out variable))
            {
                variable = Solver.CreateVariable();
                _variableMap.Add(term, variable);
            }
            return(Solver.CreateLeafVertex(variable, Solver.BooleanVariableChildren));
        }
        internal override IEnumerable <LiteralVertexPair <T_Identifier> > GetSuccessors(Vertex vertex)
        {
            LiteralVertexPair <T_Identifier>[] successors = new LiteralVertexPair <T_Identifier> [2];

            Debug.Assert(2 == vertex.Children.Length);
            Vertex then  = vertex.Children[0];
            Vertex @else = vertex.Children[1];

            // get corresponding term expression
            InitializeInverseVariableMap();
            TermExpr <T_Identifier> term = _inverseVariableMap[vertex.Variable];

            // add positive successor (then)
            Literal <T_Identifier> literal = new Literal <T_Identifier>(term, true);

            successors[0] = new LiteralVertexPair <T_Identifier>(then, literal);

            // add negative successor (else)
            literal       = literal.MakeNegated();
            successors[1] = new LiteralVertexPair <T_Identifier>(@else, literal);
            return(successors);
        }
 /// <summary>
 /// Given a term in BoolExpr, returns the corresponding decision diagram vertex.
 /// </summary>
 internal abstract Vertex TranslateTermToVertex(TermExpr <T_Identifier> term);
Ejemplo n.º 6
0
 public bool Equals(TermExpr <T_Identifier> other)
 {
     return(_comparer.Equals(_identifier, other._identifier));
 }
Ejemplo n.º 7
0
 internal override BoolExpr <T_Identifier> VisitTerm(TermExpr <T_Identifier> expression)
 {
     return(expression);
 }
Ejemplo n.º 8
0
 internal abstract T_Return VisitTerm(TermExpr <T_Identifier> expression);
Ejemplo n.º 9
0
 internal override Vertex VisitTerm(TermExpr <T_Identifier> expression)
 {
     return(_context.TranslateTermToVertex(expression));
 }
Ejemplo n.º 10
0
 internal override BoolExpr <T_To> VisitTerm(TermExpr <T_From> expression)
 {
     return(_translator(expression));
 }
Ejemplo n.º 11
0
 internal override bool VisitTerm(TermExpr <T_Identifier> expression)
 {
     _terms.Add(expression);
     return(true);
 }
Ejemplo n.º 12
0
 internal override int VisitTerm(TermExpr <T_Identifier> expression)
 {
     return(1);
 }
Ejemplo n.º 13
0
 internal override BoolExpr <DomainConstraint <T_Variable, T_Element> > VisitTerm(TermExpr <DomainConstraint <T_Variable, T_Element> > expression)
 {
     return(new TermExpr <DomainConstraint <T_Variable, T_Element> >(expression.Identifier.InvertDomainConstraint()));
 }