Example #1
0
 private void checkVariableInRelation(HashSet <IRelation> relations, HashSet <Entity> parameters)
 {
     foreach (IRelation r in relations)
     {
         if (r.GetType() == typeof(BinaryRelation))
         {
             BinaryRelation br = r as BinaryRelation;
             if (parameters.Contains(br.Source) == false)
             {
                 throw new System.ArgumentException("ActionDefinition: One variable of pre or post condition is not inside parameter set", "HashSet<ActionParameter> parameters: " + br.Source.Name + " is missing");
             }
             if (parameters.Contains(br.Destination) == false)
             {
                 throw new System.ArgumentException("ActionDefinition: One variable of pre or post condition is not inside parameter set", "HashSet<ActionParameter> parameters: " + br.Destination.Name + " is missing");
             }
         }
         else if (r.GetType() == typeof(UnaryRelation))
         {
             UnaryRelation ur = r as UnaryRelation;
             if (parameters.Contains(ur.Source) == false)
             {
                 throw new System.ArgumentException("ActionDefinition: One variable of pre or post condition is not inside parameter set", "HashSet<ActionParameter> parameters: " + ur.Source.Name + " is missing");
             }
         }
     }
 }
Example #2
0
        // This method sobsitutes the new parameters in the precondition or postconditions of an action
        // since they're bot collections of IRelations, which deal with entities and not ActionParameters
        // we need to cast them before passing them to this method
        private HashSet <IRelation> sobstituteEntitiesInConditions(Dictionary <Entity, Entity> sobstitutions, HashSet <IRelation> conditions)
        {
            HashSet <IRelation> newConditions = new HashSet <IRelation>();

            foreach (IRelation item in conditions)
            {
                if (item.GetType() == typeof(UnaryRelation))
                {
                    UnaryRelation ur = item as UnaryRelation;
                    Entity        source;
                    if (sobstitutions.TryGetValue(ur.Source, out source))
                    {
                        newConditions.Add(new UnaryRelation(source, ur.Predicate, ur.Value));
                    }
                }
                else if (item.GetType() == typeof(BinaryRelation))
                {
                    BinaryRelation br = item as BinaryRelation;
                    Entity         source, destination;
                    if (sobstitutions.TryGetValue(br.Source, out source) && sobstitutions.TryGetValue(br.Destination, out destination))
                    {
                        newConditions.Add(new BinaryRelation(source, br.Predicate, destination, br.Value));
                    }
                }
            }
            return(newConditions);
        }
Example #3
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (obj.GetType() != typeof(UnaryRelation))
            {
                return(false);
            }

            UnaryRelation other = obj as UnaryRelation;

            if (other.Source.Equals(_source) == false)
            {
                return(false);
            }
            if (other.Predicate.Equals(_predicate) == false)
            {
                return(false);
            }

            if (other.Value.Equals(_value) == false)
            {
                return(false);
            }

            return(true);
        }
Example #4
0
        public UnaryRelation generateRelationFromPredicateName(string name, Entity source, RelationValue value)
        {
            UnaryRelation  relation = null;
            UnaryPredicate up       = null;
            IPredicate     p        = getPredicate(name);

            if (p.GetType() == typeof(UnaryPredicate))
            {
                up       = p as UnaryPredicate;
                relation = new UnaryRelation(source, up, value);
            }
            else
            {
                throw new System.ArgumentException("The specified Predicate name is not UnaryPredicate", "generateRelationFromPredicateName(name, source)");
            }
            return(relation);
        }
Example #5
0
        public bool EqualsThroughPredicate(IRelation other)
        {
            if (other == null)
            {
                return(false);
            }

            UnaryRelation otherUnaryRelation = other as UnaryRelation;

            if (_source.Type.Equals(otherUnaryRelation.Source.Type) == false)
            {
                return(false);
            }

            if (_predicate.Equals(otherUnaryRelation.Predicate) == false)
            {
                return(false);
            }

            return(true);
        }
Example #6
0
        public override string ToString()
        {
            string value = "Action: " + _name + "(";

            foreach (ActionParameter item in _parameters)
            {
                value += item.Name + " ,";
            }

            value += ") \nPRECONDITION:\n";
            foreach (IRelation r in _preConditions)
            {
                if (r.GetType() == typeof(UnaryRelation))
                {
                    UnaryRelation ur = r as UnaryRelation;
                    value += ur.ToString() + "\n";
                }
                else if (r.GetType() == typeof(BinaryRelation))
                {
                    BinaryRelation br = r as BinaryRelation;
                    value += br.ToString() + "\n";
                }
            }

            value += "POSTCONDITION:\n";
            foreach (IRelation r in _postConditions)
            {
                if (r.GetType() == typeof(UnaryRelation))
                {
                    UnaryRelation ur = r as UnaryRelation;
                    value += ur.ToString() + "\n";
                }
                else if (r.GetType() == typeof(BinaryRelation))
                {
                    BinaryRelation br = r as BinaryRelation;
                    value += br.ToString() + "\n";
                }
            }
            return(value);
        }
Example #7
0
 public void addRelation(IRelation r)
 {
     if (_relations.Contains(r))
     {
         throw new System.ArgumentException("Relation is already defined in the current state", r.ToString());
     }
     if (r.GetType() == typeof(UnaryRelation))
     {
         UnaryRelation ur = r as UnaryRelation;
         // check that the source entitiy in the relation is already part of the state
         if (_entities.Contains(ur.Source) == false)
         {
             throw new System.ArgumentException("Relation source " + ur.Source + " does not exist in this state");
         }
         // check that all the predicate in the relation is defined in the domain
         if (_domain.Predicates.Contains(ur.Predicate) == false)
         {
             throw new System.ArgumentException("Relation predicate " + ur.Predicate + " does not exist in this domain");
         }
     }
     if (r.GetType() == typeof(BinaryRelation))
     {
         BinaryRelation br = r as BinaryRelation;
         // check that the source and destination entitiy in the relation is already part of the state
         if (_entities.Contains(br.Source) == false)
         {
             throw new System.ArgumentException("Relation source " + br.Source + " does not exist in this state");
         }
         if (_entities.Contains(br.Destination) == false)
         {
             throw new System.ArgumentException("Relation destination " + br.Destination + " does not exist in this state");
         }
         // check that all the predicate in the relation is defined in the domain
         if (_domain.Predicates.Contains(br.Predicate) == false)
         {
             throw new System.ArgumentException("Relation predicate " + br.Predicate + " does not exist in this domain");
         }
     }
     _relations.Add(r);
 }
Example #8
0
        public bool EqualsWithoutValue(IRelation other)
        {
            if (other == null)
            {
                return(false);
            }

            if (other.GetType() != typeof(UnaryRelation))
            {
                return(false);
            }

            UnaryRelation otherUnaryRelation = other as UnaryRelation;

            if (_source.Equals(otherUnaryRelation.Source) == false)
            {
                return(false);
            }
            if (_predicate.Equals(otherUnaryRelation.Predicate) == false)
            {
                return(false);
            }
            return(true);
        }