Example #1
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 #2
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 #3
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

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

            BinaryRelation other = obj as BinaryRelation;

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

            return(true);
        }
Example #4
0
        public bool EqualsWithoutValue(IRelation other)
        {
            if (other == null)
            {
                return(false);
            }

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

            BinaryRelation otherRelation = other as BinaryRelation;

            if (_source.Equals(otherRelation.Source) == false)
            {
                return(false);
            }
            if (_predicate.Equals(otherRelation.Predicate) == false)
            {
                return(false);
            }
            if (_destination.Equals(otherRelation.Destination) == false)
            {
                return(false);
            }
            return(true);
        }
Example #5
0
        // Use this for initialization
        void Start()
        {
            flag = false;

            EntityType character = new EntityType("CHARACTER");
            EntityType location  = new EntityType("LOCATION");

            //(can-move ?from-l1 ?to-l2)
            BinaryPredicate isConnectedTo = new BinaryPredicate(location, "IS_CONNECTED_TO", location);
            //(at ?characther ?location)
            BinaryPredicate at = new BinaryPredicate(character, "AT", location);
            //(been-at ?characther ?location)
            BinaryPredicate beenAt = new BinaryPredicate(character, "BEEN_AT", location);


            //              MOVE ACTION
            // Parameters
            Entity character1 = new Entity(character, "CHARACTER1");
            Entity location1  = new Entity(location, "LOCATION1");
            Entity location2  = new Entity(location, "LOCATION2");

            HashSet <Entity> moveActionParameters = new HashSet <Entity>();

            moveActionParameters.Add(character1);
            moveActionParameters.Add(location1);
            moveActionParameters.Add(location2);

            // Preconditions
            HashSet <IRelation> moveActionPreconditions = new HashSet <IRelation>();
            BinaryRelation      characterAtL1           = new BinaryRelation(character1, at, location1, RelationValue.TRUE);

            moveActionPreconditions.Add(characterAtL1);
            BinaryRelation isConnectedFromL1ToL2 = new BinaryRelation(location1, isConnectedTo, location2, RelationValue.TRUE);

            moveActionPreconditions.Add(isConnectedFromL1ToL2);

            // Postconditions
            HashSet <IRelation> moveActionPostconditions = new HashSet <IRelation>();
            BinaryRelation      notCharacterAtL1         = new BinaryRelation(character1, at, location1, RelationValue.FALSE);

            moveActionPostconditions.Add(notCharacterAtL1);
            BinaryRelation characterAtL2 = new BinaryRelation(character1, at, location2, RelationValue.TRUE);

            moveActionPostconditions.Add(characterAtL2);
            BinaryRelation characterBeenAtL1 = new BinaryRelation(character1, beenAt, location1, RelationValue.TRUE);

            moveActionPostconditions.Add(characterBeenAtL1);

            // TODO: fix this
            // Action moveAction = new Action(moveActionPreconditions, "MOVE", moveActionParameters, moveActionPostconditions);
            // actions.Add(moveAction);
        }
Example #6
0
        public BinaryRelation generateRelationFromPredicateName(string name, Entity source, Entity destination, RelationValue value)
        {
            BinaryRelation  relation = null;
            BinaryPredicate bp       = null;
            IPredicate      p        = getPredicate(name);

            if (p.GetType() == typeof(BinaryPredicate))
            {
                bp       = p as BinaryPredicate;
                relation = new BinaryRelation(source, bp, destination, value);
            }
            else
            {
                throw new System.ArgumentException("The specified Predicate name is not BinaryPredicate", "generateRelationFromPredicateName(name, source, destination)");
            }
            return(relation);
        }
Example #7
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 #8
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);
 }