Esempio n. 1
0
        public static CausualGraph computeCausualGraph(PAD.Planner.SAS.Problem problem)
        {
            CausualGraph result = new CausualGraph();

            result.vertices          = new List <int>(problem.Variables.Count);
            result.isEdge            = new bool[problem.Variables.Count, problem.Variables.Count];
            result.isMentionedInGoal = new bool[problem.Variables.Count];
            for (int i = 0; i < problem.Variables.Count; i++)
            {
                result.vertices.Add(i);
                result.isMentionedInGoal[i] = problem.GoalConditions.Any(g => g.GetVariable() == i);
            }

            foreach (PAD.Planner.SAS.IOperator item in problem.Operators)
            {
                foreach (var precond in item.GetPreconditions())
                {
                    foreach (var eff in item.GetEffects())
                    {
                        if (eff.GetAssignment().GetVariable() != precond.GetVariable())
                        {
                            result.setEdge(precond.GetVariable(), eff.GetAssignment().GetVariable());
                        }
                    }
                }
                foreach (var eff in item.GetEffects())
                {
                    ConditionalEffect condEff = eff as ConditionalEffect;
                    if (condEff != null)
                    {
                        foreach (var cond in condEff.Conditions)
                        {
                            if (eff.GetAssignment().GetVariable() != cond.GetVariable())
                            {
                                result.setEdge(cond.GetVariable(), eff.GetAssignment().GetVariable());
                            }
                        }
                    }
                }
                foreach (var eff in item.GetEffects())
                {
                    foreach (var eff2 in item.GetEffects())
                    {
                        if (eff.GetAssignment().GetVariable() != eff2.GetAssignment().GetVariable())
                        {
                            result.setEdge(eff.GetAssignment().GetVariable(), eff2.GetAssignment().GetVariable());
                        }
                    }
                }
            }

            return(result);
        }
Esempio n. 2
0
        public CausualGraph projection(HashSet <int> variables)
        {
            CausualGraph result = new CausualGraph();

            result.vertices = new List <int>();
            int max = 0;

            foreach (var item in this.vertices)
            {
                if (variables.Contains(item))
                {
                    result.vertices.Add(item);
                    if (max < item)
                    {
                        max = item;
                    }
                }
            }
            result.isEdge = new bool[max, max];
            for (int i = 0; i < max; i++)
            {
                for (int j = 0; j < max; j++)
                {
                    if (this.isEdge[i, j])
                    {
                        result.setEdge(i, j);
                    }
                }
            }
            return(result);
        }