Exemplo n.º 1
0
        public override string ToString()
        {
            string value = "";

            value += "ENTITY TYPES:\n";
            foreach (EntityType et in _entityTypes)
            {
                value += et.ToString() + "\n";
            }

            value += "\nPREDICATES:\n";
            foreach (IPredicate p in _predicates)
            {
                if (p.GetType() == typeof(UnaryPredicate))
                {
                    UnaryPredicate up = p as UnaryPredicate;
                    value += up.ToString() + "\n";
                }
                else if (p.GetType() == typeof(BinaryPredicate))
                {
                    BinaryPredicate bp = p as BinaryPredicate;
                    value += bp.ToString() + "\n";
                }
            }

            value += "\nACTIONS:\n";
            foreach (Action a in _actions)
            {
                value += a.ToString() + "\n";
            }

            return(value);
        }
Exemplo n.º 2
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

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

            BinaryPredicate otherPredicate = obj as BinaryPredicate;

            if (_source.Equals(otherPredicate.Source) == false)
            {
                return(false);
            }
            if (_name.Equals(otherPredicate.Name) == false)
            {
                return(false);
            }
            if (_destination.Equals(otherPredicate.Destination) == false)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        public void addPredicate(IPredicate p)
        {
            if (_predicates.Contains(p))
            {
                throw new System.ArgumentException("Predicate has already been declared", p.Name);
            }
            if (_entityTypes.Contains(p.Source) == false)
            {
                throw new System.ArgumentException("The specified Entity Type does not exist", p.Source.ToString());
            }

            if (p.GetType() == typeof(BinaryPredicate))
            {
                BinaryPredicate bp = p as BinaryPredicate;
                if (_entityTypes.Contains(bp.Destination) == false)
                {
                    throw new System.ArgumentException("The specified Entity Type does not exist", bp.Destination.ToString());
                }
            }

            _predicates.Add(p);
        }
Exemplo n.º 6
0
        public bool Equals(IPredicate other)
        {
            if (other.GetType() != typeof(BinaryPredicate))
            {
                return(false);
            }
            if (_source.Equals(other.Source) == false)
            {
                return(false);
            }
            if (_name.Equals(other.Name) == false)
            {
                return(false);
            }

            BinaryPredicate otherBinaryPredicate = other as BinaryPredicate;

            if (_destination.Equals(otherBinaryPredicate.Destination) == false)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 7
0
        public BinaryRelation(Entity source, IPredicate predicate, Entity destination, RelationValue value)
        {
            if (source == null)
            {
                throw new System.ArgumentNullException("Relation source cannot be null", "source");
            }
            if (predicate == null)
            {
                throw new System.ArgumentNullException("Relation predicate cannot be null", "predicate");
            }
            if (destination == null)
            {
                throw new System.ArgumentNullException("Relation destination cannot be null", "destination");
            }

            if (predicate.GetType() != typeof(BinaryPredicate))
            {
                throw new System.ArgumentNullException("Binary relation predicate must be a binary predicate", "predicate");
            }

            BinaryPredicate binaryPredicate = predicate as BinaryPredicate;

            if (source.Type.Equals(predicate.Source) == false)
            {
                throw new System.ArgumentException("Relation source is not of the specified predicate type", source + " " + predicate.Source);
            }
            if (destination.Type.Equals(binaryPredicate.Destination) == false)
            {
                throw new System.ArgumentException("Relation destination is not of the specified predicate type", source + " " + binaryPredicate.Destination);
            }

            _source      = source;
            _predicate   = binaryPredicate;
            _destination = destination;
            _value       = value;
        }