コード例 #1
0
        public void ConstrainVars(Var v1, Var v2)
        {
            Check(
                ((v1 is ScalarVar) && (v2 is ScalarVar)) ||
                ((v1 is VectorVar) && (v2 is VectorVar)),
                "Incompatible variable kinds " + v1.ToString() + " and " + v2.ToString());

            ConstrainVars(v1.ToString(), v2.ToString());
        }
コード例 #2
0
ファイル: ConstraintSolverUtil.cs プロジェクト: noprompt/cat
        public bool AreVarsEqual(Var x, Var y)
        {
            string s = x.ToString();

            if (ContainsKey(s))
            {
                return(this[s].Equals(y.ToString()));
            }
            else
            {
                Add(s, y.ToString());
                return(true);
            }
        }
コード例 #3
0
        public Constraint GetRecursiveVar(Constraint c, Stack <Constraint> visited)
        {
            if (!(c is Var))
            {
                return(null);
            }
            Var v = c as Var;

            Constraint[] a            = visited.ToArray();
            Relation     prevRelation = null;

            for (int i = 0; i < a.Length; ++i)
            {
                Constraint tmp = a[i];
                if (tmp is Var)
                {
                    Var v2 = tmp as Var;
                    if (v2.ToString().Equals(v.ToString()))
                    {
                        if (prevRelation == null)
                        {
                            // Recursive variable
                            Trace.Assert(c is VectorVar);
                            return(c);
                        }
                        return(new RecursiveRelation());
                    }
                }
                else if (tmp is Relation)
                {
                    prevRelation = tmp as Relation;
                }
            }
            return(null);
        }
コード例 #4
0
        public void AddVarConstraint(Var v, Constraint c)
        {
            if (c is RecursiveRelation)
            {
                return;
            }

            AddConstraintToList(c, GetConstraints(v.ToString()));
        }
コード例 #5
0
        public Constraint GetUnifierFor(Var v)
        {
            Constraint ret = GetUnifierFor(v.ToString());

            if (ret == null)
            {
                return(v);
            }
            return(ret);
        }
コード例 #6
0
ファイル: ConstraintSolverUtil.cs プロジェクト: noprompt/cat
 public bool ContainsVar(Var v)
 {
     foreach (Constraint c in this)
     {
         if (c.EqualsVar(v.ToString()))
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #7
0
        public Constraint ResolveRelationConstraint(Constraint c, Stack <Constraint> visited,
                                                    Relation parent, VarNameList topVars, VarNameList allVars)
        {
            VarNameList nonGenerics = parent.GetNonGenericsForChildren();

            if (c is Var)
            {
                Var        v = c as Var;
                Constraint u = Resolve(v, visited, parent);

                if (u is Relation)
                {
                    Relation r = u as Relation;
                    // Make sure we don't add variables to the non-generics
                    // list which occured in a duplicate.
                    if (!topVars.Contains(v))
                    {
                        VarNameList subVars = r.GetAllVarNames();
                        foreach (string s in subVars)
                        {
                            if (allVars.Contains(s))
                            {
                                nonGenerics.Add(s);
                            }
                        }
                        allVars.AddRange(subVars);
                    }
                    else
                    {
                        Log("duplicate of variable " + v.ToString() + ", with unifier " + r.ToString());
                        QueueForRenamingOfGenerics(r);
                    }
                }
                else if (u is Var)
                {
                    nonGenerics.Add(u as Var);
                }

                topVars.Add(v);
                return(u);
            }
            else
            {
                Constraint u = Resolve(c, visited, parent);

                // non-vars should not resolve to vars
                Trace.Assert(!(u is Var));

                if (u is Relation)
                {
                    Relation    r       = u as Relation;
                    VarNameList subVars = r.GetAllVarNames();
                    foreach (string s in subVars)
                    {
                        if (allVars.Contains(s))
                        {
                            nonGenerics.Add(s);
                        }
                    }
                    allVars.AddRange(subVars);
                }

                return(u);
            }
        }
コード例 #8
0
ファイル: ConstraintSolverUtil.cs プロジェクト: noprompt/cat
 public bool Contains(Var v)
 {
     return(base.Contains(v.ToString()));
 }
コード例 #9
0
ファイル: ConstraintSolverUtil.cs プロジェクト: noprompt/cat
 public void Add(Var v)
 {
     Add(v.ToString());
 }