Esempio n. 1
0
    private void DescribeObjectState()
    {
        Text myText = GameObject.Find("Content").GetComponent <Text>();

        Domain     domainFirstLevel     = Utils.roverWorldDomainFirstLevel();
        WorldState worldStateFirstLevel = Utils.roverWorldStateFirstLevel(domainFirstLevel);

        foreach (IRelation r in worldStateFirstLevel.Relations)
        {
            if (r.GetType() == typeof(BinaryRelation))
            {
                BinaryRelation rel = r as BinaryRelation;
                if (rel.Source.ToString() == selectedObject.name || rel.Destination.ToString() == selectedObject.name)
                {
                    BinaryPredicate pred = r as BinaryPredicate;
                    myText.text += pred.Description + "\n";
                }
            }
            else
            {
                UnaryRelation rel = r as UnaryRelation;
                if (rel.Source.ToString() == selectedObject.name)
                {
                    BinaryPredicate pred = r as BinaryPredicate;
                    myText.text += pred.Description + "\n";
                }
            }
        }

        myText.text += "ciaoooooo";
    }
Esempio n. 2
0
        public ISinglePredicateState Compare(object value, BinaryOperationType operationType)
        {
            Argument.NotNull(value, "value");
            var predicate = new BinaryPredicate(_expression, value, operationType);

            return(InitialPredicateState(predicate, _negate));
        }
Esempio n. 3
0
    public void ActionConditionsEntitiesMustBeInParameters()
    {
        EntityType sourceEntityType1 = new EntityType("CHARACTER");

        EntityType destinationEntityType1 = new EntityType("ARTIFACT");

        Entity sourceEntity1 = new Entity(sourceEntityType1, "JOHN");

        Entity destinationEntity1 = new Entity(destinationEntityType1, "APPLE");

        BinaryPredicate bp1 = new BinaryPredicate(sourceEntityType1, "PICK_UP", destinationEntityType1);

        BinaryRelation br1 = new BinaryRelation(sourceEntity1, bp1, destinationEntity1, RelationValue.TRUE);

        HashSet <ActionParameter> parametersAction1 = new HashSet <ActionParameter>();
        // parametersAction1.Add(sourceEntity1);
        // parametersAction1.Add(destinationEntity1);

        HashSet <IRelation> preconditionsAction1 = new HashSet <IRelation>();

        preconditionsAction1.Add(br1);
        HashSet <IRelation> postconditionsAction1 = new HashSet <IRelation>();

        postconditionsAction1.Add(br1);

        Assert.That(() => new Action(preconditionsAction1, "PICK_UP", parametersAction1, postconditionsAction1), Throws.ArgumentException);
    }
Esempio n. 4
0
    public void CloneReturnsEqualBinaryPredicate()
    {
        BinaryPredicate bp1 = new BinaryPredicate(new EntityType("CHARACTER"), "IS_AT", new EntityType("LOCATION"));
        BinaryPredicate bp2 = bp1.Clone() as BinaryPredicate;

        Assert.AreEqual(bp1, bp2);
    }
Esempio n. 5
0
 public static BinaryPredicate <Arg> Not2Pred <Arg>(BinaryPredicate <Arg> func)
 {
     return(delegate(Arg arg1, Arg arg2)
     {
         return !func(arg1, arg2);
     });
 }
Esempio n. 6
0
        public IPredicateDisjunctionState Compare(object value, BinaryOperationType operationType)
        {
            Argument.NotNull(value, "value");
            var predicate = new BinaryPredicate(Expression, value, operationType);

            return(PredicateDisjunctionState(predicate, _negate));
        }
Esempio n. 7
0
    public void BinaryRelationSourceMustBeAnExistingEntity()
    {
        Domain     domain    = new Domain();
        EntityType character = new EntityType("CHARACTER");

        domain.addEntityType(character);

        EntityType location = new EntityType("LOCATION");

        domain.addEntityType(location);

        BinaryPredicate isAt = new BinaryPredicate(character, "IS_AT", location);

        domain.addPredicate(isAt);

        WorldState worldState = new WorldState(domain);
        Entity     john       = new Entity(character, "JOHN");
        // worldState.addEntity(john);

        Entity school = new Entity(location, "SCHOOL");

        worldState.addEntity(school);

        BinaryRelation johnIsAtSchool = new BinaryRelation(john, isAt, school, RelationValue.TRUE);

        Assert.That(() => worldState.addRelation(johnIsAtSchool), Throws.ArgumentException);
    }
Esempio n. 8
0
    public void thirdLODRoverCanDropImageIfPreconditionsAreSatisfied()
    {
        Domain domain = Utils.roverWorldDomainThirdLevel();

        WorldState worldState = new WorldState(domain);

        EntityType entityTypeRover = new EntityType("ROVER");
        Entity     entityRover     = new Entity(entityTypeRover, "ROVER");

        worldState.addEntity(entityRover);

        EntityType entityTypeBattery = new EntityType("BATTERY");
        Entity     entityBattery1    = new Entity(entityTypeBattery, "BATTERY");

        worldState.addEntity(entityBattery1);

        EntityType entityTypeWheel = new EntityType("WHEEL");
        Entity     entityWheels    = new Entity(entityTypeWheel, "WHEELS");

        worldState.addEntity(entityWheels);

        Entity wayPointAlpha = new Entity(new EntityType("WAYPOINT"), "WAYPOINT");

        worldState.addEntity(wayPointAlpha);

        Entity entitySample = new Entity(new EntityType("SAMPLE"), "SAMPLE");

        worldState.addEntity(entitySample);

        UnaryRelation  wayPointIsDroppingDock = domain.generateRelationFromPredicateName("IS_DROPPING_DOCK", wayPointAlpha, RelationValue.TRUE);
        BinaryRelation roverIsAtWaypoint      = domain.generateRelationFromPredicateName("AT", entityRover, wayPointAlpha, RelationValue.TRUE);
        BinaryRelation roverCarriesSample     = domain.generateRelationFromPredicateName("CARRY", entityRover, entitySample, RelationValue.TRUE);

        worldState.addRelation(wayPointIsDroppingDock);
        worldState.addRelation(roverIsAtWaypoint);
        worldState.addRelation(roverCarriesSample);

        BinaryPredicate predicateHasBattery      = new BinaryPredicate(entityTypeRover, "HAS", entityTypeBattery);
        BinaryRelation  relationRoverHasBattery1 = new BinaryRelation(entityRover, predicateHasBattery, entityBattery1, RelationValue.TRUE);

        worldState.addRelation(relationRoverHasBattery1);

        BinaryPredicate predicateHasWheels     = new BinaryPredicate(entityTypeRover, "HAS", entityTypeWheel);
        BinaryRelation  relationRoverHasWheels = new BinaryRelation(entityRover, predicateHasWheels, entityWheels, RelationValue.TRUE);

        worldState.addRelation(relationRoverHasWheels);

        UnaryRelation batteryCharged = domain.generateRelationFromPredicateName("BATTERY_CHARGED", entityBattery1, RelationValue.TRUE);

        worldState.addRelation(batteryCharged);

        UnaryRelation wheelsInflated = domain.generateRelationFromPredicateName("WHEELS_INFLATED", entityWheels, RelationValue.TRUE);

        worldState.addRelation(wheelsInflated);

        Action actionDropSample = worldState.Domain.getAction("DROP_SAMPLE");

        Assert.True(worldState.getPossibleActions().Contains(actionDropSample));
    }
Esempio n. 9
0
    public void ActionPreconditionsMustBeExistingPredicates()
    {
        Domain domain = new Domain();

        EntityType rover = new EntityType("ROVER");

        domain.addEntityType(rover);

        EntityType wayPoint = new EntityType("WAYPOINT");

        domain.addEntityType(wayPoint);

        //(can-move ?from-waypoint ?to-waypoint)
        BinaryPredicate isConnectedTo = new BinaryPredicate(wayPoint, "IS_CONNECTED_TO", wayPoint);
        // domain.addPredicate(isConnectedTo);
        //(been-at ?rover ?waypoint)
        BinaryPredicate beenAt = new BinaryPredicate(rover, "BEEN_AT", wayPoint);
        // domain.addPredicate(beenAt);
        //(at ?rover ?waypoint)
        BinaryPredicate at = new BinaryPredicate(rover, "AT", wayPoint);
        // domain.addPredicate(at);
        //              MOVE ACTION
        // Parameters
        Entity curiosity    = new Entity(rover, "ROVER");
        Entity fromWayPoint = new Entity(wayPoint, "WAYPOINT1");
        Entity toWayPoint   = new Entity(wayPoint, "WAYPOINT2");

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

        moveActionParameters.Add(new ActionParameter(curiosity, ActionParameterRole.ACTIVE));
        moveActionParameters.Add(new ActionParameter(fromWayPoint, ActionParameterRole.PASSIVE));
        moveActionParameters.Add(new ActionParameter(toWayPoint, ActionParameterRole.PASSIVE));

        // Preconditions
        HashSet <IRelation> moveActionPreconditions = new HashSet <IRelation>();
        BinaryRelation      roverAtfromWP           = new BinaryRelation(curiosity, at, fromWayPoint, RelationValue.TRUE);

        moveActionPreconditions.Add(roverAtfromWP);
        BinaryRelation isConnectedFromWP1ToWP2 = new BinaryRelation(fromWayPoint, isConnectedTo, toWayPoint, RelationValue.TRUE);

        moveActionPreconditions.Add(isConnectedFromWP1ToWP2);

        // Postconditions
        HashSet <IRelation> moveActionPostconditions = new HashSet <IRelation>();
        BinaryRelation      notRoverAtFromWP         = new BinaryRelation(curiosity, at, fromWayPoint, RelationValue.FALSE);

        moveActionPostconditions.Add(notRoverAtFromWP);
        BinaryRelation roverAtToWP = new BinaryRelation(curiosity, at, toWayPoint, RelationValue.TRUE);

        moveActionPostconditions.Add(roverAtToWP);
        BinaryRelation roverBeenAtToWP = new BinaryRelation(curiosity, beenAt, toWayPoint, RelationValue.TRUE);

        moveActionPostconditions.Add(roverBeenAtToWP);

        Action moveAction = new Action(moveActionPreconditions, "MOVE", moveActionParameters, moveActionPostconditions);

        Assert.That(() => domain.addAction(moveAction), Throws.ArgumentException);
    }
Esempio n. 10
0
    public void thirdLODRoverCanTakeImageIfPreconditionsAreSatisfied()
    {
        Domain domain = Utils.roverWorldDomainThirdLevel();

        WorldState worldState = new WorldState(domain);

        EntityType entityTypeRover = new EntityType("ROVER");
        Entity     entityRover     = new Entity(entityTypeRover, "ROVER");

        worldState.addEntity(entityRover);

        EntityType entityTypeBattery = new EntityType("BATTERY");
        Entity     entityBattery1    = new Entity(entityTypeBattery, "BATTERY");

        worldState.addEntity(entityBattery1);

        EntityType entityTypeWheel = new EntityType("WHEEL");
        Entity     entityWheels    = new Entity(entityTypeWheel, "WHEELS");

        worldState.addEntity(entityWheels);

        Entity wayPointAlpha = new Entity(new EntityType("WAYPOINT"), "WAYPOINT");

        worldState.addEntity(wayPointAlpha);

        Entity entityObjective = new Entity(new EntityType("OBJECTIVE"), "OBJECTIVE");

        worldState.addEntity(entityObjective);

        BinaryRelation roverIsAtWaypoint = domain.generateRelationFromPredicateName("AT", entityRover, wayPointAlpha, RelationValue.TRUE);
        BinaryRelation objectiveIsVisibleFromWaypoint = domain.generateRelationFromPredicateName("IS_VISIBLE", entityObjective, wayPointAlpha, RelationValue.TRUE);

        worldState.addRelation(roverIsAtWaypoint);
        worldState.addRelation(objectiveIsVisibleFromWaypoint);

        BinaryPredicate predicateHasBattery      = new BinaryPredicate(entityTypeRover, "HAS", entityTypeBattery);
        BinaryRelation  relationRoverHasBattery1 = new BinaryRelation(entityRover, predicateHasBattery, entityBattery1, RelationValue.TRUE);

        worldState.addRelation(relationRoverHasBattery1);

        BinaryPredicate predicateHasWheels     = new BinaryPredicate(entityTypeRover, "HAS", entityTypeWheel);
        BinaryRelation  relationRoverHasWheels = new BinaryRelation(entityRover, predicateHasWheels, entityWheels, RelationValue.TRUE);

        worldState.addRelation(relationRoverHasWheels);

        UnaryRelation batteryCharged = domain.generateRelationFromPredicateName("BATTERY_CHARGED", entityBattery1, RelationValue.TRUE);

        worldState.addRelation(batteryCharged);

        UnaryRelation wheelsInflated = domain.generateRelationFromPredicateName("WHEELS_INFLATED", entityWheels, RelationValue.TRUE);

        worldState.addRelation(wheelsInflated);

        Action actionTakeImage = worldState.Domain.getAction("TAKE_IMAGE");

        Assert.True(worldState.getPossibleActions().Contains(actionTakeImage));
    }
Esempio n. 11
0
    public void BinaryPredicatesAreNotEqualIfNameIsNotEqual()
    {
        EntityType      character = new EntityType("CHARACTER");
        EntityType      artifact  = new EntityType("ARTIFACT");
        BinaryPredicate bp1       = new BinaryPredicate(character, "PICK_UP", artifact);
        BinaryPredicate bp2       = new BinaryPredicate(character, "PICK_UP2", artifact);

        Assert.False(bp1.Equals(bp2) || bp1.GetHashCode() == bp2.GetHashCode());
    }
Esempio n. 12
0
    public static WorldState roverWorldStateThirdLevel(Domain domain)
    {
        WorldState detailedState = roverWorldStateSecondLevel(domain);

        EntityType entityTypeRover   = new EntityType("ROVER");
        EntityType entityTypeBattery = new EntityType("BATTERY");
        EntityType entityTypeWheel   = new EntityType("WHEEL");

        Entity entityBatteryRover1 = new Entity(entityTypeBattery, "BATTERY_ROVER1");
        Entity entityBatteryRover2 = new Entity(entityTypeBattery, "BATTERY_ROVER2");

        Entity entityWheelsRover1 = new Entity(entityTypeWheel, "WHEELS_ROVER1");
        Entity entityWheelsRover2 = new Entity(entityTypeWheel, "WHEELS_ROVER2");

        detailedState.addEntity(entityBatteryRover1);
        detailedState.addEntity(entityBatteryRover2);

        detailedState.addEntity(entityWheelsRover1);
        detailedState.addEntity(entityWheelsRover2);

        // Rovers have their respective batteries
        BinaryPredicate predicateHasBattery = new BinaryPredicate(entityTypeRover, "HAS", entityTypeBattery);

        BinaryRelation relationRover1HasBattery1 = new BinaryRelation(detailedState.getEntity("ROVER1"), predicateHasBattery, entityBatteryRover1, RelationValue.TRUE);
        BinaryRelation relationRover2HasBattery2 = new BinaryRelation(detailedState.getEntity("ROVER2"), predicateHasBattery, entityBatteryRover2, RelationValue.TRUE);

        detailedState.addRelation(relationRover1HasBattery1);
        detailedState.addRelation(relationRover2HasBattery2);

        // the batteries are charged
        UnaryRelation relationBatteryRover1IsCharged = detailedState.Domain.generateRelationFromPredicateName("BATTERY_CHARGED", entityBatteryRover1, RelationValue.TRUE);
        UnaryRelation relationBatteryRover2IsCharged = detailedState.Domain.generateRelationFromPredicateName("BATTERY_CHARGED", entityBatteryRover2, RelationValue.TRUE);

        detailedState.addRelation(relationBatteryRover1IsCharged);
        detailedState.addRelation(relationBatteryRover2IsCharged);

        // Rovers have their respective wheels
        BinaryPredicate predicateHasWheels = new BinaryPredicate(entityTypeRover, "HAS", entityTypeWheel);

        BinaryRelation relationRover1HasWheels1 = new BinaryRelation(detailedState.getEntity("ROVER1"), predicateHasWheels, entityWheelsRover1, RelationValue.TRUE);
        BinaryRelation relationRover2HasWheels2 = new BinaryRelation(detailedState.getEntity("ROVER2"), predicateHasWheels, entityWheelsRover2, RelationValue.TRUE);

        detailedState.addRelation(relationRover1HasWheels1);
        detailedState.addRelation(relationRover2HasWheels2);

        // the wheels are inflated
        UnaryRelation relationWheelsRover1Inflated = detailedState.Domain.generateRelationFromPredicateName("WHEELS_INFLATED", entityWheelsRover1, RelationValue.TRUE);
        UnaryRelation relationWheelsRover2Inflated = detailedState.Domain.generateRelationFromPredicateName("WHEELS_INFLATED", entityWheelsRover2, RelationValue.TRUE);

        detailedState.addRelation(relationWheelsRover1Inflated);
        detailedState.addRelation(relationWheelsRover2Inflated);

        return(detailedState);
    }
        public override bool Equals(object obj)
        {
            if (obj is BinaryPredicate)
            {
                BinaryPredicate that = obj as BinaryPredicate;

                return(this.Letter == that.Letter);
            }

            throw new EngineException("BinaryPredicate compared to non-BinaryPredicate.");
        }
Esempio n. 14
0
    public void BinaryRelationDestinationMustBeOfCorrectPredicateType()
    {
        EntityType character = new EntityType("CHARACTER");
        Entity     john      = new Entity(character, "JOHN");

        EntityType location = new EntityType("LOCATION");
        Entity     school   = new Entity(location, "SCHOOL");

        BinaryPredicate isAt = new BinaryPredicate(character, "IS_AT", location);

        Assert.That(() => new BinaryRelation(john, isAt, john, RelationValue.TRUE), Throws.ArgumentException);
    }
Esempio n. 15
0
    public void BinaryPredicatesAreEqualIfAllAttributesAreEqual()
    {
        EntityType character = new EntityType("CHARACTER");
        EntityType artifact  = new EntityType("ARTIFACT");

        EntityType character2 = new EntityType("CHARACTER");
        EntityType artifact2  = new EntityType("ARTIFACT");

        BinaryPredicate bp1 = new BinaryPredicate(character, "PICK_UP", artifact);
        BinaryPredicate bp2 = new BinaryPredicate(character2, "PICK_UP", artifact2);

        Assert.True(bp1.Equals(bp2) && bp1.GetHashCode() == bp2.GetHashCode());
    }
Esempio n. 16
0
        public static bool MainCheck(int num, int count, int n, BinaryPredicate op)
        {
            int counter = 0;

            foreach (KeyValuePair <char, int> keyValue in PullDictionary(num))
            {
                if (op(keyValue.Value, count))
                {
                    ++counter;
                }
            }
            return(counter == n);
        }
Esempio n. 17
0
    public void BinaryPredicateDestinationCanOnlyBeOfExistingType()
    {
        Domain     domain    = new Domain();
        EntityType character = new EntityType("CHARACTER");

        domain.addEntityType(character);

        EntityType location = new EntityType("LOCATION");
        // domain.addEntityType(location);

        BinaryPredicate isAt = new BinaryPredicate(character, "IS_AT", location);

        Assert.That(() => domain.addPredicate(isAt), Throws.ArgumentException);
    }
Esempio n. 18
0
    public void CloneReturnsEqualBinaryRelation()
    {
        EntityType entityTypeRover = new EntityType("ROVER");
        Entity     entityRover     = new Entity(entityTypeRover, "ROVER");

        EntityType entityTypeWaypoint = new EntityType("WAYPOINT");
        Entity     entityWaypoint     = new Entity(entityTypeWaypoint, "WAYPOINT");

        BinaryPredicate predicateRoverisAtWaypoint      = new BinaryPredicate(entityTypeRover, "IS_AT", entityTypeWaypoint);
        BinaryRelation  relationRoverIsAtWaypoint       = new BinaryRelation(entityRover, predicateRoverisAtWaypoint, entityWaypoint, RelationValue.TRUE);
        BinaryRelation  relationClonedRoverIsAtWaypoint = relationRoverIsAtWaypoint.Clone() as BinaryRelation;

        Assert.AreEqual(relationRoverIsAtWaypoint, relationClonedRoverIsAtWaypoint);
    }
Esempio n. 19
0
        protected void VerifyOp <K>(BinaryPredicate <K> baseline, BinaryPredicate <K> op, bool nonzero = false,
                                    [CallerMemberName] string caller = null, [CallerFilePath] string file = null, [CallerLineNumber] int?line = null)
            where K : struct
        {
            var kind   = PrimalKinds.kind <K>();
            var lhs    = RandArray <K>();
            var rhs    = RandArray <K>(nonzero);
            var len    = length(lhs, rhs);
            var timing = stopwatch();

            for (var i = 0; i < len; i++)
            {
                Claim.eq(baseline(lhs[i], rhs[i]), op(lhs[i], rhs[i]), caller, file, line);
            }
        }
Esempio n. 20
0
    public void ActionsAreNotEqualIfNamesAreNotEqual()
    {
        EntityType sourceEntityType1 = new EntityType("CHARACTER");
        EntityType sourceEntityType2 = new EntityType("CHARACTER");

        EntityType destinationEntityType1 = new EntityType("ARTIFACT");
        EntityType destinationEntityType2 = new EntityType("ARTIFACT");

        Entity sourceEntity1 = new Entity(sourceEntityType1, "JOHN");
        Entity sourceEntity2 = new Entity(sourceEntityType2, "JOHN");

        Entity destinationEntity1 = new Entity(destinationEntityType1, "APPLE");
        Entity destinationEntity2 = new Entity(destinationEntityType2, "APPLE");

        BinaryPredicate bp1 = new BinaryPredicate(sourceEntityType1, "PICK_UP", destinationEntityType1);
        BinaryPredicate bp2 = new BinaryPredicate(sourceEntityType2, "PICK_UP", destinationEntityType2);

        BinaryRelation br1 = new BinaryRelation(sourceEntity1, bp1, destinationEntity1, RelationValue.TRUE);
        BinaryRelation br2 = new BinaryRelation(sourceEntity2, bp2, destinationEntity2, RelationValue.TRUE);

        HashSet <ActionParameter> parametersAction1 = new HashSet <ActionParameter>();

        parametersAction1.Add(new ActionParameter(sourceEntity1, ActionParameterRole.ACTIVE));
        parametersAction1.Add(new ActionParameter(destinationEntity1, ActionParameterRole.PASSIVE));
        HashSet <IRelation> preconditionsAction1 = new HashSet <IRelation>();

        preconditionsAction1.Add(br1);
        HashSet <IRelation> postconditionsAction1 = new HashSet <IRelation>();

        postconditionsAction1.Add(br1);

        Action a1 = new Action(preconditionsAction1, "PICK_UP", parametersAction1, postconditionsAction1);

        HashSet <ActionParameter> parametersAction2 = new HashSet <ActionParameter>();

        parametersAction2.Add(new ActionParameter(sourceEntity2, ActionParameterRole.ACTIVE));
        parametersAction2.Add(new ActionParameter(destinationEntity2, ActionParameterRole.PASSIVE));
        HashSet <IRelation> preconditionsAction2 = new HashSet <IRelation>();

        preconditionsAction2.Add(br2);
        HashSet <IRelation> postconditionsAction2 = new HashSet <IRelation>();

        postconditionsAction2.Add(br2);

        Action a2 = new Action(preconditionsAction2, "PICK_UP2", parametersAction2, postconditionsAction2);

        Assert.False(a1.Equals(a2) || a1.GetHashCode() == a2.GetHashCode());
    }
Esempio n. 21
0
    public void CloneReturnsEqualAction()
    {
        EntityType rover    = new EntityType("ROVER");
        EntityType wayPoint = new EntityType("WAYPOINT");

        Entity curiosity    = new Entity(rover, "ROVER");
        Entity fromWayPoint = new Entity(wayPoint, "WAYPOINT1");
        Entity toWayPoint   = new Entity(wayPoint, "WAYPOINT2");

        BinaryPredicate isConnectedTo = new BinaryPredicate(wayPoint, "IS_CONNECTED_TO", wayPoint);
        BinaryPredicate at            = new BinaryPredicate(rover, "AT", wayPoint);
        BinaryPredicate beenAt        = new BinaryPredicate(rover, "BEEN_AT", wayPoint);

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

        moveActionParameters.Add(new ActionParameter(curiosity, ActionParameterRole.ACTIVE));
        moveActionParameters.Add(new ActionParameter(fromWayPoint, ActionParameterRole.PASSIVE));
        moveActionParameters.Add(new ActionParameter(toWayPoint, ActionParameterRole.PASSIVE));

        // Preconditions
        HashSet <IRelation> moveActionPreconditions = new HashSet <IRelation>();
        BinaryRelation      roverAtfromWP           = new BinaryRelation(curiosity, at, fromWayPoint, RelationValue.TRUE);

        moveActionPreconditions.Add(roverAtfromWP);
        BinaryRelation isConnectedFromWP1ToWP2 = new BinaryRelation(fromWayPoint, isConnectedTo, toWayPoint, RelationValue.TRUE);

        moveActionPreconditions.Add(isConnectedFromWP1ToWP2);

        // Postconditions
        HashSet <IRelation> moveActionPostconditions = new HashSet <IRelation>();
        BinaryRelation      notRoverAtFromWP         = new BinaryRelation(curiosity, at, fromWayPoint, RelationValue.FALSE);

        moveActionPostconditions.Add(notRoverAtFromWP);
        BinaryRelation roverAtToWP = new BinaryRelation(curiosity, at, toWayPoint, RelationValue.TRUE);

        moveActionPostconditions.Add(roverAtToWP);
        BinaryRelation roverBeenAtToWP = new BinaryRelation(curiosity, beenAt, toWayPoint, RelationValue.TRUE);

        moveActionPostconditions.Add(roverBeenAtToWP);

        Action moveAction       = new Action(moveActionPreconditions, "MOVE", moveActionParameters, moveActionPostconditions);
        Action clonedMoveAction = moveAction.Clone();

        Assert.AreEqual(moveAction, clonedMoveAction);
    }
Esempio n. 22
0
    public void GetPredicateReturnsCorrectEntityType()
    {
        Domain domain = new Domain();

        EntityType character = new EntityType("CHARACTER");
        EntityType artifact  = new EntityType("ARTIFACT");

        domain.addEntityType(character);
        domain.addEntityType(artifact);

        BinaryPredicate binaryPredicate = new BinaryPredicate(character, "PICK_UP", artifact);

        domain.addPredicate(binaryPredicate);

        object getBinaryPredicate = domain.getPredicate("PICK_UP");

        Assert.AreEqual(getBinaryPredicate, binaryPredicate);
    }
Esempio n. 23
0
    public void BinaryPredicateMustBeUnique()
    {
        Domain     domain    = new Domain();
        EntityType character = new EntityType("CHARACTER");

        domain.addEntityType(character);

        EntityType location = new EntityType("LOCATION");

        domain.addEntityType(location);

        BinaryPredicate isAt = new BinaryPredicate(character, "IS_AT", location);

        domain.addPredicate(isAt);

        BinaryPredicate isAt2 = new BinaryPredicate(character, "IS_AT", location);

        Assert.That(() => domain.addPredicate(isAt2), Throws.ArgumentException);
    }
Esempio n. 24
0
    public static Domain roverWorldDomainSecondLevel()
    {
        Domain domain = roverWorldDomainFirstLevel();

        EntityType entityTypeWayPoint = domain.getEntityType("WAYPOINT");

        BinaryPredicate predicateObstacleBetween = new BinaryPredicate(entityTypeWayPoint, "OBSTACLE_BETWEEN", entityTypeWayPoint);

        domain.addPredicate(predicateObstacleBetween);

        Entity fromWayPoint = new Entity(entityTypeWayPoint, "WAYPOINT1");
        Entity toWayPoint   = new Entity(entityTypeWayPoint, "WAYPOINT2");

        BinaryRelation relationNotObstacleBetween = new BinaryRelation(fromWayPoint, predicateObstacleBetween, toWayPoint, RelationValue.FALSE);

        Action moveAction = domain.getAction("MOVE");

        moveAction.PreConditions.Add(relationNotObstacleBetween);

        return(domain);
    }
Esempio n. 25
0
    public void GetActionReturnsCorrectAction()
    {
        Domain domain = new Domain();

        EntityType sourceEntityType1      = new EntityType("CHARACTER");
        EntityType destinationEntityType1 = new EntityType("ARTIFACT");

        domain.addEntityType(sourceEntityType1);
        domain.addEntityType(destinationEntityType1);

        Entity sourceEntity1      = new Entity(sourceEntityType1, "JOHN");
        Entity destinationEntity1 = new Entity(destinationEntityType1, "APPLE");

        BinaryPredicate bp1 = new BinaryPredicate(sourceEntityType1, "PICK_UP", destinationEntityType1);

        domain.addPredicate(bp1);

        BinaryRelation br1 = new BinaryRelation(sourceEntity1, bp1, destinationEntity1, RelationValue.TRUE);

        HashSet <ActionParameter> parametersAction1 = new HashSet <ActionParameter>();

        parametersAction1.Add(new ActionParameter(sourceEntity1, ActionParameterRole.ACTIVE));
        parametersAction1.Add(new ActionParameter(destinationEntity1, ActionParameterRole.PASSIVE));

        HashSet <IRelation> preconditionsAction1 = new HashSet <IRelation>();

        preconditionsAction1.Add(br1);
        HashSet <IRelation> postconditionsAction1 = new HashSet <IRelation>();

        postconditionsAction1.Add(br1);

        Action action = new Action(preconditionsAction1, "PICK_UP", parametersAction1, postconditionsAction1);

        domain.addAction(action);

        object getAction = domain.getAction("PICK_UP");

        Assert.AreEqual(action, getAction);
    }
Esempio n. 26
0
    public void BinaryRelationsAreNotEqualIfDestinationsAreNotEqual()
    {
        EntityType sourceEntityType1 = new EntityType("CHARACTER");
        EntityType sourceEntityType2 = new EntityType("CHARACTER");

        EntityType destinationEntityType1 = new EntityType("ARTIFACT");
        EntityType destinationEntityType2 = new EntityType("ARTIFACT");

        Entity sourceEntity1 = new Entity(sourceEntityType1, "JOHN");
        Entity sourceEntity2 = new Entity(sourceEntityType2, "JOHN");

        Entity destinationEntity1 = new Entity(destinationEntityType1, "APPLE");
        Entity destinationEntity2 = new Entity(destinationEntityType2, "APPLE2");

        BinaryPredicate bp1 = new BinaryPredicate(sourceEntityType1, "PICK_UP", destinationEntityType1);
        BinaryPredicate bp2 = new BinaryPredicate(sourceEntityType2, "PICK_UP", destinationEntityType2);

        BinaryRelation br1 = new BinaryRelation(sourceEntity1, bp1, destinationEntity1, RelationValue.TRUE);
        BinaryRelation br2 = new BinaryRelation(sourceEntity2, bp2, destinationEntity2, RelationValue.TRUE);

        Assert.False(br1.Equals(br2) || br1.GetHashCode() == br2.GetHashCode());
    }
Esempio n. 27
0
    public static Domain roverWorldDomainThirdLevel()
    {
        Domain domain = roverWorldDomainSecondLevel();

        EntityType entityTypeBattery = new EntityType("BATTERY");

        domain.addEntityType(entityTypeBattery);
        EntityType entityTypeWheel = new EntityType("WHEEL");

        domain.addEntityType(entityTypeWheel);
        UnaryPredicate predicateBatteryCharged = new UnaryPredicate(entityTypeBattery, "BATTERY_CHARGED");

        domain.addPredicate(predicateBatteryCharged);
        UnaryPredicate predicateWheelsInflated = new UnaryPredicate(entityTypeWheel, "WHEELS_INFLATED");

        domain.addPredicate(predicateWheelsInflated);

        EntityType entityTypeRover = domain.getEntityType("ROVER");

        BinaryPredicate predicateHasBattery = new BinaryPredicate(entityTypeRover, "HAS", entityTypeBattery);

        domain.addPredicate(predicateHasBattery);
        BinaryPredicate predicateHasWheels = new BinaryPredicate(entityTypeRover, "HAS", entityTypeWheel);

        domain.addPredicate(predicateHasWheels);

        HashSet <ActionParameter> actionChargeParameters = new HashSet <ActionParameter>();
        Entity entityRover   = new Entity(entityTypeRover, "ROVER");
        Entity entityBattery = new Entity(entityTypeBattery, "BATTERY");

        actionChargeParameters.Add(new ActionParameter(entityRover, ActionParameterRole.ACTIVE));
        actionChargeParameters.Add(new ActionParameter(entityBattery, ActionParameterRole.PASSIVE));

        HashSet <IRelation> actionChargePreconditions = new HashSet <IRelation>();
        BinaryRelation      relationRoverHasBattery   = new BinaryRelation(entityRover, predicateHasBattery, entityBattery, RelationValue.TRUE);

        actionChargePreconditions.Add(relationRoverHasBattery);
        UnaryRelation relationBatteryDischarged = new UnaryRelation(entityBattery, predicateBatteryCharged, RelationValue.FALSE);

        actionChargePreconditions.Add(relationBatteryDischarged);

        HashSet <IRelation> actionChargePostconditions = new HashSet <IRelation>();
        UnaryRelation       relationBatteryCharged     = new UnaryRelation(entityBattery, predicateBatteryCharged, RelationValue.TRUE);

        actionChargePostconditions.Add(relationBatteryCharged);

        Action actionChargeBattery = new Action(actionChargePreconditions, "CHARGE_BATTERY", actionChargeParameters, actionChargePostconditions);

        domain.addAction(actionChargeBattery);

        HashSet <IRelation> actionDischargePreconditions = new HashSet <IRelation>();

        actionDischargePreconditions.Add(relationRoverHasBattery);
        actionDischargePreconditions.Add(relationBatteryCharged);

        HashSet <IRelation> actionDischargePostconditions = new HashSet <IRelation>();

        actionDischargePostconditions.Add(relationBatteryDischarged);

        Action actionDischargeBattery = new Action(actionDischargePreconditions, "DISCHARGE_BATTERY", actionChargeParameters, actionDischargePostconditions);

        domain.addAction(actionDischargeBattery);

        HashSet <ActionParameter> actionInflateParameters = new HashSet <ActionParameter>();
        Entity entityWheels = new Entity(entityTypeWheel, "WHEELS");

        actionInflateParameters.Add(new ActionParameter(entityRover, ActionParameterRole.ACTIVE));
        actionInflateParameters.Add(new ActionParameter(entityWheels, ActionParameterRole.PASSIVE));

        HashSet <IRelation> actionInflatePreconditions = new HashSet <IRelation>();
        BinaryRelation      relationRoverHasWheels     = new BinaryRelation(entityRover, predicateHasWheels, entityWheels, RelationValue.TRUE);

        actionInflatePreconditions.Add(relationRoverHasWheels);
        UnaryRelation relationWheelsDeflated = new UnaryRelation(entityWheels, predicateWheelsInflated, RelationValue.FALSE);

        actionInflatePreconditions.Add(relationWheelsDeflated);

        HashSet <IRelation> actionInflatePostconditions = new HashSet <IRelation>();
        UnaryRelation       relationWheelsInflated      = new UnaryRelation(entityWheels, predicateWheelsInflated, RelationValue.TRUE);

        actionInflatePostconditions.Add(relationWheelsInflated);

        Action actionInflate = new Action(actionInflatePreconditions, "INFLATE_WHEELS", actionInflateParameters, actionInflatePostconditions);

        domain.addAction(actionInflate);

        HashSet <IRelation> actionDeflatePreconditions = new HashSet <IRelation>();

        actionDeflatePreconditions.Add(relationRoverHasWheels);
        actionDeflatePreconditions.Add(relationWheelsInflated);

        HashSet <IRelation> actionDeflatePostconditions = new HashSet <IRelation>();

        actionDeflatePostconditions.Add(relationWheelsDeflated);

        Action actionDeflate = new Action(actionDeflatePreconditions, "DEFLATE_WHEELS", actionInflateParameters, actionDeflatePostconditions);

        domain.addAction(actionDeflate);

        Action          moveAction             = domain.getAction("MOVE");
        ActionParameter actionParameterBattery = new ActionParameter(entityBattery, ActionParameterRole.PASSIVE);
        ActionParameter actionParameterWheels  = new ActionParameter(entityWheels, ActionParameterRole.PASSIVE);

        moveAction.addParameter(actionParameterBattery);
        moveAction.addParameter(actionParameterWheels);
        moveAction.addPrecondition(relationRoverHasBattery);
        moveAction.addPrecondition(relationRoverHasWheels);
        moveAction.addPrecondition(relationBatteryCharged);
        moveAction.addPrecondition(relationWheelsInflated);

        Action takeSampleAction = domain.getAction("TAKE_SAMPLE");

        takeSampleAction.addParameter(actionParameterBattery);
        takeSampleAction.addPrecondition(relationRoverHasBattery);
        takeSampleAction.addPrecondition(relationBatteryCharged);

        Action dropSampleAction = domain.getAction("DROP_SAMPLE");

        dropSampleAction.addParameter(actionParameterBattery);
        dropSampleAction.addPrecondition(relationRoverHasBattery);
        dropSampleAction.addPrecondition(relationBatteryCharged);

        Action takeImageAction = domain.getAction("TAKE_IMAGE");

        takeImageAction.addParameter(actionParameterBattery);
        takeImageAction.addPrecondition(relationRoverHasBattery);
        takeImageAction.addPrecondition(relationBatteryCharged);

        return(domain);
    }
 // ReSharper disable PossibleMultipleEnumeration
 public static IEnumerable <T> AssertContains <T>(this IEnumerable <T> values, T value, BinaryPredicate <T> predicate = null)
 {
     predicate = predicate ?? ((x, y) => x.Equals(y));
     Assert.Contains(values, x => predicate(x, value));
     return(values);
 }
Esempio n. 29
0
    public static Domain roverWorldDomainFirstLevel()
    {
        Domain domain = new Domain();

        EntityType rover = new EntityType("ROVER");

        domain.addEntityType(rover);

        EntityType wayPoint = new EntityType("WAYPOINT");

        domain.addEntityType(wayPoint);

        EntityType sample = new EntityType("SAMPLE");

        domain.addEntityType(sample);

        EntityType objective = new EntityType("OBJECTIVE");

        domain.addEntityType(objective);

        //(can-move ?from-waypoint ?to-waypoint)
        BinaryPredicate isConnectedTo = new BinaryPredicate(wayPoint, "IS_CONNECTED_TO", wayPoint, "is connected to");

        domain.addPredicate(isConnectedTo);
        //(is-visible ?objective ?waypoint)
        BinaryPredicate isVisible = new BinaryPredicate(objective, "IS_VISIBLE", wayPoint, "is visible");

        domain.addPredicate(isVisible);
        //(is-in ?sample ?waypoint)
        BinaryPredicate isIn = new BinaryPredicate(sample, "IS_IN", wayPoint, "is in");

        domain.addPredicate(isIn);
        //(been-at ?rover ?waypoint)
        BinaryPredicate beenAt = new BinaryPredicate(rover, "BEEN_AT", wayPoint, "has been at");

        domain.addPredicate(beenAt);
        //(carry ?rover ?sample)
        BinaryPredicate carry = new BinaryPredicate(rover, "CARRY", sample, "is carrying");

        domain.addPredicate(carry);
        //(at ?rover ?waypoint)
        BinaryPredicate at = new BinaryPredicate(rover, "AT", wayPoint, "is at");

        domain.addPredicate(at);
        //(is-dropping-dock ?waypoint)
        UnaryPredicate isDroppingDock = new UnaryPredicate(wayPoint, "IS_DROPPING_DOCK", "is dropping the dock");

        domain.addPredicate(isDroppingDock);
        //(taken-image ?objective)
        UnaryPredicate takenImage = new UnaryPredicate(objective, "TAKEN_IMAGE", "is taking an image");

        domain.addPredicate(takenImage);
        //(stored-sample ?sample)
        UnaryPredicate storedSample = new UnaryPredicate(sample, "STORED_SAMPLE", "has stored the sample");

        domain.addPredicate(storedSample);
        //(empty ?rover)
        UnaryPredicate isEmpty = new UnaryPredicate(rover, "IS_EMPTY", "is empty");

        domain.addPredicate(isEmpty);

        Entity curiosity = new Entity(rover, "ROVER");

        //              IDLE ACTION
        Action actionIdle = new Action(new HashSet <IRelation>(), "IDLE",
                                       new HashSet <ActionParameter>()
        {
            new ActionParameter(curiosity, ActionParameterRole.ACTIVE)
        }, new HashSet <IRelation>());

        domain.addAction(actionIdle);

        //              MOVE ACTION
        // Parameters
        Entity fromWayPoint = new Entity(wayPoint, "WAYPOINT1");
        Entity toWayPoint   = new Entity(wayPoint, "WAYPOINT2");

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

        moveActionParameters.Add(new ActionParameter(curiosity, ActionParameterRole.ACTIVE));
        moveActionParameters.Add(new ActionParameter(fromWayPoint, ActionParameterRole.PASSIVE));
        moveActionParameters.Add(new ActionParameter(toWayPoint, ActionParameterRole.PASSIVE));

        // Preconditions
        HashSet <IRelation> moveActionPreconditions = new HashSet <IRelation>();
        BinaryRelation      roverAtfromWP           = new BinaryRelation(curiosity, at, fromWayPoint, RelationValue.TRUE);

        moveActionPreconditions.Add(roverAtfromWP);
        BinaryRelation isConnectedFromWP1ToWP2 = new BinaryRelation(fromWayPoint, isConnectedTo, toWayPoint, RelationValue.TRUE);

        moveActionPreconditions.Add(isConnectedFromWP1ToWP2);

        // Postconditions
        HashSet <IRelation> moveActionPostconditions = new HashSet <IRelation>();
        BinaryRelation      notRoverAtFromWP         = new BinaryRelation(curiosity, at, fromWayPoint, RelationValue.FALSE);

        moveActionPostconditions.Add(notRoverAtFromWP);
        BinaryRelation roverAtToWP = new BinaryRelation(curiosity, at, toWayPoint, RelationValue.TRUE);

        moveActionPostconditions.Add(roverAtToWP);
        BinaryRelation roverBeenAtToWP = new BinaryRelation(curiosity, beenAt, toWayPoint, RelationValue.TRUE);

        moveActionPostconditions.Add(roverBeenAtToWP);

        Action moveAction = new Action(moveActionPreconditions, "MOVE", moveActionParameters, moveActionPostconditions);

        domain.addAction(moveAction);

        //              TAKE SAMPLE ACTION
        // Parameters
        Entity ESample   = new Entity(sample, "SAMPLE");
        Entity EWayPoint = new Entity(wayPoint, "WAYPOINT");

        HashSet <ActionParameter> takeSampleActionParameters = new HashSet <ActionParameter>();

        takeSampleActionParameters.Add(new ActionParameter(curiosity, ActionParameterRole.ACTIVE));
        takeSampleActionParameters.Add(new ActionParameter(ESample, ActionParameterRole.PASSIVE));
        takeSampleActionParameters.Add(new ActionParameter(EWayPoint, ActionParameterRole.PASSIVE));

        // Preconditions
        HashSet <IRelation> takeSampleActPreconditions = new HashSet <IRelation>();
        BinaryRelation      sampleIsInWayPoint         = new BinaryRelation(ESample, isIn, EWayPoint, RelationValue.TRUE);

        takeSampleActPreconditions.Add(sampleIsInWayPoint);
        BinaryRelation roverIsAtWayPoint = new BinaryRelation(curiosity, at, EWayPoint, RelationValue.TRUE);

        takeSampleActPreconditions.Add(roverIsAtWayPoint);
        UnaryRelation roverIsEmpty = new UnaryRelation(curiosity, isEmpty, RelationValue.TRUE);

        takeSampleActPreconditions.Add(roverIsEmpty);

        // Postconditions
        HashSet <IRelation> takeSampleActPostconditions = new HashSet <IRelation>();
        BinaryRelation      sampleIsNotInWayPoint       = new BinaryRelation(ESample, isIn, EWayPoint, RelationValue.FALSE);

        takeSampleActPostconditions.Add(sampleIsNotInWayPoint);
        UnaryRelation roverIsNotEmpty = new UnaryRelation(curiosity, isEmpty, RelationValue.FALSE);

        takeSampleActPostconditions.Add(roverIsNotEmpty);
        BinaryRelation roverCarriesSample = new BinaryRelation(curiosity, carry, ESample, RelationValue.TRUE);

        takeSampleActPostconditions.Add(roverCarriesSample);

        Action takeSampleAction = new Action(takeSampleActPreconditions, "TAKE_SAMPLE", takeSampleActionParameters, takeSampleActPostconditions);

        domain.addAction(takeSampleAction);

        //              DROP SAMPLE ACTION
        // Parameters
        HashSet <ActionParameter> dropSampleActionParameters = new HashSet <ActionParameter>();

        dropSampleActionParameters.Add(new ActionParameter(curiosity, ActionParameterRole.ACTIVE));
        dropSampleActionParameters.Add(new ActionParameter(ESample, ActionParameterRole.PASSIVE));
        dropSampleActionParameters.Add(new ActionParameter(EWayPoint, ActionParameterRole.PASSIVE));

        // Preconditions
        HashSet <IRelation> dropSampleActPreconditions = new HashSet <IRelation>();
        UnaryRelation       wayPointIsDroppingDock     = new UnaryRelation(EWayPoint, isDroppingDock, RelationValue.TRUE);

        dropSampleActPreconditions.Add(wayPointIsDroppingDock);
        dropSampleActPreconditions.Add(roverIsAtWayPoint);
        dropSampleActPreconditions.Add(roverCarriesSample);

        // Postconditions
        HashSet <IRelation> dropSampActPostconditions = new HashSet <IRelation>();

        dropSampActPostconditions.Add(sampleIsInWayPoint);
        dropSampActPostconditions.Add(roverIsEmpty);
        BinaryRelation notRoverCarriesSample = new BinaryRelation(curiosity, carry, ESample, RelationValue.FALSE);

        dropSampActPostconditions.Add(notRoverCarriesSample);

        Action dropSampleAction = new Action(dropSampleActPreconditions, "DROP_SAMPLE", dropSampleActionParameters, dropSampActPostconditions);

        domain.addAction(dropSampleAction);

        //              TAKE IMAGE ACTION
        // Parameters
        Entity EObjective = new Entity(objective, "OBJECTIVE");

        HashSet <ActionParameter> takeImageActionParameters = new HashSet <ActionParameter>();

        takeImageActionParameters.Add(new ActionParameter(curiosity, ActionParameterRole.ACTIVE));
        takeImageActionParameters.Add(new ActionParameter(EObjective, ActionParameterRole.PASSIVE));
        takeImageActionParameters.Add(new ActionParameter(EWayPoint, ActionParameterRole.PASSIVE));

        // Preconditions
        HashSet <IRelation> takeImageActionPreconditions = new HashSet <IRelation>();

        takeImageActionPreconditions.Add(roverIsAtWayPoint);
        BinaryRelation objectiveIsVisibleFromWayPoint = new BinaryRelation(EObjective, isVisible, EWayPoint, RelationValue.TRUE);

        takeImageActionPreconditions.Add(objectiveIsVisibleFromWayPoint);

        // Postconditions
        HashSet <IRelation> takeImageActionPostconditions = new HashSet <IRelation>();
        UnaryRelation       roverHasTakenImageOfObjective = new UnaryRelation(EObjective, takenImage, RelationValue.TRUE);

        takeImageActionPostconditions.Add(roverHasTakenImageOfObjective);

        Action takeImageAction = new Action(takeImageActionPreconditions, "TAKE_IMAGE", takeImageActionParameters, takeImageActionPostconditions);

        domain.addAction(takeImageAction);

        return(domain);
    }
        // ReSharper restore PossibleMultipleEnumeration

        public static T AssertContainedBy <T>(this T value, IEnumerable <T> values, BinaryPredicate <T> predicate = null)
        {
            AssertContains(values, value, predicate);
            return(value);
        }